fix(client): allow ClientSessionGroup to connect to servers without components
Closed
AL
3mo ago+25+25+01234567890123456789-5-5-0123456789
Summary
Fixes #3384.
Connecting a ClientSessionGroup to an MCP server that legitimately exposes no tools, resources, or prompts previously triggered a del self._session_exit_stacks[session] in _aggregate_components.
This caused two issues:
- When connected via
connect_with_session(), the session exit stack was never inserted intoself._session_exit_stacks, leading to an uncaughtKeyError. - When connected via
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
- Removed the incorrect
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. - Added regression test
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).