@devries-cameron20 / composio Mirror · read-only / commits / fe96cf40d
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 19:30 UTC

providers initi update

Sushmithamallesh committed Oct 12, 2025 at 21:36 UTC fe96cf40d01873e98226708a69cd589c5d3388d0
4 files changed +6 -366
fern/pages/src/mcp/providers-dummy.mdx deleted
-360
@@ -1,360 +0,0 @@
1 ----
2 -
3 -title: MCP Providers
4 -subtitle: "Guide to Using Composio MCP Servers with Your Agent Framework"
5 -image: "https://og.composio.dev/api/og?title=MCP%20Providers" # image for socials
6 -keywords: ""
7 -hide-nav-links: true
8 -
9 ----
10 -
11 -<Warning title="Only available for TypeScript SDK" icon="warning">At this time, MCP providers using the Composio SDK are only supported in the TypeScript SDK. Support for the Python SDK is coming soon.</Warning>
12 -
13 -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.
14 -
15 -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.
16 -
17 ----
18 -
19 -## 1. Anthropic Provider
20 -
21 -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.
22 -
23 -<CodeGroup>
24 - <CodeGroupItem title="TypeScript">
25 -
26 -```typescript
27 -import { Composio } from '@composio/core';
28 -import { AnthropicProvider } from '@composio/anthropic';
29 -import Anthropic from '@anthropic-ai/sdk';
30 -
31 -// Initialize Anthropic client
32 -const anthropic = new Anthropic({
33 - apiKey: process.env.ANTHROPIC_API_KEY,
34 -});
35 -
36 -// Initialize Composio with the Anthropic provider
37 -const composio = new Composio({
38 - apiKey: process.env.COMPOSIO_API_KEY,
39 - provider: new AnthropicProvider({ cacheTools: true }),
40 -});
41 -
42 -// Create MCP server with the new API structure
43 -const mcpConfig = await composio.mcp.create({
44 - name: "Gmail Readonly Server",
45 - serverConfig: [
46 - {
47 - authConfigId: "<auth_config_id>", // Your auth config ID
48 - allowedTools: ["GMAIL_FETCH_EMAILS"]
49 - }
50 - ],
51 - options: {
52 - isChatAuth: true
53 - }
54 -});
55 -
56 -console.log(`✅ MCP server created: ${mcpConfig.id}`);
57 -console.log(`🔧 Available toolkits: ${mcpConfig.toolkits.join(", ")}`);
58 -
59 -// Check user connection status before proceeding
60 -const connectionStatus = await composio.mcp.getUserConnectionStatus({
61 - id: mcpConfig.id,
62 - userId: "utkarsh-dixit"
63 -});
64 -
65 -if (!connectionStatus.connected) {
66 - console.log("❌ User needs to connect required accounts");
67 - // Handle authentication as needed
68 - return;
69 -}
70 -
71 -// Retrieve server instances for connected accounts
72 -const serverInstances = await mcpConfig.getServer({
73 - userId: "utkarsh-dixit",
74 -});
75 -
76 -console.log("Server instances for connected accounts:", serverInstances);
77 -
78 -console.log("\n=== Fetching and Summarizing Recent Emails ===");
79 -
80 -const stream = await anthropic.beta.messages.stream(
81 -{
82 - model: "claude-3-5-sonnet-20241022",
83 - max_tokens: 1000,
84 - mcp_servers: serverInstances,
85 - messages: [
86 - {
87 - role: "user",
88 - content:
89 - "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.",
90 - },
91 - ],
92 -},
93 -{
94 - headers: {
95 - "anthropic-beta": "mcp-client-2025-04-04",
96 - },
97 -}
98 -);
99 -
100 -console.log("\n📬 Email Summary:");
101 -for await (const event of stream) {
102 - if (
103 - event.type === "content_block_delta" &&
104 - event.delta.type === "text_delta"
105 - ) {
106 - process.stdout.write(event.delta.text);
107 - }
108 -}
109 -process.stdout.write("\n");
110 -
111 -console.log("\n✅ Anthropic MCP example completed successfully!");
112 -```
113 -
114 - </CodeGroupItem>
115 -</CodeGroup>
116 -
117 ----
118 -
119 -## 2. Mastra Provider
120 -
121 -The **Mastra Provider** is tailored for the [Mastra](https://mastra.ai/en/docs/tools-mcp/overview#creating-tools) TypeScript-native agent framework. This client provides a getServer method to obtain the Composio MCP Server URL, configured for your user.
122 -
123 -<CodeGroup>
124 - <CodeGroupItem title="Mastra">
125 -
126 -```typescript
127 -import { MastraProvider } from '@composio/mastra';
128 -import { Composio } from '@composio/core';
129 -import { MCPClient } from '@mastra/mcp';
130 -import { Agent } from '@mastra/core/agent';
131 -import { openai } from '@ai-sdk/openai';
132 -import type { MastraMCPServerDefinition } from '@mastra/mcp';
133 -
134 -const composio = new Composio({
135 - apiKey: process.env.COMPOSIO_API_KEY,
136 - provider: new MastraProvider(),
137 -});
138 -
139 -// Create an MCP server with the Gmail toolkit using new API structure
140 -const mcpConfig = await composio.mcp.create({
141 - name: "Gmail Readonly Server",
142 - serverConfig: [
143 - {
144 - authConfigId: "<auth_config_id>", // Your auth config ID
145 - allowedTools: ["GMAIL_FETCH_EMAILS"]
146 - }
147 - ],
148 - options: {
149 - isChatAuth: true
150 - }
151 -});
152 -
153 -console.log(`✅ MCP server created: ${mcpConfig.id}`);
154 -console.log(`🔧 Available toolkits: ${mcpConfig.toolkits.join(", ")}`);
155 -
156 -// Check user connection status
157 -const connectionStatus = await composio.mcp.getUserConnectionStatus({
158 - id: mcpConfig.id,
159 - userId: "utkarsh-dixit"
160 -});
161 -
162 -console.log("Connection status:", connectionStatus.connected);
163 -
164 -if (!connectionStatus.connected) {
165 - console.log("❌ User needs to authenticate with required services");
166 - // Handle authentication flow
167 - Object.entries(connectionStatus.connectedToolkits).forEach(([toolkit, status]) => {
168 - if (!status.connected) {
169 - console.log(`Please connect ${toolkit}`);
170 - }
171 - });
172 - return;
173 -}
174 -
175 -// Retrieve server instance for connected accounts
176 -const serverInstance = await mcpConfig.getServer({
177 - userId: "utkarsh-dixit"
178 -});
179 -
180 -console.log("Server instance for connected accounts:", serverInstance);
181 -
182 -// Initialize MCPClient with the server URLs
183 -const mcpClient = new MCPClient({
184 -servers: Object.fromEntries(
185 - Object.entries(serverInstance as Record<string, { url: string }>).map(
186 - ([key, value]) => [key, { url: new URL(value.url) }]
187 - )
188 -) satisfies Record<string, MastraMCPServerDefinition>,
189 -});
190 -
191 -// List available tools from MCP client
192 -const tools = await mcpClient.getTools();
193 -console.log(`🔧 Available tools: ${Object.keys(tools).join(", ")}`);
194 -
195 -// Create a Gmail agent using the MCP tools
196 -const gmailAgent = new Agent({
197 - name: "Gmail Assistant",
198 - instructions: `
199 - You are a helpful Gmail assistant that fetches and summarizes emails.
200 - When fetching emails, provide a clear summary of the results including sender, subject, and date.
201 - Be concise and provide actionable information based on the email content.
202 - `,
203 - model: openai("gpt-4o-mini"),
204 - tools,
205 -});
206 -
207 -// Fetch and summarize recent emails
208 -console.log("\n=== Fetching and Summarizing Recent Emails ===");
209 -const emailResponse = await gmailAgent.generate(
210 -"Fetch the latest 10 emails and provide a detailed summary with sender, subject, date, and brief content overview for each email"
211 -);
212 -console.log("\n📬 Email Summary:");
213 -console.log(emailResponse.text);
214 -
215 -console.log("\n✅ Gmail MCP example completed successfully!");
216 -```
217 -
218 - </CodeGroupItem>
219 -</CodeGroup>
220 -
221 ----
222 -
223 -## 3. OpenAI SDK Provider
224 -
225 -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.
226 -
227 -<CodeGroup>
228 - <CodeGroupItem title="TypeScript">
229 -
230 -```typescript
231 -import { Composio } from '@composio/core';
232 -import { OpenAIProvider } from '@composio/openai';
233 -import OpenAI from 'openai';
234 -
235 -const openai = new OpenAI({
236 - apiKey: process.env.OPENAI_API_KEY,
237 -});
238 -
239 -const composio = new Composio({
240 - apiKey: process.env.COMPOSIO_API_KEY,
241 - provider: new OpenAIProvider(),
242 -});
243 -
244 -// Create MCP server with new API structure
245 -const mcpConfig = await composio.mcp.create({
246 - name: "Gmail Readonly Server",
247 - serverConfig: [
248 - {
249 - authConfigId: "<auth_config_id>", // Your auth config ID
250 - allowedTools: ["GMAIL_FETCH_EMAILS"]
251 - }
252 - ],
253 - options: {
254 - isChatAuth: true
255 - }
256 -});
257 -
258 -console.log(`✅ MCP server created: ${mcpConfig.id}`);
259 -console.log(`🔧 Available toolkits: ${mcpConfig.toolkits.join(", ")}`);
260 -
261 -// Check if user has necessary connections
262 -const connectionStatus = await composio.mcp.getUserConnectionStatus({
263 - id: mcpConfig.id,
264 - userId: "utkarsh-dixit"
265 -});
266 -
267 -if (!connectionStatus.connected) {
268 - console.log("❌ User authentication required");
269 - // Handle missing connections
270 - for (const [toolkit, status] of Object.entries(connectionStatus.connectedToolkits)) {
271 - if (!status.connected) {
272 - const authParams = await composio.mcp.getConnectionParams({
273 - id: mcpConfig.id,
274 - toolkit
275 - });
276 -
277 - const authRequest = await composio.mcp.authorize({
278 - id: mcpConfig.id,
279 - userId: "utkarsh-dixit",
280 - toolkit
281 - });
282 -
283 - if (authRequest.redirectUrl) {
284 - console.log(`Please authenticate with ${toolkit}: ${authRequest.redirectUrl}`);
285 - }
286 - }
287 - }
288 - return;
289 -}
290 -
291 -// Retrieve server URLs for connected accounts
292 -const serverUrls = await mcpConfig.getServer({
293 - userId: "utkarsh-dixit",
294 - options: {
295 - limitTools: ["GMAIL_FETCH_EMAILS"] // Optional: limit to specific tools
296 - }
297 -});
298 -
299 -console.log("Server URLs for your MCP server:", serverUrls);
300 -
301 -// Use with OpenAI (example with hypothetical OpenAI MCP integration)
302 -const completion = await openai.chat.completions.create({
303 - model: "gpt-4o-mini",
304 - messages: [
305 - {
306 - role: "user",
307 - content: "I've connected to Gmail and I want to fetch the latest email from my inbox and summarize it"
308 - }
309 - ],
310 - // Note: This is a hypothetical integration - actual OpenAI MCP support may differ
311 - tools: serverUrls,
312 -});
313 -
314 -console.log("\n📬 Email Summary:");
315 -console.log(completion.choices[0].message.content);
316 -
317 -console.log("\n✅ OpenAI MCP example completed successfully!");
318 -console.log("\n💡 Note: The MCP server URLs can also be used to connect from other MCP-compatible clients.");
319 -console.log(`📍 Server ID for future reference: ${mcpConfig.id}`);
320 -```
321 -
322 - </CodeGroupItem>
323 -</CodeGroup>
324 -
325 ----
326 -
327 -## Managing Existing Servers
328 -
329 -You can also work with previously created MCP servers:
330 -
331 -```typescript
332 -// Find a server by name
333 -const existingServer = await composio.mcp.getByName("Gmail Readonly Server");
334 -
335 -// Check connection status for the existing server
336 -const status = await composio.mcp.getUserConnectionStatus({
337 - id: existingServer.id,
338 - userId: "user123@example.com"
339 -});
340 -
341 -// Generate URLs for the existing server
342 -const urls = await composio.mcp.getServer({
343 - id: existingServer.id,
344 - userId: "user123@example.com",
345 - options: {
346 - isChatAuth: true
347 - }
348 -});
349 -```
350 -
351 -## Best Practices for Providers
352 -
353 -1. **Always check connection status** before using MCP servers to ensure users are authenticated
354 -2. **Handle authentication gracefully** by providing clear instructions and redirect URLs
355 -3. **Use meaningful server names** to make management easier
356 -4. **Limit tools appropriately** to only what your application needs
357 -5. **Cache server configurations** when possible to reduce API calls
358 -6. **Monitor connection health** and provide re-authentication flows when needed
359 -
360 -By using Composio MCP Servers with these providers, 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.
\ No newline at end of file
fern/snippets/mcp/python/anthropic-client.py
+2 -2
@@ -8,7 +8,7 @@ mcp_server_url = "https://backend.composio.dev/v3/mcp/YOUR_SERVER_ID?include_com
8
9 # Use MCP with Anthropic (beta feature)
10 response = client.beta.messages.create(
11 - model="claude-3-5-sonnet-20241022",
11 + model="claude-sonnet-4-5",
12 max_tokens=1000,
13 messages=[{
14 "role": "user",
@@ -19,7 +19,7 @@ response = client.beta.messages.create(
19 "url": mcp_server_url,
20 "name": "composio-gmail-calendar-mcp-server"
21 }],
22 - betas=["mcp-client-2025-01-15"] # Enable MCP beta
22 + betas=["mcp-client-2025-04-04"] # Enable MCP beta
23 )
24
25 print(response.content)
\ No newline at end of file
fern/snippets/mcp/python/anthropic-provider.py
+2 -2
@@ -20,7 +20,7 @@ instance = server.generate("user@example.com")
20
21 # Use MCP with Anthropic to manage development workflow
22 response = anthropic.beta.messages.create(
23 - model="claude-3-5-sonnet-20241022",
23 + model="claude-sonnet-4-5",
24 max_tokens=1000,
25 messages=[{
26 "role": "user",
@@ -31,7 +31,7 @@ response = anthropic.beta.messages.create(
31 "url": instance['url'],
32 "name": "composio-mcp-server"
33 }],
34 - betas=["mcp-client-2025-01-15"] # Enable MCP beta
34 + betas=["mcp-client-2025-04-04"] # Enable MCP beta
35 )
36
37 print(response.content)
\ No newline at end of file
fern/snippets/mcp/typescript/anthropic-provider.ts
+2 -2
@@ -23,7 +23,7 @@ const instance = await server.generate("user@example.com");
23
24 // Use MCP with Anthropic for spreadsheet operations
25 const response = await anthropic.beta.messages.create({
26 - model: "claude-3-5-sonnet-20241022",
26 + model: "claude-sonnet-4-5",
27 max_tokens: 1000,
28 messages: [{
29 role: "user",
@@ -34,7 +34,7 @@ const response = await anthropic.beta.messages.create({
34 url: instance.url,
35 name: "composio-mcp-server"
36 }],
37 - betas: ["mcp-client-2025-01-15"] // Enable MCP beta
37 + betas: ["mcp-client-2025-04-04"] // Enable MCP beta
38 });
39
40 console.log(response.content);
\ No newline at end of file