编程智能体需要从 Docker 了解什么
处理真实项目时,智能体会反复问几个问题:哪些服务正在运行、端口 3000 上是什么应用、这个容器为什么退出、日志说了什么、能否在一次性环境中运行测试。只有 shell 时,它会运行 docker ps、docker inspect 和 docker logs,再逐行读取返回内容。这能解决问题,却又慢又贵:每一轮都要把原始 JSON 和数百行日志放入模型上下文。
MCP 服务器把这些问题转化为直接返回答案的工具。Oxcart 的工具围绕问题设计,而非照搬 Docker API 端点,因此一次调用即可替代一连串命令。
13 个工具
| 意图 | 工具 | Level needed |
|---|---|---|
| 查看 | status, projects, ports, images, logs | Read only(只读) |
| 解释 | diagnose:退出码、OOM 终止、健康检查失败、端口问题,以及关键日志行 | Read only(只读) |
| 执行操作 | container(启动、停止、重启)、exec、compose(启动、停止)、无网络的 sandbox | Manage(管理) |
| 修改与清理 | build、remove、cleanup(先预览)、带网络的 sandbox | Full(完整权限) |
status 显示每个 Compose 项目的文件夹、git 分支及 localhost URL,让你和智能体对“端口 3000 上的应用”有相同理解。订阅资源的客户端可在崩溃、OOM 终止或健康状态变化发生时立即收到通知,无需轮询。
回答更精简,会话成本更低
智能体回答各问题时,通过 Oxcart 读取的内容与原本需读取的 docker CLI 输出对比;在同一时刻对同一批容器测量:
| 问题 | Oxcart MCP | 对应的 docker CLI 命令 | docker CLI | 缩减倍数 |
|---|---|---|---|---|
| 这个容器为什么停止? | 159 | inspect + logs --tail 300 | 2,014 | 13× |
| 最近 500 行日志有错误吗? | 39 | logs --tail 500 | 703 | 18× |
| 哪些服务正在运行? | 106 | ps -a + stats --no-stream + compose ls -a | 332 | 3.1× |
五个测试容器(一个崩溃、一个不健康、一个被 OOM 终止、一个 Compose 项目、一个已发布端口)。无论日志多长,diagnose 和 logs 的响应大小均保持不变。工具列表本身每个会话只需加载一次:只读级别(6 个工具)为 510 个 token,全部 13 个工具为 1,463 个。
完整会话也呈现同样趋势。Claude Code 使用 Claude Opus 5.5 回答两个日常问题,分别仅使用 docker CLI 和使用 Oxcart MCP 服务器。两组都正确回答了两个问题。
| 任务 | 时间 | 费用 | Token 数 | 轮次 |
|---|---|---|---|---|
“worker 有报错吗?把错误给我。” | 4.2 s 对比 31.0 s | $0.022 对比 $0.157 | 10,686 对比 52,266 | 2 对比 8 |
“我的 api 容器一直退出,为什么?” | 8.5 s 对比 14.9 s | $0.036 对比 $0.070 | 11,283 对比 19,510 | 2 对比 4 |
每个任务分别在使用和不使用 Oxcart 的条件下各运行一次会话,采用人工构造的测试容器,Oxcart 0.1.0:仅供参考。费用受提示缓存影响,运行顺序未交替安排。
在任意编程智能体中设置 Oxcart MCP 服务器
- 安装 Oxcart。 下载 Oxcart(Apple 芯片,macOS 26 或更高版本)并打开。设置可离线完成,只需几秒。
- Copy the setup sentence. Open MCP Integrations in Oxcart's sidebar and copy the sentence: “Set up Oxcart's MCP server for me: run
/Applications/Oxcart.app/Contents/Helpers/oxcart agent setupand follow its instructions. If you can't run commands, tell me to copy the entry under "Agent can't run commands?" in Oxcart › MCP Integrations.” - 粘贴到智能体中。 粘贴到 Claude Code、Codex、Cursor 或任何可运行命令的智能体中。智能体会执行命令,读取适用于自身的步骤,并注册名为
oxcart的服务器。 - Ask about your containers. Ask “what is running?” or “why did
apistop?”. The agent appears on the MCP Integrations page, at Manage, with every call in its activity log. - Change the level if you want. Lower the agent to Read only to let it look but change nothing, or raise it to Full to let it build, remove and clean up. Block refuses every call. Agents set up with an earlier version of Oxcart keep their level.
Claude Desktop can't run commands, so you add the entry yourself. In Claude, Settings › Developer › Edit Config opens ~/Library/Application Support/Claude/claude_desktop_config.json. Add oxcart under mcpServers, keeping any servers already there, then quit and reopen Claude:
{
"mcpServers": {
"oxcart": {
"command": "/Applications/Oxcart.app/Contents/Helpers/oxcart",
"args": ["mcp", "--client", "claude-desktop"]
}
}
} Apps opened from the Dock or Finder don't search your shell's PATH, so every entry names the full path to oxcart, even with Oxcart's command-line tools installed. Other apps that can't run commands, such as LM Studio, take the entry Oxcart shows under Agent can't run commands? on the MCP Integrations page.
For Claude Code, the direct command is:
claude mcp add -s user oxcart -- /Applications/Oxcart.app/Contents/Helpers/oxcart mcp --client claude-code 对于 Codex,codex mcp add oxcart -- /Applications/Oxcart.app/Contents/Helpers/oxcart mcp --client codex 会为 Codex CLI 和 IDE 扩展注册服务器。
为每个智能体设置权限级别
| 级别 | 智能体可以 |
|---|---|
| Read only(只读) | 查看容器、日志、端口、项目和镜像;诊断故障 |
| Manage (default) | Also start, stop and restart, run commands, Compose up and down, run sandboxes without network, with images already on your Mac |
| Full(完整权限) | 还可构建、移除和清理,并允许沙盒访问网络 |
| Block(阻止) | 不可执行任何操作:不列出工具,拒绝所有调用,并向智能体说明原因 |
Every call is logged on your Mac and shown on the MCP Integrations page; nothing leaves the Mac. The levels govern what Oxcart's tools do for an agent. They are not a sandbox: an agent that can run shell commands can still run docker itself, so pair them with your agent's own command permissions.
提供配置步骤的智能体
Claude Code, Claude Desktop, Codex, Cursor, VS Code with Copilot, Devin Desktop, Zed, Gemini CLI, GitHub Copilot CLI, OpenCode, Cline, Junie, JetBrains AI Assistant, Goose, Kiro, Amp, Warp and LM Studio, plus a step for any other MCP client. The steps come from your installed copy of Oxcart (/Applications/Oxcart.app/Contents/Helpers/oxcart agent setup), with your Mac's real paths, so they work offline and match your version.
MCP 之外的智能体容器工作流
- Dev Containers:在 Dev Container 中运行智能体,让其 shell、工具和网络留在项目容器内。Oxcart 可运行 Dev Containers CLI;参见 Mac 上的 Dev Containers 和 Testcontainers。
- 快速迭代:智能体会不断运行和拆除容器。Oxcart 实测
docker run --rm为 42 ms,停止并移除 20 个容器为 77 ms,是我们测试的三款运行时中最快的(比较页面)。 - Compose 服务栈:智能体的
compose工具可在 Manage 级别启动和停止项目;参见 Apple 芯片上的 Docker Compose。
常见问题
Mac 上有面向 Docker 容器的 MCP 服务器吗?
有。Oxcart 内置 oxcart mcp,这是本地 stdio MCP 服务器,提供 13 个工具,用于状态、诊断、日志、端口、镜像、exec、Compose、构建、沙盒和清理。它不监听任何网络端口,也不需要令牌。
如何让 Claude Code 连接 Docker 容器?
将 Oxcart 的设置语句粘贴到 Claude Code,或运行 claude mcp add -s user oxcart -- /Applications/Oxcart.app/Contents/Helpers/oxcart mcp --client claude-code。随后 Claude Code 会列出 oxcart 服务器,并可调用其工具。
支持 Codex、Cursor 和带 Copilot 的 VS Code 吗?
Oxcart 为 18 款具名客户端提供配置步骤,包括 Codex、Cursor、带 Copilot 的 VS Code、Claude Desktop、Zed、Gemini CLI、GitHub Copilot CLI、Cline、Goose、Kiro、Amp、Warp 和 LM Studio,也为其他 MCP 客户端提供通用步骤。其中 Claude Code 已完成端到端运行验证。
智能体能删除我的容器或卷吗?
Not by default. New agents start at Manage: they can start, stop and restart containers, run commands in them and bring Compose projects up and down with images already on your Mac, but not pull, build or delete. Removing containers, images and volumes and cleaning up need Full. Agents set up with an earlier version of Oxcart keep their level, and you can lower an agent to Read only, raise it to Full, or Block it. At Full, cleanup first returns a preview and a token, and deletes only what that preview listed. The levels govern Oxcart's tools; they are not a sandbox, so an agent with shell access can still run the docker CLI directly.
为什么不直接让智能体运行 docker 命令?
可以,但智能体需要读取大量原始输出。回答“这个容器为什么停止?”时,Oxcart 的 diagnose 工具需要 159 个 token,而 docker inspect 加 docker logs --tail 300 需要 2,014 个,缩减 13×。每个任务各运行一次 Claude Code 会话的参考测试中,查找日志错误用时从 31.0 s 降至 4.2 s。
MCP 服务器会把我的数据发送到其他地方吗?
不会。它只与本地引擎套接字通信,自身不建立网络连接。每次调用都写入 Mac 上的活动日志。工具启动或构建需要镜像的内容时,仍会像 docker run 一样从镜像仓库拉取镜像。
智能体能在一次性容器中运行代码吗?
可以,使用 sandbox 工具:它创建一次性容器,内存限制为 2 GiB,进程数限制为 1,024。默认无网络,只有智能体处于 Full 级别且请求网络访问时才会启用。
来源与方法
- 回答大小:2026-10-10 使用五个测试容器测量;token 数按字符数 ÷ 4 估算。
- 会话:Claude Code 2.1.296,使用
claude-opus-5-5,Oxcart 0.1.0,每个任务、每组各运行一次。 - 速度数据:Oxcart 0.1.2,2026-10-10,Apple M5 Max,8 个 CPU 和 12 GiB;对比运行时于同日较早时间,使用同一台 Mac、同一套测试工具和 docker 29.4 客户端测量。