Title: MCPIntegration bypasses ignore_errors when FastMCP wraps exceptions in ToolError · Issue #5473 · getsentry/sentry-python · GitHub
Open Graph Title: MCPIntegration bypasses ignore_errors when FastMCP wraps exceptions in ToolError · Issue #5473 · getsentry/sentry-python
X Title: MCPIntegration bypasses ignore_errors when FastMCP wraps exceptions in ToolError · Issue #5473 · getsentry/sentry-python
Description: Problem The MCPIntegration (auto-enabled since sentry-sdk 2.45) captures exceptions that should be filtered by ignore_errors because it sees the FastMCP-wrapped ToolError instead of the original exception type. When using ignore_errors t...
Open Graph Description: Problem The MCPIntegration (auto-enabled since sentry-sdk 2.45) captures exceptions that should be filtered by ignore_errors because it sees the FastMCP-wrapped ToolError instead of the original ex...
X Description: Problem The MCPIntegration (auto-enabled since sentry-sdk 2.45) captures exceptions that should be filtered by ignore_errors because it sees the FastMCP-wrapped ToolError instead of the original ex...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/5473
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MCPIntegration bypasses ignore_errors when FastMCP wraps exceptions in ToolError","articleBody":"## Problem\n\nThe `MCPIntegration` (auto-enabled since sentry-sdk 2.45) captures exceptions that should be filtered by `ignore_errors` because it sees the FastMCP-wrapped `ToolError` instead of the original exception type.\n\nWhen using `ignore_errors` to suppress specific exception types raised by MCP tool handlers, the filtering doesn't work because of the order of exception wrapping:\n\n1. Tool handler raises a custom exception (e.g. `ExpectedToolError`)\n2. FastMCP's `tool_manager.call_tool()` catches it and wraps it in `ToolError`: `raise ToolError(...) from e`\n3. `ToolError` propagates up through FastMCP's `_call_tool_mcp`\n4. The `MCPIntegration`'s `_async_handler_wrapper` catches `ToolError` and calls `sentry_sdk.capture_exception(e)` ([link](https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/mcp.py#L429))\n5. `_is_ignored_error` checks `issubclass(ToolError, ExpectedToolError)` → **False** → event is sent to Sentry\n\nThe `ignore_errors` configuration never sees the original exception type because FastMCP has already wrapped it.\n\n## Expected Behavior\n\nExceptions listed in `ignore_errors` (or their subclasses) should not be sent to Sentry, even when FastMCP wraps them in `ToolError`. The integration should either walk the exception chain (`__cause__`) or skip capturing exceptions that are already handled by the framework.\n\n## Reproduction\n\n```python\nimport sentry_sdk\nfrom sentry_sdk.integrations.mcp import MCPIntegration\nfrom fastmcp import FastMCP\n\nclass ExpectedToolError(Exception):\n \"\"\"Should not be reported to Sentry.\"\"\"\n pass\n\nsentry_sdk.init(\n dsn=\"...\",\n ignore_errors=[ExpectedToolError],\n)\n\nmcp = FastMCP(\"test\")\n\n@mcp.tool()\ndef my_tool() -> str:\n raise ExpectedToolError(\"This is expected and should not go to Sentry\")\n```\n\nWhen `my_tool` is called, the `ExpectedToolError` ends up in Sentry because the MCPIntegration captures the wrapping `ToolError`.\n\n## Workaround\n\nDisable the `MCPIntegration` if you handle MCP error reporting yourself:\n\n```python\nsentry_sdk.init(\n dsn=\"...\",\n disabled_integrations=[MCPIntegration()],\n ignore_errors=[ExpectedToolError],\n)\n```\n\n## Environment\n\n- sentry-sdk: 2.51.0\n- fastmcp: 2.14.4\n- mcp: 1.26.0\n- Python: 3.13","author":{"url":"https://github.com/flostadler","@type":"Person","name":"flostadler"},"datePublished":"2026-02-17T13:32:55Z","url":"https://github.com/getsentry/sentry-python/issues/5473"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:34cf3006-3a1b-66d3-65ee-057989232f27 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CD24:928E2:498ED6:6406C7:6B00CD57 |
| html-safe-nonce | 9be53ab3bbf33eb26c7c27c137b07c93171decd9b96097af9e404e585a554b72 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDI0OjkyOEUyOjQ5OEVENjo2NDA2Qzc6NkIwMENENTciLCJ2aXNpdG9yX2lkIjoiNjc1ODQ0NzExNzI4NDQ2MTkxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8e84bc24f986b4182135e253ea3f11e37865c6fc1fd6a2494d85602b8eebdbd4 |
| hovercard-subject-tag | issue:3952796607 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/5473/issue_layout |
| twitter:image | https://opengraph.githubassets.com/48cc80573cc9fc5f8a2b84dc377746e15dadbbe6cc2121c26ea6615e6a7c6a1a/getsentry/sentry-python/issues/5473 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/48cc80573cc9fc5f8a2b84dc377746e15dadbbe6cc2121c26ea6615e6a7c6a1a/getsentry/sentry-python/issues/5473 |
| og:image:alt | Problem The MCPIntegration (auto-enabled since sentry-sdk 2.45) captures exceptions that should be filtered by ignore_errors because it sees the FastMCP-wrapped ToolError instead of the original ex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | flostadler |
| hostname | github.com |
| expected-hostname | github.com |
| None | 85bbdfe2b6ba16e234513bc6ceff5d848ef8449820c900692a2b4e67061931e5 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 137814779 |
| octolytics-dimension-repository_nwo | getsentry/sentry-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 137814779 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4943239a6d2c591325dad6e5c313e1cafda877f6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width