Skip to content

fix(core): use sessionId for MCP transport correlation#19172

Draft
betegon wants to merge 15 commits intodevelopfrom
bete/fix/mcp-wrapper-transport-correlation
Draft

fix(core): use sessionId for MCP transport correlation#19172
betegon wants to merge 15 commits intodevelopfrom
bete/fix/mcp-wrapper-transport-correlation

Conversation

@betegon
Copy link
Member

@betegon betegon commented Feb 4, 2026

Summary

Fixes MCP server instrumentation not recording events for wrapper transport patterns (like NodeStreamableHTTPServerTransport which wraps WebStandardStreamableHTTPServerTransport).

The root cause: wrapper transports proxy onmessage/send via getters/setters, causing different this values. The previous WeakMap<transport, ...> correlation couldn't match requests to responses. This changes to Map<sessionId, ...> correlation which works regardless of transport object reference.

Changes

  • Changed correlation.ts to use sessionId-based Maps instead of transport-based WeakMaps
  • Changed sessionManagement.ts to use sessionId-based session lookup
  • Added unit tests with mock wrapper transport utility
  • Added E2E tests for StreamableHTTP transport across node-express, node-express-v5, and tsx-express

Test Plan

  • Unit tests: cd packages/core && yarn test (2010 tests pass)
  • E2E tests: All pass
    • node-express: 14/14
    • node-express-v5: 12/12
    • tsx-express: 10/10

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).
  • Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked.

Closes getsentry/sentry-mcp#767

Thanks @gotenxds for reporting and debugging this issue!

…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.
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.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Codecov Results 📊


Generated by Codecov Action

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

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.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,129 - 10,979 -17%
GET With Sentry 1,707 19% 1,810 -6%
GET With Sentry (error only) 5,960 65% 7,340 -19%
POST Baseline 1,188 - 1,076 +10%
POST With Sentry 592 50% 539 +10%
POST With Sentry (error only) 1,030 87% 957 +8%
MYSQL Baseline 3,240 - 3,800 -15%
MYSQL With Sentry 452 14% 453 -0%
MYSQL With Sentry (error only) 2,667 82% 3,032 -12%

View base workflow run

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 server aint recording events - req/res transport issue

1 participant