Skip to content

Support publishing additional container ports in thv run #3812

@jerm-dro

Description

@jerm-dro

Problem

Some MCP server images expose multiple ports — for example, one port for the MCP transport and a secondary port for a frontend UI or metrics endpoint. Currently, thv run only exposes a single port (the MCP transport port via --target-port), with no mechanism to publish additional container ports to the host.

This was reported in #3721 (reply in thread), where a user attempted to expose a secondary frontend port alongside the MCP transport port. Working directly with Podman succeeds:

podman run -d -p 8002:8000 -p 8003:8001 ghcr.io/manykarim/rf-mcp:latest

But there is no equivalent in thv run — the --publish flag does not exist and is silently ignored.

Root Cause

The container runtime layer (DeployWorkloadOptions) already supports multiple port mappings via its ExposedPorts and PortBindings maps. However, no layer above it populates more than one port:

Layer File Supports multiple ports?
CLI flags cmd/thv/app/run_flags.go No — only --proxy-port and --target-port
RunConfig pkg/runner/config.go No — only Port and TargetPort fields
Setup pkg/runtime/setup.go:72-94 No — only adds targetPort to exposed/bindings
DeployWorkloadOptions pkg/container/runtime/types.go Yes — maps ready for multiple entries
Docker/Podman client pkg/container/docker/client.go Yes — correctly applies all ports from options

Additionally, HostConfig.PublishAllPorts is never set to true, so even ports declared with EXPOSE in the Dockerfile are not automatically published to the host.

Proposed Solution

Add a --publish / -p flag to thv run (matching Docker/Podman convention) that accepts hostPort:containerPort mappings:

thv run --name my-mcp --transport streamable-http \
  --target-port 8000 \
  --publish 8003:8001 \
  ghcr.io/manykarim/rf-mcp:latest

This would require changes across the stack:

  1. CLI: Add --publish flag (string slice) to run_flags.go
  2. RunConfig: Add AdditionalPorts field (or similar) to config.go
  3. Setup: Thread additional ports into DeployWorkloadOptions.ExposedPorts and PortBindings in setup.go

The Docker/Podman container creation layer already handles multiple ports correctly — no changes needed there.

Metadata

Metadata

Labels

cliChanges that impact CLI functionalityenhancementNew feature or requestgoPull requests that update go codetoolhive-platformToolHive Platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions