GitHub 리포지토리를 세션 샌드박스에 마운트하고 풀 리퀘스트를 생성하기 위해 GitHub MCP에 연결할 수 있습니다.
GitHub 리포지토리는 캐시되므로 동일한 리포지토리를 사용하는 이후 세션은 더 빠르게 시작됩니다.
모든 Managed Agents API 요청에는 managed-agents-2026-04-01 베타 헤더가 필요합니다. SDK는 베타 헤더를 자동으로 설정합니다.
먼저 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 |
| 이슈 읽기 | repo (비공개) 또는 public_repo |
| 이슈 생성 | repo (비공개) 또는 public_repo |
필요한 최소 권한만 가진 세분화된 개인 액세스 토큰(fine-grained personal access token)을 사용하세요. 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 서버를 연결하여 에이전트에 추가 도구를 제공하세요
리포지토리와 함께 샌드박스에 파일을 마운트하세요
Was this page helpful?