FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Align stdio shutdown sequence with spec by davenpi · Pull Request #765 · modelcontextprotocol/python-sdk · GitHub

Align stdio shutdown sequence with spec - #765

Closed
davenpi wants to merge 1 commit into
modelcontextprotocol:mainfrom
davenpi:fix/stdio-shutdown-spec
Closed

Align stdio shutdown sequence with spec#765
davenpi wants to merge 1 commit into
modelcontextprotocol:mainfrom
davenpi:fix/stdio-shutdown-spec

Conversation

davenpi commented May 21, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

Align the stdio shutdown sequence with the MCP spec: close the server’s input, wait for exit, send SIGTERM if needed, and SIGKILL as a last resort.

Motivation and Context

The MCP spec recommends a careful shutdown sequence for stdio transport to avoid leaving orphaned or stuck server processes. This change follows those steps, making shutdowns more reliable and predictable.

How Has This Been Tested?

All tests pass (except one unrelated skipped test).

Breaking Changes

None

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

None

davenpi commented May 22, 2025

Copy link
Copy Markdown
Contributor Author

Hey @ihrpr! Do you have a sec to review this PR? It makes the SDK follow the stdio shutdown procedure to the letter!

davenpi force-pushed the fix/stdio-shutdown-spec branch from 35eaaaf to b997748 Compare May 22, 2025 12:00
ihrpr added this to the r-05-25 milestone May 23, 2025

ihrpr commented May 28, 2025

Copy link
Copy Markdown
Contributor

related PR: #555

ihrpr modified the milestones: r-05-25, stdio shutdown May 28, 2025

ihrpr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you @davenpi for working on this.

There are a lot of issues reported around the shutdown for stdio, if would be great to have additional tests and verify on different platforms that the solution works.

felixweinberger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hi @davenpi, thank you for making this PR!

As @ihrpr mentioned we have a couple of different fixes all related to shutdown behavior, and we'll need to reconcile this with #555 which unifies behavior across Windows and POSIX (no more special handling for Windows).

We'll want to land #555 first, and then land your change here on top - ideally with testing for both.

I went ahead and created #1044 with both of these changes + tests for each - if you could take a look at the last commit here (with tests for #765) and add them to this PR + rebase on main that would be great!

felixweinberger added a commit that referenced this pull request Jul 1, 2025
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>

Copy link
Copy Markdown
Contributor

Thank you again @davenpi for submitting this PR.

I spent yesterday and today trying to unify all the different approaches and fixes we have pending in this process termination space at the moment, as there are several interrelated fixes that either conflict or depend on each other - specifically #555, #729, #765, and #850.

I've added your change to #1044 as a draft with you as a co-author + added extensive regression testing. Would you be OK with consolidating this change into #1044 for the comprehensive testing & process handling introduced there?

davenpi commented Jul 1, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @felixweinberger for taking the time to coordinate all this! Consolidation sounds good.

felixweinberger added a commit that referenced this pull request Jul 4, 2025
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>
felixweinberger requested review from felixweinberger and removed request for felixweinberger July 6, 2025 15:20
felixweinberger added a commit that referenced this pull request Jul 8, 2025
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>

ihrpr commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Thank you @davenpi! Will close this one and we can continue in #1091

ihrpr closed this Jul 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL