fix(client): allow ClientSessionGroup to connect to servers without components - #3386
Conversation
|
Thanks for the contribution. This repository only keeps pull requests open when they're linked to an issue that a maintainer has assigned to the author — CONTRIBUTING.md explains why and how we work. This PR has been closed for now because you aren't currently assigned to #3384. If a maintainer would like this change as a PR from you, they'll assign you to #3384 and this PR will reopen automatically — there's nothing more you need to do. (If you opened the issue, this PR already shows up on its timeline.) There's no need to open a new PR — this one will be reopened. While it's closed, please push any updates as new commits rather than force-pushing, since GitHub can't reopen a PR whose branch has been rewritten. Maintainers: reopening this PR, removing the |
Summary
Fixes #3384.
Connecting a
ClientSessionGroupto an MCP server that legitimately exposes no tools, resources, or prompts previously triggered adel self._session_exit_stacks[session]in_aggregate_components.This caused two issues:
connect_with_session(), the session exit stack was never inserted intoself._session_exit_stacks, leading to an uncaughtKeyError.connect_to_server(), the stack was removed without closing or tracking, leaving the session registered inself._sessionsbut with no cleanup path ondisconnect_from_server().Changes
del self._session_exit_stacks[session]cleanup in_aggregate_components. Empty component sets are valid and properly recorded as empty component sets for the connected session.test_client_session_group_connect_empty_server_succeedsintests/client/test_session_group.py.Verification
uv run pytest tests/client/test_session_group.py(13 passed).uv run ruff check src/ tests/(passed).uv run ruff format --check tests/client/test_session_group.py(passed).uv run pyright(0 errors).