Skip to content

Conversation

@kashishhora
Copy link
Member

@kashishhora kashishhora commented Nov 24, 2025

Summary

Added

  • New exceptions.py module with capture_exception() for structured error capture
  • Stack trace parsing via parse_python_traceback() that walks the traceback chain
  • is_in_app() detection to distinguish user code from library code (site-packages, stdlib)
  • Exception chain unwrapping for __cause__ (explicit raise from) and __context__ (implicit)
  • Context line extraction using linecache for user code frames
  • Context variables (store_captured_error/get_captured_error) to preserve exceptions before MCP SDK converts them
  • ErrorData, StackFrame, and ChainedErrorData TypedDicts in types.py
  • Comprehensive test suite with 30 tests

Modified

  • official/monkey_patch.py: Uses capture_exception() for full stack traces, preserves exceptions before MCP SDK conversion
  • community/monkey_patch.py: Same error capture improvements

Test Plan

  • All 30 exception tests pass (uv run python -m pytest tests/test_exceptions.py)
  • Manually test with a FastMCP server that throws exceptions
  • Verify error events in MCPcat dashboard show full stack traces and cause chains

@kashishhora kashishhora requested a review from naji247 November 24, 2025 22:57
if stdlib_pattern in abs_path.replace("\\", "/"):
return False

return True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit odd to me that the default case here is true and not the otherway around. This function works by saying "is it any of these known formats for 3rd party packages?" whereas I would have guessed the opposite logic of "this matches our inapp expectation".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked about it offline, this is the same behavior as our TypeScript SDK

@kashishhora kashishhora merged commit de6fb6a into main Dec 2, 2025
61 of 62 checks passed
@kashishhora kashishhora deleted the feat/exception-chain-capturing branch December 2, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants