Skip to content

fix: allow StdioClientTransport to reconnect without a new process - #1281

Open
prathamgoyal787 wants to merge 1 commit into
modelcontextprotocol:mainfrom
prathamgoyal787:fix/stdio-client-reconnect-after-failed-init
Open

prathamgoyal787 wants to merge 1 commit into
modelcontextprotocol:mainfrom
prathamgoyal787:fix/stdio-client-reconnect-after-failed-init

Conversation

@prathamgoyal787

Copy link
Copy Markdown

When the client re-initializes, for example after an initialize request timed out against a slow-starting server, it creates a new session, which connects the transport again. StdioClientTransport then started a second server process and subscribed its single-subscriber sinks again, which failed. The first process was left running, and its replies still went to the abandoned session, so the client could never initialize.

connect now starts the server process once, and on later calls only replaces the inbound message handler.

Added StdioClientTransportReinitializationTests, using a small test server that ignores the first initialize. It fails on main and passes with this change.

The client creates a new session, which connects the transport again,
whenever it re-initializes, for instance after an initialize request
timed out. StdioClientTransport started a second server process on each
connect and subscribed its single-subscriber sinks again, which failed.
The first process was left running, and replies still went to the
abandoned session, so the client could never initialize.

connect now only replaces the inbound message handler once the server
process is running.

This branch has not been deployed

No deployments
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.

1 participant