Anthropic Agent SDK

Use STACK with the Anthropic Agent SDK by registering STACK as an MCP server in your agent loop. Anthropic invented MCP; the SDK is built around it. STACK is MCP-native, so the integration is one registration and you get the whole STACK tool surface inside the agent.

For the why-this-matters framing — what STACK adds on top of the Anthropic SDK and why MCP-native end-to-end matters — read /with/anthropic. This page is the technical guide.

1. Prerequisites

  • Python 3.10+ and an Anthropic API key (https://console.anthropic.com).
  • A STACK operator account. Sign up at https://getstack.run.
  • A STACK API key from https://getstack.run/account (or a member key from /team).
  • At least one upstream service connected on the STACK side at https://getstack.run/services.

2. Install

bash
pip install anthropic getstack

3. Register STACK as an MCP server

The Anthropic Messages API supports MCP servers via the mcp_servers request param (beta header mcp-client-2025-04-04). Pass STACK as one of the servers, with your STACK API key as a Bearer token:

python
import anthropic
import os

client = anthropic.Anthropic()

response = client.beta.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=4096,
    mcp_servers=[
        {
            "type": "url",
            "url": "https://mcp.getstack.run/mcp",
            "name": "stack",
            "authorization_token": os.environ["STACK_API_KEY"],
        }
    ],
    extra_headers={"anthropic-beta": "mcp-client-2025-04-04"},
    messages=[
        {
            "role": "user",
            "content": "Post 'deploy started' to #engineering on Slack via STACK.",
        }
    ],
)

print(response.content)

The model sees STACK's tool list at the start of the turn and calls stack_proxy_request (or a more specific tool) when it needs a service. STACK injects the credential at the proxy and lands the call in your audit chain.

4. Mission-context passport pattern

For agents that need a tightly scoped credential for a specific intent, mint a passport up front and register STACK with that passport instead of an admin key. The narrow-only scope rules in the passport apply to every call the agent makes during the run:

python
from getstack import StackClient
import anthropic

stack = StackClient(api_key=os.environ["STACK_API_KEY"])

passport = stack.passports.issue(
    agent_id="agent_deploy_bot",
    intent="post_to_slack_engineering",
    ttl_seconds=900,  # 15 min
)

client = anthropic.Anthropic()
response = client.beta.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=4096,
    mcp_servers=[
        {
            "type": "url",
            "url": "https://mcp.getstack.run/mcp",
            "name": "stack",
            "authorization_token": passport.token,
        }
    ],
    extra_headers={"anthropic-beta": "mcp-client-2025-04-04"},
    messages=[{"role": "user", "content": "Post 'deploy started' to #engineering."}],
)

stack.passports.revoke(passport.id)

5. Claude API direct (no SDK)

If you're calling the Messages API directly without the Python SDK, the same mcp_servers field works. The full STACK tool surface gets exposed to the model on every turn.

6. Audit and revoke

Every call the agent makes through STACK shows up in the hash-chained audit log with the agent ID, passport, intent, scope, and result. Revoke the passport via stack.passports.revoke() or the dashboard at getstack.run/agents; sub-60-second propagation to every connected service.

Next

stack | docs