-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Create ClientSessionGroup
for managing multiple session connections.
#639
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
Conversation
This abstraction concurrently manages multiple MCP session connections. Tools, resources, and prompts are aggregated across servers. Servers may be connected to or disconnected from at any point after initialization. This abstractions can handle naming collisions using a custom user-provided hook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this!
We need to make sure that this ClientSessionGroup/Host abstraction supports all current transports in SDK
…onGroup This change introduces additional support for the other MCP transports and includes respective server parameter types to align with the stdio client implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you so much for the quick turnaround!
there a few things we need to add:
- ClientSessionGroup to implement
__aenter__/__aexit__
- Ability to use
async with ClientSessionGroup():
- disconnect_from_server removes sessions from tracking but doesn't remove them from _exit_stack
- add documentation on how to use
215d0bc
to
fcbdd79
Compare
cca631c
to
d4a28ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small changes and we are good to merge! Thank you
d4a28ca
to
a42f953
Compare
This changes enables context management for setting up and tearing down async exit stacks durring server connection and disconnection respectively. Documentation has been added to show an example use case that demonstrates how `ClientSessionGroup` can be used with `async with`.
595e777
to
e798eeb
Compare
the client and can be accessed via the session. | ||
Example Usage: | ||
name_fn = lambda name, server_info: f"{(server_info.name)}-{name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that both a tool name and a server_info name would conflict? would there be enough information for the hook to disambiguate?
related to #9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
This abstraction concurrently manages multiple MCP session connections.
Tools, resources, and prompts are aggregated across servers. Servers may be connected to or disconnected from at any point after initialization.
This abstractions can handle naming collisions using a custom user-provided hook.
Motivation and Context
This change alleviates the need for users to re-implement a multi-session "manager" anytime more than 1 session needs to be established.
Testing
Code branches are covered via pytest unit tests.
Breaking Changes
This is a no-op as it introduces a new class without modifying existing dependencies.
Types of changes
Checklist