René's URL Explorer Experiment


Title: Concurrent requests sharing a JSON-RPC id on one session receive each other's responses · Issue #3137 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Concurrent requests sharing a JSON-RPC id on one session receive each other's responses · Issue #3137 · modelcontextprotocol/python-sdk

X Title: Concurrent requests sharing a JSON-RPC id on one session receive each other's responses · Issue #3137 · modelcontextprotocol/python-sdk

Description: Concurrent requests sharing a JSON-RPC id on one session receive each other's responses Repo: modelcontextprotocol/python-sdk Versions: reproduced on mcp 1.28.1 (latest) with fastmcp 3.4.4, and on mcp 1.26.0 with fastmcp 3.2.0. Python 3....

Open Graph Description: Concurrent requests sharing a JSON-RPC id on one session receive each other's responses Repo: modelcontextprotocol/python-sdk Versions: reproduced on mcp 1.28.1 (latest) with fastmcp 3.4.4, and on ...

X Description: Concurrent requests sharing a JSON-RPC id on one session receive each other's responses Repo: modelcontextprotocol/python-sdk Versions: reproduced on mcp 1.28.1 (latest) with fastmcp 3.4.4, and...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3137

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Concurrent requests sharing a JSON-RPC id on one session receive each other's responses","articleBody":"# Concurrent requests sharing a JSON-RPC id on one session receive each other's responses\n\n**Repo:** `modelcontextprotocol/python-sdk`\n**Versions:** reproduced on `mcp` 1.28.1 (latest) with `fastmcp` 3.4.4, and on `mcp` 1.26.0 with `fastmcp` 3.2.0. Python 3.14, macOS + Linux.\n**Transport:** streamable HTTP, stateful (default)\n\n## Summary\n\nIn stateful streamable HTTP, the server registers each in-flight request's response stream in a per-session dict keyed by the **bare JSON-RPC request id**. In `_handle_post_request` (`src/mcp/server/streamable_http.py`), both the JSON-response and SSE branches do this:\n\n```python\nrequest_id = str(message.id)\n...\nself._request_streams[request_id] = anyio.create_memory_object_stream[EventMessage](\n    REQUEST_STREAM_BUFFER_SIZE\n)\nrequest_stream_reader = self._request_streams[request_id][1]\n```\n\nThe assignment is unconditional. If a second request arrives on the same session with an id that is already in flight, it silently **overwrites** the first request's stream entry. When the first request's handler completes, the response is routed to whatever stream currently sits at that key:\n\n```python\nif request_stream_id in self._request_streams:\n    await self._request_streams[request_stream_id][0].send(EventMessage(message, event_id))\n```\n\nThe result is that **one caller receives another caller's response payload**, and the rightful caller's POST hangs until it times out.\n\nJSON-RPC 2.0 requires ids to be unique only within a client's own request stream. Any component that multiplexes multiple logical clients over one MCP session — a gateway, a proxy, a connector with a shared session pool — will produce colliding ids as normal operation, because each client leg numbers its own requests independently from 1.\n\n## Reproduction\n\n`server.py`:\n\n```python\nimport time\nfrom fastmcp import FastMCP\n\nmcp = FastMCP(\"crossing-repro\")\n\n@mcp.tool()\ndef alice() -> str:\n    \"\"\"Finishes first (1s).\"\"\"\n    time.sleep(1)\n    return \"SECRET-BELONGING-TO-ALICE\"\n\n@mcp.tool()\ndef bob() -> str:\n    \"\"\"Finishes later (3s).\"\"\"\n    time.sleep(3)\n    return \"SECRET-BELONGING-TO-BOB\"\n\nif __name__ == \"__main__\":\n    mcp.run(transport=\"http\", host=\"127.0.0.1\", port=8177, show_banner=False)\n```\n\n`client.py` — one session, two concurrent `tools/call` POSTs sharing `id=2`. Leg A calls `alice` at t=0; leg B calls `bob` at t=0.3s:\n\n```python\nimport json, threading, httpx\n\nBASE = \"http://127.0.0.1:8177/mcp\"\nHEADERS = {\"Content-Type\": \"application/json\",\n           \"Accept\": \"application/json, text/event-stream\"}\nCOLLIDING_ID = 2\n\ndef payloads(resp):\n    msgs = [json.loads(l[6:]) for l in resp.text.splitlines() if l.startswith(\"data: \")]\n    out = []\n    for msg in msgs:\n        try:\n            out.append(msg[\"result\"][\"content\"][0][\"text\"])\n        except (KeyError, IndexError, TypeError):\n            out.append(json.dumps(msg))\n    return out\n\nwith httpx.Client(timeout=12) as c:\n    r = c.post(BASE, headers=HEADERS, json={\n        \"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"initialize\",\n        \"params\": {\"protocolVersion\": \"2025-06-18\", \"capabilities\": {},\n                   \"clientInfo\": {\"name\": \"repro\", \"version\": \"0\"}}})\n    h = dict(HEADERS, **{\"mcp-session-id\": r.headers[\"mcp-session-id\"]})\n    c.post(BASE, headers=h, json={\"jsonrpc\": \"2.0\",\n                                  \"method\": \"notifications/initialized\"})\n\n    results = {}\n    def leg(name, tool, delay):\n        import time as t\n        t.sleep(delay)\n        try:\n            rr = c.post(BASE, headers=h, json={\n                \"jsonrpc\": \"2.0\", \"id\": COLLIDING_ID, \"method\": \"tools/call\",\n                \"params\": {\"name\": tool, \"arguments\": {}}})\n            results[name] = (tool, rr.status_code, payloads(rr))\n        except httpx.ReadTimeout:\n            results[name] = (tool, \"TIMEOUT\", [])\n\n    ts = [threading.Thread(target=leg, args=(\"leg A\", \"alice\", 0.0)),\n          threading.Thread(target=leg, args=(\"leg B\", \"bob\", 0.3))]\n    for t_ in ts: t_.start()\n    for t_ in ts: t_.join()\n    for name in (\"leg A\", \"leg B\"):\n        tool, status, body = results[name]\n        print(f\"{name} called {tool!r:8} -> HTTP {status}; \"\n              f\"received: {body[0] if body else '(nothing — request hung)'}\")\n```\n\n## Actual output\n\n```\nleg A called 'alice'  -> HTTP TIMEOUT; received: (nothing — request hung)\nleg B called 'bob'    -> HTTP 200;     received: SECRET-BELONGING-TO-ALICE\n```\n\nLeg B asked for `bob` and was handed `alice`'s return value. Leg A never received anything. Identical output on `mcp` 1.28.1 / `fastmcp` 3.4.4 and on 1.26.0 / 3.2.0.\n\n## Expected\n\nEach POST receives the response to the request it sent. If the server cannot support a duplicate in-flight id on one session, it should reject the second request explicitly (e.g. an `-32600` error naming the collision) rather than silently rerouting a response to the wrong caller.\n\n## Why this matters\n\nBeyond the correctness bug, on a multi-tenant or gateway-fronted server the misrouted payload is **another caller's data**, delivered to a caller that never requested it and cannot tell it is wrong. There is no error, no warning, and nothing in the response that identifies the mismatch — the payload is a well-formed JSON-RPC result carrying the colliding id. We hit this in production: a tool call returned a completely unrelated tool's receipt from a different logical session, and the only reason it was caught is that the payload shape was obviously wrong for the call that was made. A same-shaped response would have passed silently.\n\n## Workaround (verified)\n\nRunning the server in stateless mode gives each request its own transport, so the shared per-session registry never comes into play. Same repro, `FASTMCP_STATELESS_HTTP=true`:\n\n```\nleg A called 'alice'  -> HTTP 200; received: SECRET-BELONGING-TO-ALICE   [OK]\nleg B called 'bob'    -> HTTP 200; received: SECRET-BELONGING-TO-BOB     [OK]\n```\n\nThis is only available to servers that don't need stateful features (server-initiated messages, resumability, subscriptions).\n\n## Related\n\n#1764 touches the same `_request_streams` registration but is a different failure mode (zero-buffer deadlock, since fixed by `REQUEST_STREAM_BUFFER_SIZE`). The id-collision misrouting described here is unaffected by that fix and reproduces on current `main`'s logic.\n\n## Suggested fix\n\nEither:\n\n1. **Key the registry by something unique per request** rather than the raw JSON-RPC id — e.g. `(stream/transport identity, request id)`, or an internally-minted token. This preserves current behavior for well-behaved single-client sessions and fixes multiplexed ones.\n2. **Reject the collision explicitly** — if `request_id` is already present in `_request_streams`, return a JSON-RPC error for the second request instead of overwriting. Less useful for gateways, but it converts silent data misrouting into a loud, diagnosable failure.\n\nOption 1 is preferable: id collisions across independent client legs are legal JSON-RPC, so a gateway shouldn't have to rewrite ids to stay correct.\n\nI'm happy to open a PR for either approach if you'd like to indicate a preference.\n","author":{"url":"https://github.com/touchedtone","@type":"Person","name":"touchedtone"},"datePublished":"2026-07-19T23:10:20Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3137"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:49053abf-f6ec-7117-6b8e-8baae5968d75
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCA5C:29AEE8:A1E9D:DD44A:6B00B9A2
html-safe-nonce9d41d6f4c649f521ef4927841d9869e3c8b8d4335464b9c5b2d57a6d91685de0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTVDOjI5QUVFODpBMUU5RDpERDQ0QTo2QjAwQjlBMiIsInZpc2l0b3JfaWQiOiIxOTg3MjgzOTQyMzM5ODE5OTM4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac094e4a5f5e01dd7f75689cec3b04d00b505abc18dbd7be88094844a90162fce0
hovercard-subject-tagissue:4924751237
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3137/issue_layout
twitter:imagehttps://opengraph.githubassets.com/cc606213e80fced1474f1619c93ce4fc8221038365e904e3d33635900b2308d8/modelcontextprotocol/python-sdk/issues/3137
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/cc606213e80fced1474f1619c93ce4fc8221038365e904e3d33635900b2308d8/modelcontextprotocol/python-sdk/issues/3137
og:image:altConcurrent requests sharing a JSON-RPC id on one session receive each other's responses Repo: modelcontextprotocol/python-sdk Versions: reproduced on mcp 1.28.1 (latest) with fastmcp 3.4.4, and on ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametouchedtone
hostnamegithub.com
expected-hostnamegithub.com
None1d07c25977adfc5ff6acb0a962a9bc168c07afbda6fef765f9761c350c2ae4a2
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5429cbfc6aca8c7b9a086a3c8f47400346f38cc9
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/3137#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3137
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3137
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3137
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3137
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3137
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues308 (308)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
https://github.com/modelcontextprotocol/python-sdk
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3137
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3137
Concurrent requests sharing a JSON-RPC id on one session receive each other's responseshttps://github.com/modelcontextprotocol/python-sdk/issues/3137#top
https://github.com/touchedtone
touchedtonehttps://github.com/touchedtone
on Jul 19, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3137#issue-4924751237
#1764https://github.com/modelcontextprotocol/python-sdk/issues/1764
https://github.com/Ben-Home
Ben-Homehttps://github.com/Ben-Home
on Jul 20, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3137#issuecomment-5024935919
ariaxhanhttps://github.com/ariaxhan
on Jul 24, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3137#event-28459657507
fix(streamable-http): keep concurrent requests sharing a JSON-RPC id …https://github.com/ariaxhan/python-sdk/commit/0aea6ac315247a232b2f8a10b04ba8dee4daa55f
https://docs.github.com/articles/closing-issues-via-commit-messages
0aea6achttps://github.com/ariaxhan/python-sdk/commit/0aea6ac315247a232b2f8a10b04ba8dee4daa55f
https://github.com/tirthfx
tirthfxhttps://github.com/tirthfx
on Jul 25, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3137#issuecomment-5078859153
#3163https://github.com/modelcontextprotocol/python-sdk/pull/3163
https://github.com/maxisbey
maxisbeyhttps://github.com/maxisbey
on Aug 14, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3137#issuecomment-5292551502
#2655https://github.com/modelcontextprotocol/python-sdk/issues/2655
#3060https://github.com/modelcontextprotocol/python-sdk/issues/3060
#2655https://github.com/modelcontextprotocol/python-sdk/issues/2655
#2655https://github.com/modelcontextprotocol/python-sdk/issues/2655
AI Disclaimerhttps://gist.github.com/maxisbey/6123d132484e4c533eab519a2800693d
maxisbeyhttps://github.com/maxisbey
not plannedhttps://github.com/modelcontextprotocol/python-sdk/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Aug 14, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3137#event-29453920991
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3137
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3137
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.