Title: Client never retries after -32020 HeaderMismatch, and there is no public way to pre-load the x-mcp-header map (SEP-2243 client SHOULD/MAY both unimplemented) · Issue #3483 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Client never retries after -32020 HeaderMismatch, and there is no public way to pre-load the x-mcp-header map (SEP-2243 client SHOULD/MAY both unimplemented) · Issue #3483 · modelcontextprotocol/python-sdk
X Title: Client never retries after -32020 HeaderMismatch, and there is no public way to pre-load the x-mcp-header map (SEP-2243 client SHOULD/MAY both unimplemented) · Issue #3483 · modelcontextprotocol/python-sdk
Description: Summary At 2026-07-28, a ClientSession that has not listed a tool sends tools/call with no Mcp-Param-* headers, the server rejects it with -32020, and the client stops there. SEP-2243 says it SHOULD re-list and retry, and there is no way...
Open Graph Description: Summary At 2026-07-28, a ClientSession that has not listed a tool sends tools/call with no Mcp-Param-* headers, the server rejects it with -32020, and the client stops there. SEP-2243 says it SHOUL...
X Description: Summary At 2026-07-28, a ClientSession that has not listed a tool sends tools/call with no Mcp-Param-* headers, the server rejects it with -32020, and the client stops there. SEP-2243 says it SHOUL...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3483
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Client never retries after -32020 HeaderMismatch, and there is no public way to pre-load the x-mcp-header map (SEP-2243 client SHOULD/MAY both unimplemented)","articleBody":"### Summary\n\nAt `2026-07-28`, a `ClientSession` that has not listed a tool sends `tools/call` with no `Mcp-Param-*` headers, the server rejects it with `-32020`, and **the client stops there**. SEP-2243 says it SHOULD re-list and retry, and there is no way for an application to supply the map instead — `_x_mcp_header_maps` is private and `_absorb_tool_listing` is its only writer.\n\nEverything below reproduces against the SDK's own client and server, no third-party server involved.\n\n### Reproduction\n\n```python\nimport anyio, httpx2, uvicorn\nfrom typing import Annotated\nfrom pydantic import Field\nfrom mcp.client import Client\nfrom mcp.client.streamable_http import streamable_http_client\nfrom mcp.server.mcpserver import MCPServer\nfrom mcp.shared.exceptions import MCPError\n\nserver = MCPServer(\"repro\")\n\n@server.tool()\nasync def fetch(\n owner: Annotated[str, Field(json_schema_extra={\"x-mcp-header\": \"owner\"})],\n) -> str:\n \"\"\"One annotated argument, as the SEP's examples have.\"\"\"\n return f\"fetched for {owner}\"\n\nURL = \"http://127.0.0.1:8931/mcp\"\n\nasync def exercise() -> None:\n await anyio.sleep(1.5)\n async with httpx2.AsyncClient() as http:\n print(\"== a session that never listed ==\")\n async with Client(streamable_http_client(URL, http_client=http), mode=\"auto\") as client:\n print(\"negotiated:\", client.protocol_version)\n try:\n r = await client.call_tool(\"fetch\", {\"owner\": \"octocat\"})\n print(\" result:\", r.content)\n except MCPError as exc:\n print(f\" MCPError code={exc.error.code}\")\n print(f\" message={exc.error.message!r}\")\n\n print(\"== a session that listed first ==\")\n async with Client(streamable_http_client(URL, http_client=http), mode=\"auto\") as client:\n await client.list_tools()\n r = await client.call_tool(\"fetch\", {\"owner\": \"octocat\"})\n print(\" result:\", r.content)\n\nasync def main() -> None:\n config = uvicorn.Config(server.streamable_http_app(), host=\"127.0.0.1\", port=8931, log_level=\"error\")\n http_server = uvicorn.Server(config)\n async with anyio.create_task_group() as tg:\n tg.start_soon(http_server.serve)\n await exercise()\n http_server.should_exit = True\n\nanyio.run(main)\n```\n\nOutput on `mcp` 2.1.1:\n\n```\n== a session that never listed ==\nnegotiated: 2026-07-28\n MCPError code=-32020\n message=\"Mcp-Param-owner header is missing but the request body's 'owner' argument is present\"\n== a session that listed first ==\n result: [TextContent(type='text', text='fetched for octocat', ...)]\n```\n\nThe `-32020` arrives as HTTP 400. The client neither re-lists nor retries.\n\n### What the spec asks for\n\nSEP-2243, *Client Behavior*:\n\n> **Implementation Note**: Clients MUST construct `Mcp-Param-*` headers using the most recently obtained `inputSchema` for the tool. A client that has never obtained the tool's `inputSchema` SHOULD send the request without `Mcp-Param-*` headers. **If the server rejects the request because required `Mcp-Param-*` headers are missing or do not match the body, the client SHOULD call `tools/list` to obtain the current `inputSchema`, then retry the original request with the appropriate headers.** Clients MAY pre-load tool definitions via other means (e.g., from a previous session or configuration) to enable header emission without a prior `tools/list` call.\n\nTwo mechanisms in one paragraph. The SDK implements neither.\n\n`HEADER_MISMATCH` has **zero** readers under `mcp/client/` — every occurrence is server-side (`mcp/server/_streamable_http_modern.py`, `mcp/shared/inbound.py`), producing the rejection rather than reacting to one.\n\n### Why the second half matters as much as the first\n\nAn application that opens a session per operation — for connection hygiene, or because it holds no long-lived session — has the schema in hand already, from the listing it built its tool surface with. The SEP explicitly blesses using it (*\"MAY pre-load tool definitions via other means\"*). But `_x_mcp_header_maps` is private, and the only writer is `_absorb_tool_listing`, reachable only through an in-session `list_tools()`. So the sanctioned cheap path is unreachable and the only route is a redundant wire request per call.\n\nFor us that request is ~1.3 s and ~122 KiB against a 44-tool server, paid on the calling session purely to repopulate state we already had.\n\n### What this cost, concretely\n\nWe hit this in production against the GitHub MCP server: **36 of its 44 tools** were refused with `-32020`, because our client opens one session per `tools/call` and never lists on it. The client-side symptom was a bare `-32020` from the server; nothing on our side could say why, because:\n\n`ClientSession._resolve_param_headers` (`mcp/client/session.py:1118`) returns `{}` silently when the session holds no map for the tool:\n\n```python\ndef _resolve_param_headers(self, name: str, arguments: Mapping[str, Any]) -> dict[str, str]:\n \"\"\"`Mcp-Param-*` headers for a `tools/call`, or empty when the tool was never listed.\"\"\"\n header_map = self._x_mcp_header_maps.get(name)\n if header_map is None:\n return {}\n return mcp_param_headers(header_map, arguments)\n```\n\nAt a modern protocol version, \"this tool was never listed on this session\" is a strong signal that the call is about to be refused. The listing filter one screen away already logs when it drops a tool (`logger.warning(\"dropping tool %r: invalid x-mcp-header (%s)\", ...)`), so the precedent for saying something here is right there.\n\n### Suggested fixes, in the order we would value them\n\n1. **A public way to seed the map** — e.g. `ClientSession.preload_tool_listing(result)`, or a `tools=` argument to `adopt()`. Implements the SEP's \"MAY pre-load\" sentence, and lets a session-per-call client emit correct headers with no extra round trip.\n2. **The `-32020` retry**, bounded to one attempt: re-list, rebuild, resend. This is the SHOULD, and it is the only thing that heals a schema that gains an annotation mid-session.\n3. **A warning in `_resolve_param_headers`** when a modern session has no map for the tool it is calling. Cheapest of the three, and the one that would have turned our incident into a log line instead of an investigation.\n\nHappy to open a PR for any of these if the direction is agreeable — 1 and 3 look small; 2 needs a decision about where the retry lives relative to `validate_tool_result`.\n\n### Environment\n\n- `mcp` 2.1.1, `mcp-types` 2.1.1, Python 3.12.9\n- Transport: streamable HTTP, `mode=\"auto\"`, negotiated `2026-07-28`\n","author":{"url":"https://github.com/atsuki-shirasawa","@type":"Person","name":"atsuki-shirasawa"},"datePublished":"2026-09-09T01:28:29Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3483"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:040c7718-7533-18bb-1c80-47f11d1ca9f9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C7C:FC5BE:12C517D:18F36B7:6B0123A1 |
| html-safe-nonce | 2110451a272f789b00277f86ecceeaa34cb7c4b8b64ec174569b0d67960d98be |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzdDOkZDNUJFOjEyQzUxN0Q6MThGMzZCNzo2QjAxMjNBMSIsInZpc2l0b3JfaWQiOiIzMTQ5Mzk3NDA3MTA0NTc0MzcwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | acb2a34562f6f52fee1daf183c91cf5447f54c3787dab2a34d4e44847c023cd0 |
| hovercard-subject-tag | issue:5393775217 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3483/issue_layout |
| twitter:image | https://opengraph.githubassets.com/77b0385d40e9fca361998eeb7900694925f1110b837029553cfdbca20fdbe4e8/modelcontextprotocol/python-sdk/issues/3483 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/77b0385d40e9fca361998eeb7900694925f1110b837029553cfdbca20fdbe4e8/modelcontextprotocol/python-sdk/issues/3483 |
| og:image:alt | Summary At 2026-07-28, a ClientSession that has not listed a tool sends tools/call with no Mcp-Param-* headers, the server rejects it with -32020, and the client stops there. SEP-2243 says it SHOUL... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | atsuki-shirasawa |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width