Repository navigation
Description
Summary
mcpcompat's server session reports the MCP protocol version the session negotiated at initialize, and whether it is known, next to the declared client capabilities that #447 exposes. A consumer can then follow version-gated MCP rules, such as only sending -32042 URLElicitationRequiredError on a 2025-11-25 session.
Consumed by stacklok/toolhive#7023, which is blocked on this.
Use case
stacklok/toolhive#7023 AC2.1: a vMCP Legacy session receives -32042 only when the client declared elicitation.url and negotiated 2025-11-25. A client that negotiated an older revision (2025-06-18, 2025-03-26, 2024-11-05) gets the isError fallback even if it declares elicitation.url, because -32042 and URL-mode elicitation don't exist in those revisions.
SessionWithClientCapabilities.DeclaredClientCapabilities() (v0.0.59) returns capabilities only. A tool handler can't see the version any other way:
wrapToolHandlerdoesn't copy request headers (MCP-Protocol-Version) intomcp.CallToolRequest.Header.- go-sdk v1.8 keeps the negotiated version in
ServerSessionState.NegotiatedProtocolVersion, with no exported getter onServerSession. - Reading the header through a context value in the consumer is an anti-pattern there (vmcp-anti-patterns Add package graduation criteria to README #1).
Scenario 1. A handler reads the negotiated protocol version
Work:
mcpcompat/server: extend the read-only accessor so a handler can get the negotiated protocol version with the sameknownsemantics asDeclaredClientCapabilities. Two possible shapes: a sibling methodNegotiatedProtocolVersion() (version string, known bool), or one method returning both. The value is go-sdk's negotiation result (negotiatedVersion(InitializeParams().ProtocolVersion, supported)), not the raw requested version.- Same
knownrule as mcpcompat: expose a session's declared client capabilities #447: false on a rehydrated session (whose version is seeded from the header or defaulted), on a stateless request, on SSE and stdio sessions, and beforeinitializecompletes.
Acceptance:
- AC1.1: Inside a tool handler on a session that saw
initialize, the accessor reportsknowntrue and the negotiated version,2025-11-25for a go-sdk v1.8 client, and2025-06-18for a client that requested2025-06-18.- verify:
Unit: TestClientSession_NegotiatedProtocolVersion
- verify:
- AC1.2: On a rehydrated session and on a stateless request, the accessor reports
knownfalse.- verify:
Unit: TestClientSession_NegotiatedProtocolVersion_UnknownWhenNotObserved
- verify:
Out of scope
| Item | Defer to | Why |
|---|---|---|
| Persisting the negotiated version through rehydration | Unscheduled, with #447's capability persistence | Consumers fall back when unknown |
| Modern (2026-07-28) per-request version | n/a | Carried per request in _meta |
Delivery shape
One PR, released as a tagged toolhive-core version.
Activity
mcpcompat/server: expose a session's negotiated protocol version (#468)