Repository navigation
fix(server): Mark calls to unregistered tools as failed spans - #1952
Merged
Merged
Conversation
Since EXPOSE_ALL_TOOLS stopped registering search_sentry_tools and execute_sentry_tool, clients that still call them get a -32602 "Tool not found" JSON-RPC error. Sentry's MCP instrumentation treats -32602 as a client error and leaves the tools/call span status unset, and our request attributes are only set inside tool handlers, so these calls showed up as successful 0ms spans without app.transport. Wrap the SDK's tools/call handler so a call to a name this server did not register sets error.type: unknown_tool, an error span status, and the request attributes before the SDK rejects it. The removed gateway tools get a message that tells the client to call tools directly. No Sentry issue is created for these client mistakes. Co-Authored-By: David Cramer <[email protected]>
Replace the mocked getActiveSpan assertions with a test that runs the real wrapMcpServerWithSentry under an AsyncLocalStorage context strategy and checks the finished span's status and error.type. Keep the not-found test outside the EXPOSE_ALL_TOOLS block, guard the private handler map with instanceof Map, and compute the tool-call span attributes once. Co-Authored-By: David Cramer <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
dcramer
approved these changes
Nov 4, 2026
7 tasks done
This was referenced Nov 11, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since #1868 turned on
EXPOSE_ALL_TOOLS,search_sentry_toolsandexecute_sentry_toolare no longer registered, but clients still call them (~200/hour each on the hosted server). The MCP SDK rejects these calls with JSON-RPC-32602 Tool … not found. Sentry's MCP instrumentation treats-32602as a client error and leaves thetools/callspan status unset, so these failures were recorded asok0ms spans and didn't show up in tool failure rates. They also lackedapp.transport, because we set it only inside tool handlers, and those never run for unknown names.This wraps the SDK's
tools/callhandler. When a call names a tool this server did not register, the wrapper marks the active span as failed (error.type: unknown_tool, statusnot_found) and adds the usual request attributes (app.transport,app.client.family, constraints, skills). The removed gateway tools get a clear message:Other unknown names keep the SDK's error. The response stays a
-32602JSON-RPC error, which the MCP spec prescribes for unknown tools. No Sentry issue is created: this is a client mistake, and neither our code nor the SDK captures-32602.The SDK has no hook for unknown tool names, so the wrapper uses the Protocol's private
_requestHandlersmap. If an SDK upgrade changes that map, the wrapper does nothing (it checksinstanceof Mapand that a handler exists) and the new span test fails.Evidence
sentry/mcp-serverspans, 2026-11-03T20:15Z–2026-11-04T17:15Z:mcp.tool.namespan.statusrpc.response.status_codeapp.transportAll of them have
network.transport: tcpand an HTTPmcp.transport(WebStandardStreamableHTTPServerTransportorPerRequestHTTPServerTransport), and their parenthttp.server POST /mcp/…spans carryapp.transport: http. They come from hosted HTTP clients across many client families, not from stdio. The missingapp.transportonly means our handler never ran. Thecliproject has nomcp.*spans in the last 30 days. The same gap also hid other unknown names, mostly the deprecatedsearch_events(~1.2k calls in the same window).Local repro with
@sentry/node11.6.0 and the realwrapMcpServerWithSentry:tools/call execute_sentry_toolspan isokwithrpc.response.status_code: -32602.errorwitherror.type: unknown_toolandapp.transport: http, and no error events are sent.telem/unknown-tool.test.tscovers the same path. It uses a realServerRuntimeClientand the real MCP instrumentation under an AsyncLocalStorage context strategy, and asserts the finished span's status anderror.type. It fails without theserver.tschange.Deploy note
This adds roughly 400–500 failed
tools/callspans per hour, which were previously recorded asok. Most of them (~420/hour) are the removed gateway names, and the rest are other unknown names such assearch_events. Tool failure-rate alerts and dashboards for mcp-server may jump after deploy. These are failures that were already happening and are now visible, not a regression.SDK follow-up
The root behavior is in getsentry/sentry-javascript.
completeSpanWithResults(packages/core/src/integrations/mcp-server/correlation.ts) sets an error status only whenisJsonRpcServerError(errorCapture.ts) is true, and that check excludes-32602. Not capturing an exception for client errors makes sense, but the span should probably still get an error status, anderror.typeshould be the JSON-RPC code, sotools/callfailure rates include protocol-level client errors.Out of scope
isErrorresult) also lackapp.transport, for the same reason: our handler never runs.search_eventsshould get a replacement hint is a separate product decision.Review
Independent review: ready, no must-fix.
ServerRuntimeClient, the realwrapMcpServerWithSentryand an async context. Main records the call asokwithoutapp.transport. This branch records it aserrorwitherror.type=unknown_toolandapp.transport=http, and sends 0 error events. Registered tools are unaffected._requestHandlers.getActiveSpan.instanceof Mapand that a handler exists before wrapping.EXPOSE_ALL_TOOLS.pnpm run tsc,pnpm run lint, and themcp-core(2,044 tests) andmcp-cloudflare(447 tests) suites pass locally. In the sandbox, somepackages/clifilesystem-permission tests fail on cleanmaintoo.via @dcramer.
--
View Session [Sentry]