Skip to content

fix(core): handle stateless MCP wrapper transport correlation#20293

Open
logaretm wants to merge 2 commits intodevelopfrom
awad/js-2164-wrapmcpserverwithsentry-tool-call-spans
Open

fix(core): handle stateless MCP wrapper transport correlation#20293
logaretm wants to merge 2 commits intodevelopfrom
awad/js-2164-wrapmcpserverwithsentry-tool-call-spans

Conversation

@logaretm
Copy link
Copy Markdown
Member

@logaretm logaretm commented Apr 14, 2026

This PR handles stateless MCP wrappers by using the connected transport instance as the stable MCP correlation key across wrapper layers.

I verified the issue and the fix by adding a regression test for stateless wrapper transports where the request path runs on the inner transport and the response path runs on the wrapper.

Closes #20290

Use the connected transport as the stable correlation key for MCP wrapper transports in stateless mode, and add a regression test covering the inner-vs-outer transport split.

Co-Authored-By: GPT-5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 14, 2026 21:04
@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes MCP server transport span correlation when using stateless wrapper transports (e.g. StreamableHTTPServerTransport with sessionIdGenerator: undefined) by using the connected transport instance as the correlation key across wrapper layers, and adds a regression test to cover this scenario.

Changes:

  • Use the transport passed to connect() (instead of handler this) as the key for span/session correlation in transport wrappers.
  • Add a regression test ensuring tool-call spans are properly completed for stateless wrapper transports.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/integrations/mcp-server/transport.ts Switch correlation/session operations to use the connected transport instance for wrapper-layer stability.
packages/core/test/lib/integrations/mcp-server/transportInstrumentation.test.ts Add regression test reproducing stateless wrapper onmessage/send split and asserting span completion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/integrations/mcp-server/transport.ts
Comment thread packages/core/src/integrations/mcp-server/transport.ts
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c4271fc. Configure here.

Comment thread packages/core/src/integrations/mcp-server/transport.ts
Use the connected transport as the stable key for MCP span attribute building as well as correlation/session writes, and add a regression test covering initialize metadata on later stateless wrapper spans.

Co-Authored-By: GPT-5 <noreply@anthropic.com>
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.

wrapMcpServerWithSentry: tool-call spans missing with stateless StreamableHTTPServerTransport

2 participants