Skip to content

ClientSessionGroup leaves old tools after disconnecting a re-registered session #3713

Open

Description

@inanna-malick

Initial Checks

Release line

2.x (current stable)

Description

Registering the same caller-owned session twice can leave tools behind after disconnect. The first catalog contains old; the second contains only new. Both connect_with_session() calls return successfully. After disconnect_from_server(), group.sessions == [] but group.tools still contains old.

I expected disconnect to remove every tool registered through that session. A deliberate rejection of repeated registration or a coherent refresh would both be reasonable; this report concerns the accepted repeat leaving stale entries.

The aggregation path replaces the session's reverse index with the latest catalog while updating the aggregate dictionary, which retains the earlier entries. Disconnect then removes only the names in the replacement index. This differs from #3490's transport leak after a rejected connection and #3384's empty-catalog failure.

Example Code

Self-contained failing test using public Client, connect_with_session(), and disconnect_from_server() APIs. Test-only branch; no production changes.

After checking out that branch:

uv run --frozen pytest tests/client/test_session_group.py::test_disconnect_removes_all_tools_after_same_session_reregistration -q

Python & MCP Python SDK

Python 3.14.7, Linux x86_64. Reproduces on latest stable 2.3.0 (2118f14f8a19bc158d8a1cf90af58d85d187f849) and main 754254c08fe1c3eda18b69da3d336106fe8d72d6. The other 12 session-group tests pass against each source revision.

AI-assisted investigation and test reproduction, with a human in the loop.

Activity

  1. added
    bugSomething isn't working
    v2Affects the v2 line (2.x on main)
    v1Affects the v1.x maintenance line
    on Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingv1Affects the v1.x maintenance linev2Affects the v2 line (2.x on main)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions