| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
The MCP specification recommends closing stdin first to allow servers to exit gracefully before resorting to signals. This approach gives well-behaved servers the opportunity to detect stdin closure and perform clean shutdown without forceful termination. The shutdown sequence now follows a graceful escalation path: first closing stdin and waiting 2 seconds for voluntary exit, then sending SIGTERM if needed, and finally using SIGKILL as a last resort. This minimizes the risk of data loss or corruption while ensuring cleanup always completes. This unified approach works consistently across all platforms and improves compatibility with MCP servers that monitor stdin for lifecycle management. resolves #765 Co-authored-by: davenpi <davenport.ianc@gmail.com>
|
@dsp-ant rework of this change we discussed offline. |
Sorry, something went wrong.
This test shows that MCP server cleanup code in lifespan doesn't run when the process is terminated, but does run when stdin is closed first (as implemented in PR #1044). The test includes: - Demonstration of current broken behavior (cleanup doesn't run) - Verification that stdin closure allows graceful shutdown - Windows-specific ResourceWarning handling - Detailed documentation of the issue and solution Github-Issue:#1027
This test shows that MCP server cleanup code in lifespan doesn't run when the process is terminated, but does run when stdin is closed first (as implemented in PR #1044). The test includes: - Demonstration of current broken behavior (cleanup doesn't run) - Verification that stdin closure allows graceful shutdown - Windows-specific ResourceWarning handling - Detailed documentation of the issue and solution Github-Issue:#1027
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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:
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?
Types of changes
Checklist
Implementation Details
The shutdown sequence now follows a graceful escalation path:
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