Was this page helpful?
세션 컨테이너에 GitHub 저장소를 마운트하고 GitHub MCP에 연결하여 풀 요청을 만들 수 있습니다.
GitHub 저장소는 캐시되므로 동일한 저장소를 사용하는 향후 세션이 더 빠르게 시작됩니다.
모든 Managed Agents API 요청에는 managed-agents-2026-04-01 베타 헤더가 필요합니다. SDK는 베타 헤더를 자동으로 설정합니다.
먼저 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 저장소를 마운트하는 세션을 생성합니다:
resources[].authorization_token은 저장소 복제 작업을 인증하며 API 응답에서 반복되지 않습니다.
GitHub 토큰을 제공할 때 필요한 최소 권한을 사용합니다:
| 작업 | 필수 범위 |
|---|---|
| 비공개 저장소 복제 | repo |
| PR 생성 | repo |
| 이슈 읽기 | repo (비공개) 또는 public_repo |
| 이슈 생성 | repo (비공개) 또는 public_repo |
필요한 최소 권한이 있는 세분화된 개인 액세스 토큰을 사용합니다. GitHub 계정에 광범위한 액세스 권한이 있는 토큰 사용을 피합니다.
resources 배열에 항목을 추가하여 여러 저장소를 마운트합니다:
세션이 생성된 후 저장소 리소스를 나열하고 인증 토큰을 회전할 수 있습니다. 각 리소스에는 세션 생성 시간에 반환되는 id(또는 resources.list를 통해)가 있으며, 이를 업데이트에 사용합니다. 저장소는 세션의 수명 동안 연결되어 있습니다. 마운트된 저장소를 변경하려면 새 세션을 생성합니다.
GitHub MCP 서버를 사용하면 에이전트가 브랜치를 생성하고, 변경 사항을 커밋하고, 푸시할 수 있습니다:
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='[
{
"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
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"
}
JSONcurl -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