fix(core): use sessionId for MCP transport correlation#19172
Draft
fix(core): use sessionId for MCP transport correlation#19172
Conversation
…n spans This introduces `recordInputs` and `recordOutputs` options to the MCP server wrapper and related functions, allowing for more granular control over the data captured in spans.
…to avoid breaking changes
…t input/output handlin
Wrapper transports (like NodeStreamableHTTPServerTransport wrapping WebStandardStreamableHTTPServerTransport) proxy onmessage/send via getters/setters, causing different 'this' values in each callback. This changes correlation from WeakMap<transport> to Map<sessionId> to correctly correlate requests with responses regardless of which transport object reference is used. Reported-by: @gotenxds
Add mock wrapper transport utility and tests verifying that instrumentation correctly handles transports that proxy onmessage/send via getters/setters (common pattern with StreamableHTTP transports).
Add E2E tests for MCP StreamableHTTP transport across node-express, node-express-v5, and tsx-express test applications. Tests verify that transactions are recorded correctly for the wrapper transport pattern used by NodeStreamableHTTPServerTransport.
3 tasks
Contributor
Codecov Results 📊Generated by Codecov Action |
Contributor
Codecov Results 📊✅ 23 passed | ⏭️ 7 skipped | Total: 30 | Pass Rate: 76.67% | Execution Time: 10.04s All tests are passing successfully. Generated by Codecov Action |
Contributor
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
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
Fixes MCP server instrumentation not recording events for wrapper transport patterns (like
NodeStreamableHTTPServerTransportwhich wrapsWebStandardStreamableHTTPServerTransport).The root cause: wrapper transports proxy
onmessage/sendvia getters/setters, causing differentthisvalues. The previousWeakMap<transport, ...>correlation couldn't match requests to responses. This changes toMap<sessionId, ...>correlation which works regardless of transport object reference.Changes
correlation.tsto use sessionId-based Maps instead of transport-based WeakMapssessionManagement.tsto use sessionId-based session lookupTest Plan
cd packages/core && yarn test(2010 tests pass)yarn lint) & (yarn test).Closes getsentry/sentry-mcp#767
Thanks @gotenxds for reporting and debugging this issue!