René's URL Explorer Experiment


Title: Issue · GitHub

Open Graph Title: Issue · modelcontextprotocol/python-sdk

X Title: Issue · modelcontextprotocol/python-sdk

Description: The official Python SDK for Model Context Protocol servers and clients - Issue · modelcontextprotocol/python-sdk

Open Graph Description: The official Python SDK for Model Context Protocol servers and clients - Issue · modelcontextprotocol/python-sdk

X Description: The official Python SDK for Model Context Protocol servers and clients - Issue · modelcontextprotocol/python-sdk

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"RequestResponder.__exit__ leaks CancelledError on cancelled request, killing the stdio receive loop","articleBody":"## Summary\n\nWhen a client sends `notifications/cancelled` for an in-flight request handled over stdio, the server's receive loop task group dies. The process stays alive but stops reading stdin, so every subsequent request hangs and the client eventually reports `MCP error -32000: Connection closed`. The bug is racy — it reproduces in roughly 40–80% of attempts depending on platform timing.\n\nAffects: `mcp` 1.26.0 and 1.27.1 (latest at time of writing). Confirmed with FastMCP 3.1.x and the in-tree stdio server.\n\n## Reproduction\n\nA standalone subprocess test is in [mlorentedev/hive `tests/test_transport_recovery.py`](https://github.com/mlorentedev/hive/blob/master/tests/test_transport_recovery.py). The relevant flow:\n\n1. `initialize` → ack\n2. `notifications/initialized`\n3. `tools/call id=2`\n4. `notifications/cancelled` for `requestId=2` (within a few ms of step 3)\n5. Receive: `{\"id\": 2, \"error\": {\"code\": 0, \"message\": \"Request cancelled\"}}` ← OK\n6. `tools/call id=3`\n7. **No response.** Server is alive but `proc.stdout.readline()` hangs.\n\n## Root cause\n\n`mcp.shared.session.RequestResponder.__exit__`:\n\n```python\ndef __exit__(self, exc_type, exc_val, exc_tb):\n    try:\n        if self._completed:\n            self._on_complete(self)\n    finally:\n        self._entered = False\n        ...\n        self._cancel_scope.__exit__(exc_type, exc_val, exc_tb)  # ← (A)\n```\n\nWhen `notifications/cancelled` arrives, `RequestResponder.cancel()` calls `self._cancel_scope.cancel()` and sends the error response. The handler task catches the `CancelledError` in `mcp/server/lowlevel/server.py` (around line 766) and `return`s. The `with responder:` block then exits with `exc_type=None` while the cancel scope is still in cancelled state — at line (A), anyio's `CancelScope.__exit__` re-raises `CancelledError`.\n\nThat exception bubbles up to:\n\n```python\nasync with anyio.create_task_group() as tg:\n    async for message in session.incoming_messages:\n        tg.start_soon(self._handle_message, ...)\n```\n\n…in `Server._run`. anyio task groups cancel all sibling tasks and propagate the cancellation. The receive loop is one of those sibling tasks, so it dies.\n\n## Suggested fix\n\nSwallow the spurious cancellation when the responder has already sent its response:\n\n```python\ndef __exit__(self, exc_type, exc_val, exc_tb):\n    try:\n        if self._completed:\n            self._on_complete(self)\n    finally:\n        self._entered = False\n        if not self._cancel_scope:\n            raise RuntimeError(\"No active cancel scope\")\n        try:\n            self._cancel_scope.__exit__(exc_type, exc_val, exc_tb)\n        except BaseException as exc:\n            if self._completed and isinstance(exc, anyio.get_cancelled_exc_class()):\n                # cancel() already sent the error response — the scope's\n                # re-raised cancellation is spurious.\n                return\n            raise\n```\n\nMirrors what we ship in [hive `src/hive/_compat.py`](https://github.com/mlorentedev/hive/blob/master/src/hive/_compat.py).\n\n## Workaround used downstream\n\nWe monkey-patch `RequestResponder.__exit__` at import time. The patch is self-gated (only fires when `_completed=True` AND the leaking exception is `anyio.get_cancelled_exc_class()`), so it stays inert once a fix lands upstream.\n\n## Environment\n\n- Reproduced on Windows 11 (`mcp` 1.26.0, 1.27.1) and via Claude Code as the host.\n- Tracked downstream in [mlorentedev/hive#75](https://github.com/mlorentedev/hive/issues/75).\n- Regression test passes 5/5 with the patch applied on Python 3.12; fails 2/5 — 4/5 without it.\n- Python 3.13 appears to have additional uncancel semantics that the patch does not yet fully cover — verification in progress.","author":{"url":"https://github.com/mlorentedev","@type":"Person","name":"mlorentedev"},"datePublished":"2026-05-15T19:52:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/2610/python-sdk/issues/2610"}

route-pattern/:user_id/:repository/issues/:id(.:format)
route-controllerissues
route-actionshow
fetch-noncev2:c37da62a-b0b8-6f4e-e36c-c67be7f9d04f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE61C:84D9B:56882E:7B991D:6A59E465
html-safe-noncea1c2143cf710aa5df1822ef081148453b43aba80253067a4bb0ea5a4101e0ef0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjFDOjg0RDlCOjU2ODgyRTo3Qjk5MUQ6NkE1OUU0NjUiLCJ2aXNpdG9yX2lkIjoiMTk2MzY4ODE4NjU3MzYxMjEzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac85c3242447647783ddd82376b77a227e972424bfbd87a0d2e7804afb8befa87e
hovercard-subject-tagrepository:862584018
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///issues/show
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/issues/2610
twitter:imagehttps://opengraph.githubassets.com/0c85fdcdce59303eecd8e75d43b66bc4c32ef2d2d1f6371b5f07b246412f03a6/modelcontextprotocol/python-sdk
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0c85fdcdce59303eecd8e75d43b66bc4c32ef2d2d1f6371b5f07b246412f03a6/modelcontextprotocol/python-sdk
og:image:altThe official Python SDK for Model Context Protocol servers and clients - Issue · modelcontextprotocol/python-sdk
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneba3976babb66479b1c943a8edc0777d96157da48fadc0161f9ddb219deee8353
turbo-cache-controlno-cache
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
release26f17126414f953984d8ae42f57c0db48e7dbde3
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/2610#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F2610
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%2F2610
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%2Fissues%2Fshow&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2610
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2610
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2610
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/issues/2610
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
#2624https://github.com/modelcontextprotocol/python-sdk/pull/2624
RequestResponder.__exit__ leaks CancelledError on cancelled request, killing the stdio receive loophttps://github.com/modelcontextprotocol/python-sdk/issues/2610#top
#2624https://github.com/modelcontextprotocol/python-sdk/pull/2624
potentially closeBot recommends closing — needs maintainer reviewhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22potentially%20close%22
https://github.com/mlorentedev
mlorentedevhttps://github.com/mlorentedev
on May 15, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2610#issue-4456573446
mlorentedev/hive tests/test_transport_recovery.pyhttps://github.com/mlorentedev/hive/blob/master/tests/test_transport_recovery.py
hive src/hive/_compat.pyhttps://github.com/mlorentedev/hive/blob/master/src/hive/_compat.py
mlorentedev/hive#75https://github.com/mlorentedev/hive/issues/75
potentially closeBot recommends closing — needs maintainer reviewhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22potentially%20close%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.