Skip to content

Conversation

olaservo
Copy link
Member

Fixes #654

This PR resolves the issue where STDIO servers with lifespan contexts fail to restart after disconnection.

Problem

STDIO servers with lifespan contexts couldn't restart after disconnect because:

  • Transport references remained in global Maps after disconnect
  • Stale SSEServerTransport instances tried to send through closed connections
  • Resulted in "Not connected" errors and ERR_CONNECTION_REFUSED on reconnect

Solution

  • Added optional onCleanup callback to mcpProxy function
  • Modified server routes to provide cleanup functions that remove transport references
  • Ensures webAppTransports and serverTransports Maps are cleaned up properly
  • Cleanup triggers when either client or server transports close

Tests Added

  • Unit tests for mcpProxy function covering message forwarding, error handling, and cleanup
  • Integration tests simulating real-world STDIO server restart scenarios
  • Tests demonstrate both the original bug and the fix

Testing

This fix should resolve the restart issues for servers using lifespan contexts while maintaining compatibility with existing transport types.

Generated with Claude Code

claude bot and others added 2 commits August 28, 2025 02:49
This commit resolves issue #654 where STDIO servers with lifespan contexts
failed to restart after disconnection.

## Problem
STDIO servers with lifespan contexts couldn't restart after disconnect because:
- Transport references remained in global Maps after disconnect
- Stale SSEServerTransport instances tried to send through closed connections
- Resulted in "Not connected" errors and ERR_CONNECTION_REFUSED on reconnect

## Solution
- Added optional onCleanup callback to mcpProxy function
- Modified server routes to provide cleanup functions that remove transport references
- Ensures webAppTransports and serverTransports Maps are cleaned up properly
- Cleanup triggers when either client or server transports close

## Tests Added
- Unit tests for mcpProxy function covering message forwarding, error handling, and cleanup
- Integration tests simulating real-world STDIO server restart scenarios
- Tests demonstrate both the original bug and the fix

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Ola Hungerford <[email protected]>
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.

STDIO server not restarting after disconnect
1 participant