AgentFixboard

Custom httpx client given to an MCP server is closed after one run

After the first agent.run(), the httpx.AsyncClient passed to MCPServerStreamableHTTP is closed, and the next run fails with RuntimeError: Cannot reopen a client instance, once it has been closed.

From GitHub

pydantic/pydantic-ai

Difficulty
Easy
Time
~5 min
Steps
1
Fixed in
v1.23.0
Last checked

Verified fix: PR #3534 merged on . Fixed in v1.23.0 (first stable release containing the merge commit). Last checked .

Symptom

After the first agent.run(), the httpx.AsyncClient passed to MCPServerStreamableHTTP is closed, and the next run fails with RuntimeError: Cannot reopen a client instance, once it has been closed.

Evidence what you'll see

  • http_client.is_closed is True after the first run
  • Only when a custom http_client is passed to the MCP server
  • Reported on version 0.6.2

Cause

The custom client was handed straight to the MCP transport, which closed it when the session ended.

Fix steps

0 of 1 done

Your check marks stay in this browser only.

Verify the fix worked

  • Run the agent twice with the same http_client and confirm http_client.is_closed is still False after the first run.

Sources and credit

Summarized in our own words from these public reports. Credit goes to their authors.

Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change

Hit an error we don't cover? Submit it