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())