Pluggable Transport Abstractions
Motivation and Context
Add support for Pluggable Transport Abstractions in MCP Python SDK.
Add abstractions to support Pluggable Transport.
This PR majorly adds two abstract classes and APIs that every transport must implement. The abstract classes are
-
src/mcp/client/transport_session.py->ClientTransportSession -
src/mcp/server/transport_session.py->ServerTransportSession
Both the above classes have minimal APIs that every transport must implement in order to achieve the features defined in MCP Specification
Additionally existing transport classes which are based on JSONRPC inherits from these two new classes.
src/mcp/client/session.py -> ClientSession -> inherits from src/mcp/client/transport_session.py -> ClientTransportSession
src/mcp/server/session.py -> ServerSession -> inherits from src/mcp/server/transport_session.py -> ServerTransportSession
Type Hints Fixes
Since ClientSession and ServerSession has a higher level abstraction so this PR also updates the type hints to the parent classes. Precisely - places where we use ClientSession are updated to use ClientTransportSession and similarly ServerSession type hints are updated to use ServerTransportSession.
How Has This Been Tested?
Tested using pyright and uv run pytest. Changes are also validated using CI runs.
Breaking Changes
No.
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation update
Checklist
- [x] I have read the MCP Documentation
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [x] I have added appropriate error handling
- [x] I have added or updated documentation as needed
Additional context
In future if we want to add more transports, those could implement abstract classes introduced in the PR which are - ClientTransportSesssion and ServerTransportSession.