Loading...
    • 建構
    • 管理
    • 模型與定價
    • 客戶端 SDK
    • API 參考
    Search...
    ⌘K
    第一步
    Claude 簡介快速入門
    使用 Claude 建構
    功能概覽使用 Messages API處理停止原因
    模型功能
    延伸思考自適應思考效能快速模式(測試版:研究預覽)結構化輸出引用來源串流訊息批次處理搜尋結果串流拒絕多語言支援嵌入向量
    工具
    概覽工具使用方式網路搜尋工具網路擷取工具程式碼執行工具記憶體工具Bash 工具電腦使用工具文字編輯器工具
    工具基礎架構
    工具搜尋程式化工具呼叫細粒度工具串流
    上下文管理
    上下文視窗壓縮上下文編輯提示快取Token 計數
    處理檔案
    Files APIPDF 支援圖像與視覺
    技能
    概覽快速入門最佳實踐企業版技能API 中的技能
    MCP
    遠端 MCP 伺服器MCP 連接器
    提示工程
    概覽提示最佳實踐Console 提示工具
    測試與評估
    定義成功標準並建立評估在 Console 中使用評估工具降低延遲
    強化防護欄
    減少幻覺提高輸出一致性防範越獄減少提示洩漏
    資源
    詞彙表
    版本說明
    Claude Platform
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    定義您的代理

    MCP 連接器

    將 MCP 伺服器連接到您的代理程式,以存取外部工具和資料來源。

    Was this page helpful?

    • 在代理程式上宣告 MCP 伺服器
    • 支援的 MCP 伺服器類型

    Claude Managed Agents 支援將 Model Context Protocol (MCP) 伺服器連接到您的代理程式。這讓代理程式能夠透過標準化協定存取外部工具、資料來源和服務。

    MCP 設定分為兩個步驟:

    1. 代理程式建立:透過名稱和 URL 宣告代理程式連接的 MCP 伺服器。
    2. 工作階段建立:透過參照預先註冊的 vault 為這些伺服器提供驗證。

    這種分離方式讓機密資訊不會出現在可重複使用的代理程式定義中,同時允許每個工作階段使用自己的憑證進行驗證。

    所有 Managed Agents API 請求都需要 managed-agents-2026-04-01 beta 標頭。SDK 會自動設定 beta 標頭。

    在代理程式上宣告 MCP 伺服器

    在建立代理程式時,於 mcp_servers 陣列中指定 MCP 伺服器。每個伺服器需要一個 type、一個唯一的 name 以及一個 url。此階段不提供驗證權杖。

    您在 MCP 伺服器陣列中指定的 name 用於參照工具陣列中的 mcp_toolset 項目。

    agent_response=$(curl -sS --fail-with-body https://api.anthropic.com/v1/agents \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      -H "content-type: application/json" \
      -d @- <<'EOF'
    {
      "name": "GitHub Assistant",
      "model": "claude-sonnet-4-6",
      "mcp_servers": [
        {
          "type": "url",
          "name": "github",
          "url": "https://api.githubcopilot.com/mcp/"
        }
      ],
      "tools": [
        {"type": "agent_toolset_20260401"},
        {"type": "mcp_toolset", "mcp_server_name": "github"}
      ]
    }
    EOF
    )
    agent_id=$(jq -r '.id' <<<"$agent_response")

    MCP 工具集預設的權限政策為 always_ask,這需要在每次工具呼叫前取得使用者核准。請參閱權限政策以設定此行為。

    在工作階段建立時提供驗證

    啟動工作階段時,傳遞 vault_ids 以為您的 MCP 伺服器提供憑證。Vault 是您一次性註冊並透過 ID 參照的憑證集合。請參閱使用 vault 進行驗證以了解如何建立 vault 和管理憑證。

    如果 vault 中提供的授權憑證無效,工作階段建立仍會成功,且互動仍可進行。系統會發出 session.error 事件,描述 MCP 驗證失敗的情況。您可以決定是否要在此錯誤上封鎖進一步的互動、觸發憑證更新,或允許工作階段在沒有 MCP 的情況下繼續。驗證重試將在下一次 session.status_idle 到 session.status_running 的轉換時發生。請參閱工作階段事件串流以了解使用 session.error 和其他事件的詳細資訊。

    支援的 MCP 伺服器類型

    Claude Managed Agents 連接到公開 HTTP 端點的遠端 MCP 伺服器。伺服器必須支援 MCP 協定的可串流 HTTP 傳輸。

    有關 MCP 和建立 MCP 伺服器的更多資訊,請參閱 MCP 文件。

    session_response=$(curl -sS --fail-with-body https://api.anthropic.com/v1/sessions \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      -H "content-type: application/json" \
      -d @- <<EOF
    {
      "agent": "$agent_id",
      "environment_id": "$environment_id",
      "vault_ids": ["$vault_id"]
    }
    EOF
    )
    session_id=$(jq -r '.id' <<<"$session_response")