Skip to content

MCP server aint recording events - req/res transport issue #767

@gotenxds

Description

@gotenxds

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

10.34.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

Hello, I've been debugging this issue for a few days I think I understand why it happens, here is what I found.

The sentryMcpWrapper is storing the sessions in a weakmap from the transport to the session data.

The issue is, that the transport received in the onMessage method can be a different level of abstraction from the one recived in the send method

Here you can see images of both events for the same mcp call:

onMessage:
Image

onSend:
Image

As you can see in the images above, this is the same request, but on response (send) the sdk exposes a different transport (a warpper that holds the original transport)

This happens because the send method is being called from a StreamableHTTPServerTransport which overrides the method, but it does not override the onMessage method so that one is being called from the super class which means the code is getting different this values in each invocation.

Because the weakmap uses the class of the transport itself as the key for the entire transaction this causes the event to not be found and not send to sentry.

A solution might be trying to use the prototype class or just forgo using classes at all there and trying to use the session id generated by the transport but I dont know all the details and I'm sure there was a good reason for this approach.

Steps to Reproduce

As far as I see this happens always if you create your own StreamableHTTPServerTransport and use mcpServer.connect(transport)

Expected Result

Events to be sent to sentry

Actual Result

Events are not being sent

Additional Context

No response

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions