Loading...
  • ビルド
  • 管理
  • モデルと料金
  • クライアントSDK
  • APIリファレンス
Search...
⌘K
Log in
GitHubへのアクセス
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
  • 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
ビルド/エージェントへの作業委任

GitHubへのアクセス

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

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

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-7}' \
  --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リポジトリをマウントするセッションを作成します。

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

トークンの権限

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

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

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

複数のリポジトリ

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

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

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

プルリクエストの作成

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

Was this page helpful?

  • GitHub MCPとセッションリソース
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 = [
    {
        "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",
    },
]
# List resources on the session
listed = client.beta.sessions.resources.list(session.id)
repo_resource_id = listed.data[0].id
print(repo_resource_id)  # "sesrsc_01ABC..."

# Rotate the authorization token
client.beta.sessions.resources.update(
    repo_resource_id,
    session_id=session.id,
    authorization_token="ghp_your_new_github_token",
)
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.",
                },
            ],
        },
    ],
)