René's URL Explorer Experiment


Title: streamable-http client: no size bound before JSONRPCMessage.model_validate_json — one large server message can OOM the client · Issue #3330 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: streamable-http client: no size bound before JSONRPCMessage.model_validate_json — one large server message can OOM the client · Issue #3330 · modelcontextprotocol/python-sdk

X Title: streamable-http client: no size bound before JSONRPCMessage.model_validate_json — one large server message can OOM the client · Issue #3330 · modelcontextprotocol/python-sdk

Description: Summary StreamableHTTPTransport parses every inbound SSE event and JSON response body with JSONRPCMessage.model_validate_json / model_validate_json(content) and no size bound. Because pydantic validation of a large JSON document allocate...

Open Graph Description: Summary StreamableHTTPTransport parses every inbound SSE event and JSON response body with JSONRPCMessage.model_validate_json / model_validate_json(content) and no size bound. Because pydantic vali...

X Description: Summary StreamableHTTPTransport parses every inbound SSE event and JSON response body with JSONRPCMessage.model_validate_json / model_validate_json(content) and no size bound. Because pydantic vali...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"streamable-http client: no size bound before JSONRPCMessage.model_validate_json — one large server message can OOM the client","articleBody":"### Summary\n\n`StreamableHTTPTransport` parses every inbound SSE event and JSON response body with `JSONRPCMessage.model_validate_json` / `model_validate_json(content)` and no size bound. Because pydantic validation of a large JSON document allocates several times the wire size in live Python objects, a single oversized message from a server can exhaust the client's memory. There is no hook to inspect or reject a message before it is parsed.\n\nWe hit this in production: a client connected to ~30 MCP servers, one of which answered `tools/list` with a **21.9 MB** single SSE event. Measured with `tracemalloc` at the parse site:\n\n```\n#1  663.4 MB in 9,957,044 blocks\n    mcp/client/streamable_http.py:217\n      message = JSONRPCMessage.model_validate_json(sse.data)\n#2  46.9 MB in 3 blocks\n    httpx_sse/_decoders.py:61   (whole event buffered as one string)\n#3  46.9 MB in 2 blocks\n    httpx_sse/_decoders.py:120  (copy from slicing)\n```\n\nRoughly a 7× amplification of the wire size in live objects, transient but concurrent with other parses. A trivial request that triggered only catalogue loading peaked at **2.35 GB** RSS from a 56 MB baseline; heavier concurrent work reached **4.2 GB**. Removing that one server dropped the same request's peak to **456 MB**. Versions: `mcp` 1.27.1, Python 3.14.\n\n### Why a client-side bound is needed\n\nThe client cannot know in advance that a server will return a huge payload, and a misbehaving or misconfigured server should not be able to OOM its client. Today the only outcome is process death with nothing identifying the responsible server — the failure surfaces as an unexplained kill rather than an actionable error.\n\n### What we did as a workaround, and why it was awkward\n\nWe wrapped `StreamableHTTPTransport._handle_sse_event` and `_handle_json_response` to measure `sse.data` / the response body and reject anything over a configured cap before parsing. Two things made this harder than expected, and both seem worth addressing upstream:\n\n1. **Raising from the handler is not viable.** Every call site wraps it in `except Exception: logger.debug(...)` and then reconnects with `Last-Event-ID`, which replays the same oversized payload. The raise is swallowed and the pending request hangs.\n2. **Delivering a bare `Exception` on the read stream does not fail the request either.** In `BaseSession._receive_loop`, `isinstance(message, Exception)` routes to `_handle_incoming`, which for the default message handler is a no-op; only a `JSONRPCResponse`/`JSONRPCError` matching `_response_streams[request_id]` completes `send_request`, and that awaits with `timeout=None`. To fail the request we had to synthesize a `JSONRPCError` and recover the request id from the raw payload with a regex, since parsing it is exactly what we were trying to avoid.\n\n### Suggested improvements\n\n- An optional client-side maximum message size (constructor argument and/or environment variable) enforced **before** `model_validate_json`, on both the SSE and `application/json` paths.\n- When it trips, fail the corresponding pending request with a distinct error identifying the endpoint and the observed size, rather than letting the reconnect path replay the payload.\n- Failing that, a documented hook to inspect a raw message before parsing would let clients implement this without patching private methods.\n- Independently: `_handle_sse_event` returning `False` for a parse failure causes the caller to treat the stream as ended and reconnect with `Last-Event-ID`; for a deterministic failure (such as a payload that will always be too large, or malformed JSON) this retries something that cannot succeed.\n\nHappy to open a PR if a maintainer indicates the preferred shape (constructor arg vs. env var vs. pre-parse hook).\n","author":{"url":"https://github.com/aartaria","@type":"Person","name":"aartaria"},"datePublished":"2026-08-18T08:15:17Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3330"}

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:3f10b36e-0d34-9ef3-82d7-e99457ac494e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8660:1148D3:14EFC26:1AC2059:6B0130FE
html-safe-nonced17e43ff387d903464c6ab433167f2ef4a211328dfc4a8568660fa09cd67dda3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjYwOjExNDhEMzoxNEVGQzI2OjFBQzIwNTk6NkIwMTMwRkUiLCJ2aXNpdG9yX2lkIjoiMjgxODM0NDI3ODU3MTQzMDE0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9c71a51f972bf19ea1bb2bafd13d16949664e3cc10a37fabcaebc0bd88348c8e
hovercard-subject-tagissue:5179664911
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/3330/issue_layout
twitter:imagehttps://opengraph.githubassets.com/33b4386eae4fb86916afb8de5b21ab8eeb49c1b5647dfe18ab1d7be330834de0/modelcontextprotocol/python-sdk/issues/3330
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/33b4386eae4fb86916afb8de5b21ab8eeb49c1b5647dfe18ab1d7be330834de0/modelcontextprotocol/python-sdk/issues/3330
og:image:altSummary StreamableHTTPTransport parses every inbound SSE event and JSON response body with JSONRPCMessage.model_validate_json / model_validate_json(content) and no size bound. Because pydantic vali...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameaartaria
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/3330#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F3330
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%2F3330
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/3330
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3330
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/3330
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues315 (315)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/3330
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3330
streamable-http client: no size bound before JSONRPCMessage.model_validate_json — one large server message can OOM the clienthttps://github.com/modelcontextprotocol/python-sdk/issues/3330#top
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
v1Affects the v1.x maintenance linehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v1%22
v2Affects the v2 line (2.x on main)https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
https://github.com/aartaria
aartariahttps://github.com/aartaria
on Aug 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3330#issue-5179664911
https://github.com/Ben-Home
Ben-Homehttps://github.com/Ben-Home
on Aug 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3330#issuecomment-5328001477
maxisbeyhttps://github.com/maxisbey
v1Affects the v1.x maintenance linehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v1%22
v2Affects the v2 line (2.x on main)https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
on Aug 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3330#event-29625190976
https://github.com/tarunag10
tarunag10https://github.com/tarunag10
on Aug 20, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3330#issuecomment-5352650031
#3338https://github.com/modelcontextprotocol/python-sdk/pull/3338
https://github.com/Vish12345678673
Vish12345678673https://github.com/Vish12345678673
on Sep 18, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3330#issuecomment-5730414781
claudehttps://github.com/apps/claude
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
on Oct 8, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3330#event-32781087140
https://github.com/Suhas-123-cell
Suhas-123-cellhttps://github.com/Suhas-123-cell
on Oct 29, 2026https://github.com/modelcontextprotocol/python-sdk/issues/3330#issuecomment-6494809649
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3330
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/3330
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
v1Affects the v1.x maintenance linehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v1%22
v2Affects the v2 line (2.x on main)https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22v2%22
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.