stacklok / stacklok/toolhive

MCP that uses non-HTTP TCP connections can't connect via egress proxy

Open
#758 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Go
Stars
2.2k
Forks
300
Avg merge
1d 15h
Merged PRs (30d)
184

Description

Summary

MCP servers that make outbound connections which are NOT http or https cannot connect through the Squid egress proxy.

The specific MCP I was working with is MongoDB, but I assume the same issue would apply to other similar database MCPs.

Example

The MongoDB MCP server can't connect to an Atlas database via the new egress proxy currently in main. It works with v0.0.47 (no egress proxy).

The MCP container fails to start with a connection error (full error at bottom):

Failed to connect to MongoDB instance using the connection string from the config:  MongoNetworkError: connect ENETUNREACH 89.192.235.203:27017 - Local (0.0.0.0:0)

Platform: macOS with Docker Desktop 4.42.0
MCP server: official mongodb MCP, tested with both their image and npx:// protocol handler

Note that MongoDB connects on port 27017 using MongoDB's wire protocol, not HTTP/HTTPS.

Reproduce

Get a free tier MongoDB Atlas instance from https://www.mongodb.com/cloud/atlas/register, load the sample data, and put your connection string into a ToolHive secret:

thv secret set mongodb
<enter when prompted>

(Or, I can share mine 😄)

Run the MCP server against main:

task build
./bin/thv run --name mongodb --secret mongodb,target=MDB_MCP_CONNECTION_STRING mongodb/mongodb-mcp-server:lates
t

Get the logs and observe the connection error (see below for full error):

./bin/thv logs mongodb

I verified that it's using the default network profile which should permit access (from ~/Library/Application\ Support/toolhive/runconfigs/mongodb.json):

  "permission_profile": {
    "name": "network",
    "network": {
      "outbound": {
        "insecure_allow_all": true
      }
    }
  },

Expected behavior

Run the mongodb MCP with v0.0.47:

thv run --name mongodb --secret mongodb,target=MDB_MCP_CONNECTION_STRING mongodb/mongodb-mcp-server:lates
t

The server starts up successfully and you can use the tools from a client (example prompt: "list my mongodb databases" returns the list of databases):

Image

Logs

Full MongoDB error:

Failed to connect to MongoDB instance using the connection string from the config:  MongoNetworkError: connect ENETUNREACH 89.192.235.215:27017 - Local (0.0.0.0:0)
    at TLSSocket.<anonymous> (/usr/local/lib/node_modules/mongodb-mcp-server/node_modules/mongodb/lib/cmap/connect.js:286:44)
    at Object.onceWrapper (node:events:633:26)
    at TLSSocket.emit (node:events:518:28)
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  errorLabelSet: Set(1) { 'ResetPool' },
  beforeHandshake: false,
  [cause]: Error: connect ENETUNREACH 89.192.235.215:27017 - Local (0.0.0.0:0)
      at internalConnect (node:net:1115:16)
      at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)
      at GetAddrInfoReqWrap.emitLookup [as callback] (node:net:1522:9)
      at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:134:8) {
    errno: -101,
    code: 'ENETUNREACH',
    syscall: 'connect',
    address: '89.192.235.215',
    port: 27017
  }
}
{"method":"notifications/message","params":{"level":"emergency","data":"[server]: Fatal error running server: Error: Failed to connect to MongoDB instance using the connection string from the config"},"jsonrpc":"2.0"}

Nothing is logged by the mongodb-egress container's squid logs.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the MongoDB MCP connection against main and comparing it with v0.0.47, using the documented network profile and the mongodb-egress container logs. Trace how the egress proxy handles non-HTTP TCP traffic; done means the MongoDB MCP can connect to Atlas through the proxy and its traffic appears in the proxy logs.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, mongodb
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.