Skip to content

wrapMcpServerWithSentry: tool-call spans missing with stateless StreamableHTTPServerTransport #20290

@maxproske

Description

@maxproske

AI disclaimer: used Claude Code to generate as much useful context as possible.

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node - express

SDK Version

10.48.0

Framework Version

@modelcontextprotocol/sdk 2.x (Node StreamableHTTPServerTransport)

Link to Sentry event

N/A — no spans are emitted

Reproduction Example/SDK Setup

Sentry.init({ dsn: process.env.DSN, tracesSampleRate: 1.0 });

app.all('/mcp', auth, async (req, res) => {
  const transport = new StreamableHTTPServerTransport({
    sessionIdGenerator: undefined,   // stateless
    enableJsonResponse: true,
  });
  const server = Sentry.wrapMcpServerWithSentry(
    new McpServer({ name: 'x', version: '1.0.0' }),
    { recordInputs: true, recordOutputs: true },
  );
  registerTools(server);
  await server.connect(transport);
  await transport.handleRequest(req, res, req.body);
});

Steps to Reproduce

  1. Use @sentry/node ≥ 10.39.0 (post-#19172).
  2. Construct a per-request McpServer + Node StreamableHTTPServerTransport with sessionIdGenerator: undefined (stateless mode, per the official MCP SDK simpleStatelessStreamableHttp.ts example).
  3. Wrap with wrapMcpServerWithSentry, server.connect(transport), transport.handleRequest(...).
  4. Call any tool from a client.

Expected Result

An mcp.server span with mcp.tool.name attribute for each tools/call, visible on the MCP insights dashboard.

Actual Result

Zero mcp.server spans emitted. http.server transactions for POST /mcp are recorded fine, but tool-call correlation never resolves, so spans are created on onmessage and never .end()-ed on send.

Additional Context

This is the stateless follow-up to JS-1663 / PR #19172, which the reporter flagged in this comment and a maintainer acknowledged here ("about the stateless issue, we'll get that fixed, it slipped by").

I'm using stateless because I am deploying to a scale-to-zero Fly.io server.

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

No fields configured for issues without a type.

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions