Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
feat: add mcp support for open ai (#1667)
Apoorv Taneja committed
Jun 19, 2025 at 15:50 UTC
63f76f4faa70fdee643f233a33a1e4c780e4c572
15 files changed
+218
-324
ts/examples/openai/package.json
+1
@@ -10,6 +10,7 @@
10
"start:assistant": "bun src/assistants.ts",
11
"start:agents": "bun src/agents-api/index.ts",
12
"examples": "bun src/examples.ts",
13
+ "start:mcp": "bun src/mcp.ts",
14
"test": "echo \"Error: no test specified\" && exit 1"
15
},
16
"keywords": [],
ts/examples/openai/src/mcp.ts
new
+90
@@ -0,0 +1,90 @@
1
+/**
2
+ * OpenAI MCP Gmail Example
3
+ *
4
+ * This example demonstrates how to use Composio MCP with OpenAI to:
5
+ * 1. Create an MCP server for Gmail toolkit
6
+ * 2. Generate URLs for the server
7
+ * 3. Use OpenAI to summarize emails
8
+ *
9
+ */
10
+
11
+import { OpenAIResponsesProvider } from '@composio/openai';
12
+import { Composio } from '@composio/core';
13
+import OpenAI from 'openai';
14
+import dotenv from 'dotenv';
15
+dotenv.config();
16
+
17
+/**
18
+ * Initialize Composio with OpenAI provider
19
+ */
20
+const composio = new Composio({
21
+ apiKey: process.env.COMPOSIO_API_KEY,
22
+ provider: new OpenAIResponsesProvider(),
23
+});
24
+
25
+/**
26
+ * Initialize OpenAI client
27
+ */
28
+const openai = new OpenAI({
29
+ apiKey: process.env.OPENAI_API_KEY,
30
+});
31
+
32
+// Create an MCP server with Gmail toolkit
33
+const mcpConfig = await composio.mcp.create(
34
+ "gmail-mcp-openai-" + Date.now(),
35
+ [
36
+ {
37
+ toolkit: "gmail",
38
+ authConfigId: "<auth_config_id>", // Replace with your auth config ID
39
+ allowedTools: [
40
+ "GMAIL_FETCH_EMAILS"
41
+ ]
42
+ }
43
+ ],
44
+ { useComposioManagedAuth: true }
45
+);
46
+
47
+console.log(`✅ MCP server created: ${mcpConfig.id}`);
48
+console.log(`🔧 Available toolkits: ${mcpConfig.toolkits.join(', ')}`);
49
+
50
+// Get server URLs with connected accounts (using convenience method)
51
+const serverUrls = await mcpConfig.getServer({
52
+ connectedAccountIds: {
53
+ "gmail": "<connected_account_id>" // Replace with your connected account ID
54
+ }
55
+});
56
+
57
+// Alternative: You can also use the standalone method to get URLs later
58
+// const serverUrls = await composio.mcp.getServer(mcpConfig.id, {
59
+// connectedAccountIds: {
60
+// "gmail": "<connected_account_id>"
61
+// }
62
+// });
63
+
64
+console.log("Server URLs for connected accounts:", serverUrls);
65
+
66
+// Function to fetch and summarize emails
67
+async function fetchAndSummarizeEmails() {
68
+ try {
69
+ // Use OpenAI to summarize the emails
70
+ console.log('\n=== Generating Email Summary ===');
71
+ const completion = await openai.responses.create({
72
+ model: "gpt-4o-mini",
73
+ input: "I've connected to gmail and I want to fetch the latest email from my inbox and summarize it",
74
+ tools: serverUrls,
75
+ });
76
+
77
+ console.log('\n📬 Email Summary:');
78
+ console.log(completion.output_text);
79
+
80
+ } catch (error) {
81
+ console.error('Error fetching or summarizing emails:', error);
82
+ }
83
+}
84
+
85
+// Run the email summarization
86
+await fetchAndSummarizeEmails();
87
+
88
+console.log('\n✅ OpenAI MCP Example completed successfully!');
89
+console.log('\n💡 Note: The MCP server URLs can be used to connect from other MCP-compatible clients');
90
+console.log(`📍 Server ID for future reference: ${mcpConfig.id}`);
ts/packages/core/src/models/MCP.ts
+24
-18
@@ -17,7 +17,6 @@ import {
17
CustomCreateResponseSchema,
18
GenerateURLResponseSchema,
19
GenerateURLParamsSnakeCaseSchema,
20
- GenerateURLParamsValidated,
20
McpListResponseSchema,
21
McpRetrieveResponseSchema,
22
McpDeleteResponseSchema,
@@ -497,9 +496,7 @@ export class MCP<T = McpServerGetResponse> {
496
*
497
* @param data - The MCP URL response data (in camelCase)
498
* @param serverName - Name of the MCP server
500
- * @param connectedAccountIds - Optional array of connected account IDs
501
- * @param userIds - Optional array of user IDs
502
- * @param toolkits - Optional array of toolkit names
499
+
500
* @returns Transformed response in appropriate format
501
*/
502
private wrapMcpServerResponse(
@@ -511,20 +508,29 @@ export class MCP<T = McpServerGetResponse> {
508
): T {
509
// Check if provider has a custom transform method
510
if (this.provider && typeof this.provider.wrapMcpServerResponse === 'function') {
514
- // Convert to snake_case for backward compatibility with providers
515
- const snakeCaseData: McpUrlResponse = {
516
- mcp_url: data.mcpUrl,
517
- ...(data.connectedAccountUrls && { connected_account_urls: data.connectedAccountUrls }),
518
- ...(data.userIdsUrl && { user_ids_url: data.userIdsUrl }),
519
- };
520
-
521
- const transformed = this.provider.wrapMcpServerResponse(
522
- snakeCaseData,
523
- serverName,
524
- connectedAccountIds,
525
- userIds,
526
- toolkits
527
- );
511
+ // Convert to array of name and url based on connected accounts or user ids
512
+ let snakeCaseData: McpUrlResponse;
513
+
514
+ if (data.connectedAccountUrls?.length) {
515
+ snakeCaseData = data.connectedAccountUrls.map((url, index) => ({
516
+ name: serverName + '-' + connectedAccountIds?.[index],
517
+ url: url,
518
+ }));
519
+ } else if (data.userIdsUrl?.length) {
520
+ snakeCaseData = data.userIdsUrl.map((url, index) => ({
521
+ name: serverName + '-' + userIds?.[index],
522
+ url: url,
523
+ }));
524
+ } else {
525
+ snakeCaseData = [
526
+ {
527
+ name: serverName,
528
+ url: data.mcpUrl,
529
+ },
530
+ ];
531
+ }
532
+
533
+ const transformed = this.provider.wrapMcpServerResponse(snakeCaseData);
534
return transformed as T;
535
}
536
ts/packages/core/src/provider/BaseProvider.ts
+2
-10
@@ -66,18 +66,10 @@ abstract class BaseProvider<TMcpResponse = McpServerGetResponse> {
66
*
67
* @param data - The MCP URL response data
68
* @param serverName - Name of the MCP server
69
- * @param connectedAccountIds - Optional array of connected account IDs
70
- * @param userIds - Optional array of user IDs
71
- * @param toolkits - Optional array of toolkit names
69
+
70
* @returns Transformed response in provider-specific format, or undefined to use default transformation
71
*/
74
- wrapMcpServerResponse?(
75
- data: McpUrlResponse,
76
- serverName: string,
77
- connectedAccountIds?: string[],
78
- userIds?: string[],
79
- toolkits?: string[]
80
- ): TMcpResponse;
72
+ wrapMcpServerResponse?(data: McpUrlResponse): TMcpResponse;
73
}
74
75
/**
ts/packages/core/src/provider/OpenAIProvider.ts
+5
-29
@@ -51,37 +51,13 @@ export class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection,
51
* OpenAI uses the standard format by default.
52
*
53
* @param data - The MCP URL response data
54
- * @param serverName - Name of the MCP server
55
- * @param connectedAccountIds - Optional array of connected account IDs
56
- * @param userIds - Optional array of user IDs
57
- * @param toolkits - Optional array of toolkit names
54
* @returns Standard MCP server response format
55
*/
60
- wrapMcpServerResponse(
61
- data: McpUrlResponse,
62
- serverName: string,
63
- connectedAccountIds?: string[],
64
- userIds?: string[],
65
- toolkits?: string[]
66
- ): McpServerGetResponse {
67
- // OpenAI uses the standard format
68
- if (connectedAccountIds?.length && data.connected_account_urls) {
69
- return data.connected_account_urls.map((url: string, index: number) => ({
70
- url: new URL(url),
71
- name: `${serverName}-${connectedAccountIds[index]}`,
72
- toolkit: toolkits?.[index],
73
- })) as McpServerGetResponse;
74
- } else if (userIds?.length && data.user_ids_url) {
75
- return data.user_ids_url.map((url: string, index: number) => ({
76
- url: new URL(url),
77
- name: `${serverName}-${userIds[index]}`,
78
- toolkit: toolkits?.[index],
79
- })) as McpServerGetResponse;
80
- }
81
- return {
82
- url: new URL(data.mcp_url),
83
- name: serverName,
84
- } as McpServerGetResponse;
56
+ wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse {
57
+ return data.map(item => ({
58
+ url: new URL(item.url),
59
+ name: item.name,
60
+ }));
61
}
62
63
/**
ts/packages/core/src/types/mcp.types.ts
+3
-4
@@ -193,10 +193,9 @@ export type McpUrlResponseCamelCase = {
193
194
// Snake_case URL response (for internal API use)
195
export type McpUrlResponse = {
196
- connected_account_urls?: string[];
197
- user_ids_url?: string[];
198
- mcp_url: string;
199
-};
196
+ name: string;
197
+ url: string;
198
+}[];
199
200
export type McpServerCreateResponse<T> = (McpCreateResponse | CustomCreateResponse) & {
201
toolkits: string[];
ts/packages/core/test/models/mcp.test.ts
+12
-11
@@ -168,17 +168,12 @@ class MockProvider extends BaseAgenticProvider<MockToolCollection, MockTool, Moc
168
return tools.map(tool => this.wrapTool(tool, executeTool));
169
}
170
171
- wrapMcpServerResponse(
172
- data: McpUrlResponse,
173
- serverName: string,
174
- connectedAccountIds?: string[],
175
- userIds?: string[],
176
- toolkits?: string[]
177
- ): MockMcpResponse {
171
+ wrapMcpServerResponse(data: McpUrlResponse): MockMcpResponse {
172
+ // McpUrlResponse is an array of { name, url } objects
173
return {
174
customFormat: true,
180
- serverName,
181
- urls: data.connected_account_urls || [data.mcp_url],
175
+ serverName: data[0]?.name || 'test-mcp-server',
176
+ urls: data.map(item => item.url),
177
};
178
}
179
}
@@ -384,7 +379,12 @@ describe('MCP', () => {
379
managedAuthViaComposio: mockRetrieveResponse.managed_auth_via_composio,
380
});
381
387
- mockClient.mcp.generate.url.mockResolvedValue(mockGenerateUrlResponse);
382
+ // Mock a response with only one URL for the single userId
383
+ const singleUserResponse = {
384
+ user_ids_url: ['https://mcp.example.com/user_123'],
385
+ mcp_url: 'https://mcp.example.com/server',
386
+ };
387
+ mockClient.mcp.generate.url.mockResolvedValue(singleUserResponse);
388
389
const result = await mcpWithProvider.getServer('mcp_123', {
390
userId: 'user_123',
@@ -392,7 +392,8 @@ describe('MCP', () => {
392
393
expect(result).toMatchObject({
394
customFormat: true,
395
- serverName: 'test-mcp-server',
395
+ serverName: 'test-mcp-server-user_123',
396
+ urls: ['https://mcp.example.com/user_123'],
397
});
398
});
399
});
ts/packages/providers/anthropic/src/index.ts
+5
-28
@@ -298,36 +298,13 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
298
* but this method is here to show providers can customize if needed.
299
*
300
* @param data - The MCP URL response data
301
- * @param serverName - Name of the MCP server
302
- * @param connectedAccountIds - Optional array of connected account IDs
303
- * @param userIds - Optional array of user IDs
304
- * @param toolkits - Optional array of toolkit names
301
* @returns Standard MCP server response format
302
*/
307
- wrapMcpServerResponse(
308
- data: McpUrlResponse,
309
- serverName: string,
310
- connectedAccountIds?: string[],
311
- userIds?: string[],
312
- toolkits?: string[]
313
- ): McpServerGetResponse {
303
+ wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse {
304
// Anthropic uses the standard format
315
- if (connectedAccountIds?.length && data.connected_account_urls) {
316
- return data.connected_account_urls.map((url: string, index: number) => ({
317
- url: new URL(url),
318
- name: `${serverName}-${connectedAccountIds[index]}`,
319
- toolkit: toolkits?.[index],
320
- })) as McpServerGetResponse;
321
- } else if (userIds?.length && data.user_ids_url) {
322
- return data.user_ids_url.map((url: string, index: number) => ({
323
- url: new URL(url),
324
- name: `${serverName}-${userIds[index]}`,
325
- toolkit: toolkits?.[index],
326
- })) as McpServerGetResponse;
327
- }
328
- return {
329
- url: new URL(data.mcp_url),
330
- name: serverName,
331
- } as McpServerGetResponse;
305
+ return data.map(item => ({
306
+ url: new URL(item.url),
307
+ name: item.name,
308
+ })) as McpServerGetResponse;
309
}
310
}
ts/packages/providers/cloudflare/src/index.ts
+9
-31
@@ -52,41 +52,19 @@ export class CloudflareProvider extends BaseNonAgenticProvider<
52
}
53
54
/**
55
- * Transform MCP URL response into Cloudflare-specific format.
56
- * Cloudflare uses the standard format by default.
55
+ * Transform MCP URL response into Anthropic-specific format.
56
+ * By default, Anthropic uses the standard format (same as default),
57
+ * but this method is here to show providers can customize if needed.
58
*
59
* @param data - The MCP URL response data
59
- * @param serverName - Name of the MCP server
60
- * @param connectedAccountIds - Optional array of connected account IDs
61
- * @param userIds - Optional array of user IDs
62
- * @param toolkits - Optional array of toolkit names
60
* @returns Standard MCP server response format
61
*/
65
- wrapMcpServerResponse(
66
- data: McpUrlResponse,
67
- serverName: string,
68
- connectedAccountIds?: string[],
69
- userIds?: string[],
70
- toolkits?: string[]
71
- ): McpServerGetResponse {
72
- // Cloudflare uses the standard format
73
- if (connectedAccountIds?.length && data.connected_account_urls) {
74
- return data.connected_account_urls.map((url: string, index: number) => ({
75
- url: new URL(url),
76
- name: `${serverName}-${connectedAccountIds[index]}`,
77
- toolkit: toolkits?.[index],
78
- })) as McpServerGetResponse;
79
- } else if (userIds?.length && data.user_ids_url) {
80
- return data.user_ids_url.map((url: string, index: number) => ({
81
- url: new URL(url),
82
- name: `${serverName}-${userIds[index]}`,
83
- toolkit: toolkits?.[index],
84
- })) as McpServerGetResponse;
85
- }
86
- return {
87
- url: new URL(data.mcp_url),
88
- name: serverName,
89
- } as McpServerGetResponse;
62
+ wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse {
63
+ // Anthropic uses the standard format
64
+ return data.map(item => ({
65
+ url: new URL(item.url),
66
+ name: item.name,
67
+ })) as McpServerGetResponse;
68
}
69
70
/**
ts/packages/providers/google/src/index.ts
+9
-31
@@ -71,41 +71,19 @@ export class GoogleProvider extends BaseNonAgenticProvider<GoogleGenAIToolCollec
71
}
72
73
/**
74
- * Transform MCP URL response into Google-specific format.
75
- * Google uses the standard format by default.
74
+ * Transform MCP URL response into Anthropic-specific format.
75
+ * By default, Anthropic uses the standard format (same as default),
76
+ * but this method is here to show providers can customize if needed.
77
*
78
* @param data - The MCP URL response data
78
- * @param serverName - Name of the MCP server
79
- * @param connectedAccountIds - Optional array of connected account IDs
80
- * @param userIds - Optional array of user IDs
81
- * @param toolkits - Optional array of toolkit names
79
* @returns Standard MCP server response format
80
*/
84
- wrapMcpServerResponse(
85
- data: McpUrlResponse,
86
- serverName: string,
87
- connectedAccountIds?: string[],
88
- userIds?: string[],
89
- toolkits?: string[]
90
- ): McpServerGetResponse {
91
- // Google uses the standard format
92
- if (connectedAccountIds?.length && data.connected_account_urls) {
93
- return data.connected_account_urls.map((url: string, index: number) => ({
94
- url: new URL(url),
95
- name: `${serverName}-${connectedAccountIds[index]}`,
96
- toolkit: toolkits?.[index],
97
- })) as McpServerGetResponse;
98
- } else if (userIds?.length && data.user_ids_url) {
99
- return data.user_ids_url.map((url: string, index: number) => ({
100
- url: new URL(url),
101
- name: `${serverName}-${userIds[index]}`,
102
- toolkit: toolkits?.[index],
103
- })) as McpServerGetResponse;
104
- }
105
- return {
106
- url: new URL(data.mcp_url),
107
- name: serverName,
108
- } as McpServerGetResponse;
81
+ wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse {
82
+ // Anthropic uses the standard format
83
+ return data.map(item => ({
84
+ url: new URL(item.url),
85
+ name: item.name,
86
+ })) as McpServerGetResponse;
87
}
88
89
/**
ts/packages/providers/langchain/src/index.ts
+9
-31
@@ -52,41 +52,19 @@ export class LangchainProvider extends BaseAgenticProvider<
52
}
53
54
/**
55
- * Transform MCP URL response into LangChain-specific format.
56
- * LangChain uses the standard format by default.
55
+ * Transform MCP URL response into Anthropic-specific format.
56
+ * By default, Anthropic uses the standard format (same as default),
57
+ * but this method is here to show providers can customize if needed.
58
*
59
* @param data - The MCP URL response data
59
- * @param serverName - Name of the MCP server
60
- * @param connectedAccountIds - Optional array of connected account IDs
61
- * @param userIds - Optional array of user IDs
62
- * @param toolkits - Optional array of toolkit names
60
* @returns Standard MCP server response format
61
*/
65
- wrapMcpServerResponse(
66
- data: McpUrlResponse,
67
- serverName: string,
68
- connectedAccountIds?: string[],
69
- userIds?: string[],
70
- toolkits?: string[]
71
- ): McpServerGetResponse {
72
- // LangChain uses the standard format
73
- if (connectedAccountIds?.length && data.connected_account_urls) {
74
- return data.connected_account_urls.map((url: string, index: number) => ({
75
- url: new URL(url),
76
- name: `${serverName}-${connectedAccountIds[index]}`,
77
- toolkit: toolkits?.[index],
78
- })) as McpServerGetResponse;
79
- } else if (userIds?.length && data.user_ids_url) {
80
- return data.user_ids_url.map((url: string, index: number) => ({
81
- url: new URL(url),
82
- name: `${serverName}-${userIds[index]}`,
83
- toolkit: toolkits?.[index],
84
- })) as McpServerGetResponse;
85
- }
86
- return {
87
- url: new URL(data.mcp_url),
88
- name: serverName,
89
- } as McpServerGetResponse;
62
+ wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse {
63
+ // Anthropic uses the standard format
64
+ return data.map(item => ({
65
+ url: new URL(item.url),
66
+ name: item.name,
67
+ })) as McpServerGetResponse;
68
}
69
70
/**
ts/packages/providers/mastra/src/index.ts
+10
-35
@@ -37,44 +37,19 @@ export class MastraProvider extends BaseAgenticProvider<
37
}
38
39
/**
40
- * Transform MCP URL response into Mastra-specific format.
41
- * Mastra expects URLs in a key-value map format.
40
+ * Transform MCP URL response into Anthropic-specific format.
41
+ * By default, Anthropic uses the standard format (same as default),
42
+ * but this method is here to show providers can customize if needed.
43
*
44
* @param data - The MCP URL response data
44
- * @param serverName - Name of the MCP server
45
- * @param connectedAccountIds - Optional array of connected account IDs
46
- * @param userIds - Optional array of user IDs
47
- * @returns Transformed MastraUrlMap
45
+ * @returns Standard MCP server response format
46
*/
49
- wrapMcpServerResponse(
50
- data: McpUrlResponse,
51
- serverName: string,
52
- connectedAccountIds?: string[],
53
- userIds?: string[]
54
- ): MastraUrlMap {
55
- if (connectedAccountIds?.length && data.connected_account_urls) {
56
- return data.connected_account_urls.reduce(
57
- (prev: MastraUrlMap, url: string, index: number) => {
58
- prev[`${serverName}-${index}`] = {
59
- url: url,
60
- };
61
- return prev;
62
- },
63
- {}
64
- );
65
- } else if (userIds?.length && data.user_ids_url) {
66
- return data.user_ids_url.reduce((prev: MastraUrlMap, url: string, index: number) => {
67
- prev[`${serverName}-${index}`] = {
68
- url: url,
69
- };
70
- return prev;
71
- }, {});
72
- }
73
- return {
74
- [serverName]: {
75
- url: data.mcp_url,
76
- },
77
- };
47
+ wrapMcpServerResponse(data: McpUrlResponse): MastraUrlMap {
48
+ // Transform to Mastra's URL map format
49
+ return data.reduce((acc: MastraUrlMap, item) => {
50
+ acc[item.name] = { url: item.url };
51
+ return acc;
52
+ }, {});
53
}
54
55
wrapTool(tool: Tool, executeTool: ExecuteToolFn): MastraTool {
ts/packages/providers/openai-agents/src/index.ts
+9
-31
@@ -56,41 +56,19 @@ export class OpenAIAgentsProvider extends BaseAgenticProvider<
56
}
57
58
/**
59
- * Transform MCP URL response into OpenAI Agents-specific format.
60
- * OpenAI Agents uses the standard format by default.
59
+ * Transform MCP URL response into Anthropic-specific format.
60
+ * By default, Anthropic uses the standard format (same as default),
61
+ * but this method is here to show providers can customize if needed.
62
*
63
* @param data - The MCP URL response data
63
- * @param serverName - Name of the MCP server
64
- * @param connectedAccountIds - Optional array of connected account IDs
65
- * @param userIds - Optional array of user IDs
66
- * @param toolkits - Optional array of toolkit names
64
* @returns Standard MCP server response format
65
*/
69
- wrapMcpServerResponse(
70
- data: McpUrlResponse,
71
- serverName: string,
72
- connectedAccountIds?: string[],
73
- userIds?: string[],
74
- toolkits?: string[]
75
- ): McpServerGetResponse {
76
- // OpenAI Agents uses the standard format
77
- if (connectedAccountIds?.length && data.connected_account_urls) {
78
- return data.connected_account_urls.map((url: string, index: number) => ({
79
- url: new URL(url),
80
- name: `${serverName}-${connectedAccountIds[index]}`,
81
- toolkit: toolkits?.[index],
82
- })) as McpServerGetResponse;
83
- } else if (userIds?.length && data.user_ids_url) {
84
- return data.user_ids_url.map((url: string, index: number) => ({
85
- url: new URL(url),
86
- name: `${serverName}-${userIds[index]}`,
87
- toolkit: toolkits?.[index],
88
- })) as McpServerGetResponse;
89
- }
90
- return {
91
- url: new URL(data.mcp_url),
92
- name: serverName,
93
- } as McpServerGetResponse;
66
+ wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse {
67
+ // Anthropic uses the standard format
68
+ return data.map(item => ({
69
+ url: new URL(item.url),
70
+ name: item.name,
71
+ })) as McpServerGetResponse;
72
}
73
74
/**
ts/packages/providers/openai/src/OpenAIResponsesProvider.ts
+21
-33
@@ -17,12 +17,11 @@ import {
17
ExecuteToolModifiers,
18
ExecuteToolFnOptions,
19
removeNonRequiredProperties,
20
- logger,
20
McpUrlResponse,
22
- McpServerGetResponse,
21
} from '@composio/core';
22
23
export type OpenAiTool = OpenAI.Responses.FunctionTool;
24
+export type OpenAiMcpTool = OpenAI.Responses.Tool.Mcp;
25
export type OpenAiToolCollection = Array<OpenAiTool>;
26
export type OpenAIResponsesProviderOptions = {
27
/**
@@ -31,9 +30,19 @@ export type OpenAIResponsesProviderOptions = {
30
*/
31
strict?: boolean;
32
};
33
+
34
+/**
35
+ * OpenAI-specific MCP server response format
36
+ */
37
+export interface OpenAIMcpServerResponse {
38
+ type: 'mcp';
39
+ server_label: string;
40
+ server_url: string;
41
+}
42
export class OpenAIResponsesProvider extends BaseNonAgenticProvider<
43
OpenAiToolCollection,
36
- OpenAiTool
44
+ OpenAiTool,
45
+ OpenAIMcpServerResponse[]
46
> {
47
readonly name = 'openai';
48
private strict: boolean | null;
@@ -70,40 +79,19 @@ export class OpenAIResponsesProvider extends BaseNonAgenticProvider<
79
80
/**
81
* Transform MCP URL response into OpenAI Responses-specific format.
73
- * OpenAI Responses uses the standard format by default.
82
+ * OpenAI Responses uses a custom format with type, server_label, server_url, and require_approval fields.
83
*
84
* @param data - The MCP URL response data
85
* @param serverName - Name of the MCP server
77
- * @param connectedAccountIds - Optional array of connected account IDs
78
- * @param userIds - Optional array of user IDs
79
- * @param toolkits - Optional array of toolkit names
80
- * @returns Standard MCP server response format
86
+ * @returns OpenAI-specific MCP server response format
87
*/
82
- wrapMcpServerResponse(
83
- data: McpUrlResponse,
84
- serverName: string,
85
- connectedAccountIds?: string[],
86
- userIds?: string[],
87
- toolkits?: string[]
88
- ): McpServerGetResponse {
89
- // OpenAI Responses uses the standard format
90
- if (connectedAccountIds?.length && data.connected_account_urls) {
91
- return data.connected_account_urls.map((url: string, index: number) => ({
92
- url: new URL(url),
93
- name: `${serverName}-${connectedAccountIds[index]}`,
94
- toolkit: toolkits?.[index],
95
- })) as McpServerGetResponse;
96
- } else if (userIds?.length && data.user_ids_url) {
97
- return data.user_ids_url.map((url: string, index: number) => ({
98
- url: new URL(url),
99
- name: `${serverName}-${userIds[index]}`,
100
- toolkit: toolkits?.[index],
101
- })) as McpServerGetResponse;
102
- }
103
- return {
104
- url: new URL(data.mcp_url),
105
- name: serverName,
106
- } as McpServerGetResponse;
88
+ wrapMcpServerResponse(data: McpUrlResponse): OpenAiMcpTool[] {
89
+ return data.map(item => ({
90
+ type: 'mcp',
91
+ server_label: item.name,
92
+ server_url: item.url,
93
+ require_approval: 'never',
94
+ }));
95
}
96
97
/**
ts/packages/providers/vercel/src/index.ts
+9
-32
@@ -14,7 +14,6 @@ import {
14
BaseAgenticProvider,
15
Tool,
16
ExecuteToolFn,
17
- jsonSchemaToZodSchema,
17
McpUrlResponse,
18
McpServerGetResponse,
19
} from '@composio/core';
@@ -182,40 +181,18 @@ export class VercelProvider extends BaseAgenticProvider<VercelToolCollection, Ve
181
}
182
183
/**
185
- * Transform MCP URL response into Vercel-specific format.
186
- * Vercel uses the standard format by default.
184
+ * Transform MCP URL response into Anthropic-specific format.
185
+ * By default, Anthropic uses the standard format (same as default),
186
+ * but this method is here to show providers can customize if needed.
187
*
188
* @param data - The MCP URL response data
189
- * @param serverName - Name of the MCP server
190
- * @param connectedAccountIds - Optional array of connected account IDs
191
- * @param userIds - Optional array of user IDs
192
- * @param toolkits - Optional array of toolkit names
189
* @returns Standard MCP server response format
190
*/
195
- wrapMcpServerResponse(
196
- data: McpUrlResponse,
197
- serverName: string,
198
- connectedAccountIds?: string[],
199
- userIds?: string[],
200
- toolkits?: string[]
201
- ): McpServerGetResponse {
202
- // Vercel uses the standard format
203
- if (connectedAccountIds?.length && data.connected_account_urls) {
204
- return data.connected_account_urls.map((url: string, index: number) => ({
205
- url: new URL(url),
206
- name: `${serverName}-${connectedAccountIds[index]}`,
207
- toolkit: toolkits?.[index],
208
- })) as McpServerGetResponse;
209
- } else if (userIds?.length && data.user_ids_url) {
210
- return data.user_ids_url.map((url: string, index: number) => ({
211
- url: new URL(url),
212
- name: `${serverName}-${userIds[index]}`,
213
- toolkit: toolkits?.[index],
214
- })) as McpServerGetResponse;
215
- }
216
- return {
217
- url: new URL(data.mcp_url),
218
- name: serverName,
219
- } as McpServerGetResponse;
191
+ wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse {
192
+ // Anthropic uses the standard format
193
+ return data.map(item => ({
194
+ url: new URL(item.url),
195
+ name: item.name,
196
+ })) as McpServerGetResponse;
197
}
198
}