-
Notifications
You must be signed in to change notification settings - Fork 198
Thv serve crashes when experimental MCP server fails to initialize #4392
Description
Description
When running thv serve --experimental-mcp, the entire HTTP server process crashes if the embedded MCP server fails to initialize (e.g., due to a registry authentication error).
This happens because mcpserver.New() is called synchronously in the serve command's RunE function, and any error from it is returned directly — killing the whole process, including the main HTTP API server.
Steps to reproduce
- Configure a custom registry API that requires OAuth authentication
- Let the OAuth token expire (or misconfigure the credentials)
- Run
thv serve --experimental-mcp - The process exits immediately with:
failed to create MCP server: failed to create ToolHive handler: failed to get registry provider: registry authentication required
Expected behavior
The main HTTP API server (s.Serve) should continue running even if the experimental MCP server fails to initialize. The MCP failure should be logged as an error but not be fatal to the process.
Actual behavior
The entire thv serve process crashes, making the HTTP API unavailable. This is particularly problematic for ToolHive Studio (Electron), which relies on the HTTP API being available regardless of the MCP server state.
Proposed fix
Move mcpserver.New() inside the goroutine alongside mcpServer.Start(), so that a failure in MCP initialization only terminates the goroutine, not the main process. The error is logged with slog.Error and the HTTP server continues running normally.