You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mcp: ClientSession.CallTool omits Mcp-Param-* headers unless the tool is in the ListTools cache, so a call without a prior tools/list is rejected #1481
On 2026-07-28, ClientSession.CallTool gets the tool definition for SEP-2243 x-mcp-header headers only from lookupTool, which searches toolsCache (mcp/client.go:599, used at :1292 in v1.8.0; same on main). If the session never called ListTools, no Mcp-Param-* header is sent, and a go-sdk server rejects the call in validateParamHeaders with 400. There is no exported way to supply the definition: toolContextKey is unexported and CallToolParams has no slot for it.
Calling cs.ListTools first makes it succeed (Mcp-Param-Region: us-west1).
Why it matters
Gateways and proxies cache upstream catalogs centrally and open a fresh ClientSession per proxied call (per-user upstream credentials, multiple replicas), so a tools/list before every call doubles the round trips. Clients that persist catalogs across sessions, and short-lived stateless 2026-07-28 sessions in general, hit the same thing.
Proposal (in order of preference)
func WithTool(ctx context.Context, tool *Tool) context.Context — exposes the mechanism that already exists; takes precedence over the cache.
I've put up a fix in #1483, which the bot closed until this issue is assigned. On a cache miss, CallTool pages through tools/list to find the tool, only for 2026-07-28 sessions over the streamable transport, and the repro above is its regression test. If you'd rather callers pass the definition themselves, I can switch it to that. Could you assign this to me so the PR can reopen?
AI-assisted: I used an AI coding assistant and reviewed and tested every change.
Rather than eagerly calling tools/list before tools/call on every cache miss (as in #1483), we should implement the reactive recovery prescribed by the 2026-07-28 Streamable HTTP spec (which is also what the TypeScript and Python SDKs do):
If the server rejects a request with a HeaderMismatch (-32020) error because required Mcp-Param-* headers are missing or do not match the body, the client SHOULD call tools/list to check for changes to the tool's inputSchema, then retry the original request with the appropriate headers.
Concretely, in ClientSession.CallTool:
Send tools/call immediately using cs.lookupTool(params.Name) as today.
If that call fails with a *jsonrpc.Error whose Code == CodeHeaderMismatch (-32020) on a 2026-07-28 Streamable HTTP session:
Invalidate cs.toolsCache.
Page through ListTools and stop as soon as params.Name is found.
If the tool is found, retry tools/call. If listing fails or the tool isn't listed, return the original -32020 error.
Retrying once on -32020 is safe because servers reject HeaderMismatch during HTTP header validation before invoking the tool handler, and this covers both cold-cache calls and mid-session schema changes without expanding the public API.
Activity
sundarshahi commentedon Oct 31, 2026
I've put up a fix in #1483, which the bot closed until this issue is assigned. On a cache miss,
CallToolpages throughtools/listto find the tool, only for 2026-07-28 sessions over the streamable transport, and the repro above is its regression test. If you'd rather callers pass the definition themselves, I can switch it to that. Could you assign this to me so the PR can reopen?AI-assisted: I used an AI coding assistant and reviewed and tested every change.
guglielmo-san commentedon Nov 2, 2026
Rather than eagerly calling
tools/listbeforetools/callon every cache miss (as in #1483), we should implement the reactive recovery prescribed by the2026-07-28Streamable HTTP spec (which is also what the TypeScript and Python SDKs do):Concretely, in
ClientSession.CallTool:tools/callimmediately usingcs.lookupTool(params.Name)as today.*jsonrpc.ErrorwhoseCode == CodeHeaderMismatch(-32020) on a2026-07-28Streamable HTTP session:cs.toolsCache.ListToolsand stop as soon asparams.Nameis found.tools/call. If listing fails or the tool isn't listed, return the original-32020error.Retrying once on
-32020is safe because servers rejectHeaderMismatchduring HTTP header validation before invoking the tool handler, and this covers both cold-cache calls and mid-session schema changes without expanding the public API.mcp: re-list and retry tools/call on HeaderMismatch (modelcontextprot…