| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…ck if the MCP server process exits
There was a problem hiding this comment.
Thank you for working on this issue! The problem you're addressing is real and needs fixing. However, I'd like to suggest an alternative approach that addresses the root cause more directly.
We need to correctly handle scenarios like missing API keys or configuration and fail with a clear message, in other words we should validate the process started successfully before yielding, instead of monitoring inside the context
Sorry, something went wrong.
|
Just checked and #333 is fixing the same problem and is already merged. The only fix is needed for the test to work is handling ProcessLookupError error. Thank you for contributing to MCP Python SDK! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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
Checklist
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:
Fixes #428