Repository navigation
Conversation
|
This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3810. If a maintainer assigns you to #3810, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
Fixes #3810
Records tool error results on the client OpenTelemetry span when
CallToolResult.isErrorisTrue.Motivation and Context
In MCP, application-level tool errors return a successful JSON-RPC response containing
isError=Truein the result payload rather than a JSON-RPCErrorDataprotocol error. Previously,send_raw_requestonly checked ifoutcomewas anErrorDatainstance to record errors on the client OpenTelemetry span. Consequently, when a tool execution failed withCallToolResult.isError=True, the client span remained withStatusCode.UNSETand no error attributes, diverging from server spans which recordStatusCode.ERRORanderror.type="tool_error".This change updates
send_raw_requestinsrc/mcp/shared/jsonrpc_dispatcher.pyto check formethod == "tools/call"withoutcome.get("isError") is True. When encountered, the client span is marked withspan.set_status(StatusCode.ERROR)andspan.set_attribute("error.type", "tool_error"), adhering to OpenTelemetry GenAI MCP semantic conventions without settingrpc.response.status_code.How Has This Been Tested?
Added unit test
test_client_and_server_spans_agree_on_tool_errorintests/shared/test_otel.py:MCPServerwith anoktool (returning"fine") and afailtool (raisingToolError("upstream unavailable")).Client(server, mode="legacy")and inspected spans captured via Logfire (CaptureLogfire).StatusCode.UNSETwith noerror.type.StatusCode.ERRORanderror.type="tool_error".trace_idand thatrpc.response.status_codeis not set on the client span.Breaking Changes
None. This change only updates OpenTelemetry client span status and attributes for failed tool calls.
Types of changes
Checklist
help wanted, or I'm a maintainer)Additional context
shared/jsonrpc_dispatcher.pywithserver/_otel.py(following [v2] JSON-RPC error responses leave client OpenTelemetry spans UNSET #3174) under OpenTelemetry GenAI semantic conventions for MCP tool calls.