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 저장소를 마운트하고 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-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 저장소를 마운트하는 세션을 생성합니다:

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

필요한 최소 권한이 있는 세분화된 개인 액세스 토큰을 사용합니다. 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",
    },
]

실행 중인 세션에서 저장소 관리

세션이 생성된 후 저장소 리소스를 나열하고 인증 토큰을 회전할 수 있습니다. 각 리소스에는 세션 생성 시간에 반환되는 id(또는 resources.list를 통해)가 있으며, 이를 업데이트에 사용합니다. 저장소는 세션의 수명 동안 연결되어 있습니다. 마운트된 저장소를 변경하려면 새 세션을 생성합니다.

# 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",
)

풀 요청 생성

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.",
                },
            ],
        },
    ],
)

Was this page helpful?

  • GitHub MCP 및 세션 리소스