使用 YAML 配置 MCP 服务器

Docker 与 Anthropic 合作,为 MCP 服务器的参考实现提供容器镜像。这些镜像可在 Docker Hub 的mcp 命名空间下找到。

当您在终端中运行 `docker ai` 命令时,Gordon 会在您的工作目录中查找 `gordon-mcp.yml` 文件。如果存在,此文件会列出 Gordon 在该上下文中应使用的 MCP 服务器。`gordon-mcp.yml` 文件是一个 Docker Compose 文件,用于将 MCP 服务器配置为 Gordon 可以访问的 Compose 服务。

以下极简示例展示了如何使用mcp-time 服务器为 Gordon 提供时间功能。有关更多详细信息,请参阅源代码和文档

在您的工作目录中创建 `gordon-mcp.yml` 文件并添加时间服务器

services:
  time:
    image: mcp/time

有了此文件,您现在可以要求 Gordon 告诉您另一个时区的时间

$ docker ai 'what time is it now in kiribati?'

    • Calling get_current_time

  The current time in Kiribati (Tarawa) is 9:38 PM on January 7, 2025.

Gordon 会找到 MCP 时间服务器并在需要时调用其工具。

使用高级 MCP 服务器功能

某些 MCP 服务器需要访问您的文件系统或系统环境变量。Docker Compose 有助于解决此问题。由于 `gordon-mcp.yml` 是一个 Compose 文件,您可以使用标准的 Docker Compose 语法添加绑定挂载。这使得您的文件系统资源可用于容器

services:
  fs:
    image: mcp/filesystem
    command:
      - /rootfs
    volumes:
      - .:/rootfs

`gordon-mcp.yml` 文件为 Gordon 添加了文件系统访问功能。由于所有内容都在容器内运行,Gordon 只能访问您指定的目录。

Gordon 可以使用任意数量的 MCP 服务器。例如,使用 `mcp/fetch` 服务器为 Gordon 提供互联网访问

services:
  fetch:
    image: mcp/fetch
  fs:
    image: mcp/filesystem
    command:
      - /rootfs
    volumes:
      - .:/rootfs

您现在可以要求 Gordon 获取内容并将其写入文件

$ docker ai can you fetch rumpl.dev and write the summary to a file test.txt

    • Calling fetch ✔️
    • Calling write_file ✔️

  The summary of the website rumpl.dev has been successfully written to the
  file test.txt in the allowed directory. Let me know if you need further
  assistance!

$ cat test.txt
The website rumpl.dev features a variety of blog posts and articles authored
by the site owner. Here's a summary of the content:

1. **Wasmio 2023 (March 25, 2023)**: A recap of the WasmIO 2023 conference 
   held in Barcelona. The author shares their experience as a speaker and 
   praises the organizers for a successful event.

2. **Writing a Window Manager in Rust - Part 2 (January 3, 2023)**: The 
   second part of a series on creating a window manager in Rust. This 
   installment focuses on enhancing the functionality to manage windows 
   effectively.

3. **2022 in Review (December 29, 2022)**: A personal and professional recap 
   of the year 2022. The author reflects on the highs and lows of the year, 
   emphasizing professional achievements.

4. **Writing a Window Manager in Rust - Part 1 (December 28, 2022)**: The 
   first part of the series on building a window manager in Rust. The author 
   discusses setting up a Linux machine and the challenges of working with 
   X11 and Rust.

5. **Add docker/docker to your dependencies (May 10, 2020)**: A guide for Go 
   developers on how to use the Docker client library in their projects. The 
   post includes a code snippet demonstrating the integration.

6. **First (October 11, 2019)**: The inaugural post on the blog, featuring a 
   simple "Hello World" program in Go.

接下来是什么?

既然您知道如何将 MCP 服务器与 Gordon 一起使用,请尝试以下步骤

  • 实验:尝试将一个或多个经过测试的 MCP 服务器集成到您的 `gordon-mcp.yml` 文件中,并探索它们的功能。
  • 探索生态系统。请参阅 GitHub 上的参考实现 或浏览 Docker Hub MCP 命名空间 以查找可能适合您需求的更多服务器。
  • 构建您自己的。如果现有服务器都不能满足您的需求,或者您想了解更多信息,请开发一个自定义 MCP 服务器。请使用 MCP 规范 作为指导。
  • 分享您的反馈。如果您发现与 Gordon 配合良好的新服务器或遇到问题,请分享您的发现,以帮助改进生态系统

通过 MCP 支持,Gordon 为您的用例提供了强大的可扩展性和灵活性,无论您需要时间感知、文件管理还是互联网访问。

© . This site is unofficial and not affiliated with Kubernetes or Docker Inc.