Skip to content

fix(mcp): Set error.type for tool results with isError - #8041

Closed
4ktLuffy wants to merge 1 commit into
getsentry:masterfrom
4ktLuffy:fix/mcp-tool-iserror
Closed

4ktLuffy wants to merge 1 commit into
getsentry:masterfrom
4ktLuffy:fix/mcp-tool-iserror

Conversation

@4ktLuffy

Copy link
Copy Markdown

Description

When an MCP tool call returns a result with isError=true, the span currently looks like a success, so failed tool calls can't be counted or alerted on. This sets error.type to "tool_error" on the span in that case, for both the mcp 1.x handler wrapper and the mcp 2.x tool-call middleware (including the 2.x MCPServer, which turns a raised tool exception into an isError result).

This follows the OTel MCP conventions, which say error.type SHOULD be "tool_error" when a CallToolResult has isError set to true:
https://github.com/open-telemetry/semantic-conventions-genai/blob/4a39b6ef1363fab57bc40e18c82abb32cc89ebcd/docs/gen-ai/mcp.md#L187-L192
It also matches what the JS SDK does.

The span status is left unchanged, as discussed in the issue (the JSON-RPC call itself succeeded, like the GraphQL 200 case). No custom attribute is added.

Tests cover isError true/false, a raising MCPServer tool, and a raised exception in a lowlevel handler (no error.type, existing behaviour), in static and streaming mode, on mcp 2.x and 1.x.

Issues

@alexander-alderman-webb

Copy link
Copy Markdown
Collaborator

Closing as this needs further discussion per the issue.

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.

MCP integration records tool calls that return isError as successful

2 participants