[BUG]: Gateway forwards the client 2026-07-28 envelope `_meta` keys to handshake-era upstreams; MCP Python SDK 2.x stdio servers behind `translate` reject every call
Existing issue check
- [x] I searched the existing issues for this bug
Bug summary
When a modern client (2026-07-28, e.g. Claude Code 2.1.x) calls a tool, tools/call carries the per-request envelope in params._meta: io.modelcontextprotocol/protocolVersion, clientInfo, clientCapabilities. The gateway copies the whole inbound _meta (streamablehttp_transport.call_tool → meta_data = dict(ctx.meta)) and passes it as meta= to the upstream session.call_tool().
If the upstream session is handshake-era (the upstream answered initialize, or server/discover failed), the SDK client's handshake stamp only sets the MCP-Protocol-Version header and leaves the caller's _meta alone. The inbound hop's envelope keys therefore reach a handshake-era connection.
An MCP Python SDK 2.x server on stdio (serve_dual_era_loop, python-sdk#3152) locks the connection's era on its first request and refuses any enveloped request on a handshake connection with -32600:
MCP server error: this connection serves the handshake protocol era; requests carrying the 2026-07-28 envelope are not accepted on it
This hits every stdio server wrapped by mcpgateway.translate --stdio … --expose-streamable-http. That bridge forwards each POST /mcp body as-is to a single shared stdio process, so the first request after startup fixes the era for every client. A health-check initialize usually arrives first, which gives the handshake era.
Steps to reproduce
- A
mcp2.3.0 server on stdio, e.g.netbox-mcp-server1.3.1 (fastmcp 4.2.6), behindpython -m mcpgateway.translate --stdio netbox-mcp-server --expose-streamable-http --port 9100. - Send one
initializeto:9100/mcp(as a container health check does). - Register
http://…:9100/mcpas a STREAMABLEHTTP gateway and put its tools in a virtual server. - Call a tool through
/servers/<id>/mcp:
| inbound client | result |
|---|---|
mcp.Client(mode="auto") → 2026-07-28 (envelope stamped by the SDK) |
-32600 above |
mcp.Client(mode="legacy"), _meta without the key |
OK |
mcp.Client(mode="legacy"), _meta={"io.modelcontextprotocol/protocolVersion": …} |
-32600 |
Claude Code 2.1.326 (claude -p, http MCP) |
-32600 |
Expected behavior
The envelope keys describe the inbound hop (client↔gateway). validators.MCP_ENVELOPE_META_KEYS already treats them as protocol metadata for limits. They should not be relayed upstream as user _meta:
- when the upstream session is handshake-era, strip
MCP_ENVELOPE_META_KEYSfrom the forwardedmeta_data. A handshake connection must not carry a 2026-07-28 envelope at all. - when it is modern, the upstream
Clientstamps its own envelope over these keys (observed: no refusal). Onmain, client-capability mirroring (#6642) readsctx.session.client_capabilities, not the raw_meta, so stripping the raw keys does not affect it.
Once python-sdk#3863 is fixed (a header/_meta mismatch gets 400 HeaderMismatch), the same relay would break HTTP handshake-era upstreams too, not only stdio ones.
Other forwarded keys (progressToken, traceparent, identity) stay as they are.
Actual behavior
Every tools/call from a 2026-07-28 client to a handshake-era stdio upstream fails with:
MCP server error: this connection serves the handshake protocol era; requests carrying the 2026-07-28 envelope are not accepted on it
The same server run natively over streamable HTTP is not affected, nor is a stdio wrapper that removes the three keys before the child process. over streamable HTTP is not affected, nor is a stdio wrapper that removes the three keys before the child process. MCP_CLIENT_CONNECT_MODE=legacy does not help. MCP_INBOUND_PROTOCOL_MODE=legacy does, because clients then fall back to initialize and stop stamping, but it disables 2026-07-28 for every client of the gateway.
Affected area
- [x] Gateway core (API, services, middleware)
- [ ] Admin UI
- [x] Federation or transports (SSE, WebSocket, stdio, gRPC)
- [ ] Auth, RBAC, or security
- [ ] Rust runtime (crates/mcp_runtime)
- [ ] CLI, Makefile, or scripts
- [ ] Containers or CI
- [ ] Documentation
- [ ] Other
Environment
- Version or commit: ContextForge v1.1.1 (
ghcr.io/ibm/mcp-context-forge:v1.1.1,mcp2.3.0);mcpgateway.translate1.1.1 (mcp2.2.0). Onmain(b438548367, 2026-11-25),_upstream_call_meta()dropsbaggageand replaces the trace fields but still copies the envelope keys. - Runtime: Python 3.12;
MCP_CLIENT_CONNECT_MODE=auto,MCP_INBOUND_PROTOCOL_MODE=auto - Platform / OS: Kubernetes (K3s) for the gateway; Docker for the
translatebridge - Container: official gateway image; bridge built from
mcp-contextforge-gateway1.1.1
Additional context (optional)
Possibly related: #6568 (closed, "_meta translation between MCP protocol versions": forwarding rules per key); #6642 (closed, client capabilities forwarded upstream); #7203 (open, reverse-proxy era negotiation, "handshake-era payloads pass through untouched"). SDK side, by design: python-sdk#3152; adjacent: python-sdk#3851 (era latched by the first request), #3863 (streamable HTTP routes by header only, which is why HTTP servers are not affected today).
Secondary, for translate: because one stdio process serves every HTTP client, the era depends on which client speaks first. If a server/discover arrives first, the process locks to 2026-07-28 and every later initialize, including the health check, is refused with -32022. We observed this when the gateway's registration probe reached a freshly started bridge first. translate could pin the child to the handshake era (send its own initialize at startup and strip envelope keys), or spawn one child per session.
Drafted with AI assistance (Claude); reproduced and verified on a real deployment before filing.
The fix needs three call sites, not one. The same intake block is in all three Streamable HTTP handlers: meta_data = dict(ctx.meta) at streamablehttp_transport.py 2331 (call_tool), 3302 (get_prompt) and 3521 (read_resource), and each forwards it into the same service path (2397, 2456 and 2546 for tools, 3324 for prompts, 3558 and 3577 for resources). Strip only in call_tool and a modern client behind translate still gets -32600 from prompts/get and resources/read on the same locked connection.
The split already exists in the tree: validators.py 2571 defines MCP_ENVELOPE_META_KEYS and 2627 builds user_keys from it for the limits. The shared helper can be that same comprehension, applied before _reject_invalid_meta, so all three handlers inherit one filter.
Strip unconditionally rather than branching on the upstream era: on an envelope-era hop the SDK stamps its own envelope values, so the upstream still receives the right ones.
Regression worth adding: a health-check initialize first (which locks the era), then prompts/get and resources/read through the same bridge. A call_tool-only fix leaves both of those failing.