Using with MCP clients

Every Tool Router session provides a unique MCP server URL. This URL exposes the exact session you created - with the specific user, toolkits, and auth configs you configured. Any MCP client that supports HTTP transport can connect using just the URL and your API key.

Jump to examples for:

Claude Agent SDK

Installation

$pip install python-dotenv composio claude-agent-sdk

Usage

Create a Tool Router session and execute tasks with Claude:

  • Set your COMPOSIO_API_KEY environment variable with your API key from Settings.
  • Set your ANTHROPIC_API_KEY environment variable with your Anthropic API key.
1import asyncio
2from dotenv import load_dotenv
3from claude_agent_sdk.client import ClaudeSDKClient
4from claude_agent_sdk.types import (
5 ClaudeAgentOptions,
6 AssistantMessage,
7 TextBlock,
8 ToolUseBlock,
9)
10from composio import Composio
11
12load_dotenv()
13
14# Initialize Composio (API key from env var COMPOSIO_API_KEY or pass explicitly)
15composio = Composio()
16
17# Unique identifier of the user
18user_id = "user_123"
19# Create a tool router session for the user
20session = composio.create(user_id=user_id)
21
22# Configure Claude with Composio MCP server
23options = ClaudeAgentOptions(
24 system_prompt=(
25 "You are a helpful assistant with access to external tools. "
26 "Always use the available tools to complete user requests."
27 ),
28 mcp_servers={
29 "composio": {
30 "type": "http",
31 "url": session.mcp.url,
32 "headers": session.mcp.headers, # Authentication headers for the Composio MCP server
33 }
34 },
35 permission_mode="bypassPermissions", # Auto-approve tools (demo only)
36)
37
38async def main():
39 print("""
40What task would you like me to help you with?
41I can use tools like Gmail, GitHub, Linear, Notion, and more.
42(Type 'exit' to exit)
43Example tasks:
44 • 'Summarize my emails from today'
45 • 'List all open issues on the composio github repository and create a notion page with the issues'
46""")
47
48 async with ClaudeSDKClient(options) as client:
49 # Multi-turn conversation with agentic tool calling
50 while True:
51 user_input = input("\nYou: ").strip()
52 if user_input.lower() == "exit":
53 break
54
55 print("\nClaude: ", end="", flush=True)
56 try:
57 await client.query(user_input)
58 async for msg in client.receive_response():
59 if isinstance(msg, AssistantMessage):
60 for block in msg.content:
61 if isinstance(block, ToolUseBlock):
62 print(f"\n[Using tool: {block.name}]", end="")
63 elif isinstance(block, TextBlock):
64 print(block.text, end="", flush=True)
65 except Exception as e:
66 print(f"\n[Error]: {e}")
67
68if __name__ == "__main__":
69 asyncio.run(main())

OpenAI Agents SDK

Installation

$pip install python-dotenv composio openai-agents

Usage

Create a Tool Router session and execute tasks with OpenAI agents:

  • Set COMPOSIO_API_KEY environment variable with your API key from Settings.
  • Set OPENAI_API_KEY environment variable with your OpenAI API key.
1from dotenv import load_dotenv
2from composio import Composio
3from agents import Agent, Runner, HostedMCPTool
4
5load_dotenv()
6
7# Initialize Composio (API key from env var COMPOSIO_API_KEY)
8composio = Composio()
9# Unique identifier of the user
10user_id = "user_123"
11
12# Create a Tool Router session for the user
13session = composio.create(user_id=user_id)
14
15# Configure OpenAI agent with Composio MCP server
16agent = Agent(
17 name="Personal Assistant",
18 instructions="You are a helpful personal assistant. Use Composio tools to take action.",
19 model="gpt-5.2",
20 tools=[
21 HostedMCPTool(
22 tool_config={
23 "type": "mcp",
24 "server_label": "composio",
25 "server_url": session.mcp.url,
26 "require_approval": "never",
27 "headers": session.mcp.headers,
28 }
29 )
30 ],
31)
32
33# Execute the task
34print("Fetching GitHub issues from the Composio repository @ComposioHQ/composio...\n")
35try:
36 result = Runner.run_sync(
37 starting_agent=agent,
38 input="Fetch all the open GitHub issues on the composio repository and group them by bugs/features/docs.",
39 )
40 print(result.final_output)
41except Exception as e:
42 print(f"[Error]: {e}")
43
44print("\n\n---")
45print("Tip: If prompted to authenticate, complete the auth flow and run again.")

Vercel AI SDK

Installation

$npm install dotenv @composio/core ai @ai-sdk/anthropic @ai-sdk/mcp

Usage

Use Tool Router with Vercel AI SDK’s generateText for single completions:

  • Set COMPOSIO_API_KEY environment variable with your API key from Settings.
  • Set ANTHROPIC_API_KEY environment variable with your Anthropic API key.
TypeScript
1import "dotenv/config";
2import { anthropic } from "@ai-sdk/anthropic";
3import { experimental_createMCPClient as createMCPClient } from "@ai-sdk/mcp";
4import { Composio } from "@composio/core";
5import { stepCountIs, streamText } from "ai";
6
7// Initialize Composio (API key from env var COMPOSIO_API_KEY or pass explicitly: { apiKey: "your-key" })
8const composio = new Composio();
9
10// Unique identifier of the user
11const userId = "user_123";
12
13// Create a tool router session for the user
14const { mcp } = await composio.create(userId);
15
16// Create an MCP client to connect to the Composio tool router
17const client = await createMCPClient({
18 transport: {
19 type: "http",
20 url: mcp.url,
21 headers: mcp.headers, // Authentication headers for the Composio MCP server
22 },
23});
24const tools = await client.tools();
25
26console.log("Summarizing your emails from today");
27
28const stream = await streamText({
29 system: "You are a helpful personal assistant. Use Composio tools to take action.",
30 model: anthropic("claude-sonnet-4-5"),
31 prompt: "Summarize my emails from today",
32 stopWhen: stepCountIs(10),
33 onStepFinish: (step) => {
34 for (const toolCall of step.toolCalls) {
35 console.log(`[Using tool: ${toolCall.toolName}]`);
36 }
37 },
38 tools,
39});
40
41for await (const textPart of stream.textStream) {
42 process.stdout.write(textPart);
43}
44
45console.log("\n\n---");
46console.log("Tip: If prompted to authenticate, complete the auth flow and run again.")