Cookbook
Agents & skills · for AI agents
連接您自己的 MCP 伺服器
註冊遠端 MCP 伺服器,讓您的代理程式可以呼叫其工具 — 透過主控台或 REST API。
MCP tools:
list_mcp_serverslist_toolsupdate_agentBring your own tools:註冊一個 remote MCP 伺服器,其工具即可附加至您的 agents。系統刻意不提供「建立 MCP 伺服器」工具——註冊伺服器代表信任該伺服器對您的 tenant 進行操作,因此這是透過控制台(或 REST 呼叫)執行的明確動作,而非 agent 自行執行。
1. 註冊伺服器
在控制台中:Tools / MCP → Add MCP server — 提供名稱、選擇傳輸協議(Streamable HTTP 或 SSE),以及 URL 和任何驗證標頭。
或使用 REST,搭配您的 tenant 金鑰($BASE = https://api.agent4.io/v1):
curl -X POST $BASE/mcp-servers -H "X-API-Key: $KEY" -H 'Content-Type: application/json' \
-d '{"name":"my-tools","transport":"streamable_http",
"config":{"url":"https://tools.example.com/mcp","headers":{"Authorization":"Bearer …"}}}'僅接受 remote 傳輸協議。stdio(本機命令)會被拒絕——伺服器運行於平台上,而非您的機器上,因此本機命令對您而言毫無用處,且存在程式碼執行風險。
2. 查看其工具
list_mcp_servers() # the MCP servers registered on your tenant
list_tools() # every tool you can attach to an agent, including the ones from your servers3. 將工具附加至 agent
update_agent(name="Support", add_tools=["…"]) # incremental; use tool names exactly as list_tools() reports them現在,agent 可在對話期間呼叫這些工具。請保持工具集精簡——少數相關工具勝過大量堆疊(請參閱 設計原則)。