-
Notifications
You must be signed in to change notification settings - Fork 3k
Add ergonomic Client class for testing MCP servers #1870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+1,298
−526
Conversation
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
e3c2972 to
0b610a8
Compare
Contributor
Author
|
Key files to review:
Remainder is tests being updated to use the new interface. NOTE: This only implements test support. Refactoring Client to support different transports for the end-user API (streamable HTTP, stdio, SSE, etc.) is coming, marked as TODO in the Client docstring. |
felixweinberger
commented
Jan 16, 2026
felixweinberger
commented
Jan 16, 2026
Contributor
Author
Follow-up tasks
|
bf03f32 to
a7659d1
Compare
This was referenced Jan 16, 2026
a7659d1 to
27f896d
Compare
Kludex
reviewed
Jan 16, 2026
Kludex
previously approved these changes
Jan 16, 2026
Kludex
previously approved these changes
Jan 16, 2026
Add a high-level Client class that wraps ClientSession with transport
management, making it easier to test MCP servers.
Key changes:
- Add Client class with async context manager support
- Add InMemoryTransport for in-memory server connections
- Migrate test files to use new Client(server) API
- Update testing documentation with Client usage examples
Usage:
async with Client(server) as client:
result = await client.call_tool('my_tool', {'arg': 'value'})
6e60a85 to
621081e
Compare
Kludex
approved these changes
Jan 16, 2026
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.
Summary
Adds a high-level
Clientclass that provides an ergonomic API for testing MCP servers with in-memory transport.Motivation and Context
Testing MCP servers currently requires using the verbose
create_connected_server_and_client_sessionfunction. This PR introduces a simpler API:Related issues:
How Has This Been Tested?
ClientandInMemoryTransportcreate_connected_server_and_client_sessionto new APIBreaking Changes
create_connected_server_and_client_sessionfrommcp.shared.memory(v2 breaking change)Types of changes
Checklist
Additional context
New API
High-level (recommended):
Low-level (for advanced use cases):