Skip to content

Commit fa9c543

Browse files
committed
Adapt the legacy_routing story to the Mcp-Method header rung in classify_inbound_request
`classify_inbound_request` now also requires the `Mcp-Method` header to match the body's method (and `Mcp-Name` for name-bearing methods). The story's "shown directly" demonstration hand-builds a modern header set, so it now carries `Mcp-Method` too; the real HTTP arms already did via `Client`.
1 parent b7081bf commit fa9c543

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

examples/stories/legacy_routing/client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from mcp_types.version import LATEST_HANDSHAKE_VERSION, LATEST_MODERN_VERSION
88

99
from mcp.client import Client
10-
from mcp.shared.inbound import MCP_PROTOCOL_VERSION_HEADER, InboundLadderRejection
10+
from mcp.shared.inbound import MCP_METHOD_HEADER, MCP_PROTOCOL_VERSION_HEADER, InboundLadderRejection
1111
from stories._harness import TargetFactory, run_client
1212

1313
from .server import classify_era
@@ -31,9 +31,9 @@ async def main(targets: TargetFactory, *, mode: str = "auto") -> None:
3131
assert legacy.protocol_version == LATEST_HANDSHAKE_VERSION
3232
assert _arm(await legacy.call_tool("which_arm", {})) == "legacy"
3333

34-
# ── the exported predicate, shown directly. A body carrying the 2026 _meta
35-
# envelope classifies as modern; a bare initialize body classifies as legacy;
36-
# a 2026 envelope whose header disagrees is a rejection (NOT legacy).
34+
# ── the exported predicate, shown directly. A 2026 _meta envelope whose
35+
# `Mcp-Protocol-Version`/`Mcp-Method` headers mirror it is modern; a bare
36+
# initialize body is legacy; a header that disagrees is a rejection (NOT legacy).
3737
modern_body: dict[str, Any] = {
3838
"jsonrpc": "2.0",
3939
"id": 1,
@@ -46,12 +46,15 @@ async def main(targets: TargetFactory, *, mode: str = "auto") -> None:
4646
}
4747
},
4848
}
49-
assert classify_era(modern_body, headers={MCP_PROTOCOL_VERSION_HEADER: LATEST_MODERN_VERSION}) == "modern"
49+
modern_headers = {MCP_PROTOCOL_VERSION_HEADER: LATEST_MODERN_VERSION, MCP_METHOD_HEADER: "tools/list"}
50+
assert classify_era(modern_body, headers=modern_headers) == "modern"
5051

5152
legacy_body: dict[str, Any] = {"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}
5253
assert classify_era(legacy_body, headers={}) == "legacy"
5354

54-
mismatched = classify_era(modern_body, headers={MCP_PROTOCOL_VERSION_HEADER: LATEST_HANDSHAKE_VERSION})
55+
# The SAME complete header set, with only the protocol version disagreeing with the body.
56+
mismatched_headers = modern_headers | {MCP_PROTOCOL_VERSION_HEADER: LATEST_HANDSHAKE_VERSION}
57+
mismatched = classify_era(modern_body, headers=mismatched_headers)
5558
assert isinstance(mismatched, InboundLadderRejection), mismatched
5659

5760

0 commit comments

Comments
 (0)