-
Notifications
You must be signed in to change notification settings - Fork 583
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 to suppress specific exception types raised by MCP tool handlers, the filtering doesn't work because of the order of exception wrapping:
- Tool handler raises a custom exception (e.g.
ExpectedToolError) - FastMCP's
tool_manager.call_tool()catches it and wraps it inToolError:raise ToolError(...) from e ToolErrorpropagates up through FastMCP's_call_tool_mcp- The
MCPIntegration's_async_handler_wrappercatchesToolErrorand callssentry_sdk.capture_exception(e)(link) _is_ignored_errorchecksissubclass(ToolError, ExpectedToolError)→ False → event is sent to Sentry
The ignore_errors configuration never sees the original exception type because FastMCP has already wrapped it.
Expected Behavior
Exceptions 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.
Reproduction
import sentry_sdk
from sentry_sdk.integrations.mcp import MCPIntegration
from fastmcp import FastMCP
class ExpectedToolError(Exception):
"""Should not be reported to Sentry."""
pass
sentry_sdk.init(
dsn="...",
ignore_errors=[ExpectedToolError],
)
mcp = FastMCP("test")
@mcp.tool()
def my_tool() -> str:
raise ExpectedToolError("This is expected and should not go to Sentry")When my_tool is called, the ExpectedToolError ends up in Sentry because the MCPIntegration captures the wrapping ToolError.
Workaround
Disable the MCPIntegration if you handle MCP error reporting yourself:
sentry_sdk.init(
dsn="...",
disabled_integrations=[MCPIntegration()],
ignore_errors=[ExpectedToolError],
)Environment
- sentry-sdk: 2.51.0
- fastmcp: 2.14.4
- mcp: 1.26.0
- Python: 3.13
Metadata
Metadata
Assignees
Labels
Projects
Status