Skip to main content

Overview

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

Installation

uv add anthropic mcp httpx

Quick Start

Connect to StackOne MCP and use tools with Claude:
import os
import asyncio
import base64
from anthropic import Anthropic
from mcp.client.streamable_http import streamable_http_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 streamable_http_client(
        url="https://api.stackone.com/mcp",
        headers={
            "Authorization": f"Basic {auth_token}",
            "x-account-id": STACKONE_ACCOUNT_ID,
            "MCP-Protocol-Version": "2025-06-18"
        }
    ) as (read, write):
        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-3-5-sonnet-20241022",
                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

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:
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-3-5-sonnet-20241022",
            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

Next Steps