toolhive icon indicating copy to clipboard operation
toolhive copied to clipboard

Intercept intialization requests to STDIO servers

Open eleftherias opened this issue 4 months ago • 1 comments

Current Limitation

If multiple clients send an initialize request, ToolHive forwards the request to the STDIO workload, which may reject the request or behave unexpectedly, since the expected behaviour is not described by the protocol.

Proposed Solution

ToolHive can a single initialization request to the MCP server container, and intercept any initialization requests coming from the client, responding with a cached response.

Flow:

  • When an MCP server is started, ToolHive sends an initialization request and caches the response
  • When ToolHive receives an initialization request from a client:
    • It should not forward the request to the MCP server
    • It should respond with the cached response
    • It should respond with the session ID (this is already implemented)

eleftherias avatar Sep 19 '25 14:09 eleftherias

Every time a server is disabled and re-enabled in vscode/cursor config initialise is called, so any MCP server that can't handle multiple inits is in trouble anyway, regardless of the spec. See https://github.com/stacklok/toolhive/issues/2499.

On a different note, if we are muiltplexing the initialize function, how are we coping with clients with different capabilities and versions?

therealnb avatar Nov 10 '25 10:11 therealnb