Loading...
    • ビルド
    • 管理
    • モデルと料金
    • クライアントSDK
    • APIリファレンス
    Search...
    ⌘K
    はじめに
    Claudeの概要クイックスタート
    Claudeで構築する
    機能概要Messages APIの使用停止理由の処理
    モデルの機能
    拡張思考適応的思考エフォート高速モード(ベータ:リサーチプレビュー)構造化出力引用ストリーミングメッセージバッチ処理検索結果ストリーミング拒否多言語サポート埋め込み
    ツール
    概要ツール使用の仕組みウェブ検索ツールウェブフェッチツールコード実行ツールメモリツールBashツールコンピューター使用ツールテキストエディタツール
    ツールインフラ
    ツール検索プログラムによるツール呼び出し細粒度ツールストリーミング
    コンテキスト管理
    コンテキストウィンドウコンパクションコンテキスト編集プロンプトキャッシュトークンカウント
    ファイルの操作
    Files APIPDFサポート画像とビジョン
    スキル
    概要クイックスタートベストプラクティスエンタープライズ向けスキルAPIのスキル
    MCP
    リモートMCPサーバーMCPコネクター
    プロンプトエンジニアリング
    概要プロンプトのベストプラクティスConsoleプロンプトツール
    テストと評価
    成功の定義と評価の構築ConsoleでのEvaluation Toolの使用レイテンシの削減
    ガードレールの強化
    幻覚の低減出力の一貫性向上ジェイルブレイクの軽減プロンプトリークの低減
    リソース
    用語集
    リリースノート
    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
    エージェントへの作業委任

    GitHubへのアクセス

    エージェントをGitHubリポジトリに接続して、クローン、読み取り、プルリクエストの作成を行います。

    GitHubリポジトリをセッションコンテナにマウントし、GitHubMCPに接続してプルリクエストを作成できます。

    GitHubリポジトリはキャッシュされるため、同じリポジトリを使用する今後のセッションはより高速に開始されます。

    すべてのManaged Agents APIリクエストには、managed-agents-2026-04-01ベータヘッダーが必要です。SDKはベータヘッダーを自動的に設定します。

    GitHub MCPとセッションリソース

    まず、GitHub MCPサーバーを宣言するエージェントを作成します。エージェント定義はサーバーURLを保持しますが、認証トークンは保持しません。

    agent_id=$(curl -fsS 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" \
      --data @- <<JSON | jq -r '.id'
    {
      "name": "Code Reviewer",
      "model": "claude-sonnet-4-6",
      "system": "You are a code review assistant with access to GitHub.",
      "mcp_servers": [
        {
          "type": "url",
          "name": "github",
          "url": "https://api.githubcopilot.com/mcp/"
        }
      ],
      "tools": [
        {"type": "agent_toolset_20260401"},
        {
          "type": "mcp_toolset",
          "mcp_server_name": "github"
        }
      ]
    }
    JSON
    )

    次に、GitHubリポジトリをマウントするセッションを作成します。

    session_id=$(curl -fsS 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" \
      --data @- <<JSON | jq -r '.id'
    {
      "agent": "$agent_id",
      "environment_id": "$environment_id",
      "resources": [
        {
          "type": "github_repository",
          "url": "https://github.com/org/repo",
          "mount_path": "/workspace/repo",
          "authorization_token": "ghp_your_github_token"
        }
      ]
    }
    JSON
    )

    resources[].authorization_tokenはリポジトリクローン操作を認証し、APIレスポンスではエコーバックされません。

    トークンの権限

    GitHubトークンを提供する場合は、必要最小限の権限を使用してください。

    アクション必要なスコープ
    プライベートリポジトリのクローンrepo
    プルリクエストの作成repo
    イシューの読み取りrepo(プライベート)またはpublic_repo
    イシューの作成repo(プライベート)またはpublic_repo

    最小限の必要な権限を持つきめ細かいパーソナルアクセストークンを使用してください。GitHubアカウントへの広範なアクセス権を持つトークンの使用は避けてください。

    複数のリポジトリ

    resources配列にエントリを追加して、複数のリポジトリをマウントします。

    resources='[
      {
        "type": "github_repository",
        "url": "https://github.com/org/frontend",
        "mount_path": "/workspace/frontend",
        "authorization_token": "ghp_your_github_token"
      },
      {
        "type": "github_repository",
        "url": "https://github.com/org/backend",
        "mount_path": "/workspace/backend",
        "authorization_token": "ghp_your_github_token"
      }
    ]'

    実行中のセッションでリポジトリを管理する

    セッションが作成された後、そのリポジトリリソースをリストし、認証トークンをローテーションできます。各リソースには、セッション作成時(またはresources.list経由)に返されるidがあり、これを更新に使用します。リポジトリはセッションの存続期間中アタッチされます。マウントされるリポジトリを変更するには、新しいセッションを作成してください。

    # List resources on the session
    repo_resource_id=$(curl -fsS "https://api.anthropic.com/v1/sessions/$session_id/resources" \
      -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" | jq -r '.data[0].id')
    echo "$repo_resource_id"  # "sesrsc_01ABC..."
    
    # Rotate the authorization token
    curl -fsS "https://api.anthropic.com/v1/sessions/$session_id/resources/$repo_resource_id" \
    # ...
      -o /dev/null \
      --data @- <<JSON
    {
      "authorization_token": "ghp_your_new_github_token"
    }
    JSON

    プルリクエストの作成

    GitHub MCPサーバーを使用すると、エージェントはブランチを作成し、変更をコミットしてプッシュできます。

    curl -fsS "https://api.anthropic.com/v1/sessions/$session_id/events" \
      -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" \
      -o /dev/null \
      --data @- <<JSON
    {
      "events": [
        {
          "type": "user.message",
          "content": [
            {
              "type": "text",
              "text": "Fix the type error in src/utils.ts, commit it to a new branch, and push it."
            }
          ]
        }
      ]
    }
    JSON

    Was this page helpful?

    • GitHub MCPとセッションリソース