docker-mcp

docker-mcp

Wraps the Docker Engine API as MCP tools for container and image management. Reduces token consumption by providing typed tools with default summaries and field selection.

Category
访问服务器

README

docker-mcp

MCP (Model Context Protocol) server wrapping the Docker Engine API. Exposes Docker operations as typed MCP tools, reducing token consumption versus generating CLI commands.

Quick Start

npx docker-mcp

Or add to your MCP client config (OpenCode, Claude Desktop, etc.):

{
  "mcpServers": {
    "docker": {
      "command": "npx",
      "args": ["docker-mcp"]
    }
  }
}

Configuration

Configure via environment variables, matching Docker CLI conventions:

Variable Purpose Example
DOCKER_HOST Docker daemon address ssh://user@192.168.1.111
DOCKER_TLS_VERIFY Enable TLS 1
DOCKER_CERT_PATH TLS cert directory ~/.docker/certs

Default: Connects to local Docker socket (/var/run/docker.sock).

Connection methods (recommended order)

  1. SSH (preferred): DOCKER_HOST=ssh://user@host — dockerode handles SSH natively. Pre-populate ~/.ssh/known_hosts to avoid host key prompts.
  2. TCP + TLS: DOCKER_HOST=tcp://host:2376 with DOCKER_TLS_VERIFY=1 and DOCKER_CERT_PATH.
  3. Plain TCP: DOCKER_HOST=tcp://host:2375 — warning: unencrypted TCP grants root access to anyone on the network. Only use on trusted LANs.

Authentication

For private registries, prefer pre-configuring credentials:

docker login myregistry.io

dockerode reads ~/.docker/config.json automatically. Inline auth parameters are also supported on image_action pull/push, but note that credentials transit the MCP protocol (stdin/stdout).

Tools (17 total)

Container tools

Tool Description
container_query List or inspect containers. Supports filters (status, label), limit, field selection, verbose mode.
container_action Start, stop, restart, pause, unpause, or remove containers.
container_create Create a container from an image with env, ports, volumes.
container_logs Get container logs with tail limit (default 100, max 10,000) and timestamps. ANSI codes stripped.
container_exec Run a command inside a running container. Output capped at 10KB/200 lines.

Image tools

Tool Description
image_query List or inspect images. Supports dangling filter, field selection.
image_action Pull, remove, tag, or push images. Supports registry auth.
image_build Build an image from a Dockerfile.

Volume tools

Tool Description
volume_query List or inspect volumes.
volume_action Create or remove volumes.

Network tools

Tool Description
network_query List or inspect networks.
network_action Create, remove, connect, or disconnect networks.

Compose tools

Tool Description
compose_action Up, down, pull, or stop Compose projects. Fire-and-forget for up (check with compose_query ps).
compose_query List services (ps), validate config, or get logs.

System tools

Tool Description
system_df Docker disk usage breakdown.
system_prune Prune unused resources by scope (all, containers, images, volumes, networks, builder).

Health

Tool Description
docker_ping Check Docker daemon connectivity and return version info.

Token Optimization

This server is designed to minimize token consumption:

  • Default summaries: Query tools return curated fields by default. Use verbose: true for full payloads.
  • Field selection: Pass fields: ["Id", "State.Status"] to get only the data you need.
  • Pagination: Use limit on list tools to cap result size.
  • Log capping: Logs default to 100 lines (max 10,000). Exec output capped at 10KB/200 lines.
  • Compact IDs: 12-character IDs by default. Use fullId: true for full 64-char IDs.
  • ANSI stripping: All output has ANSI codes stripped server-side.
  • Tool consolidation: Related operations merged into 17 tools via action enums instead of 35 individual tools.

Security Notes

  • container_exec allows arbitrary command execution in any container — equivalent to docker exec.
  • image_build accepts a context path — ensure it points to a project directory, not / or /etc.
  • Inline auth credentials on image_action transit the MCP protocol (stdio). Prefer docker login.
  • Plain TCP Docker sockets grant root access without authentication. Use SSH or TLS when accessing remote hosts.

Development

# Install
npm install

# Dev server with hot reload
npm run dev

# Build
npm run build

# Test
npm test                 # Unit tests (no Docker needed)
npm run test:integration # Integration tests (requires Docker)
npm run lint             # Lint
npm run typecheck        # TypeScript check

# Format
npm run format

Architecture

src/
  index.ts         — Entrypoint, DI wiring, stdio transport
  config.ts        — Docker client factory (reads DOCKER_HOST env vars)
  error.ts         — Centralized error handler with status-code mapper
  utils/
    compose.ts     — Compose arg builder + JSON output parser (pure)
    summarize.ts   — Token optimization utilities (field projection, ID truncation, ANSI stripping, output capping)
  tools/
    types.ts       — Shared types + tool registration helpers
    health.ts      — docker_ping (validates pipeline)
    containers.ts  — 5 container tools
    images.ts      — 3 image tools
    volumes.ts     — 2 volume tools
    networks.ts    — 2 network tools
    compose.ts     — 2 compose tools
    system.ts      — 2 system tools

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选