mcporter 是做什麼的?
透過 HTTP 或 stdio 列出、設定、驗證、呼叫及檢視 MCP 伺服器/工具。
概述
mcporter 是一個指令列工具,負責管理 MCP (Model Context Protocol) 伺服器與工具的生命週期。它將多個 MCP 伺服器抽象化為單一介面,支援 HTTP API 與標準 I/O (stdio) 兩種通訊模式。
功能
- 列出:顯示所有已註冊的 MCP 伺服器及其提供的工具。
- 設定:動態調整伺服器設定,包括端點 URL、逾時值及驗證資訊。
- 驗證:支援多種驗證機制,如 API 金鑰、OAuth 或自訂標頭。
- 呼叫:透過統一的 API 叫用特定工具,無需直接與個別伺服器通訊。
- 檢視:檢查工具的完整定義,包括輸入參數、輸出格式與任何必要條件。
安裝
# 透過 npm 安裝(範例)
npm install -g mcporter
# 或者從原始碼編譯
git clone https://github.com/steipete/mcporter.git
cd mcporter
pip install .
使用方式
啟動 mcporter 伺服器
mcporter serve --port 8080
列出所有伺服器與工具
mcporter list
設定伺服器驗證
mcporter configure myserver --auth-type api-key --api-key "your-api-key"
呼叫工具
mcporter call myserver mytool --param1 value1 --param2 value2
透過 HTTP 呼叫
curl -X POST http://localhost:8080/call \
-H "Content-Type: application/json" \
-d '{"server": "myserver", "tool": "mytool", "args": {"param1": "value1"}}'
支援的環境
- 本地環境:直接透過 stdio 或本地 HTTP 伺服器執行。
- 雲端環境:可部署為獨立服務,支援反向代理與 SSL/TLS。
- CI/CD 管道:可整合至自動化腳本,用於測試或部署前檢查。
設定檔
mcporter 會從下列位置載入設定(依優先順序):
- 指令列參數
- 環境變數(
MCPORTER_*) - 設定檔(
~/.mcporter/config.yaml) - 預設值
範例設定檔 ~/.mcporter/config.yaml:
servers:
myserver:
type: mcp
endpoint: https://api.example.com/mcp
auth:
type: api-key
key: "your-api-key"
與 AI 代理整合
此技能可直接被 AI 代理(如 Claude Code、Cursor 或 Codex)使用,透過 mcporter 的 HTTP 或 stdio 介面來動態探索與叫用 MCP 工具。代理可以自動列出可用的工具、檢查其定義,並根據使用者需求執行呼叫,無需手動設定每項工具的連線細節。
進階範例
使用 stdio 通訊
mcporter stdio --server myserver --tool mytool --args '{"param1": "value"}'
註冊多個伺服器
mcporter add-server mydb --type mcp --endpoint https://db.example.com/mcp
mcporter add-server myllm --type mcp --endpoint https://llm.example.com/mcp
偵錯模式
mcporter serve --debug --log-file mcporter.log
限制與注意事項
- 部分驗證方式(如 OAuth 2.0 with PKCE)需要使用者互動,無法完全自動化。
- 工具的回傳資料大小可能會受到 HTTP 或 stdio 緩衝區限制。
- 對於高延遲的伺服器,建議設定合適的逾時值。