使用 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 語法加入綁定掛載(bind mounts)。這能讓容器存取您的檔案系統資源。

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

gordon-mcp.yml 檔案為 Gordon 增加了檔案系統存取能力。由於一切都在容器內執行,Gordon 僅能存取您指定的目錄。

Gordon 可以使用任意數量的 MCP 伺服器。例如,若要讓 Gordon 使用 mcp/fetch 伺服器存取網際網路:

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.