Repository navigation
fix(mcp): Stop reporting rejected client requests as Sentry issues - #2282
sentry-junior[bot] wants to merge 2 commits into
Conversation
The MCP SDK's Streamable HTTP transport answers malformed requests (missing Accept media type, wrong Content-Type, unparseable body, unsupported protocol version) with a 4xx and reports each one through transport.onerror. Sentry's MCP server integration captures every onerror call as an unhandled error, and server.onerror sent it to logIssue as well, so client mistakes became high-priority issues. Classify these rejections once, drop the integration's copy in sentryBeforeSend, and log them as warnings in server.onerror. Other transport errors still create issues, and app.server.response keeps counting the 4xx responses by client family. Fixes MCP-SERVER-GFB Co-Authored-By: bete <28983162+betegon@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| const transport = new WebStandardStreamableHTTPServerTransport({ | ||
| sessionIdGenerator: undefined, | ||
| }); |
There was a problem hiding this comment.
🟠 High severity and reachable issue identified in your code:
Line 251 has a potentially vulnerable usage of @modelcontextprotocol/server, possibly introducing a high severity vulnerability.
ℹ️ Why this is reachable
A reachable issue is a possible security risk because your project actually executes the vulnerable code. This issue is reachable because your code calls vulnerable code in this version of @modelcontextprotocol/server.
Affected versions of @modelcontextprotocol/hono, @modelcontextprotocol/node, @modelcontextprotocol/sdk, and @modelcontextprotocol/server are vulnerable to Allocation of Resources Without Limits or Throttling. The MCP TypeScript SDK Streamable HTTP server transports and HTTP handlers (StreamableHTTPServerTransport, WebStandardStreamableHTTPServerTransport, NodeStreamableHTTPServerTransport, createMcpHandler, isLegacyRequest, legacyStatelessFallback, toNodeHandler/toWebRequest, createMcpHonoApp) read POST request bodies without a size limit and dispatch JSON-RPC batches of unbounded length. An unauthenticated remote client can exhaust server memory with an oversized body or block other clients with a very long batch, causing denial of service.
References: GHSA
To resolve this comment:
Upgrade this dependency to at least version 2.1.0 at pnpm-lock.yaml.
💬 Ignore this finding
To ignore this, reply with:
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
You can view more details on this finding in the Semgrep AppSec Platform here.
There was a problem hiding this comment.
Context for a maintainer to triage this (I'm not dismissing it): the flagged line is test-only code in packages/mcp-core/src/server.test.ts. That package resolves @modelcontextprotocol/server from the catalog to 2.4.0 (pnpm-lock.yaml importers), which is above the fixed 2.1.0. The @modelcontextprotocol/server@2.0.0 lockfile entry the finding points to is a transitive dependency of @mastra/core, already on main, and this PR doesn't change the lockfile. Bumping or overriding that transitive copy would be a separate dependency change, so I've left it out of this PR.
…ent-rejections # Conflicts: # packages/mcp-core/src/server.test.ts
Fixes MCP-SERVER-GFB
Not Acceptable: Client must accept both application/json and text/event-streamis the MCP SDK's Streamable HTTP transport answering a malformed client request with a 406. The transport reports every request it rejects throughtransport.onerror, and that error reaches Sentry twice:@sentry/corewrapTransportError) captures everyonerrorcall as an unhandledauto.ai.mcp_server/error_type: transportexception. This is the event we see.server.server.onerrorthen sends the same error tologIssue. The SDK skips that capture because the error was already captured, but it is still an error-level log and an issue in any path the integration doesn't wrap.So the hosted MCP turns 4xx client mistakes into high-priority issues, which the repo's 4xx/5xx policy forbids.
Evidence (all 965 events in the issue):
Go-http-client/2.0(one account) sendingnotifications/initializedwith noAcceptheader. ~280 come fromDevin-CLI(Windsurf / Devin) sendinginitializewithAccept: application/json. The rest arenode/curlsending*/*and hand-written curl requests.Bad Request: Unsupported protocol version(400) andUnsupported Media Type(415). Sibling issues MCP-SERVER-G4R and MCP-SERVER-GM8 (same 406), and MCP-SERVER-GFD, MCP-SERVER-G4W, and MCP-SERVER-G55 (SyntaxErrorfromJSON.parseof the body, 400), are the same class.auto.ai.mcp_servertransport error in the project was one of these 4xx rejections. No server fault came through this path.nodewith about 6M 200s and 57 406s. Each rejection is a specific probe or a notification. The client keeps working.Change:
isTransportClientRejectionintelem/sentry.tsnames the rejection rule once. The SDK starts each 4xx rejection message with its HTTP reason phrase (Not Acceptable:,Unsupported Media Type:,Payload Too Large:,Bad Request:,Invalid Request:), and aSyntaxErroris a body that failsJSON.parse.sentryBeforeSenddrops an event only when it has the integration's transport mechanism (auto.ai.mcp_server+error_type: transport) and the exception matches that rule. Other transport errors, and the same messages from other mechanisms, are still reported.server.onerrorlogs these rejections withlogWarnand still useslogIssuefor everything else.app.server.responsealready counts each/mcpresponse by status code andapp.client.family, and the warning log keeps the message.Not changed, on purpose: I did not make the server accept
*/*or a missingAccept. The Streamable HTTP spec (2025-11-25, Sending Messages to the Server) says the client MUST list bothapplication/jsonandtext/event-stream. The traffic data shows no client that depends on that leniency. Under RFC 9110,*/*arguably should match, so if we want that leniency it belongs in the MCP TypeScript SDK's substring check, not in a local Accept rewrite.Related, out of scope: MCP-SERVER-F1J (
JsonRpcError_-32603, 627 events) is also client input. AninitializewithoutclientInfo.versionfails SDK validation, and the SDK reports it as an internal error (-32603), so the integration captures it as aprotocolerror. It needs a separate fix.via @betegon.
--
View Session [Sentry]