Skip to content

mcpcompat: expose a session's negotiated protocol version #467

Closed

Description

@tgrunnagle

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:

  • wrapToolHandler doesn't copy request headers (MCP-Protocol-Version) into mcp.CallToolRequest.Header.
  • go-sdk v1.8 keeps the negotiated version in ServerSessionState.NegotiatedProtocolVersion, with no exported getter on ServerSession.
  • 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 same known semantics as DeclaredClientCapabilities. Two possible shapes: a sibling method NegotiatedProtocolVersion() (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 known rule 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 before initialize completes.

Acceptance:

  • AC1.1: Inside a tool handler on a session that saw initialize, the accessor reports known true and the negotiated version, 2025-11-25 for a go-sdk v1.8 client, and 2025-06-18 for a client that requested 2025-06-18.
    • verify: Unit: TestClientSession_NegotiatedProtocolVersion
  • AC1.2: On a rehydrated session and on a stateless request, the accessor reports known false.
    • verify: Unit: TestClientSession_NegotiatedProtocolVersion_UnknownWhenNotObserved

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

  1. added
    needs-triage
    on Nov 5, 2026
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

    needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions