Skip to content

Thv serve crashes when experimental MCP server fails to initialize #4392

@peppescg

Description

@peppescg

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

  1. Configure a custom registry API that requires OAuth authentication
  2. Let the OAuth token expire (or misconfigure the credentials)
  3. Run thv serve --experimental-mcp
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcliChanges that impact CLI functionalitygoPull requests that update go code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions