Claude Platform Docs
  • Messages
  • Managed Agents
  • 管理

Search...
⌘K
はじめに
概要クイックスタートコンソールでプロトタイプ作成
エージェントの定義
エージェントのセットアップツールMCPコネクタ権限ポリシーエージェントスキル
エージェント環境の設定
クラウド環境のセットアップクラウドサンドボックスリファレンス
エージェントに作業を委任する
セッションの開始セッション操作セッションイベントストリームWebhookの購読アウトカムの定義ボールトで認証
エージェントコンテキストの管理
GitHubへのアクセスファイルの添付とダウンロード
高度なオーケストレーション
マルチエージェントセッションスケジュールされたデプロイメント
リファレンス
Managed Agentsリファレンス
ファイルの操作
Files APIPDFサポート
スキル
概要ベストプラクティスエンタープライズ向けスキル
MCP
リモートMCPサーバー
クラウドプラットフォーム上のClaude
AWS上のClaude Platform

Log in
GitHubへのアクセス
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Claude Platform Docs

Solutions

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

Partners

  • Claude on AWS
  • Claude on Google Cloud

Learn

  • Blog
  • 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
  • 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
Managed Agents/エージェントコンテキストの管理

GitHubへのアクセス

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

GitHubリポジトリをセッションのサンドボックスにマウントし、プルリクエストを作成するためにGitHub MCPに接続できます。

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



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

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

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

AGENT_ID=$(ant beta:agents create \
  --name "Code Reviewer" \
  --model '{id: claude-opus-4-8}' \
  --system "You are a code review assistant with access to GitHub." \
  --mcp-server '{type: url, name: github, url: https://api.githubcopilot.com/mcp/}' \
  --tool '{type: agent_toolset_20260401}' \
  --tool '{type: mcp_toolset, mcp_server_name: github}' \
  --transform id --raw-output)

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

session = client.beta.sessions.create(
    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",
        },
    ],
)

resources[].authorization_tokenはリポジトリのクローン操作を認証するために使用され、APIレスポンスには返されません。

トークンの権限

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

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

必要最小限の権限を持つきめ細かいパーソナルアクセストークン(fine-grained personal access tokens)を使用してください。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があり、更新時にこれを使用します。リポジトリはセッションの存続期間中アタッチされます。マウントするリポジトリを変更するには、新しいセッションを作成してください。

# セッション上のリソースを一覧表示
listed = client.beta.sessions.resources.list(session.id)
repo_resource_id = listed.data[0].id
print(repo_resource_id)  # "sesrsc_01ABC..."

# 認証トークンをローテーション
client.beta.sessions.resources.update(
    repo_resource_id,
    session_id=session.id,
    authorization_token="ghp_your_new_github_token",
)

プルリクエストの作成

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

client.beta.sessions.events.send(
    session.id,
    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.",
                },
            ],
        },
    ],
)

次のステップ


セッションイベントストリーム

エージェントがプルリクエストを開いている間、イベントをストリーミングしてエージェントを誘導します


MCPコネクタ

さらに多くのMCPサーバーを接続して、エージェントに追加のツールを提供します


ファイルの追加

リポジトリと一緒にサンドボックスにファイルをマウントします

Was this page helpful?

  • GitHub MCPとセッションリソース
  • トークンの権限
  • 複数のリポジトリ
  • 実行中のセッションでのリポジトリ管理
  • プルリクエストの作成
  • 次のステップ