You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ClientSessionGroup raises KeyError when connecting a server that exposes no components #3578
ClientSessionGroup._aggregate_components deletes the session from _session_exit_stacks whenever a connected server exposes no prompts, resources,
or tools:
Via connect_with_session(server_info, session) the caller supplies a session
that was never registered in _session_exit_stacks, so this raises KeyError.
Via connect_to_server it drops the freshly-registered exit stack, so a later disconnect_from_server can't close that session's transport.
Why it matters
A valid MCP server can legitimately register zero tools/resources/prompts (e.g.
one that only does sampling/roots), and list_* failures are swallowed into
empty dicts too. In both cases connecting an otherwise-fine server either crashes
or leaks a transport until group teardown.
Minimal reproduction
group=ClientSessionGroup()
# server_info + an in-memory session whose list_tools/resources/prompts are emptyawaitgroup.connect_with_session(server_info, session) # -> KeyError
Suggested fix
Remove the empty-server cleanup block so an empty server is aggregated like any
other. Happy to open a PR (branch already prepared).
Confirmed this reproduces exactly as described — I hit the same KeyError via
connect_with_session with an empty-component server (no tools/resources/prompts
registered). I've traced it to the cleanup block in _aggregate_components and
have a fix ready that removes it and adds regression coverage for both
connect_with_session and connect_to_server (the latter silently drops the exit
stack instead of raising, which I think is worth covering too). Happy to open
a PR once assigned.
Both reports identify the same empty-component ClientSessionGroup cleanup block, including the KeyError and lost transport exit stack. This is tracked in #3384, so I’m closing this as a duplicate. AI-assisted triage; I reviewed both reports.
Activity
baselarw commentedon Sep 24, 2026
Confirmed this reproduces exactly as described — I hit the same KeyError via
connect_with_session with an empty-component server (no tools/resources/prompts
registered). I've traced it to the cleanup block in _aggregate_components and
have a fix ready that removes it and adds regression coverage for both
connect_with_session and connect_to_server (the latter silently drops the exit
stack instead of raising, which I think is worth covering too). Happy to open
a PR once assigned.
Kludex commentedon Oct 10, 2026
Both reports identify the same empty-component
ClientSessionGroupcleanup block, including theKeyErrorand lost transport exit stack. This is tracked in #3384, so I’m closing this as a duplicate. AI-assisted triage; I reviewed both reports.