使用 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 為您的用例提供了強大的可擴充套件性和靈活性,無論您需要時間感知、檔案管理還是網際網路訪問。