Title: fweinberger/align shutdown with spec by felixweinberger · Pull Request #1091 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fweinberger/align shutdown with spec by felixweinberger · Pull Request #1091 · modelcontextprotocol/python-sdk
X Title: fweinberger/align shutdown with spec by felixweinberger · Pull Request #1091 · modelcontextprotocol/python-sdk
Description: Motivation and Context This PR implements the MCP spec-compliant stdio shutdown sequence as defined in the MCP specification. The MCP specification recommends that stdio transport clients should: Close the input stream to the server process Wait for the server to exit Send SIGTERM if the server doesn't exit quickly Send SIGKILL if the server doesn't exit after SIGTERM This approach gives well-behaved servers the opportunity to detect stdin closure and perform clean shutdown without forceful termination, minimizing the risk of data loss or corruption while ensuring cleanup always completes. Resolves #765 How Has This Been Tested? All existing stdio tests pass Added new tests: test_stdio_client_graceful_stdin_exit: Verifies processes that monitor stdin exit gracefully test_stdio_client_stdin_close_ignored: Verifies escalation to SIGTERM when stdin closure is ignored Tested on both POSIX and Windows platforms Types of changes Bug fix (non-breaking change which fixes an issue) New feature (non-breaking change which adds functionality) Breaking change (fix or feature that would cause existing functionality to change) Checklist I have read the MCP Documentation My code follows the code style of this repository My change requires a change to the documentation I have updated the documentation accordingly I have added tests to cover my changes All new and existing tests passed I have added appropriate error handling Implementation Details The shutdown sequence now follows a graceful escalation path: Close stdin and wait 2 seconds for voluntary exit If the process hasn't exited, call the platform-specific _terminate_process_tree which handles: SIGTERM with 2-second timeout SIGKILL as final resort This unified approach works consistently across all platforms and improves compatibility with MCP servers that monitor stdin for lifecycle management. The implementation leverages the existing platform-specific process termination utilities introduced in PRs #1044 and #1078, ensuring robust child process cleanup on both Windows (using Job Objects) and POSIX systems (using process groups). Co-authored-by: davenpi davenport.ianc@gmail.com
Open Graph Description: Motivation and Context This PR implements the MCP spec-compliant stdio shutdown sequence as defined in the MCP specification. The MCP specification recommends that stdio transport clients should: ...
X Description: Motivation and Context This PR implements the MCP spec-compliant stdio shutdown sequence as defined in the MCP specification. The MCP specification recommends that stdio transport clients should: ...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/1091
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:bf7ff92e-936c-99b1-4d92-b40c9ea18c9a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BDC4:1FC98B:A20A81:D84B9E:6A5B5F7F |
| html-safe-nonce | be59eb4eda9623d0afe446527bfa7d94f582e67483647101adb715b1afea6f91 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCREM0OjFGQzk4QjpBMjBBODE6RDg0QjlFOjZBNUI1RjdGIiwidmlzaXRvcl9pZCI6IjIyNjQxNzc1MDMxOTQ3OTk5OTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 248c8005073957ecb236c73aa82ccfe4c16c073385cbe1ee967ed122ec551790 |
| hovercard-subject-tag | pull_request:2642002694 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/1091/files |
| twitter:image | https://avatars.githubusercontent.com/u/3823880?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/3823880?s=400&v=4 |
| og:image:alt | Motivation and Context This PR implements the MCP spec-compliant stdio shutdown sequence as defined in the MCP specification. The MCP specification recommends that stdio transport clients should: ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width