fix(client): allow ClientSessionGroup to connect to servers without components

Closed
AL
3mo ago
+25-5

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:

  1. When connected via connect_with_session(), the session exit stack was never inserted into self._session_exit_stacks, leading to an uncaught KeyError.
  2. When connected via connect_to_server(), the stack was removed without closing or tracking, leaving the session registered in self._sessions but with no cleanup path on disconnect_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_succeeds in tests/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).