Conversation
ClientSessionGroup could aggregate resources and prompts and call_tool against them, but offered no routed way to actually read a resource or get a prompt: callers had to track the owning session themselves. Add read_resource(name, ...) and get_prompt(name, arguments, ...) mirroring call_tool: they resolve the aggregate key (honoring component_name_hook) to the owning session via new _resource_to_session / _prompt_to_session reverse indexes and forward the resource's wire URI / prompt's wire name. Both carry the same allow_input_required overloads as ClientSession. Reverse indexes are cleaned up on disconnect_from_server. Adds unit + in-memory end-to-end tests and documents the methods in the session-groups guide.
|
This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3579. If a maintainer assigns you to #3579, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
Fixes #3579
Add
ClientSessionGroup.read_resource()andClientSessionGroup.get_prompt()so thegroup can route resource reads and prompt fetches to the owning server, the same way
call_tool()already does.Motivation and Context
ClientSessionGroupaggregates tools, resources, and prompts from every connectedserver into one view, and
call_tool(name, ...)resolves a name to the session thatowns it and forwards the call. But that routing existed only for tools. A caller who
wanted to read an aggregated resource or fetch an aggregated prompt had to track the
owning
ClientSessionthemselves and bypass the group entirely — an asymmetry in anotherwise "one object, one view" abstraction.
This adds the two missing routed calls:
read_resource(name, ...)get_prompt(name, arguments, ...)Both resolve the aggregate key (honoring
component_name_hook) to the owning sessionvia new
_resource_to_session/_prompt_to_sessionreverse indexes, then forward theresource's real wire URI / the prompt's real wire name. They carry the same
allow_input_requiredoverloads asClientSession, so a server that needs inputmid-call behaves identically through the group. The reverse indexes are cleaned up in
disconnect_from_server, matching how_tool_to_sessionis already handled.How Has This Been Tested?
owning session and forwards the correct wire identifier and arguments, plus
KeyErrorfor unknown names.
Client(server)against realMCPServerinstances:one reads a resource (
library://hours), one fetches a prompt, both routed through thegroup.
AGENTS.md:pytest,ruff format,ruff check,pyright,100% coverage on
src/mcp/client/session_group.py,strict-no-cover, and markdownlinton the docs page. All green.
Breaking Changes
None. This only adds two methods to an existing public class and internal reverse
indexes. No existing signature or behavior changes.
Types of changes
Checklist
help wanted, or I'm a maintainer)Additional context
read_resource/get_promptdeliberately mirror the existingcall_tooldesign: samereverse-index routing, same "aggregate key in, real wire identifier out" behavior, and
the same
allow_input_requiredoverload pair. Docs updated indocs/client/session-groups.mdwith a new "Reading resources and prompts" section and arecap line.