fix(mcp): use negotiated protocol version in transport request headers#14427
Open
hiteshbandhu wants to merge 1 commit intovercel:mainfrom
Open
fix(mcp): use negotiated protocol version in transport request headers#14427hiteshbandhu wants to merge 1 commit intovercel:mainfrom
hiteshbandhu wants to merge 1 commit intovercel:mainfrom
Conversation
After a successful initialize handshake, HttpMCPTransport and SseMCPTransport were hardcoding LATEST_PROTOCOL_VERSION (2025-11-25) in every subsequent request header instead of the version actually negotiated with the server. This caused 400 errors against servers that only support older versions — notably Figma Dev Mode MCP (supports up to 2025-06-18). DefaultMCPClient now stores result.protocolVersion on the transport after init, and both transports use it in commonHeaders(), falling back to LATEST_PROTOCOL_VERSION only before the handshake completes. Fixes vercel#14413. Thanks to @stevering for the detailed report and local validation.
Author
|
Hey @gr2m, would appreciate a quick review ! |
|
@hiteshbandhu thank you for the investiguation 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #14413.
After a successful
initializehandshake,HttpMCPTransportandSseMCPTransportwere sendingmcp-protocol-version: 2025-11-25(LATEST_PROTOCOL_VERSION) in every subsequent request header — ignoring the version the server actually negotiated down to. The MCP spec says the client SHOULD use the negotiated version in all post-init requests.Real-world impact
Two confirmed broken server types:
Figma Dev Mode MCP (supports up to
2025-06-18) — reported by @stevering in #14413.FastMCP < 2.12.0 (supports up to
2025-06-18) — the failure always occurs onnotifications/initialized, the very first post-init message:The server correctly negotiates down to
2025-06-18duringinitialize, but the client ignores that and keeps sending2025-11-25in subsequent headers — causing the server to reject every post-init request.What changed
MCPTransportinterface — added optionalprotocolVersion?: string | nullfield so the client can inject the negotiated version into any transport after init. Custom transports that don't set it are unaffected.SseMCPTransport+HttpMCPTransport— addedprotocolVersion: string | null = null;commonHeaders()now usesthis.protocolVersion ?? LATEST_PROTOCOL_VERSION(falls back to latest only before the handshake completes).DefaultMCPClient.init()— after theSUPPORTED_PROTOCOL_VERSIONScheck and capability storage, setsthis.transport.protocolVersion = result.protocolVersion.protocolVersionand assert subsequent request headers use the negotiated value.Test plan
pnpm testinpackages/mcp— 181 tests pass (node + edge)should use negotiated protocol version in POST headers after protocolVersion is setin bothmcp-sse-transport.test.tsandmcp-http-transport.test.tsexamples/— the bug requires a live third-party MCP server, which cannot run in CI. The regression tests cover the same code path.Credit: @stevering filed the detailed report, provided the repro trace against a real Figma Desktop MCP server, and validated this exact patch locally via
pnpm patch. Thank you!