Skip to content

Conversation

@johnnyasantoss
Copy link
Contributor

Fixes #271

Motivation and Context

I'm also seeing a bunch of process get forgotten on my computer (especially when using docker run --rm -i ...)

How Has This Been Tested?

Yes, both with a node server and a server running on a container (my usual problem as docker does not necessarily delivers signals)

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

I followed the work previously done by #314

@johnnyasantoss
Copy link
Contributor Author

/cc @Skn0tt

pinging for a review :]

Copy link
Contributor

@Skn0tt Skn0tt left a comment

Choose a reason for hiding this comment

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

as per spec, you should start with closing the stdin stream. the rest looks good. funnily, I ended up opening a very similar PR at a very similar time 😁 #821

@johnnyasantoss
Copy link
Contributor Author

Rebased and polished tests. It seems that something unrelated from main is affecting CI. I ran the affected tests locally and they passed.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 17, 2025

Open in StackBlitz

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/sdk@818

commit: 963849b

@mattzcarey
Copy link
Contributor

Hey, I'd be happy to look at getting this merged if you could fix ci :)

@johnnyasantoss
Copy link
Contributor Author

Hey @mattzcarey, I'll take a look

@johnnyasantoss
Copy link
Contributor Author

I'm looking into reproducing the error that happens in CI. On my mac all tests pass
image

@johnnyasantoss
Copy link
Contributor Author

I get the same results on a linux x64 machine with node 24
image

- Make test servers use ts and init them with tsx - Add test to check if
hanging server actually gets killed
@johnnyasantoss
Copy link
Contributor Author

@mattzcarey after a battle with CI 😅 this is good to review

@mattzcarey mattzcarey requested review from KKonstantinov, Skn0tt and felixweinberger and removed request for Skn0tt and ihrpr November 28, 2025 15:37
@mattzcarey mattzcarey mentioned this pull request Dec 1, 2025
9 tasks
Copy link
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

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

LGTM, though would be a great opportunity to match the behavior to the spec more precisely while we're in this space

});
});

this._abortController.abort();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think according to the spec this should be after the stdin closure.

Copy link
Contributor

Choose a reason for hiding this comment

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


// waits the underlying process to exit cleanly otherwise after 1s kills it
await Promise.race([closePromise, new Promise(resolve => setTimeout(resolve, 1_000).unref())]);

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a step to send a SIGTERM if this didn't end the process to match the spec?

https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#stdio

nit: should we increase the timeout to 2s to match the Python SDK?

Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure abort calls SIGTERM already. Changed to 2s :)

@mattzcarey
Copy link
Contributor

Hey @johnnyasantoss we merged #1200 since I couldnt push to this HEAD. You are credited in the commits, closing this as completed :)

@mattzcarey mattzcarey closed this Dec 1, 2025
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.

StdioClientTransport#close() does not wait until underlying process is closed

4 participants