Agent FixboardAgentFixboard

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. The next run raises 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 published release whose tag contains the merge commit). Last checked .

Symptom

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

Evidence what you'll see

  • The report prints http_client.is_closed and it is True after the first run.
  • The client is created by the caller and passed as http_client.

Why it happens

The server closed the caller-supplied client when the request finished. The pull request title is not to close a custom httpx client passed to MCPServerHTTP. The pull request body does not give a diff.

Affected versions

Pydantic AI 0.6.2, Python 3.13. The linked issue does not name an operating system.

Fix steps

0 of 1 done

Your check marks stay in this browser only.

How to check it worked

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

If it still fails

  • The linked issue does not describe Cannot reopen a client instance on v1.23.0. On 0.6.2 the second agent.run() raises it.

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