Skip to content

[Bug] Client.close() on one MCPConfig client tears down a live Client.new() clone's backends #5824

Open

Description

@BlueX888

Summary

Client.new() is a shallow copy, so a clone shares the original's MCPConfigTransport instance. That transport keeps the backend transports of its most recent connection in a transport-wide _transports list which _build_composite() overwrites on every connect. Calling Client.close() on either client — even one that never connected — therefore closes whatever list was last written, tearing down the other client's live backends. The victim's next call fails with ToolError: Error calling tool '<name>': Connection closed.

This is the symmetric case of #5618/#5596: just as a clone connecting must not close the original's backends, an unconnected client closing must not either.

Reproduction (offline, current main adf90b6)

Two real local stdio servers (tests/client/minimal_stdio_server.py), no network:

original = Client(config)          # two servers
clone = original.new()
async with clone:                   # clone's backends are live
    await clone.call_tool("a_pid")  # ok
await original.close()              # original never connected
await clone.call_tool("a_pid")

Observed:

clone pid before: <pid>
CLONE BROKEN: ToolError Error calling tool 'pid': Connection closed

The same happens in the other direction (an unconnected clone close kills a live original), and when the original was connected before the clone connected last. Expected: each client's close() only tears down the backends owned by its own connection; the other client keeps serving.

Suggested fix

Do not keep connection-scoped transports in a transport-wide mutable list. Give Client.new() an independent MCPConfigTransport over the same MCPConfig object (shared configuration, separate connection state), and/or have close() only act on transports owned by the calling client's connection. A connected client's close() must still tear down its own backends, and connect_session's exit stack remains the owner for normal teardown.

Tests

A fix with regression tests for both close directions plus connected-close teardown (in-memory close-recording transports and real stdio subprocesses) is ready. I'll open the linked PR with the red/green evidence.

Activity

  1. added
    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.
    clientRelated to the FastMCP client SDK or client-side functionality.
    on Oct 19, 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 working. Reports of errors, unexpected behavior, or broken functionality.clientRelated to the FastMCP client SDK or client-side functionality.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions