Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
mcp client
Sushmithamalleshd00cdb6d2afa
diff --git a/fern/pages/src/get-started/quickstart-preview.mdx b/fern/pages/src/get-started/quickstart-preview.mdxindex b030d58bb..45e1c3a2d 100644--- a/fern/pages/src/get-started/quickstart-preview.mdx+++ b/fern/pages/src/get-started/quickstart-preview.mdx@@ -1,5 +1,6 @@---title: Quickstart+image: "https://og.composio.dev/api/og?title=Quickstart" # image for socialssubtitle: Connect AI agents to 500+ tools in under 5 minutesdescription: "Build production-ready AI agents with real-world tool access using Composio's powerful integration platform"---diff --git a/fern/pages/src/tool-router/using-with-mcp-clients.mdx b/fern/pages/src/tool-router/using-with-mcp-clients.mdxindex 47c5cbf11..5c7384939 100644--- a/fern/pages/src/tool-router/using-with-mcp-clients.mdx+++ b/fern/pages/src/tool-router/using-with-mcp-clients.mdx@@ -1,7 +1,91 @@----title: Using with MCP Clients+title: Using with MCP clientsimage: "https://og.composio.dev/api/og?title=Using%20with%20MCP%20Clients"description: "Use Tool Router as an MCP server with any MCP client"-keywords: "tool router"+keywords: "tool router, mcp, model context protocol, claude agent sdk, vercel ai"---+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.++## Examples for popular frameworks++Jump to examples for:+- [OpenAI Agents SDK](#openai-agents-sdk) - Python, TypeScript+- [Claude Agent SDK](#claude-agent-sdk) - Python, TypeScript+- [Vercel AI SDK](#vercel-ai-sdk) - TypeScript++## OpenAI Agents SDK++### Installation++<CodeGroup>+```bash title="Python" for="python"+pip install composio openai-agents+```+```bash title="TypeScript" for="typescript"+npm install @composio/core @openai/agents+```+</CodeGroup>++### Usage++Create a Tool Router session and execute tasks with OpenAI agents:++<Info>+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).+- Set your `OPENAI_API_KEY` environment variable with your [OpenAI API key](https://platform.openai.com/api-keys).+</Info>++<CodeGroup>+<SnippetCode src="fern/snippets/tool-router/python/mcp-openai.py" title="Python" for="python" />+<SnippetCode src="fern/snippets/tool-router/typescript/mcp-openai.ts" title="TypeScript" for="typescript" />+</CodeGroup>++## Claude Agent SDK++### Installation++<CodeGroup>+```bash title="Python" for="python"+pip install composio claude-agent-sdk+```+```bash title="TypeScript" for="typescript"+npm install @composio/core @anthropic-ai/claude-agent-sdk+```+</CodeGroup>++### Usage++Create a Tool Router session and execute tasks with Claude:++<Info>+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).+- Set your `ANTHROPIC_API_KEY` environment variable with your [Anthropic API key](https://platform.claude.com/settings/keys).+</Info>++<CodeGroup>+<SnippetCode src="fern/snippets/tool-router/python/mcp-claude.py" title="Python" for="python" />+<SnippetCode src="fern/snippets/tool-router/typescript/mcp-claude.ts" title="TypeScript" for="typescript" />+</CodeGroup>++## Vercel AI SDK+++### Installation++```bash+npm install @composio/core ai @ai-sdk/anthropic @ai-sdk/mcp+```++### Usage++Use Tool Router with Vercel AI SDK's `generateText` for single completions:++<Info>+- Set your `COMPOSIO_API_KEY` environment variable with your API key from [Settings](https://platform.composio.dev/?next_page=/settings).+- Set your `ANTHROPIC_API_KEY` environment variable with your [Anthropic API key](https://platform.claude.com/settings/keys).+</Info>++<SnippetCode src="fern/snippets/tool-router/typescript/mcp-vercel.ts" />++diff --git a/fern/snippets/tool-router/python/mcp-claude.py b/fern/snippets/tool-router/python/mcp-claude.pynew file mode 100644index 000000000..4c4d554ee--- /dev/null+++ b/fern/snippets/tool-router/python/mcp-claude.py@@ -0,0 +1,61 @@+# Execute AI tasks with Claude using Composio Tool Router++import asyncio+from claude_agent_sdk.client import ClaudeSDKClient+from claude_agent_sdk.types import ClaudeAgentOptions+from composio import Composio+import os++# Initialize Composio and create a Tool Router session+composio = Composio(api_key=os.environ["COMPOSIO_API_KEY"])+user_id = "user_123" # Your user's unique identifier+session = composio.create(user_id=user_id)++# Configure Claude with Composio MCP server+options = ClaudeAgentOptions(+ 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.",+ mcp_servers={+ "composio": {+ "type": "http",+ "url": session.mcp.url,+ "headers": {"x-api-key": os.environ["COMPOSIO_API_KEY"]},+ }+ },+ permission_mode="bypassPermissions",+)+++async def execute_task(task: str):+ """Execute a single task using Claude with MCP tools"""+ async with ClaudeSDKClient(options) as client:+ # Send the task to Claude+ await client.query(task)++ # Collect the complete response+ response = ""+ async for msg in client.receive_response():+ if hasattr(msg, 'message'):+ for block in msg.message.content:+ if block.type == "text":+ response += block.text++ return response+++# Example usage+async def main():+ # Execute a task that requires tools+ result = await execute_task(+ "Get the top story from Hacker News and summarize it"+ )+ print(result)++ # Execute another task+ result = await execute_task(+ "Create a GitHub issue in composio/composio repo about improving documentation"+ )+ print(result)+++if __name__ == "__main__":+ asyncio.run(main())\ No newline at end of filediff --git a/fern/snippets/tool-router/python/mcp-openai.py b/fern/snippets/tool-router/python/mcp-openai.pynew file mode 100644index 000000000..d7487fa6c--- /dev/null+++ b/fern/snippets/tool-router/python/mcp-openai.py@@ -0,0 +1,53 @@+# An agent that fetches and categorizes GitHub issues using OpenAI and Composio Tool Router++import os+from composio import Composio+from agents import Agent, Runner, HostedMCPTool, ModelSettings++composio_api_key = os.environ["COMPOSIO_API_KEY"]+user_id = "user_123" # Your user's unique identifier++print("Starting OpenAI agent with Composio...\n")++# Initialize Composio and create a Tool Router session+composio = Composio(api_key=composio_api_key)+session = composio.create(user_id=user_id)++# Configure OpenAI agent with Composio MCP server+agent = Agent(+ name="AI Assistant",+ instructions=(+ "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."+ ),+ model="gpt-5.1",+ model_settings=ModelSettings(+ reasoning={"effort": "low"},+ ),+ tools=[+ HostedMCPTool(+ tool_config={+ "type": "mcp",+ "server_label": "composio",+ "server_url": session.mcp.url,+ "require_approval": "never",+ "headers": {"x-api-key": composio_api_key},+ }+ )+ ],+)++# Optional: Pre-authorize tools before use (otherwise you'll get a link during execution)+# connection_request = session.authorize("github")+# print(connection_request.redirect_url)+# connected_account = connection_request.wait_for_connection(timeout=60000)+# print(f"Connected: {connected_account.id}")++print("Running the OpenAI agent to fetch GitHub issues...\n")++# Execute a task that requires GitHub access+result = Runner.run_sync(+ starting_agent=agent,+ input="Fetch all the open GitHub issues on the composio/composio repository and group them by bugs/features/docs."+)+print(f"Result: {result.final_output}")\ No newline at end of filediff --git a/fern/snippets/tool-router/typescript/mcp-claude.ts b/fern/snippets/tool-router/typescript/mcp-claude.tsnew file mode 100644index 000000000..7f26626f4--- /dev/null+++ b/fern/snippets/tool-router/typescript/mcp-claude.ts@@ -0,0 +1,62 @@+// Execute AI tasks with Claude using Composio Tool Router++import { query, type Options } from "@anthropic-ai/claude-agent-sdk";+import { Composio } from "@composio/core";++const composioApiKey = process.env.COMPOSIO_API_KEY!;+const userId = "user_123"; // Your user's unique identifier++// Initialize Composio and create a Tool Router session+const composio = new Composio({ apiKey: composioApiKey });+const session = await composio.create(userId);++// Configure Claude with Composio MCP server+const options: Options = {+ 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.",+ mcpServers: {+ composio: {+ type: "http",+ url: session.mcp.url,+ headers: { "x-api-key": composioApiKey }+ },+ },+ permissionMode: "bypassPermissions",+ allowDangerouslySkipPermissions: true,+};++/**+ * Execute a single task using Claude with MCP tools+ */+async function executeTask(task: string): Promise<string> {+ let response = "";++ // Send the task to Claude and collect the response+ for await (const msg of query({ prompt: task, options })) {+ if (msg.type === "assistant") {+ for (const block of msg.message.content) {+ if (block.type === "text") {+ response += block.text;+ }+ }+ }+ }++ return response;+}++// Example usage+async function main() {+ // Execute a task that requires tools+ let result = await executeTask(+ "Get the top story from Hacker News and summarize it"+ );+ console.log(result);++ // Execute another task+ result = await executeTask(+ "Create a GitHub issue in composio/composio repo about improving documentation"+ );+ console.log(result);+}++main().catch(console.error);\ No newline at end of filediff --git a/fern/snippets/tool-router/typescript/mcp-openai.ts b/fern/snippets/tool-router/typescript/mcp-openai.tsnew file mode 100644index 000000000..a91d26867--- /dev/null+++ b/fern/snippets/tool-router/typescript/mcp-openai.ts@@ -0,0 +1,42 @@+// An agent that fetches and categorizes GitHub issues using OpenAI and Composio Tool Router++import { Composio } from "@composio/core";+import { Agent, hostedMcpTool, run } from "@openai/agents";++const composioApiKey = process.env.COMPOSIO_API_KEY!;+const userId = "user_123"; // Your user's unique identifier++// Initialize Composio and create a Tool Router session+const composio = new Composio({ apiKey: composioApiKey });+const session = await composio.create(userId);++// Configure OpenAI agent with Composio MCP server+const agent = new Agent({+ name: "AI Assistant",+ instructions:+ "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.",+ model: "gpt-5.1",+ modelSettings: { reasoning: { effort: "low" } },+ tools: [+ hostedMcpTool({+ serverLabel: "composio",+ serverUrl: session.mcp.url,+ headers: { "x-api-key": composioApiKey },+ }),+ ],+});++// Optional: Pre-authorize tools before use (otherwise you'll get a link during execution)+// const connectionRequest = await session.authorize("github");+// console.log(connectionRequest.redirectUrl);+// const connectedAccount = await connectionRequest.waitForConnection(60000);+// console.log(`Connected: ${connectedAccount.id}`);++// Execute a task that requires GitHub access+const result = await run(+ agent,+ "Fetch all the open GitHub issues on the composio/composio repository and group them by bugs/features/docs."+);++console.log(`Result: ${result.finalOutput}`);\ No newline at end of filediff --git a/fern/snippets/tool-router/typescript/mcp-vercel.ts b/fern/snippets/tool-router/typescript/mcp-vercel.tsnew file mode 100644index 000000000..d4417499b--- /dev/null+++ b/fern/snippets/tool-router/typescript/mcp-vercel.ts@@ -0,0 +1,54 @@+// Generate text completions with Vercel AI SDK using Composio Tool Router++import { Composio } from "@composio/core";+import { createAnthropic } from "@ai-sdk/anthropic";+import { createMCPClient } from "@ai-sdk/mcp";+import { generateText } from "ai";++const composioApiKey = process.env.COMPOSIO_API_KEY!;+const userId = "user_123"; // Your user's unique identifier++// Initialize Composio and create a Tool Router session+const composio = new Composio({ apiKey: composioApiKey });+const session = await composio.create(userId);++// Create MCP client connected to Composio+const mcpClient = await createMCPClient({+ type: "http",+ url: session.mcp.url,+ headers: { "x-api-key": composioApiKey },+});++// Create Anthropic model+const anthropic = createAnthropic();++/**+ * Execute a task using Vercel AI SDK with MCP tools+ */+async function executeTask(task: string) {+ const result = await generateText({+ model: anthropic("claude-3-5-sonnet-latest"),+ prompt: task,+ tools: mcpClient.tools,+ 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.",+ });++ return result.text;+}++// Example usage+async function main() {+ // Execute a task that requires tools+ let result = await executeTask(+ "Get the current weather in San Francisco"+ );+ console.log(result);++ // Execute another task with tools+ result = await executeTask(+ "Search for the latest news about AI and summarize the top 3 stories"+ );+ console.log(result);+}++main().catch(console.error);\ No newline at end of file