MCP Providers

Guide to Using Composio MCP Servers with Your Agent Framework
Only available for TypeScript SDK
At this time, MCP providers using the Composio SDK are only supported in the TypeScript SDK. Support for the Python SDK is coming soon.

Integrating external tools into agent frameworks can be a complex and time-consuming process. Composio MCP (Model Context Protocol) servers simplify this workflow, enabling you to connect your framework to a wide array of tools and services with minimal configuration.

This guide introduces the primary MCP providers, each optimized for a popular agent framework. With these providers, you can focus on developing intelligent agent logic while Composio handles the integration details.


1. Anthropic Provider

The Anthropic Provider is purpose-built for use with the Anthropic Claude API. It supports Model Context Protocol (MCP) tools via a lightweight client that exposes a getServer method for retrieving the appropriate Composio MCP Server URL, preconfigured for your user. This provider ensures seamless compatibility between Composio tools and Anthropic’s function calling APIs.

1import { Composio } from '@composio/core';
2import { AnthropicProvider } from '@composio/anthropic';
3import Anthropic from '@anthropic-ai/sdk';
4
5// Initialize Anthropic client
6const anthropic = new Anthropic({
7 apiKey: process.env.ANTHROPIC_API_KEY,
8});
9
10// Initialize Composio with the Anthropic provider
11const composio = new Composio({
12 apiKey: process.env.COMPOSIO_API_KEY,
13 provider: new AnthropicProvider({ cacheTools: true }),
14});
15
16const mcpConfig = await composio.mcp.create(
17"Gmail Readonly Server",
18[
19 {
20 toolkit: "gmail",
21 allowedTools: ["GMAIL_FETCH_EMAILS"],
22 authConfigId: "<auth_config_id>"
23 },
24],
25{ useComposioManagedAuth: true }
26);
27
28console.log(`✅ MCP server created: ${mcpConfig.id}`);
29console.log(`🔧 Available toolkits: ${mcpConfig.toolkits.join(", ")}`);
30
31// Retrieve server instances for connected accounts
32const serverInstances = await mcpConfig.getServer({
33 userId: "utkarsh-dixit",
34});
35
36console.log("Server instances for connected accounts:", serverInstances);
37
38console.log("\n=== Fetching and Summarizing Recent Emails ===");
39
40const stream = await anthropic.beta.messages.stream(
41{
42 model: "claude-3-5-sonnet-20241022",
43 max_tokens: 1000,
44 mcp_servers: serverInstances,
45 messages: [
46 {
47 role: "user",
48 content:
49 "Please fetch the latest 10 emails and provide a detailed summary with sender, subject, date, and brief content overview for each email. Format the response in a clear, organized way.",
50 },
51 ],
52},
53{
54 headers: {
55 "anthropic-beta": "mcp-client-2025-04-04",
56 },
57}
58);
59
60console.log("\n📬 Email Summary:");
61for await (const event of stream) {
62 if (
63 event.type === "content_block_delta" &&
64 event.delta.type === "text_delta"
65 ) {
66 process.stdout.write(event.delta.text);
67 }
68}
69process.stdout.write("\n");
70
71console.log("\n✅ Anthropic MCP example completed successfully!");

2. Mastra Provider

The Mastra Provider is tailored for the Mastra TypeScript-native agent framework. This client provides a getServer method to obtain the Composio MCP Server URL, configured for your user.

1import { MastraProvider } from '@composio/mastra';
2import { Composio } from '@composio/core';
3import { MCPClient } from '@mastra/mcp';
4import { Agent } from '@mastra/core/agent';
5import { openai } from '@ai-sdk/openai';
6import type { MastraMCPServerDefinition } from '@mastra/mcp';
7
8const composio = new Composio({
9 apiKey: process.env.COMPOSIO_API_KEY,
10 provider: new MastraProvider(),
11});
12
13// Create an MCP server with the Gmail toolkit
14const mcpConfig = await composio.mcp.create(
15"Gmail Readonly Server",
16[
17 {
18 toolkit: "GMAIL",
19 allowedTools: ["GMAIL_FETCH_EMAILS"],
20 authConfigId: "<auth_config_id>"
21 },
22],
23{ useComposioManagedAuth: true }
24);
25
26console.log(`✅ MCP server created: ${mcpConfig.id}`);
27console.log(`🔧 Available toolkits: ${mcpConfig.toolkits.join(", ")}`);
28
29// Retrieve server instance for connected accounts
30const serverInstance = await mcpConfig.getServer({
31 userId: "utkarsh-dixit"
32});
33
34console.log("Server instance for connected accounts:", serverInstance);
35
36// Initialize MCPClient with the server URLs
37const mcpClient = new MCPClient({
38servers: Object.fromEntries(
39 Object.entries(serverInstance as Record<string, { url: string }>).map(
40 ([key, value]) => [key, { url: new URL(value.url) }]
41 )
42) satisfies Record<string, MastraMCPServerDefinition>,
43});
44
45// List available tools from MCP client
46const tools = await mcpClient.getTools();
47console.log(`🔧 Available tools: ${Object.keys(tools).join(", ")}`);
48
49// Create a Gmail agent using the MCP tools
50const gmailAgent = new Agent({
51 name: "Gmail Assistant",
52 instructions: `
53 You are a helpful Gmail assistant that fetches and summarizes emails.
54 When fetching emails, provide a clear summary of the results including sender, subject, and date.
55 Be concise and provide actionable information based on the email content.
56 `,
57 model: openai("gpt-4o-mini"),
58 tools,
59});
60
61// Fetch and summarize recent emails
62console.log("\n=== Fetching and Summarizing Recent Emails ===");
63const emailResponse = await gmailAgent.generate(
64"Fetch the latest 10 emails and provide a detailed summary with sender, subject, date, and brief content overview for each email"
65);
66console.log("\n📬 Email Summary:");
67console.log(emailResponse.text);
68
69console.log("\n✅ Gmail MCP example completed successfully!");

3. OpenAI SDK Provider

The OpenAI SDK Provider is designed for use with the OpenAI SDK and supports MCP tools through a streamlined client. This client provides a getServer method to obtain the Composio MCP Server URL, configured for your user.

1const composio = new Composio({
2 apiKey: process.env.COMPOSIO_API_KEY,
3 provider: new OpenAIResponsesProvider(),
4});
5
6const mcpConfig = await composio.mcp.create(
7"Gmail Readonly Server",
8[
9 {
10 toolkit: "GMAIL",
11 allowedTools: ["GMAIL_FETCH_EMAILS"],
12 authConfigId: "<auth_config_id>"
13 },
14],
15{ useComposioManagedAuth: true }
16);
17
18console.log(`✅ MCP server created: ${mcpConfig.id}`);
19console.log(`🔧 Available toolkits: ${mcpConfig.toolkits.join(", ")}`);
20
21// Retrieve server URLs for connected accounts
22const serverUrls = await mcpConfig.getServer({
23 userId: "utkarsh-dixit",
24});
25
26console.log("Server URLs for your MCP server:", serverUrls);
27
28const completion = await openai.responses.create({
29model: "gpt-4o-mini",
30input:
31 "I've connected to Gmail and I want to fetch the latest email from my inbox and summarize it",
32tools: serverUrls,
33});
34
35console.log("\n📬 Email Summary:");
36console.log(completion.output_text);
37
38console.log("\n✅ OpenAI MCP example completed successfully!");
39console.log("\n💡 Note: The MCP server URLs can also be used to connect from other MCP-compatible clients.");
40console.log(`📍 Server ID for future reference: ${mcpConfig.id}`);

By using Composio MCP Servers, you can quickly connect your agent framework to a wide range of external tools with minimal effort. This lets you streamline integration, reduce setup time, and focus more on building your AI agent.