René's URL Explorer Experiment


Title: Concurrent server-side requests are serialized end-to-end by BaseSession · Issue #2489 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Concurrent server-side requests are serialized end-to-end by BaseSession · Issue #2489 · modelcontextprotocol/python-sdk

X Title: Concurrent server-side requests are serialized end-to-end by BaseSession · Issue #2489 · modelcontextprotocol/python-sdk

Description: Description When a server tool issues multiple concurrent server to client requests over a single MCP session — for example, fanning out several ServerSession.create_message(...) (sampling) calls via asyncio.gather — only one is ever in ...

Open Graph Description: Description When a server tool issues multiple concurrent server to client requests over a single MCP session — for example, fanning out several ServerSession.create_message(...) (sampling) calls v...

X Description: Description When a server tool issues multiple concurrent server to client requests over a single MCP session — for example, fanning out several ServerSession.create_message(...) (sampling) calls v...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Concurrent server-side requests are serialized end-to-end by BaseSession","articleBody":"### Description\n\nWhen a server tool issues multiple concurrent server to client requests over a single MCP session — for example, fanning out several `ServerSession.create_message(...)` (sampling) calls via `asyncio.gather` — only one is ever in flight on the receiving side: `BaseSession._receive_loop` awaits each incoming request handler inline before reading the next message off the stream, so subsequent responses can't even be dequeued until the current handler returns. A minimal reproducer using `mcp.server.fastmcp.FastMCP` + `ClientSession` over the SDK's own in-memory transport (5 concurrent `create_message` calls, sampling callback sleeps 0.5s) shows peak in-flight = 1 and elapsed ≈ 2.5s instead of ≈ 0.5s.\n\nConcrete use case: a tool that fans out dozens of independent sampling requests per invocation against an LLM deployment with provisioned capacity sitting idle, the work is embarrassingly parallel and there's token budget to burn, but wall-clock scales linearly with the fan-out because every request blocks the next one. The same shape applies to elicitation, list-roots, and any other server to client request type, since they all flow through the same loop. \n\nI'd like the SDK to support concurrent handling of incoming requests on a single session, likely as an opt-in knob to preserve today's strict-ordering semantics for handlers that depend on them, with whatever bounding/back-pressure mechanism the maintainers prefer.\n\n### References\n\n```python\n\"\"\"Reproducer: concurrent server-\u003eclient requests are serialized end-to-end.\n\nA FastMCP tool fans out N concurrent ``ServerSession.create_message`` calls\nvia ``asyncio.gather``. The client's sampling callback records peak in-flight.\n\nExpected with concurrent dispatch:  peak == N,  elapsed ~= SLEEP\nObserved today:                     peak == 1,  elapsed ~= N * SLEEP\n\nRoot cause: ``BaseSession._receive_loop`` awaits each incoming request\nhandler inline before reading the next message off the stream\n(mcp/shared/session.py).\n\nRun:  python repro_concurrent_sampling.py\n\"\"\"\n\nimport asyncio\n\nfrom mcp.server.fastmcp import Context, FastMCP\nfrom mcp.shared.context import RequestContext\nfrom mcp.shared.memory import create_connected_server_and_client_session\nfrom mcp.types import (\n    CreateMessageRequestParams,\n    CreateMessageResult,\n    SamplingMessage,\n    TextContent,\n)\n\nN = 5\nSLEEP = 0.5\n\n\nasync def main() -\u003e None:\n    inflight = 0\n    peak = 0\n\n    async def sampling_callback(\n        _ctx: RequestContext,\n        params: CreateMessageRequestParams,\n    ) -\u003e CreateMessageResult:\n        nonlocal inflight, peak\n        inflight += 1\n        peak = max(peak, inflight)\n        try:\n            await asyncio.sleep(SLEEP)\n        finally:\n            inflight -= 1\n        msg = params.messages[0].content\n        echo = msg.text if isinstance(msg, TextContent) else \"\"\n        return CreateMessageResult(\n            role=\"assistant\",\n            content=TextContent(type=\"text\", text=f\"echo:{echo}\"),\n            model=\"test-model\",\n        )\n\n    server = FastMCP(\"repro\")\n\n    @server.tool()\n    async def fanout(ctx: Context) -\u003e str:\n        async def one(i: int) -\u003e str:\n            r = await ctx.session.create_message(\n                messages=[\n                    SamplingMessage(\n                        role=\"user\",\n                        content=TextContent(type=\"text\", text=str(i)),\n                    )\n                ],\n                max_tokens=8,\n            )\n            return r.content.text if isinstance(r.content, TextContent) else \"\"\n\n        return \",\".join(await asyncio.gather(*(one(i) for i in range(N))))\n\n    loop = asyncio.get_running_loop()\n    t0 = loop.time()\n    async with create_connected_server_and_client_session(\n        server, sampling_callback=sampling_callback\n    ) as session:\n        await session.call_tool(\"fanout\", {})\n    elapsed = loop.time() - t0\n\n    print(f\"N={N}, per-call sleep={SLEEP}s\")\n    print(f\"peak in-flight: {peak}    (concurrent: {N}, serialized: 1)\")\n    print(f\"elapsed:        {elapsed:.2f}s  (concurrent: ~{SLEEP}s, serialized: ~{N * SLEEP}s)\")\n\n    assert peak == N, (\n        f\"server-\u003eclient requests were serialized: peak in-flight={peak}, expected {N}\"\n    )\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```","author":{"url":"https://github.com/demoray","@type":"Person","name":"demoray"},"datePublished":"2026-04-21T21:00:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2489/python-sdk/issues/2489"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ca3661cf-a70d-286e-9f36-d7a3a0099d70
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD0C4:1F6472:20F08A:2E1805:6A59C3B5
html-safe-noncebb8750c5957e1429549126cc0bb6a84ce15f4af60bba893f0bcab62de614a05e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMEM0OjFGNjQ3MjoyMEYwOEE6MkUxODA1OjZBNTlDM0I1IiwidmlzaXRvcl9pZCI6IjY3ODI5MjIzNzQ5NTY4Mjc1NzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac0fbad6ccfe94f805ed27c03e7572f634ffea7afd06f5b8a674f0c0bc734204b5
hovercard-subject-tagissue:4305261666
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/2489/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f19dde24c2af54401694511b225deb921d43f0e07a056a387c9cf676c52fce79/modelcontextprotocol/python-sdk/issues/2489
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f19dde24c2af54401694511b225deb921d43f0e07a056a387c9cf676c52fce79/modelcontextprotocol/python-sdk/issues/2489
og:image:altDescription When a server tool issues multiple concurrent server to client requests over a single MCP session — for example, fanning out several ServerSession.create_message(...) (sampling) calls v...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedemoray
hostnamegithub.com
expected-hostnamegithub.com
Noneba3976babb66479b1c943a8edc0777d96157da48fadc0161f9ddb219deee8353
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
releaseab680789ae4a316cdaf0d5a292a1760140931cc4
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/2489#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F2489
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F2489
Sign up https://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/2489
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2489
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2489
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/issues/2489
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Star 23.6k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 255 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 303 https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality 6 https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Code https://github.com/modelcontextprotocol/python-sdk
Issues https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
#2838https://github.com/modelcontextprotocol/python-sdk/pull/2838
Concurrent server-side requests are serialized end-to-end by BaseSessionhttps://github.com/modelcontextprotocol/python-sdk/issues/2489#top
#2838https://github.com/modelcontextprotocol/python-sdk/pull/2838
https://github.com/demoray
demorayhttps://github.com/demoray
on Apr 21, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2489#issue-4305261666
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.