From 7177e2e3a82b79c4aa02b11a760bfc544c3dc2bb Mon Sep 17 00:00:00 2001 From: Alejandro Ponce Date: Thu, 17 Jul 2025 13:46:28 +0300 Subject: [PATCH] Changes MCP_HOST set by toolhive to 0.0.0.0 Bind MCP_HOST to all interfaces by default so that the mcp server in the container is reachable from the host --- cmd/thv/app/run_flags.go | 2 +- docs/cli/thv_run.md | 2 +- pkg/transport/http.go | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/thv/app/run_flags.go b/cmd/thv/app/run_flags.go index e59648ef0..8525cc733 100644 --- a/cmd/thv/app/run_flags.go +++ b/cmd/thv/app/run_flags.go @@ -95,7 +95,7 @@ func AddRunFlags(cmd *cobra.Command, config *RunFlags) { cmd.Flags().StringVar( &config.TargetHost, "target-host", - transport.LocalhostIPv4, + transport.TargetHostIPv4, "Host to forward traffic to (only applicable to SSE or Streamable HTTP transport)") cmd.Flags().StringVar( &config.PermissionProfile, diff --git a/docs/cli/thv_run.md b/docs/cli/thv_run.md index 89e1ecece..3bc369a3f 100644 --- a/docs/cli/thv_run.md +++ b/docs/cli/thv_run.md @@ -93,7 +93,7 @@ thv run [flags] SERVER_OR_IMAGE_OR_PROTOCOL [-- ARGS...] --proxy-mode string Proxy mode for stdio transport (sse or streamable-http) (default "sse") --proxy-port int Port for the HTTP proxy to listen on (host port) --secret stringArray Specify a secret to be fetched from the secrets manager and set as an environment variable (format: NAME,target=TARGET) - --target-host string Host to forward traffic to (only applicable to SSE or Streamable HTTP transport) (default "127.0.0.1") + --target-host string Host to forward traffic to (only applicable to SSE or Streamable HTTP transport) (default "0.0.0.0") --target-port int Port for the container to expose (only applicable to SSE or Streamable HTTP transport) --thv-ca-bundle string Path to CA certificate bundle for ToolHive HTTP operations (JWKS, OIDC discovery, etc.) --tools stringArray Filter MCP server tools (comma-separated list of tool names) diff --git a/pkg/transport/http.go b/pkg/transport/http.go index 21e13f268..4820eeab7 100644 --- a/pkg/transport/http.go +++ b/pkg/transport/http.go @@ -21,6 +21,8 @@ const ( LocalhostName = "localhost" // LocalhostIPv4 is the standard IPv4 address for localhost LocalhostIPv4 = "127.0.0.1" + // TargetHostIPv4 is the standard IPv4 address for the target host + TargetHostIPv4 = "0.0.0.0" ) // HTTPTransport implements the Transport interface using Server-Sent/Streamable Events. @@ -66,9 +68,9 @@ func NewHTTPTransport( host = LocalhostIPv4 } - // If targetHost is not specified, default to localhost + // If targetHost is not specified, default to bind to all interfaces if targetHost == "" { - targetHost = LocalhostIPv4 + targetHost = TargetHostIPv4 } return &HTTPTransport{