@devries-cameron20 / composio-1 / commits / d00cdb6d2
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

mcp client

Sushmithamallesh committed Dec 15, 2025 at 14:37 UTC d00cdb6d2afa51a23f2975a769c4f0d5f54f9442
7 files changed +359 -2
fern/pages/src/get-started/quickstart-preview.mdx
+1
@@ -1,5 +1,6 @@
1 ---
2 title: Quickstart
3 +image: "https://og.composio.dev/api/og?title=Quickstart" # image for socials
4 subtitle: Connect AI agents to 500+ tools in under 5 minutes
5 description: "Build production-ready AI agents with real-world tool access using Composio's powerful integration platform"
6 ---
fern/pages/src/tool-router/using-with-mcp-clients.mdx
+86 -2
@@ -1,7 +1,91 @@
1 ---
2 -title: Using with MCP Clients
2 +title: Using with MCP clients
3 image: "https://og.composio.dev/api/og?title=Using%20with%20MCP%20Clients"
4 description: "Use Tool Router as an MCP server with any MCP client"
5 -keywords: "tool router"
5 +keywords: "tool router, mcp, model context protocol, claude agent sdk, vercel ai"
6 ---
7
8 +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.
9 +
10 +## Examples for popular frameworks
11 +
12 +Jump to examples for:
13 +- [OpenAI Agents SDK](#openai-agents-sdk) - Python, TypeScript
14 +- [Claude Agent SDK](#claude-agent-sdk) - Python, TypeScript
15 +- [Vercel AI SDK](#vercel-ai-sdk) - TypeScript
16 +
17 +## OpenAI Agents SDK
18 +
19 +### Installation
20 +
21 +<CodeGroup>
22 +```bash title="Python" for="python"
23 +pip install composio openai-agents
24 +```
25 +```bash title="TypeScript" for="typescript"
26 +npm install @composio/core @openai/agents
27 +```
28 +</CodeGroup>
29 +
30 +### Usage
31 +
32 +Create a Tool Router session and execute tasks with OpenAI agents:
33 +
34 +<Info>
35 +- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
36 +- Set your `OPENAI_API_KEY` environment variable with your [OpenAI API key](https://platform.openai.com/api-keys).
37 +</Info>
38 +
39 +<CodeGroup>
40 +<SnippetCode src="fern/snippets/tool-router/python/mcp-openai.py" title="Python" for="python" />
41 +<SnippetCode src="fern/snippets/tool-router/typescript/mcp-openai.ts" title="TypeScript" for="typescript" />
42 +</CodeGroup>
43 +
44 +## Claude Agent SDK
45 +
46 +### Installation
47 +
48 +<CodeGroup>
49 +```bash title="Python" for="python"
50 +pip install composio claude-agent-sdk
51 +```
52 +```bash title="TypeScript" for="typescript"
53 +npm install @composio/core @anthropic-ai/claude-agent-sdk
54 +```
55 +</CodeGroup>
56 +
57 +### Usage
58 +
59 +Create a Tool Router session and execute tasks with Claude:
60 +
61 +<Info>
62 +- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
63 +- Set your `ANTHROPIC_API_KEY` environment variable with your [Anthropic API key](https://platform.claude.com/settings/keys).
64 +</Info>
65 +
66 +<CodeGroup>
67 +<SnippetCode src="fern/snippets/tool-router/python/mcp-claude.py" title="Python" for="python" />
68 +<SnippetCode src="fern/snippets/tool-router/typescript/mcp-claude.ts" title="TypeScript" for="typescript" />
69 +</CodeGroup>
70 +
71 +## Vercel AI SDK
72 +
73 +
74 +### Installation
75 +
76 +```bash
77 +npm install @composio/core ai @ai-sdk/anthropic @ai-sdk/mcp
78 +```
79 +
80 +### Usage
81 +
82 +Use Tool Router with Vercel AI SDK's `generateText` for single completions:
83 +
84 +<Info>
85 +- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).
86 +- Set your `ANTHROPIC_API_KEY` environment variable with your [Anthropic API key](https://platform.claude.com/settings/keys).
87 +</Info>
88 +
89 +<SnippetCode src="fern/snippets/tool-router/typescript/mcp-vercel.ts" />
90 +
91 +
fern/snippets/tool-router/python/mcp-claude.py new
+61
@@ -0,0 +1,61 @@
1 +# Execute AI tasks with Claude using Composio Tool Router
2 +
3 +import asyncio
4 +from claude_agent_sdk.client import ClaudeSDKClient
5 +from claude_agent_sdk.types import ClaudeAgentOptions
6 +from composio import Composio
7 +import os
8 +
9 +# Initialize Composio and create a Tool Router session
10 +composio = Composio(api_key=os.environ["COMPOSIO_API_KEY"])
11 +user_id = "user_123" # Your user's unique identifier
12 +session = composio.create(user_id=user_id)
13 +
14 +# Configure Claude with Composio MCP server
15 +options = ClaudeAgentOptions(
16 + system_prompt="You are a helpful assistant with access to external tools. Always use the available tools to complete user requests instead of just explaining how to do them.",
17 + mcp_servers={
18 + "composio": {
19 + "type": "http",
20 + "url": session.mcp.url,
21 + "headers": {"x-api-key": os.environ["COMPOSIO_API_KEY"]},
22 + }
23 + },
24 + permission_mode="bypassPermissions",
25 +)
26 +
27 +
28 +async def execute_task(task: str):
29 + """Execute a single task using Claude with MCP tools"""
30 + async with ClaudeSDKClient(options) as client:
31 + # Send the task to Claude
32 + await client.query(task)
33 +
34 + # Collect the complete response
35 + response = ""
36 + async for msg in client.receive_response():
37 + if hasattr(msg, 'message'):
38 + for block in msg.message.content:
39 + if block.type == "text":
40 + response += block.text
41 +
42 + return response
43 +
44 +
45 +# Example usage
46 +async def main():
47 + # Execute a task that requires tools
48 + result = await execute_task(
49 + "Get the top story from Hacker News and summarize it"
50 + )
51 + print(result)
52 +
53 + # Execute another task
54 + result = await execute_task(
55 + "Create a GitHub issue in composio/composio repo about improving documentation"
56 + )
57 + print(result)
58 +
59 +
60 +if __name__ == "__main__":
61 + asyncio.run(main())
\ No newline at end of file
fern/snippets/tool-router/python/mcp-openai.py new
+53
@@ -0,0 +1,53 @@
1 +# An agent that fetches and categorizes GitHub issues using OpenAI and Composio Tool Router
2 +
3 +import os
4 +from composio import Composio
5 +from agents import Agent, Runner, HostedMCPTool, ModelSettings
6 +
7 +composio_api_key = os.environ["COMPOSIO_API_KEY"]
8 +user_id = "user_123" # Your user's unique identifier
9 +
10 +print("Starting OpenAI agent with Composio...\n")
11 +
12 +# Initialize Composio and create a Tool Router session
13 +composio = Composio(api_key=composio_api_key)
14 +session = composio.create(user_id=user_id)
15 +
16 +# Configure OpenAI agent with Composio MCP server
17 +agent = Agent(
18 + name="AI Assistant",
19 + instructions=(
20 + "You are a helpful assistant with access to external tools. "
21 + "Always use the available tools to complete user requests instead of just explaining how to do them."
22 + ),
23 + model="gpt-5.1",
24 + model_settings=ModelSettings(
25 + reasoning={"effort": "low"},
26 + ),
27 + tools=[
28 + HostedMCPTool(
29 + tool_config={
30 + "type": "mcp",
31 + "server_label": "composio",
32 + "server_url": session.mcp.url,
33 + "require_approval": "never",
34 + "headers": {"x-api-key": composio_api_key},
35 + }
36 + )
37 + ],
38 +)
39 +
40 +# Optional: Pre-authorize tools before use (otherwise you'll get a link during execution)
41 +# connection_request = session.authorize("github")
42 +# print(connection_request.redirect_url)
43 +# connected_account = connection_request.wait_for_connection(timeout=60000)
44 +# print(f"Connected: {connected_account.id}")
45 +
46 +print("Running the OpenAI agent to fetch GitHub issues...\n")
47 +
48 +# Execute a task that requires GitHub access
49 +result = Runner.run_sync(
50 + starting_agent=agent,
51 + input="Fetch all the open GitHub issues on the composio/composio repository and group them by bugs/features/docs."
52 +)
53 +print(f"Result: {result.final_output}")
\ No newline at end of file
fern/snippets/tool-router/typescript/mcp-claude.ts new
+62
@@ -0,0 +1,62 @@
1 +// Execute AI tasks with Claude using Composio Tool Router
2 +
3 +import { query, type Options } from "@anthropic-ai/claude-agent-sdk";
4 +import { Composio } from "@composio/core";
5 +
6 +const composioApiKey = process.env.COMPOSIO_API_KEY!;
7 +const userId = "user_123"; // Your user's unique identifier
8 +
9 +// Initialize Composio and create a Tool Router session
10 +const composio = new Composio({ apiKey: composioApiKey });
11 +const session = await composio.create(userId);
12 +
13 +// Configure Claude with Composio MCP server
14 +const options: Options = {
15 + systemPrompt: "You are a helpful assistant with access to external tools. Always use the available tools to complete user requests instead of just explaining how to do them.",
16 + mcpServers: {
17 + composio: {
18 + type: "http",
19 + url: session.mcp.url,
20 + headers: { "x-api-key": composioApiKey }
21 + },
22 + },
23 + permissionMode: "bypassPermissions",
24 + allowDangerouslySkipPermissions: true,
25 +};
26 +
27 +/**
28 + * Execute a single task using Claude with MCP tools
29 + */
30 +async function executeTask(task: string): Promise<string> {
31 + let response = "";
32 +
33 + // Send the task to Claude and collect the response
34 + for await (const msg of query({ prompt: task, options })) {
35 + if (msg.type === "assistant") {
36 + for (const block of msg.message.content) {
37 + if (block.type === "text") {
38 + response += block.text;
39 + }
40 + }
41 + }
42 + }
43 +
44 + return response;
45 +}
46 +
47 +// Example usage
48 +async function main() {
49 + // Execute a task that requires tools
50 + let result = await executeTask(
51 + "Get the top story from Hacker News and summarize it"
52 + );
53 + console.log(result);
54 +
55 + // Execute another task
56 + result = await executeTask(
57 + "Create a GitHub issue in composio/composio repo about improving documentation"
58 + );
59 + console.log(result);
60 +}
61 +
62 +main().catch(console.error);
\ No newline at end of file
fern/snippets/tool-router/typescript/mcp-openai.ts new
+42
@@ -0,0 +1,42 @@
1 +// An agent that fetches and categorizes GitHub issues using OpenAI and Composio Tool Router
2 +
3 +import { Composio } from "@composio/core";
4 +import { Agent, hostedMcpTool, run } from "@openai/agents";
5 +
6 +const composioApiKey = process.env.COMPOSIO_API_KEY!;
7 +const userId = "user_123"; // Your user's unique identifier
8 +
9 +// Initialize Composio and create a Tool Router session
10 +const composio = new Composio({ apiKey: composioApiKey });
11 +const session = await composio.create(userId);
12 +
13 +// Configure OpenAI agent with Composio MCP server
14 +const agent = new Agent({
15 + name: "AI Assistant",
16 + instructions:
17 + "You are a helpful assistant with access to external tools. " +
18 + "Always use the available tools to complete user requests instead of just explaining how to do them.",
19 + model: "gpt-5.1",
20 + modelSettings: { reasoning: { effort: "low" } },
21 + tools: [
22 + hostedMcpTool({
23 + serverLabel: "composio",
24 + serverUrl: session.mcp.url,
25 + headers: { "x-api-key": composioApiKey },
26 + }),
27 + ],
28 +});
29 +
30 +// Optional: Pre-authorize tools before use (otherwise you'll get a link during execution)
31 +// const connectionRequest = await session.authorize("github");
32 +// console.log(connectionRequest.redirectUrl);
33 +// const connectedAccount = await connectionRequest.waitForConnection(60000);
34 +// console.log(`Connected: ${connectedAccount.id}`);
35 +
36 +// Execute a task that requires GitHub access
37 +const result = await run(
38 + agent,
39 + "Fetch all the open GitHub issues on the composio/composio repository and group them by bugs/features/docs."
40 +);
41 +
42 +console.log(`Result: ${result.finalOutput}`);
\ No newline at end of file
fern/snippets/tool-router/typescript/mcp-vercel.ts new
+54
@@ -0,0 +1,54 @@
1 +// Generate text completions with Vercel AI SDK using Composio Tool Router
2 +
3 +import { Composio } from "@composio/core";
4 +import { createAnthropic } from "@ai-sdk/anthropic";
5 +import { createMCPClient } from "@ai-sdk/mcp";
6 +import { generateText } from "ai";
7 +
8 +const composioApiKey = process.env.COMPOSIO_API_KEY!;
9 +const userId = "user_123"; // Your user's unique identifier
10 +
11 +// Initialize Composio and create a Tool Router session
12 +const composio = new Composio({ apiKey: composioApiKey });
13 +const session = await composio.create(userId);
14 +
15 +// Create MCP client connected to Composio
16 +const mcpClient = await createMCPClient({
17 + type: "http",
18 + url: session.mcp.url,
19 + headers: { "x-api-key": composioApiKey },
20 +});
21 +
22 +// Create Anthropic model
23 +const anthropic = createAnthropic();
24 +
25 +/**
26 + * Execute a task using Vercel AI SDK with MCP tools
27 + */
28 +async function executeTask(task: string) {
29 + const result = await generateText({
30 + model: anthropic("claude-3-5-sonnet-latest"),
31 + prompt: task,
32 + tools: mcpClient.tools,
33 + system: "You are a helpful assistant with access to external tools. Always use the available tools to complete user requests instead of just explaining how to do them.",
34 + });
35 +
36 + return result.text;
37 +}
38 +
39 +// Example usage
40 +async function main() {
41 + // Execute a task that requires tools
42 + let result = await executeTask(
43 + "Get the current weather in San Francisco"
44 + );
45 + console.log(result);
46 +
47 + // Execute another task with tools
48 + result = await executeTask(
49 + "Search for the latest news about AI and summarize the top 3 stories"
50 + );
51 + console.log(result);
52 +}
53 +
54 +main().catch(console.error);
\ No newline at end of file