@composio/core 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +105 -690
- package/dist/index.d.cts +538 -632
- package/dist/index.d.mts +538 -632
- package/dist/index.mjs +105 -690
- package/package.json +6 -4
package/dist/index.mjs
CHANGED
|
@@ -2993,6 +2993,37 @@ var Tools = class {
|
|
|
2993
2993
|
return modifiedTools;
|
|
2994
2994
|
}
|
|
2995
2995
|
/**
|
|
2996
|
+
* Fetches the meta tools for a tool router session.
|
|
2997
|
+
* This method fetches the meta tools from the Composio API and transforms them to the expected format.
|
|
2998
|
+
* It provides access to the underlying meta tool data without provider-specific wrapping.
|
|
2999
|
+
*
|
|
3000
|
+
* @param sessionId {string} The session id to get the meta tools for
|
|
3001
|
+
* @param options {SchemaModifierOptions} Optional configuration for tool retrieval
|
|
3002
|
+
* @param {TransformToolSchemaModifier} [options.modifySchema] - Function to transform the tool schema
|
|
3003
|
+
* @returns {Promise<ToolList>} The list of meta tools
|
|
3004
|
+
*
|
|
3005
|
+
* @example
|
|
3006
|
+
* ```typescript
|
|
3007
|
+
* const metaTools = await composio.tools.getRawToolRouterMetaTools('session_123');
|
|
3008
|
+
* console.log(metaTools);
|
|
3009
|
+
* ```
|
|
3010
|
+
*/
|
|
3011
|
+
async getRawToolRouterMetaTools(sessionId, options) {
|
|
3012
|
+
let modifiedTools = (await this.client.toolRouter.session.tools(sessionId)).items.map((tool) => this.transformToolCases(tool));
|
|
3013
|
+
if (options?.modifySchema) {
|
|
3014
|
+
const modifier = options.modifySchema;
|
|
3015
|
+
if (typeof modifier === "function") {
|
|
3016
|
+
const modifiedPromises = modifiedTools.map((tool) => modifier({
|
|
3017
|
+
toolSlug: tool.slug,
|
|
3018
|
+
toolkitSlug: tool.toolkit?.slug ?? "unknown",
|
|
3019
|
+
schema: tool
|
|
3020
|
+
}));
|
|
3021
|
+
modifiedTools = await Promise.all(modifiedPromises);
|
|
3022
|
+
} else throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
3023
|
+
}
|
|
3024
|
+
return modifiedTools;
|
|
3025
|
+
}
|
|
3026
|
+
/**
|
|
2996
3027
|
* Retrieves a specific tool by its slug from the Composio API.
|
|
2997
3028
|
*
|
|
2998
3029
|
* This method fetches a single tool in raw format without provider-specific wrapping,
|
|
@@ -3120,7 +3151,7 @@ var Tools = class {
|
|
|
3120
3151
|
*
|
|
3121
3152
|
* @param {string} sessionId - The session id to execute the tool for
|
|
3122
3153
|
* @param {Tool[]} tools - The tools to wrap
|
|
3123
|
-
* @param {
|
|
3154
|
+
* @param {SessionExecuteMetaModifiers} modifiers - The modifiers to apply to the tool
|
|
3124
3155
|
* @returns {Tool[]} The wrapped tools
|
|
3125
3156
|
*/
|
|
3126
3157
|
wrapToolsForToolRouter(sessionId, tools, modifiers) {
|
|
@@ -3152,7 +3183,7 @@ var Tools = class {
|
|
|
3152
3183
|
* Creates a function that executes a tool for a tool router session
|
|
3153
3184
|
*
|
|
3154
3185
|
* @param {string} sessionId - The session id to execute the tool for
|
|
3155
|
-
* @param {
|
|
3186
|
+
* @param {SessionExecuteMetaModifiers} modifiers - The modifiers to apply to the tool
|
|
3156
3187
|
* @returns {ExecuteToolFn} The execute tool function
|
|
3157
3188
|
*/
|
|
3158
3189
|
createExecuteToolFnForToolRouter(sessionId, modifiers) {
|
|
@@ -3290,36 +3321,36 @@ var Tools = class {
|
|
|
3290
3321
|
* @param {ToolExecuteMetaParams} body - The execution parameters
|
|
3291
3322
|
* @param {string} body.sessionId - The session id to execute the tool for
|
|
3292
3323
|
* @param {Record<string, unknown>} body.arguments - The input to pass to the tool
|
|
3293
|
-
* @param {
|
|
3324
|
+
* @param {SessionExecuteMetaModifiers} modifiers - The modifiers to apply to the tool
|
|
3294
3325
|
* @returns {Promise<ToolExecuteResponse>} The response from the tool execution
|
|
3295
3326
|
*/
|
|
3296
3327
|
async executeMetaTool(toolSlug, body, modifiers) {
|
|
3297
3328
|
const executeMetaParams = ToolExecuteMetaParamsSchema.safeParse(body);
|
|
3298
3329
|
if (!executeMetaParams.success) throw new ValidationError("Invalid tool execute meta parameters", { cause: executeMetaParams.error });
|
|
3299
|
-
|
|
3300
|
-
if (
|
|
3301
|
-
slug: toolSlug,
|
|
3302
|
-
sessionId: body.sessionId
|
|
3303
|
-
} });
|
|
3304
|
-
const params = await this.applyBeforeExecuteModifiers(tool, {
|
|
3330
|
+
let modifiedParams = body.arguments ?? {};
|
|
3331
|
+
if (modifiers?.beforeExecute) modifiedParams = await modifiers.beforeExecute({
|
|
3305
3332
|
toolSlug,
|
|
3306
|
-
toolkitSlug:
|
|
3307
|
-
|
|
3308
|
-
|
|
3333
|
+
toolkitSlug: "composio",
|
|
3334
|
+
sessionId: body.sessionId,
|
|
3335
|
+
params: modifiedParams
|
|
3336
|
+
});
|
|
3309
3337
|
const response = await this.client.toolRouter.session.executeMeta(body.sessionId, {
|
|
3310
3338
|
slug: toolSlug,
|
|
3311
|
-
arguments:
|
|
3339
|
+
arguments: modifiedParams
|
|
3312
3340
|
});
|
|
3313
|
-
|
|
3341
|
+
let result = {
|
|
3342
|
+
data: response.data,
|
|
3343
|
+
error: response.error,
|
|
3344
|
+
successful: !response.error,
|
|
3345
|
+
logId: response.log_id
|
|
3346
|
+
};
|
|
3347
|
+
if (modifiers?.afterExecute) result = await modifiers.afterExecute({
|
|
3314
3348
|
toolSlug,
|
|
3315
|
-
toolkitSlug:
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
logId: response.log_id
|
|
3321
|
-
}
|
|
3322
|
-
}, modifiers?.afterExecute);
|
|
3349
|
+
toolkitSlug: "composio",
|
|
3350
|
+
sessionId: body.sessionId,
|
|
3351
|
+
result
|
|
3352
|
+
});
|
|
3353
|
+
return result;
|
|
3323
3354
|
}
|
|
3324
3355
|
/**
|
|
3325
3356
|
* Fetches the list of all available tools in the Composio SDK.
|
|
@@ -5322,7 +5353,7 @@ const MCPServerConnectedAccountsSchema = z.record(z.string(), z.array(z.object({
|
|
|
5322
5353
|
})));
|
|
5323
5354
|
|
|
5324
5355
|
//#endregion
|
|
5325
|
-
//#region src/models/MCP.
|
|
5356
|
+
//#region src/models/MCP.ts
|
|
5326
5357
|
function transformMCPItemResponse(response) {
|
|
5327
5358
|
return transform(response).with(MCPItemSchema).using((raw) => ({
|
|
5328
5359
|
name: raw.name,
|
|
@@ -5341,7 +5372,7 @@ function transformMCPItemResponse(response) {
|
|
|
5341
5372
|
* Handles MCP server operations.
|
|
5342
5373
|
* When `config.experimental.mcp` is enabled, this class augments the features of `composio.mcp`.
|
|
5343
5374
|
*/
|
|
5344
|
-
var MCP
|
|
5375
|
+
var MCP = class {
|
|
5345
5376
|
client;
|
|
5346
5377
|
constructor(client) {
|
|
5347
5378
|
this.client = client;
|
|
@@ -6224,7 +6255,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
6224
6255
|
|
|
6225
6256
|
//#endregion
|
|
6226
6257
|
//#region package.json
|
|
6227
|
-
var version = "0.
|
|
6258
|
+
var version = "0.4.0";
|
|
6228
6259
|
|
|
6229
6260
|
//#endregion
|
|
6230
6261
|
//#region src/models/Files.ts
|
|
@@ -6305,7 +6336,8 @@ const getDefaultHeaders = (headers, provider) => {
|
|
|
6305
6336
|
const MCPServerTypeSchema = z.enum(["http", "sse"]);
|
|
6306
6337
|
const ToolRouterConfigManageConnectionsSchema = z.object({
|
|
6307
6338
|
enable: z.boolean().default(true).optional().describe("Whether to use tools to manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually"),
|
|
6308
|
-
callbackUrl: z.string().optional().describe("The callback uri to use in the tool router session")
|
|
6339
|
+
callbackUrl: z.string().optional().describe("The callback uri to use in the tool router session"),
|
|
6340
|
+
waitForConnections: z.boolean().optional().describe("Whether to wait for users to finish authenticating connections before proceeding to the next step. Defaults to false, if set to true, a wait for connections tool call will happen and finish when the connections are ready")
|
|
6309
6341
|
}).strict();
|
|
6310
6342
|
const ToolRouterToolkitsParamSchema = z.array(z.string()).describe("List of toolkits to enable in the tool router session");
|
|
6311
6343
|
const ToolRouterToolkitsDisabledConfigSchema = z.object({ disable: ToolRouterToolkitsParamSchema.describe("List of toolkits to disable in the tool router session") }).strict();
|
|
@@ -6445,6 +6477,30 @@ const transformToolRouterTagsParams = (params) => {
|
|
|
6445
6477
|
disable: params.disable
|
|
6446
6478
|
};
|
|
6447
6479
|
};
|
|
6480
|
+
const transformToolRouterManageConnectionsParams = (params) => {
|
|
6481
|
+
if (params === void 0) return { enable: true };
|
|
6482
|
+
if (typeof params === "boolean") return { enable: params };
|
|
6483
|
+
const parsedResult = ToolRouterConfigManageConnectionsSchema.safeParse(params);
|
|
6484
|
+
if (!parsedResult.success) throw new ValidationError("Failed to parse manage connections config", { cause: parsedResult.error });
|
|
6485
|
+
const config = parsedResult.data;
|
|
6486
|
+
return {
|
|
6487
|
+
enable: config.enable ?? true,
|
|
6488
|
+
callback_url: config.callbackUrl,
|
|
6489
|
+
enable_wait_for_connections: config.waitForConnections
|
|
6490
|
+
};
|
|
6491
|
+
};
|
|
6492
|
+
const transformToolRouterWorkbenchParams = (params) => {
|
|
6493
|
+
if (!params) return;
|
|
6494
|
+
return {
|
|
6495
|
+
enable_proxy_execution: params.enableProxyExecution,
|
|
6496
|
+
auto_offload_threshold: params.autoOffloadThreshold
|
|
6497
|
+
};
|
|
6498
|
+
};
|
|
6499
|
+
const transformToolRouterToolkitsParams = (params) => {
|
|
6500
|
+
if (!params) return;
|
|
6501
|
+
if (Array.isArray(params)) return { enable: params };
|
|
6502
|
+
return params;
|
|
6503
|
+
};
|
|
6448
6504
|
|
|
6449
6505
|
//#endregion
|
|
6450
6506
|
//#region src/models/ToolRouter.ts
|
|
@@ -6529,14 +6585,13 @@ var ToolRouter = class {
|
|
|
6529
6585
|
* Creates a function that wraps the tools based on the provider.
|
|
6530
6586
|
* The returned tools will be of the type the frameworks expects.
|
|
6531
6587
|
*
|
|
6532
|
-
* @param
|
|
6533
|
-
* @
|
|
6534
|
-
* @returns A function that wraps the tools based on the provider.
|
|
6588
|
+
* @param sessionId - The session id to get the tools for
|
|
6589
|
+
* @returns A function that wraps the tools based on the provider with session-specific modifiers.
|
|
6535
6590
|
*/
|
|
6536
|
-
createToolsFn = (sessionId
|
|
6591
|
+
createToolsFn = (sessionId) => {
|
|
6537
6592
|
return async (modifiers) => {
|
|
6538
6593
|
const ToolsModel = new Tools(this.client, this.config);
|
|
6539
|
-
const tools = await ToolsModel.
|
|
6594
|
+
const tools = await ToolsModel.getRawToolRouterMetaTools(sessionId, modifiers?.modifySchema ? { modifySchema: modifiers?.modifySchema } : void 0);
|
|
6540
6595
|
return ToolsModel.wrapToolsForToolRouter(sessionId, tools, modifiers);
|
|
6541
6596
|
};
|
|
6542
6597
|
};
|
|
@@ -6590,31 +6645,21 @@ var ToolRouter = class {
|
|
|
6590
6645
|
*/
|
|
6591
6646
|
async create(userId, config) {
|
|
6592
6647
|
const routerConfig = ToolRouterCreateSessionConfigSchema.parse(config ?? {});
|
|
6593
|
-
const manageConnectedAccounts = typeof routerConfig.manageConnections === "boolean" ? routerConfig.manageConnections : routerConfig.manageConnections?.enable ?? true;
|
|
6594
|
-
const toolkits = Array.isArray(routerConfig.toolkits) ? { enable: routerConfig.toolkits } : routerConfig.toolkits;
|
|
6595
|
-
const tags = transformToolRouterTagsParams(routerConfig.tags);
|
|
6596
|
-
const tools = transformToolRouterToolsParams(routerConfig.tools);
|
|
6597
6648
|
const payload = {
|
|
6598
6649
|
user_id: userId,
|
|
6599
|
-
toolkits,
|
|
6600
6650
|
auth_configs: routerConfig.authConfigs,
|
|
6601
6651
|
connected_accounts: routerConfig.connectedAccounts,
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
},
|
|
6608
|
-
workbench: routerConfig.workbench ? {
|
|
6609
|
-
enable_proxy_execution: routerConfig.workbench?.enableProxyExecution,
|
|
6610
|
-
auto_offload_threshold: routerConfig.workbench?.autoOffloadThreshold
|
|
6611
|
-
} : void 0
|
|
6652
|
+
toolkits: transformToolRouterToolkitsParams(routerConfig.toolkits),
|
|
6653
|
+
tools: transformToolRouterToolsParams(routerConfig.tools),
|
|
6654
|
+
tags: transformToolRouterTagsParams(routerConfig.tags),
|
|
6655
|
+
manage_connections: transformToolRouterManageConnectionsParams(routerConfig.manageConnections),
|
|
6656
|
+
workbench: transformToolRouterWorkbenchParams(routerConfig.workbench)
|
|
6612
6657
|
};
|
|
6613
6658
|
const session = await this.client.toolRouter.session.create(payload);
|
|
6614
6659
|
return {
|
|
6615
6660
|
sessionId: session.session_id,
|
|
6616
6661
|
mcp: this.createMCPServerConfig(session.mcp),
|
|
6617
|
-
tools: this.createToolsFn(session.session_id
|
|
6662
|
+
tools: this.createToolsFn(session.session_id),
|
|
6618
6663
|
authorize: this.createAuthorizeFn(session.session_id),
|
|
6619
6664
|
toolkits: this.createToolkitsFn(session.session_id)
|
|
6620
6665
|
};
|
|
@@ -6641,7 +6686,7 @@ var ToolRouter = class {
|
|
|
6641
6686
|
return {
|
|
6642
6687
|
sessionId: session.session_id,
|
|
6643
6688
|
mcp: this.createMCPServerConfig(session.mcp),
|
|
6644
|
-
tools: this.createToolsFn(session.session_id
|
|
6689
|
+
tools: this.createToolsFn(session.session_id),
|
|
6645
6690
|
authorize: this.createAuthorizeFn(session.session_id),
|
|
6646
6691
|
toolkits: this.createToolkitsFn(session.session_id)
|
|
6647
6692
|
};
|
|
@@ -6668,13 +6713,21 @@ var Composio = class Composio {
|
|
|
6668
6713
|
/**
|
|
6669
6714
|
* Core models for Composio.
|
|
6670
6715
|
*/
|
|
6716
|
+
/** List, retrieve, and execute tools */
|
|
6671
6717
|
tools;
|
|
6718
|
+
/** Retrieve toolkit metadata and authorize user connections */
|
|
6672
6719
|
toolkits;
|
|
6720
|
+
/** Manage webhook triggers and event subscriptions */
|
|
6673
6721
|
triggers;
|
|
6722
|
+
/** The tool provider instance used for wrapping tools in framework-specific formats */
|
|
6674
6723
|
provider;
|
|
6724
|
+
/** Upload and download files */
|
|
6675
6725
|
files;
|
|
6726
|
+
/** Manage authentication configurations for toolkits */
|
|
6676
6727
|
authConfigs;
|
|
6728
|
+
/** Manage authenticated connections */
|
|
6677
6729
|
connectedAccounts;
|
|
6730
|
+
/** Model Context Protocol server management */
|
|
6678
6731
|
mcp;
|
|
6679
6732
|
/**
|
|
6680
6733
|
* Experimental feature, use with caution
|
|
@@ -6713,10 +6766,6 @@ var Composio = class Composio {
|
|
|
6713
6766
|
*/
|
|
6714
6767
|
use;
|
|
6715
6768
|
/**
|
|
6716
|
-
* Experimental features
|
|
6717
|
-
*/
|
|
6718
|
-
experimental;
|
|
6719
|
-
/**
|
|
6720
6769
|
* Creates a new instance of the Composio SDK.
|
|
6721
6770
|
*
|
|
6722
6771
|
* The constructor initializes the SDK with the provided configuration options,
|
|
@@ -6777,31 +6826,19 @@ var Composio = class Composio {
|
|
|
6777
6826
|
logLevel: COMPOSIO_LOG_LEVEL
|
|
6778
6827
|
});
|
|
6779
6828
|
this.tools = new Tools(this.client, this.config);
|
|
6780
|
-
this.mcp = new MCP
|
|
6829
|
+
this.mcp = new MCP(this.client);
|
|
6781
6830
|
this.toolkits = new Toolkits(this.client);
|
|
6782
6831
|
this.triggers = new Triggers(this.client, this.config);
|
|
6783
6832
|
this.authConfigs = new AuthConfigs(this.client);
|
|
6784
6833
|
this.files = new Files(this.client);
|
|
6785
6834
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
6786
6835
|
this.toolRouter = new ToolRouter(this.client, this.config);
|
|
6787
|
-
this.toolRouter.create.bind(this.toolRouter);
|
|
6788
|
-
this.toolRouter.use.bind(this.toolRouter);
|
|
6789
6836
|
/**
|
|
6790
6837
|
* Initialize tool router methods
|
|
6838
|
+
* Properly bind the methods to maintain the correct 'this' context
|
|
6791
6839
|
*/
|
|
6792
|
-
this.create = this.toolRouter.create;
|
|
6793
|
-
this.use = this.toolRouter.use;
|
|
6794
|
-
/**
|
|
6795
|
-
* Initialize Experimental features
|
|
6796
|
-
*/
|
|
6797
|
-
this.experimental = {
|
|
6798
|
-
create: async (userId, routerConfig) => {
|
|
6799
|
-
return this.toolRouter.create(userId, routerConfig);
|
|
6800
|
-
},
|
|
6801
|
-
use: async (id) => {
|
|
6802
|
-
return this.toolRouter.use(id);
|
|
6803
|
-
}
|
|
6804
|
-
};
|
|
6840
|
+
this.create = this.toolRouter.create.bind(this.toolRouter);
|
|
6841
|
+
this.use = this.toolRouter.use.bind(this.toolRouter);
|
|
6805
6842
|
/**
|
|
6806
6843
|
* Initialize the client telemetry.
|
|
6807
6844
|
*/
|
|
@@ -7292,627 +7329,5 @@ const ComposioMcpUpdateResponseSchema = z$1.object({
|
|
|
7292
7329
|
tools: z$1.array(z$1.string()).optional()
|
|
7293
7330
|
});
|
|
7294
7331
|
|
|
7295
|
-
//#endregion
|
|
7296
|
-
//#region src/utils/transformers/mcp.ts
|
|
7297
|
-
/**
|
|
7298
|
-
* Transform MCP create response from snake_case to camelCase
|
|
7299
|
-
*/
|
|
7300
|
-
function transformMcpCreateResponse(response) {
|
|
7301
|
-
const result = CustomCreateResponseSchema.safeParse({
|
|
7302
|
-
id: response.id,
|
|
7303
|
-
name: response.name,
|
|
7304
|
-
createdAt: response.created_at,
|
|
7305
|
-
updatedAt: response.updated_at,
|
|
7306
|
-
status: response.status
|
|
7307
|
-
});
|
|
7308
|
-
if (!result.success) throw new ValidationError("Failed to parse MCP create response", { cause: result.error });
|
|
7309
|
-
return result.data;
|
|
7310
|
-
}
|
|
7311
|
-
/**
|
|
7312
|
-
* Transform MCP list response from snake_case to camelCase
|
|
7313
|
-
*/
|
|
7314
|
-
function transformMcpListResponse(response) {
|
|
7315
|
-
const transformedItems = response.items?.map((item) => ({
|
|
7316
|
-
id: item.id,
|
|
7317
|
-
name: item.name,
|
|
7318
|
-
createdAt: item.created_at,
|
|
7319
|
-
updatedAt: item.updated_at,
|
|
7320
|
-
status: item.status
|
|
7321
|
-
}));
|
|
7322
|
-
const result = McpListResponseSchema.safeParse({ items: transformedItems });
|
|
7323
|
-
if (!result.success) throw new ValidationError("Failed to parse MCP list response", { cause: result.error });
|
|
7324
|
-
return result.data;
|
|
7325
|
-
}
|
|
7326
|
-
/**
|
|
7327
|
-
* Transform MCP retrieve response from snake_case to camelCase
|
|
7328
|
-
*/
|
|
7329
|
-
function transformMcpRetrieveResponse(response) {
|
|
7330
|
-
const result = McpRetrieveResponseSchema.safeParse({
|
|
7331
|
-
id: response.id,
|
|
7332
|
-
name: response.name,
|
|
7333
|
-
createdAt: response.created_at,
|
|
7334
|
-
updatedAt: response.updated_at,
|
|
7335
|
-
status: response.status,
|
|
7336
|
-
toolkits: response.toolkits,
|
|
7337
|
-
tools: response.allowed_tools,
|
|
7338
|
-
managedAuthViaComposio: response.managed_auth_via_composio,
|
|
7339
|
-
authConfigIds: response.auth_config_ids,
|
|
7340
|
-
mcpUrl: response.mcp_url,
|
|
7341
|
-
commands: response.commands
|
|
7342
|
-
});
|
|
7343
|
-
if (!result.success) throw new ValidationError("Failed to parse MCP retrieve response", { cause: result.error });
|
|
7344
|
-
return result.data;
|
|
7345
|
-
}
|
|
7346
|
-
/**
|
|
7347
|
-
* Transform MCP delete response from snake_case to camelCase
|
|
7348
|
-
*/
|
|
7349
|
-
function transformMcpDeleteResponse(response) {
|
|
7350
|
-
const result = McpDeleteResponseSchema.safeParse({
|
|
7351
|
-
id: response.id,
|
|
7352
|
-
deleted: response.deleted,
|
|
7353
|
-
message: response.message
|
|
7354
|
-
});
|
|
7355
|
-
if (!result.success) throw new ValidationError("Failed to parse MCP delete response", { cause: result.error });
|
|
7356
|
-
return result.data;
|
|
7357
|
-
}
|
|
7358
|
-
/**
|
|
7359
|
-
* Transform MCP update response from snake_case to camelCase
|
|
7360
|
-
*/
|
|
7361
|
-
function transformMcpUpdateResponse(response) {
|
|
7362
|
-
const result = McpUpdateResponseSchema.safeParse({
|
|
7363
|
-
id: response.id,
|
|
7364
|
-
name: response.name,
|
|
7365
|
-
createdAt: response.created_at,
|
|
7366
|
-
updatedAt: response.updated_at,
|
|
7367
|
-
status: response.status,
|
|
7368
|
-
toolkits: response.toolkits,
|
|
7369
|
-
tools: response.tools
|
|
7370
|
-
});
|
|
7371
|
-
if (!result.success) throw new ValidationError("Failed to parse MCP update response", { cause: result.error });
|
|
7372
|
-
return result.data;
|
|
7373
|
-
}
|
|
7374
|
-
/**
|
|
7375
|
-
* Transform MCP generate URL response from snake_case to camelCase
|
|
7376
|
-
*/
|
|
7377
|
-
function transformMcpGenerateUrlResponse(response) {
|
|
7378
|
-
const result = GenerateURLResponseSchema.safeParse({
|
|
7379
|
-
connectedAccountUrls: response.connected_account_urls,
|
|
7380
|
-
userIdsUrl: response.user_ids_url,
|
|
7381
|
-
mcpUrl: response.mcp_url
|
|
7382
|
-
});
|
|
7383
|
-
if (!result.success) throw new ValidationError("Failed to parse MCP generate URL response", { cause: result.error });
|
|
7384
|
-
return result.data;
|
|
7385
|
-
}
|
|
7386
|
-
|
|
7387
|
-
//#endregion
|
|
7388
|
-
//#region src/models/MCP.ts
|
|
7389
|
-
/**
|
|
7390
|
-
* MCP (Model Control Protocol) class
|
|
7391
|
-
* Handles MCP server operations
|
|
7392
|
-
*/
|
|
7393
|
-
var MCP = class {
|
|
7394
|
-
client;
|
|
7395
|
-
toolkits;
|
|
7396
|
-
provider;
|
|
7397
|
-
constructor(client, provider) {
|
|
7398
|
-
this.client = client;
|
|
7399
|
-
this.provider = provider;
|
|
7400
|
-
this.toolkits = new Toolkits(client);
|
|
7401
|
-
telemetry.instrument(this, "MCP");
|
|
7402
|
-
}
|
|
7403
|
-
/**
|
|
7404
|
-
* Validates toolkit configurations using Zod schema
|
|
7405
|
-
* @private
|
|
7406
|
-
* @param {MCPToolkitConfig[]} toolkitConfigs - Array of toolkit configurations to validate
|
|
7407
|
-
* @param {MCPAuthOptions} [authOptions] - Authentication options to validate
|
|
7408
|
-
* @throws {ValidationError} If validation fails
|
|
7409
|
-
*/
|
|
7410
|
-
validateInputs(toolkitConfigs, authOptions) {
|
|
7411
|
-
const toolkitConfigsResult = MCPToolkitConfigsArraySchema.safeParse(toolkitConfigs);
|
|
7412
|
-
if (toolkitConfigsResult.error) throw new ValidationError("Failed to parse toolkit configurations", { cause: toolkitConfigsResult.error });
|
|
7413
|
-
if (authOptions !== void 0) {
|
|
7414
|
-
const authOptionsResult = MCPAuthOptionsSchema.safeParse(authOptions);
|
|
7415
|
-
if (authOptionsResult.error) throw new ValidationError("Failed to parse auth options", { cause: authOptionsResult.error });
|
|
7416
|
-
}
|
|
7417
|
-
}
|
|
7418
|
-
/**
|
|
7419
|
-
* Create a new MCP server
|
|
7420
|
-
* @param {Object} params - Parameters for creating the MCP server
|
|
7421
|
-
* @param {Array} params.authConfig - Array of auth configurations with id and allowed tools
|
|
7422
|
-
* @param {Object} params.options - Server creation options
|
|
7423
|
-
* @param {string} params.options.name - Unique name for the MCP server
|
|
7424
|
-
* @param {boolean} [params.options.isChatAuth] - Whether to use chat-based authentication
|
|
7425
|
-
* @returns {Promise<McpServerCreateResponse<TMcpResponse>>} Created server details with instance getter
|
|
7426
|
-
*
|
|
7427
|
-
* @example
|
|
7428
|
-
* ```typescript
|
|
7429
|
-
* const server = await composio.mcp.create("personal-mcp-server", [
|
|
7430
|
-
* {
|
|
7431
|
-
* authConfigId: "ac_xyz",
|
|
7432
|
-
* allowedTools: ["GMAIL_FETCH_EMAILS", "SLACK_SEND_MESSAGE"]
|
|
7433
|
-
* }
|
|
7434
|
-
* ],
|
|
7435
|
-
* {
|
|
7436
|
-
* isChatAuth: true
|
|
7437
|
-
* }
|
|
7438
|
-
* });
|
|
7439
|
-
*
|
|
7440
|
-
* // Use convenience method on response
|
|
7441
|
-
* const urls = await server.getServer({
|
|
7442
|
-
* userId: "user123"
|
|
7443
|
-
* });
|
|
7444
|
-
* ```
|
|
7445
|
-
*/
|
|
7446
|
-
async create(name, serverConfig, options) {
|
|
7447
|
-
if (!serverConfig || serverConfig.length === 0) throw new ValidationError("At least one auth config is required", {});
|
|
7448
|
-
if (!name) throw new ValidationError("Server name is required", {});
|
|
7449
|
-
try {
|
|
7450
|
-
const mcpServer = await this.getByName(name);
|
|
7451
|
-
const authConfigs = mcpServer.authConfigIds?.sort();
|
|
7452
|
-
const sortedCurrentAuthConfigs = serverConfig.map((config) => config.authConfigId).sort();
|
|
7453
|
-
if (authConfigs.length > 0 && !authConfigs.every((config, index) => config === sortedCurrentAuthConfigs[index])) throw new ValidationError("MCP server with this name already exists with different auth configs", { meta: { serverName: name } });
|
|
7454
|
-
const tools = mcpServer.tools?.sort();
|
|
7455
|
-
const sortedCurrentTools = serverConfig.flatMap((config) => config.allowedTools).sort();
|
|
7456
|
-
if (tools?.length > 0 && !tools.every((tool, index) => tool === sortedCurrentTools[index])) throw new ValidationError("MCP server with this name already exists with different tools", { meta: { serverName: name } });
|
|
7457
|
-
const toolkits$1 = (await Promise.all(serverConfig.map((config) => this.client.authConfigs.retrieve(config.authConfigId)))).map((config) => config.toolkit.slug);
|
|
7458
|
-
const camelCaseResponse$1 = transformMcpCreateResponse({
|
|
7459
|
-
id: mcpServer.id,
|
|
7460
|
-
name: mcpServer.name,
|
|
7461
|
-
auth_config_ids: serverConfig.map((config) => config.authConfigId),
|
|
7462
|
-
allowed_tools: serverConfig.flatMap((config) => config.allowedTools),
|
|
7463
|
-
managed_auth_via_composio: options.isChatAuth || false,
|
|
7464
|
-
commands: mcpServer.commands,
|
|
7465
|
-
created_at: mcpServer.createdAt,
|
|
7466
|
-
updated_at: mcpServer.updatedAt,
|
|
7467
|
-
mcp_url: mcpServer.mcpUrl
|
|
7468
|
-
});
|
|
7469
|
-
return {
|
|
7470
|
-
...camelCaseResponse$1,
|
|
7471
|
-
toolkits: toolkits$1,
|
|
7472
|
-
getServer: async (params) => {
|
|
7473
|
-
return this.getServer(camelCaseResponse$1.id, params.userId || "", { isChatAuth: options.isChatAuth });
|
|
7474
|
-
}
|
|
7475
|
-
};
|
|
7476
|
-
} catch (error) {
|
|
7477
|
-
if (error instanceof ValidationError && !error.message.includes("not found")) throw error;
|
|
7478
|
-
}
|
|
7479
|
-
const toolkits = (await Promise.all(serverConfig.map((config) => this.client.authConfigs.retrieve(config.authConfigId)))).map((config) => config.toolkit.slug);
|
|
7480
|
-
let mcpServerCreatedResponse;
|
|
7481
|
-
try {
|
|
7482
|
-
mcpServerCreatedResponse = await this.client.mcp.custom.create({
|
|
7483
|
-
name,
|
|
7484
|
-
toolkits,
|
|
7485
|
-
custom_tools: serverConfig.flatMap((config) => config.allowedTools),
|
|
7486
|
-
managed_auth_via_composio: options.isChatAuth || false,
|
|
7487
|
-
auth_config_ids: serverConfig.map((config) => config.authConfigId)
|
|
7488
|
-
});
|
|
7489
|
-
} catch (error) {
|
|
7490
|
-
throw new ValidationError("Failed to create MCP server", { cause: error });
|
|
7491
|
-
}
|
|
7492
|
-
const serverResponseResult = ComposioCustomCreateResponseSchema.safeParse(mcpServerCreatedResponse);
|
|
7493
|
-
if (serverResponseResult.error) throw new ValidationError("Failed to parse MCP server creation response", { cause: serverResponseResult.error });
|
|
7494
|
-
const camelCaseResponse = transformMcpCreateResponse(mcpServerCreatedResponse);
|
|
7495
|
-
return {
|
|
7496
|
-
...camelCaseResponse,
|
|
7497
|
-
toolkits,
|
|
7498
|
-
getServer: async (params) => {
|
|
7499
|
-
return this.getServer(camelCaseResponse.id, params.userId || "", { isChatAuth: options.isChatAuth });
|
|
7500
|
-
}
|
|
7501
|
-
};
|
|
7502
|
-
}
|
|
7503
|
-
/**
|
|
7504
|
-
* Get the connection status of a user for an MCP server
|
|
7505
|
-
*
|
|
7506
|
-
* Checks whether a user has the necessary connected accounts to use all toolkits
|
|
7507
|
-
* configured in the specified MCP server. Returns both overall connection status
|
|
7508
|
-
* and individual status for each toolkit.
|
|
7509
|
-
*
|
|
7510
|
-
* @param {Object} params - Parameters for checking connection status
|
|
7511
|
-
* @param {string} params.id - The UUID of the MCP server to check
|
|
7512
|
-
* @param {string} params.userId - The ID of the user to check connection status for
|
|
7513
|
-
* @returns {Promise<McpUserConnectionStatus>} Complete connection status including:
|
|
7514
|
-
* - `type`: Overall status (CONNECTED if all toolkits are connected, DISCONNECTED otherwise)
|
|
7515
|
-
* - `connected`: Boolean indicating if user can use the MCP server
|
|
7516
|
-
* - `connectedToolkits`: Record mapping each toolkit name to its individual connection status
|
|
7517
|
-
*
|
|
7518
|
-
* @throws {ValidationError} When MCP server has no toolkits configured
|
|
7519
|
-
* @throws {ValidationError} When MCP server retrieval fails
|
|
7520
|
-
*
|
|
7521
|
-
* @example
|
|
7522
|
-
* ```typescript
|
|
7523
|
-
* // Check if user can access an MCP server with Gmail and Slack toolkits
|
|
7524
|
-
* const connectionStatus = await composio.mcp.getUserConnectionStatus('user123', 'mcp-server-uuid');
|
|
7525
|
-
*
|
|
7526
|
-
* if (connectionStatus.connected) {
|
|
7527
|
-
* console.log('User can access all required toolkits');
|
|
7528
|
-
* // connectionStatus.type === ConnectionStatus.CONNECTED
|
|
7529
|
-
* } else {
|
|
7530
|
-
* console.log('User is missing some toolkit connections');
|
|
7531
|
-
* // Check individual toolkit statuses
|
|
7532
|
-
* Object.entries(connectionStatus.connectedToolkits).forEach(([toolkit, status]) => {
|
|
7533
|
-
* if (!status.connected) {
|
|
7534
|
-
* console.log(`Missing connection for toolkit: ${toolkit}`);
|
|
7535
|
-
* }
|
|
7536
|
-
* });
|
|
7537
|
-
* }
|
|
7538
|
-
* ```
|
|
7539
|
-
*
|
|
7540
|
-
* @example
|
|
7541
|
-
* ```typescript
|
|
7542
|
-
* // Example response when user has Gmail connected but missing Slack
|
|
7543
|
-
* {
|
|
7544
|
-
* type: ConnectionStatus.DISCONNECTED,
|
|
7545
|
-
* connected: false,
|
|
7546
|
-
* connectedToolkits: {
|
|
7547
|
-
* GMAIL: {
|
|
7548
|
-
* type: ConnectionStatus.CONNECTED,
|
|
7549
|
-
* connected: true,
|
|
7550
|
-
* toolkit: 'GMAIL',
|
|
7551
|
-
* connectedAccountId: 'conn_gmail_123'
|
|
7552
|
-
* },
|
|
7553
|
-
* SLACK: {
|
|
7554
|
-
* type: ConnectionStatus.DISCONNECTED,
|
|
7555
|
-
* connected: false,
|
|
7556
|
-
* toolkit: 'SLACK'
|
|
7557
|
-
* }
|
|
7558
|
-
* }
|
|
7559
|
-
* }
|
|
7560
|
-
* ```
|
|
7561
|
-
*/
|
|
7562
|
-
async getUserConnectionStatus(userId, serverId) {
|
|
7563
|
-
const serverDetails = await this.get(serverId);
|
|
7564
|
-
if (!serverDetails.toolkits || serverDetails.toolkits.length === 0) throw new ValidationError("MCP server has no toolkits configured", { meta: { serverId } });
|
|
7565
|
-
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
7566
|
-
user_ids: [userId],
|
|
7567
|
-
toolkit_slugs: serverDetails.toolkits.map((toolkit) => toolkit.toLowerCase()),
|
|
7568
|
-
statuses: ["ACTIVE"]
|
|
7569
|
-
});
|
|
7570
|
-
const connectedAccountsByToolkit = /* @__PURE__ */ new Map();
|
|
7571
|
-
connectedAccounts.items?.forEach((account) => {
|
|
7572
|
-
connectedAccountsByToolkit.set(account.toolkit.slug.toLowerCase(), account.id);
|
|
7573
|
-
});
|
|
7574
|
-
const connectedToolkits = {};
|
|
7575
|
-
let allToolkitsConnected = true;
|
|
7576
|
-
for (const toolkit of serverDetails.toolkits) {
|
|
7577
|
-
const connectedAccountId = connectedAccountsByToolkit.get(toolkit.toLowerCase());
|
|
7578
|
-
if (connectedAccountId) connectedToolkits[toolkit] = {
|
|
7579
|
-
type: ConnectionStatus.CONNECTED,
|
|
7580
|
-
connected: true,
|
|
7581
|
-
toolkit,
|
|
7582
|
-
connectedAccountId
|
|
7583
|
-
};
|
|
7584
|
-
else {
|
|
7585
|
-
connectedToolkits[toolkit] = {
|
|
7586
|
-
type: ConnectionStatus.DISCONNECTED,
|
|
7587
|
-
connected: false,
|
|
7588
|
-
toolkit
|
|
7589
|
-
};
|
|
7590
|
-
allToolkitsConnected = false;
|
|
7591
|
-
}
|
|
7592
|
-
}
|
|
7593
|
-
if (allToolkitsConnected) return {
|
|
7594
|
-
type: ConnectionStatus.CONNECTED,
|
|
7595
|
-
connected: true,
|
|
7596
|
-
connectedToolkits
|
|
7597
|
-
};
|
|
7598
|
-
else return {
|
|
7599
|
-
type: ConnectionStatus.DISCONNECTED,
|
|
7600
|
-
connected: false,
|
|
7601
|
-
connectedToolkits
|
|
7602
|
-
};
|
|
7603
|
-
}
|
|
7604
|
-
/**
|
|
7605
|
-
* Get the connection parameters for a toolkit
|
|
7606
|
-
* @param {string} serverId - The UUID of the MCP server
|
|
7607
|
-
* @param {string} toolkit - The toolkit to get connection parameters for
|
|
7608
|
-
* @returns {Promise<ToolkitAuthFieldsResponse>} Connection parameters for the toolkit
|
|
7609
|
-
*/
|
|
7610
|
-
async getConnectionParams(serverId, toolkit) {
|
|
7611
|
-
const mcpServerDetails = await this.get(serverId);
|
|
7612
|
-
const authConfig = (mcpServerDetails.authConfigIds ? await Promise.all(mcpServerDetails.authConfigIds.map((id) => this.client.authConfigs.retrieve(id))) : []).find((config) => config.toolkit.slug === toolkit);
|
|
7613
|
-
if (!authConfig) throw new ValidationError("Auth config not found", { meta: {
|
|
7614
|
-
serverId,
|
|
7615
|
-
toolkit
|
|
7616
|
-
} });
|
|
7617
|
-
return await this.toolkits.getConnectedAccountInitiationFields(toolkit, authConfig.auth_scheme);
|
|
7618
|
-
}
|
|
7619
|
-
/**
|
|
7620
|
-
* Authorize a user for a toolkit
|
|
7621
|
-
* @param {string} serverId - The UUID of the MCP server
|
|
7622
|
-
* @param {string} userId - The ID of the user to authorize
|
|
7623
|
-
* @param {string} toolkit - The toolkit to authorize
|
|
7624
|
-
* @returns {Promise<ConnectionRequest>} Connection request for the toolkit
|
|
7625
|
-
*/
|
|
7626
|
-
async authorize(userId, serverId, toolkit) {
|
|
7627
|
-
const authConfigId = (await this.get(serverId)).authConfigIds?.[0];
|
|
7628
|
-
return this.toolkits.authorize(userId, toolkit, authConfigId);
|
|
7629
|
-
}
|
|
7630
|
-
/**
|
|
7631
|
-
* Get server URLs for an existing MCP server
|
|
7632
|
-
* @param {string} serverId - Server UUID
|
|
7633
|
-
* @param {string} userId - User ID to get server URLs for
|
|
7634
|
-
* @param {Object} [options] - Additional options for server configuration
|
|
7635
|
-
* @param {string[]} [options.limitTools] - Subset of tools to limit (from MCP config)
|
|
7636
|
-
* @param {boolean} [options.isChatAuth] - Whether to use chat-based authentication
|
|
7637
|
-
* @returns {Promise<TMcpResponse>} Transformed server URLs in provider-specific format
|
|
7638
|
-
*
|
|
7639
|
-
* @example
|
|
7640
|
-
* ```typescript
|
|
7641
|
-
* // Get URLs for an existing server with basic user ID
|
|
7642
|
-
* const urls = await composio.mcp.getServer("mcp_xyz", "hey@example.com");
|
|
7643
|
-
*
|
|
7644
|
-
* // Get URLs with additional options
|
|
7645
|
-
* const urls = await composio.mcp.getServer("mcp_xyz", "hey@example.com", {
|
|
7646
|
-
* limitTools: ["GMAIL_FETCH_EMAILS", "SLACK_SEND_MESSAGE"],
|
|
7647
|
-
* isChatAuth: true
|
|
7648
|
-
* });
|
|
7649
|
-
* ```
|
|
7650
|
-
*
|
|
7651
|
-
*/
|
|
7652
|
-
async getServer(serverId, userId, options) {
|
|
7653
|
-
const serverDetails = await this.get(serverId);
|
|
7654
|
-
if (!userId) throw new ValidationError("User ID is required", {});
|
|
7655
|
-
const toolkits = serverDetails.toolkits || [];
|
|
7656
|
-
const connectedAccountIds = (await Promise.all(toolkits.map((toolkit) => this.client.connectedAccounts.list({
|
|
7657
|
-
user_ids: [userId],
|
|
7658
|
-
toolkit_slugs: [toolkit],
|
|
7659
|
-
statuses: ["ACTIVE"]
|
|
7660
|
-
}).then((res) => res.items?.[0]?.id)))).filter(Boolean);
|
|
7661
|
-
let data;
|
|
7662
|
-
try {
|
|
7663
|
-
data = await this.client.mcp.generate.url({
|
|
7664
|
-
user_ids: [userId],
|
|
7665
|
-
connected_account_ids: [],
|
|
7666
|
-
mcp_server_id: serverId,
|
|
7667
|
-
managed_auth_by_composio: options?.isChatAuth ?? serverDetails.managedAuthViaComposio ?? false
|
|
7668
|
-
});
|
|
7669
|
-
} catch (error) {
|
|
7670
|
-
throw new ValidationError("Failed to generate MCP server URL", { cause: error });
|
|
7671
|
-
}
|
|
7672
|
-
const urlResponseResult = ComposioGenerateURLResponseSchema.safeParse(data);
|
|
7673
|
-
if (urlResponseResult.error) throw new ValidationError("Failed to parse MCP URL generation response", { cause: urlResponseResult.error });
|
|
7674
|
-
const camelCaseData = transformMcpGenerateUrlResponse(data);
|
|
7675
|
-
return this.wrapMcpServerResponse(camelCaseData, serverDetails.name, connectedAccountIds, [userId], toolkits);
|
|
7676
|
-
}
|
|
7677
|
-
/**
|
|
7678
|
-
* List MCP server configurations with filtering options
|
|
7679
|
-
* @param {Object} options - Filtering and pagination options
|
|
7680
|
-
* @param {number} [options.page] - Page number for pagination
|
|
7681
|
-
* @param {number} [options.limit] - Number of items per page
|
|
7682
|
-
* @param {string[]} [options.toolkits] - Filter servers by toolkit names
|
|
7683
|
-
* @param {string[]} [options.authConfigs] - Filter servers by auth config IDs
|
|
7684
|
-
* @param {string} [options.name] - Filter servers by name
|
|
7685
|
-
* @param {string} [options.user] - Filter servers by user ID
|
|
7686
|
-
* @returns {Promise<McpListResponse>} List of MCP servers matching the filters
|
|
7687
|
-
*
|
|
7688
|
-
* @example
|
|
7689
|
-
* ```typescript
|
|
7690
|
-
* // List all servers with pagination
|
|
7691
|
-
* const servers = await composio.mcp.list({
|
|
7692
|
-
* page: 1,
|
|
7693
|
-
* limit: 10
|
|
7694
|
-
* });
|
|
7695
|
-
*
|
|
7696
|
-
* // List Gmail and Supabase servers
|
|
7697
|
-
* const filteredServers = await composio.mcp.list({
|
|
7698
|
-
* toolkits: ['GMAIL', 'SUPABASE'],
|
|
7699
|
-
* authConfigIds: ['auth_123', 'auth_456']
|
|
7700
|
-
* });
|
|
7701
|
-
* ```
|
|
7702
|
-
*/
|
|
7703
|
-
async list(options) {
|
|
7704
|
-
let listResponse;
|
|
7705
|
-
try {
|
|
7706
|
-
listResponse = await this.client.mcp.list({
|
|
7707
|
-
page_no: options.page || 1,
|
|
7708
|
-
limit: options.limit || 10,
|
|
7709
|
-
toolkits: options?.toolkits?.join(",") || void 0,
|
|
7710
|
-
auth_config_ids: options?.authConfigs?.join(",") || void 0,
|
|
7711
|
-
name: options?.name
|
|
7712
|
-
});
|
|
7713
|
-
} catch (error) {
|
|
7714
|
-
throw new ValidationError("Failed to list MCP servers", { cause: error });
|
|
7715
|
-
}
|
|
7716
|
-
const listResponseResult = ComposioMcpListResponseSchema.safeParse(listResponse);
|
|
7717
|
-
if (listResponseResult.error) throw new ValidationError("Failed to parse MCP server list response", { cause: listResponseResult.error });
|
|
7718
|
-
return transformMcpListResponse(listResponse);
|
|
7719
|
-
}
|
|
7720
|
-
/**
|
|
7721
|
-
* Get details of a specific MCP server
|
|
7722
|
-
* @param {string} serverId - Server UUID
|
|
7723
|
-
* @returns {Promise<McpRetrieveResponse>} Server details
|
|
7724
|
-
*
|
|
7725
|
-
* @example
|
|
7726
|
-
* ```typescript
|
|
7727
|
-
* const serverDetails = await composio.mcp.get('server-uuid');
|
|
7728
|
-
* ```
|
|
7729
|
-
*/
|
|
7730
|
-
async get(serverId) {
|
|
7731
|
-
let retrieveResponse;
|
|
7732
|
-
try {
|
|
7733
|
-
retrieveResponse = await this.client.mcp.retrieve(serverId);
|
|
7734
|
-
} catch (error) {
|
|
7735
|
-
throw new ValidationError("Failed to retrieve MCP server", { cause: error });
|
|
7736
|
-
}
|
|
7737
|
-
const retrieveResponseResult = McpRetrieveResponseSchema.safeParse({
|
|
7738
|
-
...retrieveResponse,
|
|
7739
|
-
mcpUrl: retrieveResponse.mcp_url
|
|
7740
|
-
});
|
|
7741
|
-
if (retrieveResponseResult.error) throw new ValidationError("Failed to parse MCP server retrieve response", { cause: retrieveResponseResult.error });
|
|
7742
|
-
return transformMcpRetrieveResponse(retrieveResponse);
|
|
7743
|
-
}
|
|
7744
|
-
/**
|
|
7745
|
-
* Delete an MCP server
|
|
7746
|
-
* @param {string} serverId - Server UUID
|
|
7747
|
-
* @returns {Promise<McpDeleteResponse>} Deletion response
|
|
7748
|
-
*
|
|
7749
|
-
* @example
|
|
7750
|
-
* ```typescript
|
|
7751
|
-
* const result = await composio.mcp.delete('server-uuid');
|
|
7752
|
-
* ```
|
|
7753
|
-
*/
|
|
7754
|
-
async delete(serverId) {
|
|
7755
|
-
let deleteResponse;
|
|
7756
|
-
try {
|
|
7757
|
-
deleteResponse = await this.client.mcp.delete(serverId);
|
|
7758
|
-
} catch (error) {
|
|
7759
|
-
throw new ValidationError("Failed to delete MCP server", { cause: error });
|
|
7760
|
-
}
|
|
7761
|
-
const deleteResponseResult = ComposioMcpDeleteResponseSchema.safeParse(deleteResponse);
|
|
7762
|
-
if (deleteResponseResult.error) throw new ValidationError("Failed to parse MCP server delete response", { cause: deleteResponseResult.error });
|
|
7763
|
-
return transformMcpDeleteResponse(deleteResponse);
|
|
7764
|
-
}
|
|
7765
|
-
/**
|
|
7766
|
-
* Update an MCP server configuration
|
|
7767
|
-
* @param {string} id - Server UUID
|
|
7768
|
-
* @param {string} name - New unique name for the server
|
|
7769
|
-
* @param {MCPToolkitConfig[]} toolkitConfigs - Array of toolkit configurations
|
|
7770
|
-
* @param {MCPAuthOptions} [authOptions] - Updated authentication options
|
|
7771
|
-
* @returns {Promise<McpUpdateResponse>} Updated server details
|
|
7772
|
-
*
|
|
7773
|
-
* @example
|
|
7774
|
-
* ```typescript
|
|
7775
|
-
* const updatedServer = await composio.mcp.update(
|
|
7776
|
-
* "server-uuid",
|
|
7777
|
-
* "my-updated-server",
|
|
7778
|
-
* [
|
|
7779
|
-
* {
|
|
7780
|
-
* toolkit: "GMAIL",
|
|
7781
|
-
* authConfigId: "ac_sdhkjfhjksdk",
|
|
7782
|
-
* allowedTools: ["GMAIL_FETCH_EMAILS"],
|
|
7783
|
-
* },
|
|
7784
|
-
* ],
|
|
7785
|
-
* {
|
|
7786
|
-
* isChatAuth: true,
|
|
7787
|
-
* }
|
|
7788
|
-
* );
|
|
7789
|
-
* ```
|
|
7790
|
-
*/
|
|
7791
|
-
async update(serverId, name, toolkitConfigs, authOptions) {
|
|
7792
|
-
this.validateInputs(toolkitConfigs, authOptions);
|
|
7793
|
-
const toolkits = toolkitConfigs.map((config) => config.toolkit);
|
|
7794
|
-
let updateResponse;
|
|
7795
|
-
try {
|
|
7796
|
-
updateResponse = await this.client.mcp.update(serverId, {
|
|
7797
|
-
name,
|
|
7798
|
-
toolkits,
|
|
7799
|
-
allowed_tools: toolkitConfigs.flatMap((config) => config.allowedTools),
|
|
7800
|
-
managed_auth_via_composio: authOptions?.isChatAuth || false
|
|
7801
|
-
});
|
|
7802
|
-
} catch (error) {
|
|
7803
|
-
throw new ValidationError("Failed to update MCP server", { cause: error });
|
|
7804
|
-
}
|
|
7805
|
-
const updateResponseResult = ComposioMcpUpdateResponseSchema.safeParse(updateResponse);
|
|
7806
|
-
if (updateResponseResult.error) throw new ValidationError("Failed to parse MCP server update response", { cause: updateResponseResult.error });
|
|
7807
|
-
return transformMcpUpdateResponse(updateResponse);
|
|
7808
|
-
}
|
|
7809
|
-
/**
|
|
7810
|
-
* Generate URL for an MCP server
|
|
7811
|
-
* @param {string} serverId - Server UUID
|
|
7812
|
-
* @param {GenerateURLParams} params - Parameters for URL generation
|
|
7813
|
-
* @returns {Promise<GenerateURLResponse>} Generated URL response
|
|
7814
|
-
*
|
|
7815
|
-
* @example
|
|
7816
|
-
* ```typescript
|
|
7817
|
-
* const urlResponse = await composio.mcp.generateUrl('server-uuid', {
|
|
7818
|
-
* userIds: ['user123'],
|
|
7819
|
-
* connectedAccountIds: ['account456'],
|
|
7820
|
-
* isChatAuth: true
|
|
7821
|
-
* });
|
|
7822
|
-
* ```
|
|
7823
|
-
*/
|
|
7824
|
-
async generateUrl(serverId, params) {
|
|
7825
|
-
const paramsResult = GenerateURLParamsSchema.safeParse(params);
|
|
7826
|
-
if (paramsResult.error) throw new ValidationError("Failed to parse generateUrl parameters", { cause: paramsResult.error });
|
|
7827
|
-
let urlResponse;
|
|
7828
|
-
try {
|
|
7829
|
-
urlResponse = await this.client.mcp.generate.url({
|
|
7830
|
-
mcp_server_id: serverId,
|
|
7831
|
-
user_ids: params.userIds,
|
|
7832
|
-
connected_account_ids: params.connectedAccountIds,
|
|
7833
|
-
managed_auth_by_composio: params.composioManagedAuth
|
|
7834
|
-
});
|
|
7835
|
-
} catch (error) {
|
|
7836
|
-
throw new ValidationError("Failed to generate MCP URL", { cause: error });
|
|
7837
|
-
}
|
|
7838
|
-
const responseResult = ComposioGenerateURLResponseSchema.safeParse(urlResponse);
|
|
7839
|
-
if (responseResult.error) throw new ValidationError("Failed to parse MCP URL generation response", { cause: responseResult.error });
|
|
7840
|
-
return transformMcpGenerateUrlResponse(urlResponse);
|
|
7841
|
-
}
|
|
7842
|
-
/**
|
|
7843
|
-
* Transform MCP URL response into the appropriate format.
|
|
7844
|
-
* If the provider has a custom transform method, use it.
|
|
7845
|
-
* Otherwise, use the default transformation.
|
|
7846
|
-
*
|
|
7847
|
-
* @param data - The MCP URL response data (in camelCase)
|
|
7848
|
-
* @param serverName - Name of the MCP server
|
|
7849
|
-
|
|
7850
|
-
* @returns Transformed response in appropriate format
|
|
7851
|
-
* @deprecated
|
|
7852
|
-
*/
|
|
7853
|
-
wrapMcpServerResponse(data, serverName, connectedAccountIds, userIds, toolkits) {
|
|
7854
|
-
if (this.provider && typeof this.provider.wrapMcpServerResponse === "function") {
|
|
7855
|
-
let snakeCaseData;
|
|
7856
|
-
if (data.connectedAccountUrls?.length) snakeCaseData = data.connectedAccountUrls.map((url, index) => ({
|
|
7857
|
-
name: serverName + "-" + connectedAccountIds?.[index],
|
|
7858
|
-
url
|
|
7859
|
-
}));
|
|
7860
|
-
else if (data.userIdsUrl?.length) snakeCaseData = data.userIdsUrl.map((url, index) => ({
|
|
7861
|
-
name: serverName + "-" + userIds?.[index],
|
|
7862
|
-
url
|
|
7863
|
-
}));
|
|
7864
|
-
else snakeCaseData = [{
|
|
7865
|
-
name: serverName,
|
|
7866
|
-
url: data.mcpUrl
|
|
7867
|
-
}];
|
|
7868
|
-
return this.provider.wrapMcpServerResponse(snakeCaseData);
|
|
7869
|
-
}
|
|
7870
|
-
if (connectedAccountIds?.length && data.connectedAccountUrls) return data.connectedAccountUrls.map((url, index) => ({
|
|
7871
|
-
url: new URL(url),
|
|
7872
|
-
name: `${serverName}-${connectedAccountIds[index]}`,
|
|
7873
|
-
toolkit: toolkits?.[index]
|
|
7874
|
-
}));
|
|
7875
|
-
else if (userIds?.length && data.userIdsUrl) return data.userIdsUrl.map((url, index) => ({
|
|
7876
|
-
url: new URL(url),
|
|
7877
|
-
name: `${serverName}-${userIds[index]}`,
|
|
7878
|
-
toolkit: toolkits?.[index]
|
|
7879
|
-
}));
|
|
7880
|
-
return {
|
|
7881
|
-
url: new URL(data.mcpUrl),
|
|
7882
|
-
name: serverName
|
|
7883
|
-
};
|
|
7884
|
-
}
|
|
7885
|
-
/**
|
|
7886
|
-
* Get details of a specific MCP server by name
|
|
7887
|
-
* @param {string} name - Server name
|
|
7888
|
-
* @returns {Promise<McpRetrieveResponse>} Server details
|
|
7889
|
-
* @throws {ValidationError} If no server found with the given name
|
|
7890
|
-
* @throws {ValidationError} If multiple servers found with the same name
|
|
7891
|
-
*
|
|
7892
|
-
* @example
|
|
7893
|
-
* ```typescript
|
|
7894
|
-
* const serverDetails = await composio.mcp.getByName('my-gmail-server');
|
|
7895
|
-
* ```
|
|
7896
|
-
*/
|
|
7897
|
-
async getByName(serverName) {
|
|
7898
|
-
if (!serverName) throw new ValidationError("Server name is required", {});
|
|
7899
|
-
let listResponse;
|
|
7900
|
-
try {
|
|
7901
|
-
listResponse = await this.client.mcp.list({
|
|
7902
|
-
name: serverName,
|
|
7903
|
-
limit: 10
|
|
7904
|
-
});
|
|
7905
|
-
} catch (error) {
|
|
7906
|
-
logger_default.error(error);
|
|
7907
|
-
throw new ValidationError("Failed to search MCP servers by name", { cause: error });
|
|
7908
|
-
}
|
|
7909
|
-
const listResponseResult = ComposioMcpListResponseSchema.safeParse(listResponse);
|
|
7910
|
-
if (listResponseResult.error) throw new ValidationError("Failed to parse MCP server list response", { cause: listResponseResult.error });
|
|
7911
|
-
const servers = listResponse.items || [];
|
|
7912
|
-
if (servers.length === 0) throw new ValidationError(`MCP server with name '${serverName}' not found`, { meta: { serverName } });
|
|
7913
|
-
return this.get(servers[0].id);
|
|
7914
|
-
}
|
|
7915
|
-
};
|
|
7916
|
-
|
|
7917
7332
|
//#endregion
|
|
7918
7333
|
export { AuthConfigCreationToolAccessConfigSchema, AuthConfigErrorCodes, AuthConfigListParamsSchema, AuthConfigListResponseSchema, AuthConfigRetrieveResponseSchema, AuthConfigToolAccessConfigSchema, AuthConfigTypes, AuthConfigUpdateParamsSchema, AuthCustomConfigUpdateParamsSchema, AuthDefaultConfigUpdateParamsSchema, AuthScheme, AuthSchemeEnum, AuthSchemeTypes, BaseAgenticProvider, BaseNonAgenticProvider, BillcomAuthConnectionDataSchema, Composio, ComposioAuthConfigNotFoundError, ComposioConnectedAccountNotFoundError, ComposioCustomCreateResponseSchema, ComposioCustomToolsNotInitializedError, ComposioError, ComposioFailedToCreateConnectedAccountLink, ComposioFailedToCreatePusherClientError, ComposioFailedToGetSDKRealtimeCredentialsError, ComposioFailedToSubscribeToPusherChannelError, ComposioFailedToUnsubscribeFromPusherChannelError, ComposioGenerateURLParamsSchema, ComposioGenerateURLResponseSchema, ComposioGlobalExecuteToolFnNotSetError, ComposioInvalidExecuteFunctionError, ComposioInvalidModifierError, ComposioMcpDeleteResponseSchema, ComposioMcpListResponseSchema, ComposioMcpRetrieveResponseSchema, ComposioMcpUpdateResponseSchema, ComposioMultipleConnectedAccountsError, ComposioNoAPIKeyError, ComposioProvider, ComposioProviderNotDefinedError, ComposioToolExecutionError, ComposioToolNotFoundError, ComposioToolVersionRequiredError, ComposioToolkitFetchError, ComposioToolkitNotFoundError, ComposioTriggerTypeNotFoundError, ComposioWebhookPayloadError, ComposioWebhookSignatureVerificationError, ConnectedAccountAuthConfigSchema, ConnectedAccountErrorCodes, ConnectedAccountListParamsSchema, ConnectedAccountListResponseSchema, ConnectedAccountRetrieveResponseSchema, ConnectedAccountStatusSchema, ConnectedAccountStatuses, ConnectionDataSchema, ConnectionRequestErrorCodes, ConnectionRequestFailedError, ConnectionRequestTimeoutError, ConnectionStatus, ConnectionStatuses, CreateAuthConfigParamsSchema, CreateAuthConfigResponseSchema, CreateComposioManagedAuthConfigParamsSchema, CreateConnectedAccountLinkOptionsSchema, CreateConnectedAccountLinkResponseSchema, CreateConnectedAccountOptionsSchema, CreateConnectedAccountParamsSchema, CreateConnectedAccountResponseSchema, CreateCustomAuthConfigParamsSchema, CustomAuthParamsSchema, CustomConnectionDataSchema, CustomCreateResponseSchema, CustomOauth1ConnectionDataSchema, CustomOauth2ConnectionDataSchema, DefaultCreateConnectedAccountParamsSchema, GenerateURLParamsSchema, GenerateURLResponseSchema, IncomingTriggerPayloadSchema, JSONSchemaPropertySchema, JsonSchemaToZodError, MCP, MCPAuthOptionsSchema, MCPGenerateURLParamsSchema, MCPGetServerParamsSchema, MCPMultiAppServerSchema, MCPServerCreateResponseSchema, MCPServerListResponseSchema, MCPServerSchema, MCPServerTypeSchema, MCPServerUpdateParamsSchema, MCPSingleAppServerSchema, MCPToolkitConfigSchema, MCPToolkitConfigsArraySchema, McpDeleteResponseSchema, McpListResponseSchema, McpRetrieveResponseSchema, McpUpdateResponseSchema, Oauth1ActiveConnectionDataSchema, Oauth1ConnectionDataSchema, Oauth1ExpiredConnectionDataSchema, Oauth1FailedConnectionDataSchema, Oauth1InactiveConnectionDataSchema, Oauth1InitiatedConnectionDataSchema, Oauth1InitiatingConnectionDataSchema, Oauth2ActiveConnectionDataSchema, Oauth2ConnectionDataSchema, Oauth2ExpiredConnectionDataSchema, Oauth2FailedConnectionDataSchema, Oauth2InactiveConnectionDataSchema, Oauth2InitiatedConnectionDataSchema, Oauth2InitiatingConnectionDataSchema, OpenAIProvider, RedirectableAuthSchemeSchema, SDKErrorCodes, ToolErrorCodes, ToolExecuteMetaParamsSchema, ToolExecuteParamsSchema, ToolExecuteResponseSchema, ToolKitItemSchema, ToolKitListResponseSchema, ToolKitMetaSchema, ToolListParamsSchema, ToolListResponseSchema, ToolProxyParamsSchema, ToolRouterConfigManageConnectionsSchema, ToolRouterConfigTagsSchema, ToolRouterConfigToolsSchema, ToolRouterCreateSessionConfigSchema, ToolRouterMCPServerConfigSchema, ToolRouterManageConnectionsConfigSchema, ToolRouterTagsEnableDisableSchema, ToolRouterTagsParamSchema, ToolRouterToolkitsDisabledConfigSchema, ToolRouterToolkitsEnabledConfigSchema, ToolRouterToolkitsOptionsSchema, ToolRouterToolkitsParamSchema, ToolRouterToolsParamSchema, ToolSchema, ToolkitAuthConfigDetailsSchema, ToolkitAuthFieldSchema, ToolkitAuthFieldsResponseSchema, ToolkitCategorySchema, ToolkitConnectionStateSchema, ToolkitConnectionsDetailsSchema, ToolkitErrorCodes, ToolkitLatestVersionSchema, ToolkitMangedByEnumSchema, ToolkitRetrieveCategoriesResponseSchema, ToolkitRetrieveResponseSchema, ToolkitSchema, ToolkitSortByEnumSchema, ToolkitVersionParamSchema, ToolkitVersionSchema, ToolkitVersionsSchema, ToolkitsListParamsSchema, TriggerErrorCodes, TriggerInstanceListActiveParamsSchema, TriggerInstanceListActiveResponseItemSchema, TriggerInstanceListActiveResponseSchema, TriggerInstanceManageDeleteResponseSchema, TriggerInstanceManageUpdateParamsSchema, TriggerInstanceManageUpdateResponseSchema, TriggerInstanceUpsertParamsSchema, TriggerInstanceUpsertResponseSchema, TriggerStatusEnum, TriggerStatuses, TriggerSubscribeParamSchema, TriggerTypeSchema, TriggersTypeListParamsSchema, TriggersTypeListResponseSchema, ValidationError, ValidationErrorCodes, VerifyWebhookParamsSchema, constants_exports as constants, createConnectionRequest, handleToolExecutionError, jsonSchemaToZodSchema, logger_default as logger, removeNonRequiredProperties };
|