Skip to content

mcp: an unknown protocol version in per-request _meta is not answered with UnsupportedProtocolVersionError #1260

Closed

Description

@jmrplens

The versioning page says that if a server does not implement the protocol version a request asks for, "whether the version is unknown to the server, or is a known version the server has chosen not to support", it MUST respond with an UnsupportedProtocolVersionError listing the versions it does support. The worked example on that page is a request asking for 1900-01-01, answered with code -32022 and a data object carrying supported and requested.

A server built on this SDK does not answer that way on stdio. It answers method "tools/list" is invalid during session initialization, a plain Go error that reaches the wire with code 0 and carries no supported list.

Where it happens. validateRequestMeta in mcp/shared.go (v1.7.0: function at line 543, the comparison at line 549; main at 5bc078a: function at line 570, comparison at line 577):

protocolVersion, ok := meta[MetaKeyProtocolVersion].(string)
if !ok || protocolVersion < protocolVersion20260728 {
	return &validatedMeta{usesNewProtocol: false, initializeParams: nil}, nil
}

The classification is a string comparison, so a request counts as modern only when its version sorts at or above 2026-07-28. Every published revision is in supportedProtocolVersions, so no published client is affected. But a version string the SDK does not know sorts wherever its characters put it, and one sorting below 2026-07-28 is classified as a legacy handshake: usesNewProtocol stays false, the request never reaches the CodeUnsupportedProtocolVersion check in (*ServerSession).handle (mcp/server.go:1873 in v1.7.0, :1963 on main), and it falls through to the initialization gate instead (mcp/server.go:1901 in v1.7.0, :1991 on main). The window holds values like 2026-01-01, 2025-11-24, 1900-01-01, 1.0, 0 and the empty string.

The same SDK already answers this question by membership one layer out. The header gate at mcp/streamable.go:354 refuses an Mcp-Protocol-Version that is not in the supported list and sorts below 2026-07-28, which is exactly the set validateRequestMeta accepts as a legacy handshake. One layer of the same server refuses those values and the other serves them.

That asymmetry is also why I only see this on stdio. Over HTTP either the header gate rejects the version first, or, when the version is carried only in _meta, the header-mismatch check refuses the request with -32020 before the classification runs. stdio has no header, so nothing catches it there.

Reproduction. A stdio server with one tool and nothing else:

package main

import (
	"context"

	"github.com/modelcontextprotocol/go-sdk/mcp"
)

func main() {
	s := mcp.NewServer(&mcp.Implementation{Name: "repro", Version: "v0.0.1"}, nil)
	mcp.AddTool(s, &mcp.Tool{Name: "greet", Description: "greet"},
		func(ctx context.Context, req *mcp.CallToolRequest, args struct{}) (*mcp.CallToolResult, any, error) {
			return &mcp.CallToolResult{}, nil, nil
		})
	if err := s.Run(context.Background(), &mcp.StdioTransport{}); err != nil {
		panic(err)
	}
}

Driven with a single request. The sleep only holds stdin open long enough for the answer to be written; without it the process can exit on EOF first.

{ printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"1900-01-01","io.modelcontextprotocol/clientInfo":{"name":"c","version":"1"},"io.modelcontextprotocol/clientCapabilities":{}}}}'; sleep 1; } | go run .

What I get:

{"jsonrpc":"2.0","id":1,"error":{"code":0,"message":"method \"tools/list\" is invalid during session initialization"}}

What the versioning page requires: code -32022 with data.supported and data.requested, which is the error this SDK already produces when a version is excluded by ServerOptions.SupportedProtocolVersions.

Observed on v1.7.0, reproduced on main at 5bc078a.

What a server built on the SDK cannot do because of this. It cannot answer an unknown version the way the specification requires, and the answer it gives instead carries the opposite meaning. The backward compatibility section of the same page says a recognized modern error such as UnsupportedProtocolVersionError identifies a modern server and makes the client retry with a supported version, while "anything else identifies a legacy server". A dual-era client probing a modern go-sdk server with a version the SDK does not know is therefore told, by an error carrying code 0, that the server is legacy, and it falls back to initialize. It is given no supported list either, so it has nothing to retry with. The server cannot repair this from the outside: the gate returns at mcp/server.go:1901 (v1.7.0), before handleReceive runs the receiving middleware chain at :1925, so no middleware ever sees the request. The only seam left is a wrapping Transport that parses params._meta before the session does, which means reimplementing this piece of the protocol outside the SDK.

I found this auditing a server against the lifecycle specification, not from a client failing in the field. No published revision is in the affected window, so what this breaks is the specified error contract and anything that exercises it, rather than a released client. The specification's own worked example landing inside that window is what convinced me it is worth reporting.

I am offering a pull request with a fix alongside this issue.

Part of #1257.

Activity

  1. added a commit that references this issue on Sep 14, 2026
    a82c86a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions