> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackone.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic SDK (Python)

> Connect StackOne MCP to Anthropic's Claude SDK using the official MCP Python client.

## Overview

Anthropic provides native MCP client support through the official `mcp` Python SDK, enabling direct integration with StackOne's MCP server.

[MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk)

## Installation

```bash theme={null}
uv add anthropic mcp httpx
```

## Quick Start

Connect to StackOne MCP and use tools with Claude:

```python theme={null}
import os
import asyncio
import base64
from anthropic import Anthropic
from mcp.client.streamable_http import streamablehttp_client
from mcp import ClientSession

# Configure StackOne account
STACKONE_ACCOUNT_ID = "<account_id>"  # Your StackOne account ID

# Encode API key for Basic auth
auth_token = base64.b64encode(
    f"{os.getenv('STACKONE_API_KEY')}:".encode()
).decode()

async def main():
    # Connect to StackOne MCP
    async with streamablehttp_client(
        url="https://api.stackone.com/mcp",
        headers={
            "Authorization": f"Basic {auth_token}",
            "x-account-id": STACKONE_ACCOUNT_ID
        }
    ) as (read, write, get_session_id):
        async with ClientSession(read, write) as session:
            await session.initialize()

            # Get StackOne tools
            tools_response = await session.list_tools()
            tools = [{
                "name": t.name,
                "description": t.description,
                "input_schema": t.inputSchema
            } for t in tools_response.tools]

            # Use with Claude
            client = Anthropic()
            messages = [{"role": "user", "content": "Search recent calls in Gong"}]

            response = client.messages.create(
                model="claude-haiku-4-5-20251001",
                max_tokens=4096,
                tools=tools,
                messages=messages
            )

            # Handle tool calls
            if response.stop_reason == "tool_use":
                for block in response.content:
                    if block.type == "tool_use":
                        result = await session.call_tool(
                            block.name,
                            arguments=block.input
                        )
                        print(result.content[0].text)

asyncio.run(main())
```

## Environment Variables

```bash theme={null}
STACKONE_API_KEY=<stackone_api_key>
ANTHROPIC_API_KEY=your_anthropic_key
```

## Agent with Tool Calling Loop

For multi-turn conversations with automatic tool execution:

```python theme={null}
async def chat_with_tools(session, user_message: str):
    """Chat with Claude using StackOne tools"""
    client = Anthropic()

    # Get tools from StackOne
    tools_response = await session.list_tools()
    tools = [{
        "name": t.name,
        "description": t.description,
        "input_schema": t.inputSchema
    } for t in tools_response.tools]

    messages = [{"role": "user", "content": user_message}]

    # Tool calling loop
    while True:
        response = client.messages.create(
            model="claude-haiku-4-5-20251001",
            max_tokens=4096,
            tools=tools,
            messages=messages
        )

        if response.stop_reason != "tool_use":
            return response.content[0].text

        # Execute tools
        tool_results = []
        for block in response.content:
            if block.type == "tool_use":
                result = await session.call_tool(block.name, arguments=block.input)
                tool_results.append({
                    "type": "tool_result",
                    "tool_use_id": block.id,
                    "content": result.content[0].text
                })

        messages.append({"role": "assistant", "content": response.content})
        messages.append({"role": "user", "content": tool_results})
```

## Resources

* [MCP Python SDK Documentation](https://github.com/modelcontextprotocol/python-sdk)
* [Anthropic Tool Use Guide](https://docs.anthropic.com/en/docs/tool-use)
* [Anthropic Python SDK](https://docs.anthropic.com/en/api/client-sdks)
* [StackOne Authentication](/mcp/auth-security)

## Next Steps

<CardGroup cols={2}>
  <Card title="Pydantic AI" icon="robot" href="/mcp/framework-guides/pydantic-ai">
    Try Pydantic AI with built-in MCP support
  </Card>

  <Card title="LangChain" icon="link" href="/mcp/framework-guides/langchain">
    Build agents with LangChain MCP adapters
  </Card>
</CardGroup>
