Python-based server restarts
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 2.2k
- Forks
- 300
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 184
Description
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
- 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 - Connect a first MCP client - works fine
- Connect a second MCP client or wait several minutes for ToolHive's internal health check
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing ToolHive's stdio proxy handling for initialize messages and reproduce the failure with the provided thv run command. Done means a second client connection or internal health check no longer forwards an invalid second initialize request, and the Python MCP server remains running.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100