feat: Add socket transport as an alternative to stdio transport#1074
Closed
qhhonx wants to merge 2 commits intomodelcontextprotocol:mainfrom
Closed
feat: Add socket transport as an alternative to stdio transport#1074qhhonx wants to merge 2 commits intomodelcontextprotocol:mainfrom
qhhonx wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
This commit introduces socket-based transport as an alternative to stdio transport, offering similar process management but with bidirectional TCP socket communication: Core Features: - Implement socket transport following stdio transport's process management pattern - Add direct TCP socket communication instead of stdin/stdout pipes - Support custom encoding and error handling like stdio transport - Add connection retry and timeout handling (not available in stdio) - Implement proper process cleanup similar to stdio transport Key Differences from stdio: - Bidirectional TCP socket vs stdin/stdout pipes - Support for custom host/port vs fixed pipe streams - Connection retry and timeout mechanisms vs immediate pipe connection - More flexible process-to-process communication patterns - Better support for distributed deployment scenarios Implementation Details: - Add SocketServerParameters extending stdio's parameter pattern - Support auto-port assignment for flexible deployment - Handle connection timeouts and retries (new capability) - Implement proper resource cleanup following stdio pattern - Add comprehensive test coverage comparing with stdio behavior FastMCP Integration: - Add socket transport alongside stdio transport - Support socket configuration in Settings - Maintain consistent API patterns with stdio transport
dd7fe38 to
98ede50
Compare
- Add graceful cancellation handling for socket reader/writer - Implement timeout-based cleanup mechanism (5s timeout) - Add force process termination for hanging cleanup - Improve server-side resource cleanup - Add comprehensive tests for cancellation and cleanup scenarios - Fix Python interpreter path resolution in tests
Member
|
I don't think we want to keep including transports into this package that are not in the MCP specification. I think the best approach for now would be to create a That said, I think this transport should support fds and uds as well. |
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces socket transport as an alternative to the existing stdio transport, offering similar process management capabilities but with enhanced flexibility through TCP socket communication.
Relationship with stdio Transport
The socket transport implementation follows similar patterns to the existing stdio transport:
Shared Patterns:
Key Differences:
Communication Channel:
Connection Management:
Deployment Flexibility:
Configuration Options:
Error Handling:
Implementation Details
The implementation maintains consistency with stdio transport while adding socket-specific features:
Enhanced Capabilities
The socket transport adds several capabilities not possible with stdio:
Network Communication:
Connection Management:
Deployment Options:
Migration and Compatibility
The socket transport is designed to be a drop-in alternative to stdio transport:
Testing Strategy
Tests are designed to verify both shared behavior with stdio and socket-specific features:
Shared Behavior Tests:
Socket-Specific Tests:
Future Considerations
Potential Enhancements:
Migration Tools: