Skip to content

Python-based server restarts #3783

Open

Description

@azavisha-snap

Bug description

Python-based MCP servers crash when a second client connects through ToolHive's stdio proxy. The proxy forwards a second initialize request to an already-initialized session, causing a Pydantic validation error that crashes the Python process.

Steps to reproduce

  1. Deploy a Python MCP server via ToolHive with stdio transport: thv run docker.io/mcp/git:latest --name git --transport stdio --proxy-mode streamable-http
  2. Connect a first MCP client - works fine
  3. Connect a second MCP client or wait several minutes for ToolHive's internal health check
  4. Container crashes with exit code 1

Expected behavior

The proxy should handle multiple client connections by either:

  • Multiplexing clients onto the single stdio session without re-sending initialize
  • Resetting the session before forwarding a new initialize

Actual behavior

The proxy forwards the second initialize request to the active stdio session. The Python MCP SDK's _receive_loop tries to validate it as a ClientRequest (which only accepts post-initialization requests like ping, tools/call, etc.), fails with validation errors, and crashes:

pydantic_core.ValidationError: 20 validation errors for ClientRequest
InitializeRequest.params                                                
  Field required [type=missing, input_value={'method': 'initialize', ...

Node.js MCP servers, for example, don't crash on unexpected messages, so they're unaffected.

Environment

  • ToolHive v0.9.3
  • Podman
  • MacOS

Activity

  1. added
    bug
    on Feb 11, 2026
  2. added
    cli
    on Feb 11, 2026
  3. jerm-dro commented on Feb 12, 2026

    @jerm-dro
    Collaborator

    Hey @azavisha-snap thanks for reporting this issue.

    I was able to reproduce the crash locally just using the python sdk and not the git server. The good news is that the latest Python MCP SDK (v1.26.0) fixes it. The server does not crash when a second MCP client connects. I also validated the git server referenced uses an old version of mcp:

    $ docker run --rm --entrypoint python mcp/git:latest -c "import importlib.metadata; print(importlib.metadata.version('mcp'))"
    1.1.0

    For my test server with the latest mcp version, I was able to connect multiple clients to the thv proxy without problem. Note: from my brief reading of the python mcp source code, it appears the subsequent sessions may overwrite the state of prior sessions. That should only be a problem if you have a stateful mcp server implementation.

    Let me know if this unblocks you or you have further questions.

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

    bugcliproxy

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions