Skip to content

Host networking lies about the MCP url #2317

@kantord

Description

@kantord

Bug description

Host networking support was introduced in toolhive in order to support the MCP-optimizer use case. This solved the root cause of networking issues that made it impossible for MCP-optimizer to reach MCP servers while running in. native containers.

However, for some reason thv still attempts to bind random ports and reports that the MCP server can be accessed on that port. This is not true, the MCP is accessible on whatever host port it decides to bind itself to (mcp-optimizer respects MCP_PORT)

Steps to reproduce

Using native containers (Linux)

❯ thv run python:3-slim --name test-bug --network host --target-port 8000 --transport streamable-http --detach -- python3 -m http.server 8000
❯ thv list | grep test-bug
A new version of ToolHive is available: v0.4.2
Currently running: v0.4.2-3-g392db5b9
test-bug   python:3-slim   running   http://127.0.0.1:18178/mcp   18178   mcp         default   2025-10-24 10:47:05.770908242 +0200 CEST

❯ curl -I http://127.0.0.1:18178/mcp
HTTP/1.1 502 Bad Gateway
Date: Fri, 24 Oct 2025 08:48:28 GMT

❯ curl -I http://127.0.0.1:18178/
HTTP/1.1 502 Bad Gateway
Date: Fri, 24 Oct 2025 08:48:48 GMT

❯ curl -I http://127.0.0.1:8000/mcp
HTTP/1.0 404 File not found
Server: SimpleHTTP/0.6 Python/3.14.0
Date: Fri, 24 Oct 2025 08:49:03 GMT
Connection: close
Content-Type: text/html;charset=utf-8
Content-Length: 460

❯ curl -I http://127.0.0.1:8000/
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.14.0
Date: Fri, 24 Oct 2025 08:49:14 GMT
Content-type: text/html; charset=utf-8
Content-Length: 946

Expected behavior

  • MCP accessible through URL reported by thv ls
  • Host networking ignored when it's not applicable

Actual behavior

  • MCP NOT accessible through URL reported by thv ls
  • Host networking seemingly enabled, even when it's not truly possible?

Environment (if relevant)

Linux with any container engine using native containers. I tested with Docker.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcliChanges that impact CLI functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions