跳到正文
DEV Community· Span Observer·· 1 小時前AI 評分65

Docker MCP Gateway:如何在閘道後方執行 MCP 伺服器

Docker MCP Gateway: run your MCP servers behind a gateway

AI 導讀

Docker MCP Gateway 以單一入口在容器中啟動 MCP 伺服器,並透過 profiles、工具允許清單及機密資料管理限制各伺服器的存取範圍。文章整理 stdio、sse 和 streaming 傳輸、Bearer token、容器限制及 OpenTelemetry 監測,並指出網絡出口不會預設全面封鎖。

正文

Your developers each start their own MCP servers with npx or uvx, with API keys sitting in local config files. Nobody has an inventory of what runs, or with which rights. Docker MCP Gateway offers one answer: a single entry point that starts every MCP server in a container and decides what it may see. This article starts from that operational decision rather than a tour of the product.

The facts come from the docker/mcp-gateway repository (README, LICENSE, docs/ folder), read on 12 November 2026. I did not install the tool for this piece, so everything below is « according to the repository », and anything I could not verify is flagged.

A neighbouring article covers a different gateway: agentgateway. Here the angle is containers and secrets, not network routing.

The problem: MCP servers nobody owns

An MCP server is a program that runs code on behalf of an agent. It reads files, calls APIs and receives tokens. When each laptop installs its own, the team loses three things: the inventory, the isolation and control of secrets. The risk is described in MCP tool poisoning: a booby-trapped tool description is enough to hijack an agent.

Before adopting anything, ask three questions. Where does the server run? Who holds its secrets? What happens if its code is malicious? The repository answers each with a specific mechanism.

Docker MCP Gateway: what the repository says

  • Licence: MIT, « Copyright 2025 Docker » according to the LICENSE file.
  • Popularity: about 1.6k stars and 293 forks on the GitHub page, read on 12 November 2026 (the page rounds the star count).
  • Activity: the latest commit on the default branch I fetched is dated 26 October 2026. The GitHub page showed no release, so I quote no version.
  • What it is: the code of the docker-mcp CLI plugin, which powers the MCP Toolkit in Docker Desktop. It can also run on its own. The go.mod file shows the language is Go.
  • Prerequisites: the README asks for Docker Desktop 4.59 or later with the MCP Toolkit feature enabled, and Go to build the plugin.

The README’s diagram fits on one line: AI client, then gateway, then MCP servers in containers. The client only ever talks to the gateway.

First decision: local stdio or a shared gateway

The default mode is stdio: the client launches the gateway as a child process. In the Claude Desktop configuration shown in the docs, the command is simply docker mcp gateway run. That suits a developer laptop.

To serve several clients, the docs offer the sse and streaming transports with a port. They also show a Compose file that starts the gateway in a container, without Docker Desktop, with the Docker socket mounted.

compose.yaml taken from the repository documentation: gateway service, docker/mcp-gateway image, --servers=duckduckgo option, Docker socket mounted; then the docker compose up and docker mcp gateway run commands with the streaming transport

Mind one detail in that file: mounting /var/run/docker.sock gives the gateway wide control over the Docker daemon. The security.md document lists the Docker daemon among the trusted components. Keep this mount for a host you control.

Second decision: profiles instead of per-laptop config

Servers are grouped into profiles. A profile can be created, exported to YAML and pushed to an OCI registry. A team can therefore share one set of servers the way it shares an image. The servers in a profile can come from a catalogue, an OCI image, the community MCP registry or a local file.

A profile also carries an allowlist of tools. That is where least privilege happens: enable github.create_issue, disable github.search_code, and the agent only sees the rest.

Commands from the README: docker mcp catalog pull, docker mcp profile create dev-tools with the catalogue github server, two tools enabled, one tool disabled, then docker mcp gateway run with the profile

The README notes that outside Docker Desktop (Docker CE, WSL2, a container) you must enable the feature with docker mcp feature enable profiles. With no profile given, the gateway uses the default profile.

Third decision: what the gateway refuses by default

The security.md file describes the default boundaries. These are the most useful ones for operations.

  1. HTTP access: on sse and streaming, a Bearer token is required. It comes from MCP_GATEWAY_AUTH_TOKEN or is generated. --allow-unauthenticated is an explicit opt-out.
  2. Images: signatures of images in the mcp/ namespace on Docker Hub are verified by default, and those images must be referenced by digest. Third-party images are not covered: their trust depends on your catalogue choice.
  3. Containers: no inheritance of the host environment, no-new-privileges, CPU and memory limits (the flag reference gives 1 CPU and 2Gb per server by default).
  4. Mounts: host folders are read-only by default, with an allowlist of paths.
  5. Secrets: each server only receives the ones it declares, and --block-secrets scans tool arguments and responses for values that look like secrets.

Summarised extracts of docs/security.md: Bearer token on HTTP transports, signature checks for mcp/ images, no-new-privileges and CPU and memory limits, read-only mounts, block-secrets and log-calls on by default, block-network to be enabled

One point to remember: network egress is not blocked globally. The document says so plainly. Servers can request disableNetwork or allowHosts, and you can start the gateway with --block-network. For a server that needs no outbound call, this is a setting you must make yourself.

Secrets and OAuth: getting keys out of JSON files

The README promises to keep secrets out of environment variables by using the secrets management of Docker Desktop. The commands are docker mcp secret and docker mcp oauth. Outside Docker Desktop, the docs show a fallback: --secrets=docker-desktop:./.env looks in Docker Desktop first, then in a local .env file. That fallback puts a plain-text file back on disk, so keep it for tests.

For OAuth, the repository documents OAuth 2.1 flows with PKCE for remote servers. I have not verified their end-to-end behaviour: read docs/oauth-flows.md before you deploy them.

Observing the gateway with OpenTelemetry

For an SRE team, the gateway is a good observation point, because every tool call goes through it. The docs/telemetry/README.md file describes OpenTelemetry instrumentation with metrics and traces. It lists, for example, mcp.tool.calls (counter), mcp.tool.duration (histogram in milliseconds) and mcp.tool.errors, plus per-server discovery counters. Metrics are exported every 30 seconds for a long-running gateway, adjustable with DOCKER_MCP_METRICS_INTERVAL.

The destination comes from the Docker context. To test with your own Collector, the docs cite DOCKER_CLI_OTEL_EXPORTER_OTLP_ENDPOINT, for example http://localhost:4317. Without an endpoint, no metric exporter is created. To read a trace in that setup, revisit the anatomy of an OpenTelemetry span.

What about Dynatrace? This article covers a third-party tool only. If you send these OTLP signals to Dynatrace, follow the official documentation and keep SaaS and Managed apart: I mix no feature here, and I have not tested that path.

Limits and open points

  • The repository describes features that are still moving: profiles need a flag outside Docker Desktop, and catalogue v3 depends on an mcp-oauth-dcr feature.
  • Isolation protects the host, not your data: a legitimate server with write access to an API can still do damage. Tool allowlists remain your safety net.
  • Security of the Docker catalogue (review, dependency scanning) belongs to a different system from this repository, according to security.md.
  • I have not measured the latency the gateway adds: assume neither zero nor negligible.

To compare with an MCP server isolated by hand, read isolating a stdio MCP server.

Best practices

  • Start with stdio on one laptop, and move to HTTP only when several clients must share the gateway.
  • Keep the Bearer token enabled and store it in a secrets manager.
  • Write one profile per use case, with the shortest possible tool allowlist.
  • Enable --block-network for servers that do not need the Internet.
  • Watch mcp.tool.errors and call duration, and alert on a sudden rise.

Frequently asked questions

Does Docker MCP Gateway require Docker Desktop?

No, according to the repository: the plugin « can work in Docker Desktop or independently », and the docs show a run on a plain Docker engine. Outside Docker Desktop a few settings are needed, such as DOCKER_MCP_IN_CONTAINER=1 and enabling profiles.

Does the gateway protect against a malicious MCP server?

It reduces what the server can read and receive: isolated container, limited secrets, read-only mounts. It does not guarantee that an allowed server behaves. Keep the tool list short and review the server’s source.

Can I see tool calls in my observability tools?

Yes, according to docs/telemetry: OpenTelemetry metrics and traces, with a configurable OTLP endpoint. Call logs record the tool name and the shape of the arguments, not their values.

Conclusion

Docker MCP Gateway shifts the question from « which MCP server should I install? » to « who governs what runs? ». For a team, profiles, secrets and default guardrails are worth a trial on one laptop before any shared rollout. Sources: docker/mcp-gateway repository.

span.observer is an independent community blog, not affiliated with Dynatrace LLC or Docker, Inc. Trademarks belong to their owners. Tools change fast: check commands and options in the official documentation.


Originally published on span.observer. French version: https://span.observer/fr/docker-mcp-gateway-serveurs-mcp-passerelle/.

來源:DEV Community · dev.to