stacklok / stacklok/toolhive

Python-based server restarts

Open
#3,783 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug cli proxy
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

  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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.