Title: Fix issue #428: ClientSession.initialize gets stuck if the MCP server process exits by AshwanthramKL · Pull Request #434 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Fix issue #428: ClientSession.initialize gets stuck if the MCP server process exits by AshwanthramKL · Pull Request #434 · modelcontextprotocol/python-sdk
X Title: Fix issue #428: ClientSession.initialize gets stuck if the MCP server process exits by AshwanthramKL · Pull Request #434 · modelcontextprotocol/python-sdk
Description: This PR fixes an issue where ClientSession.initialize gets stuck indefinitely if the MCP server process exits unexpectedly. Motivation and Context When using stdio_client to connect to an MCP server, if the server process exits unexpectedly (e.g., due to missing API keys or configuration), the client hangs indefinitely without raising an appropriate exception. This makes for a poor developer experience and can be frustrating to debug. How Has This Been Tested? Added a test case that verifies the fix works correctly by creating a server that exits during initialization and checking that the appropriate exception is raised. The test ensures that the client properly detects when the server process exits and raises a ProcessTerminatedEarlyError instead of hanging indefinitely. Breaking Changes None. This change only improves error handling and doesn't modify any existing APIs. 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) Documentation update Checklist I have read the MCP Documentation My code follows the repository's style guidelines New and existing tests pass locally I have added appropriate error handling I have added or updated documentation as needed Additional context The solution adds a process monitoring task that detects when the server process exits unexpectedly and raises a ProcessTerminatedEarlyError with a descriptive message. It also ensures proper cleanup of resources to prevent leaks. Specifically: Added a ProcessTerminatedEarlyError exception class Added a process monitoring task that detects when the process exits unexpectedly Properly closed all streams to prevent resource leaks Added error handling for the case where the process has already exited Made sure we don't raise an error when we explicitly terminate the process Fixes #428
Open Graph Description: This PR fixes an issue where ClientSession.initialize gets stuck indefinitely if the MCP server process exits unexpectedly. Motivation and Context When using stdio_client to connect to an MCP serv...
X Description: This PR fixes an issue where ClientSession.initialize gets stuck indefinitely if the MCP server process exits unexpectedly. Motivation and Context When using stdio_client to connect to an MCP serv...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/434
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:99c92927-0ed2-d46d-23e7-cc3469f9f3d8 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A488:1C9D94:C62B95:100F3B4:6A5C20E2 |
| html-safe-nonce | c0f56944096f95485774a445c753ddfec7cdd84a3e972da81fc9a699aed0dde2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDg4OjFDOUQ5NDpDNjJCOTU6MTAwRjNCNDo2QTVDMjBFMiIsInZpc2l0b3JfaWQiOiI1NTc3NjE2OTQ1MjQyMTg1OTU0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2bf0dd2cb1ff162880c02dcbced478ef358b60d0dd6368036637fd41bedde266 |
| hovercard-subject-tag | pull_request:2441027061 |
| 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/434/files |
| twitter:image | https://avatars.githubusercontent.com/u/71945723?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/71945723?s=400&v=4 |
| og:image:alt | This PR fixes an issue where ClientSession.initialize gets stuck indefinitely if the MCP server process exits unexpectedly. Motivation and Context When using stdio_client to connect to an MCP serv... |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width