René's URL Explorer Experiment


Title: Server hangs when shutting down if a connection is still open · Issue #1272 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Server hangs when shutting down if a connection is still open · Issue #1272 · modelcontextprotocol/python-sdk

X Title: Server hangs when shutting down if a connection is still open · Issue #1272 · modelcontextprotocol/python-sdk

Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue Description Hello! I was testing m...

Open Graph Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ...

X Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening t...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Server hangs when shutting down if a connection is still open","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the latest version of MCP Python SDK\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Description\n\nHello!\n\nI was testing my MCP server with the inspector `npx @modelcontextprotocol/inspector` using streamable-http and I noticed that if the inspector is connected, the MCP Server will not shutdown.\n\nWe can't keep the server running if a client forgot to disconnect right?  This is tested with the official inspector tools, so there might be other clients working the same way.\n\nShouldn't the server close its active connections/tasks on shutdown?\n\n### Reproduction\n\n1. Run the server (see code snippet)\n2. In the MCP Inspector click \"connect\"\n3. In the server's terminal hit CTRL+C\n\nAt this point\n- The server shows `Waiting for connections to close (CTRL+C to force quit)` and CTRL+C doesn't work, in fact nothing works except killing the process\n- Clicking \"Disconned\" in the Inspector cannot disconnect, because `Error in /mcp route: TypeError: fetch failed`\n\n### Evidences\n\nShell execution\n\n```shell\n$ python demo-mcp.py                 \nINFO:     Started server process [10749]\nINFO:     Waiting for application startup.\n[08/14/25 11:03:16] INFO     StreamableHTTP session manager started                                                                                                                                                                                 streamable_http_manager.py:110\nINFO:     Application startup complete.\nINFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)\n[08/14/25 11:03:21] INFO     Created new transport with session ID: 4134f60ccda44baf8a01733ed94bc0d8                                                                                                                                                streamable_http_manager.py:233\nINFO:     127.0.0.1:54629 - \"POST /mcp HTTP/1.1\" 200 OK\nINFO:     127.0.0.1:54629 - \"POST /mcp HTTP/1.1\" 202 Accepted\nINFO:     127.0.0.1:54630 - \"GET /mcp HTTP/1.1\" 200 OK\n^CINFO:     Shutting down\nINFO:     Waiting for connections to close. (CTRL+C to force quit)\n```\n\nInspector proxy Disconnect error\n```\nReceived DELETE message for sessionId dd8a78d2-d5a8-4ff2-b679-6a8571f7cd0c\nConnection refused. Is the MCP server running?\nError in /mcp route: TypeError: fetch failed\n    at node:internal/deps/undici/undici:13502:13\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async StreamableHTTPClientTransport.terminateSession (file://.../.npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js:355:30)\n    at async file://.../.npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:264:17 {\n  [cause]: Error: connect ECONNREFUSED 127.0.0.1:8000\n      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1636:16) {\n    errno: -61,\n    code: 'ECONNREFUSED',\n    syscall: 'connect',\n    address: '127.0.0.1',\n    port: 8000\n  }\n}\n```\n\n### Mitigation\n\nSetting the `timeout_graceful_shutdown` uvicorn config to a few seconds will eventually quit the process, **BUT** this is exiting with a non 0 exit code, which is an issue trying to run this in production.   (This setting has been request [here](https://github.com/modelcontextprotocol/python-sdk/issues/253) and currently available in FastMCP 2.0)\n\n\n### Example Code\n\n```Python\nfrom mcp.server.fastmcp import FastMCP\n\nmcp = FastMCP(\"demo\")\n\n@mcp.tool()\nasync def hello() -> str:\n    return \"world\"\n\nmcp.run(transport=\"streamable-http\")\n```\n\n### Python & MCP Python SDK\n\n```Text\nPython 3.12.8\nmcp 1.12.4\n```\n\n**Edit**: reproduced with mcp 1.13.0","author":{"url":"https://github.com/lindycoder","@type":"Person","name":"lindycoder"},"datePublished":"2025-08-14T15:18:25Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/1272"}

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:f3bdab5f-cd77-b938-9959-c408a8b9cef8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBA34:2CFBF7:180D1EA:21ACFE3:6AFCF893
html-safe-noncef7bd8ac580ca05132969c8b765f0b378911ecad7d2d72bdef1b2be375d5adfe4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTM0OjJDRkJGNzoxODBEMUVBOjIxQUNGRTM6NkFGQ0Y4OTMiLCJ2aXNpdG9yX2lkIjoiOTE3NjE4MTE0NTYxNDQ4MTU1NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac817cfc494e1ce7d42289cca31e40125eb77a064495e8512b4c36529879e24ad0
hovercard-subject-tagissue:3322609936
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/1272/issue_layout
twitter:imagehttps://opengraph.githubassets.com/3e4a3907f927b9b9c320b5c01b9268d633e87f4a6ecbf1aa9a7d6a170ea2a90f/modelcontextprotocol/python-sdk/issues/1272
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/3e4a3907f927b9b9c320b5c01b9268d633e87f4a6ecbf1aa9a7d6a170ea2a90f/modelcontextprotocol/python-sdk/issues/1272
og:image:altInitial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamelindycoder
hostnamegithub.com
expected-hostnamegithub.com
Nonecfabad6ee26d2b84c7afef4ae0cc71b8b692fb9d66f9f15997652ef991bfd3f4
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
release35f85b78676038389558a41adf8d76e474592ede
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/1272#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F1272
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%2F1272
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/1272
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/1272
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/1272
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues305 (305)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/1272
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/1272
#2145https://github.com/modelcontextprotocol/python-sdk/pull/2145
Server hangs when shutting down if a connection is still openhttps://github.com/modelcontextprotocol/python-sdk/issues/1272#top
#2145https://github.com/modelcontextprotocol/python-sdk/pull/2145
P1Significant bug affecting many users, highly requested featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P1%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
ready for workEnough information for someone to start working onhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22ready%20for%20work%22
https://github.com/lindycoder
lindycoderhttps://github.com/lindycoder
on Aug 14, 2025https://github.com/modelcontextprotocol/python-sdk/issues/1272#issue-3322609936
https://github.com/modelcontextprotocol/python-sdk/issueshttps://github.com/modelcontextprotocol/python-sdk/issues
herehttps://github.com/modelcontextprotocol/python-sdk/issues/253
lindycoderhttps://github.com/lindycoder
needs confirmationNeeds confirmation that the PR is actually required or needed.https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22needs%20confirmation%22
on Aug 14, 2025https://github.com/modelcontextprotocol/python-sdk/issues/1272#event-19161722152
https://github.com/davidroeca
davidroecahttps://github.com/davidroeca
on Aug 20, 2025https://github.com/modelcontextprotocol/python-sdk/issues/1272#issuecomment-3207718806
ai sdkhttps://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling#mcp-tools
felixweinbergerhttps://github.com/felixweinberger
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
ready for workEnough information for someone to start working onhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22ready%20for%20work%22
P1Significant bug affecting many users, highly requested featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P1%22
needs confirmationNeeds confirmation that the PR is actually required or needed.https://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22needs%20confirmation%22
on Oct 3, 2025https://github.com/modelcontextprotocol/python-sdk/issues/1272#event-20087104119
https://github.com/giulio-leone
giulio-leonehttps://github.com/giulio-leone
on Feb 28, 2026https://github.com/modelcontextprotocol/python-sdk/issues/1272#issuecomment-3977553145
#2181https://github.com/modelcontextprotocol/python-sdk/pull/2181
manjitjohalhttps://github.com/manjitjohal
on Mar 2, 2026https://github.com/modelcontextprotocol/python-sdk/issues/1272#event-23191675010
fix(server): graceful shutdown for open SSE connections on SIGTERMhttps://github.com/Kritmatta/google_workspace_mcp_v1/commit/dc52a14ebf9a9a83559e578c1f66a4c86f855a1e
dc52a14https://github.com/Kritmatta/google_workspace_mcp_v1/commit/dc52a14ebf9a9a83559e578c1f66a4c86f855a1e
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/1272
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/1272
P1Significant bug affecting many users, highly requested featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P1%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
ready for workEnough information for someone to start working onhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22ready%20for%20work%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.