Skip to content

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

Closed
Alphaxiaoteng wants to merge 1 commit into
modelcontextprotocol:mainfrom
Alphaxiaoteng:fix/session-group-empty-server
Closed

fix(client): allow ClientSessionGroup to connect to servers without components#3386
Alphaxiaoteng wants to merge 1 commit into
modelcontextprotocol:mainfrom
Alphaxiaoteng:fix/session-group-empty-server

Conversation

@Alphaxiaoteng

@Alphaxiaoteng Alphaxiaoteng commented Aug 25, 2026

Copy link
Copy Markdown

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).

@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Aug 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 missing-issue-link label, or adding bypass-issue-check bypasses the check.

@github-actions github-actions Bot closed this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClientSessionGroup raises KeyError when a server exposes no tools, resources or prompts

1 participant