Repository navigation
Description
What happened
The shared POST check uses content_type.lower().startswith("application/json") (src/mcp/server/transport_security.py:96). The modern route has no further media-type check, so a valid JSON-RPC body labelled application/jsonx or application/json-seq is dispatched and returns 200. The legacy route has its own check (src/mcp/server/streamable_http.py:529-534) and rejects both with 415, so the two routes disagree.
Expected
Reject POST bodies labelled with a different media type before dispatch (4xx), while still accepting application/json with parameters such as ; charset=utf-8.
Reproduce (main at 77001c9, in-process, no network, via Server.streamable_http_app()):
import json
import anyio
import httpx2
from mcp.server import Server
from mcp.server.transport_security import TransportSecuritySettings
from mcp.types import CallToolResult
from mcp_types import CLIENT_CAPABILITIES_META_KEY, PROTOCOL_VERSION_META_KEY
from mcp_types.version import LATEST_MODERN_VERSION
MODERN = {
"mcp-protocol-version": LATEST_MODERN_VERSION,
"mcp-method": "tools/call",
"mcp-name": "probe",
"accept": "application/json",
}
CALL = json.dumps({
"jsonrpc": "2.0", "id": 1, "method": "tools/call",
"params": {
"_meta": {PROTOCOL_VERSION_META_KEY: LATEST_MODERN_VERSION, CLIENT_CAPABILITIES_META_KEY: {}},
"name": "probe", "arguments": {"q": "ok"},
},
}).encode()
LEGACY_INIT = json.dumps({
"jsonrpc": "2.0", "id": 1, "method": "initialize",
"params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "t", "version": "1"}},
}).encode()
async def main():
async def tool(ctx, params):
return CallToolResult(content=[])
app = Server("probe", on_call_tool=tool).streamable_http_app(
json_response=True, stateless_http=True,
transport_security=TransportSecuritySettings(allowed_hosts=["test"]),
)
async with app.router.lifespan_context(app), httpx2.AsyncClient(
transport=httpx2.ASGITransport(app=app), base_url="http://test"
) as c:
for ct in ("application/json", "application/json; charset=utf-8",
"application/jsonx", "application/json-seq", "text/plain"):
r = await c.post("/mcp", content=CALL, headers=MODERN | {"content-type": ct})
print(f"modern tools/call {ct:33} -> {r.status_code}")
for ct in ("application/jsonx", "application/json-seq"):
r = await c.post("/mcp", content=LEGACY_INIT,
headers={"accept": "application/json, text/event-stream", "content-type": ct})
print(f"legacy initialize {ct:33} -> {r.status_code}")
anyio.run(main)Output:
modern tools/call application/json -> 200
modern tools/call application/json; charset=utf-8 -> 200
modern tools/call application/jsonx -> 200
modern tools/call application/json-seq -> 200
modern tools/call text/plain -> 400
legacy initialize application/jsonx -> 415
legacy initialize application/json-seq -> 415
Low severity. Found while hardening my own MCP server built on this SDK. If you'd take an outside PR, I'd like to fix this myself.
AI disclosure: I used AI tools in my own detection-and-fix workflow; I ran the reproduction myself.
Activity
beartester34 commentedon Dec 1, 2026
Duplicate of #3691, which already covers the
application/jsonxcase on the modern transport. I missed it in my search, sorry for the noise. Closing.