@composio/core 0.1.51 → 0.1.53
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/README.md +1 -0
- package/dist/index.cjs +929 -234
- package/dist/index.d.cts +1061 -82
- package/dist/index.d.ts +1061 -82
- package/dist/index.js +929 -234
- package/package.json +13 -11
package/dist/index.js
CHANGED
|
@@ -35,7 +35,8 @@ var AuthSchemeTypes = {
|
|
|
35
35
|
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
36
36
|
NO_AUTH: "NO_AUTH",
|
|
37
37
|
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
38
|
-
CALCOM_AUTH: "CALCOM_AUTH"
|
|
38
|
+
CALCOM_AUTH: "CALCOM_AUTH",
|
|
39
|
+
SERVICE_ACCOUNT: "SERVICE_ACCOUNT"
|
|
39
40
|
};
|
|
40
41
|
var AuthConfigCreationToolAccessConfigSchema = z.object({
|
|
41
42
|
toolsForConnectedAccountCreation: z.array(z.string()).optional()
|
|
@@ -54,7 +55,8 @@ var AuthSchemeEnum = z.enum([
|
|
|
54
55
|
"GOOGLE_SERVICE_ACCOUNT",
|
|
55
56
|
"NO_AUTH",
|
|
56
57
|
"BASIC_WITH_JWT",
|
|
57
|
-
"CALCOM_AUTH"
|
|
58
|
+
"CALCOM_AUTH",
|
|
59
|
+
"SERVICE_ACCOUNT"
|
|
58
60
|
]);
|
|
59
61
|
var CreateCustomAuthConfigParamsSchema = z.object({
|
|
60
62
|
type: z.literal("use_custom_auth"),
|
|
@@ -678,10 +680,11 @@ var ToolSchema = z3.object({
|
|
|
678
680
|
description: z3.string().optional().describe("The description of the tool"),
|
|
679
681
|
inputParameters: ParametersSchema.optional().describe("The input parameters of the tool"),
|
|
680
682
|
outputParameters: ParametersSchema.optional().describe("The output parameters of the tool"),
|
|
681
|
-
tags: z3.
|
|
682
|
-
toolkit:
|
|
683
|
-
version: z3.
|
|
684
|
-
|
|
683
|
+
tags: z3.array(z3.string()).describe("The tags of the tool. eg: Important").default([]).optional(),
|
|
684
|
+
toolkit: ToolkitSchema.describe("The toolkit of the tool").optional(),
|
|
685
|
+
version: z3.string().describe('The version of the tool, e.g. "20250909_00"').optional(),
|
|
686
|
+
availableVersions: z3.array(z3.string()).describe("Available versions of the tool.").default([]).optional(),
|
|
687
|
+
scopes: z3.array(z3.string()).describe('The scopes of the tool. eg: ["task:add"]').optional()
|
|
685
688
|
});
|
|
686
689
|
var ToolListResponseSchema = z3.object({
|
|
687
690
|
items: z3.array(ToolSchema),
|
|
@@ -715,8 +718,8 @@ var ToolExecuteParamsSchema = z3.object({
|
|
|
715
718
|
customConnectionData: CustomConnectionDataSchema.optional(),
|
|
716
719
|
arguments: z3.record(z3.string(), z3.unknown()).optional(),
|
|
717
720
|
userId: z3.string().optional(),
|
|
718
|
-
//
|
|
719
|
-
version: z3.string().optional(),
|
|
721
|
+
// we have no auth apps which can be execute
|
|
722
|
+
version: z3.union([z3.literal("latest"), z3.string()]).optional(),
|
|
720
723
|
text: z3.string().optional()
|
|
721
724
|
});
|
|
722
725
|
var ToolExecuteResponseSchema = z3.object({
|
|
@@ -769,6 +772,19 @@ var getEnvVariable = (name, defaultValue = void 0) => {
|
|
|
769
772
|
return defaultValue;
|
|
770
773
|
}
|
|
771
774
|
};
|
|
775
|
+
var getEnvsWithPrefix = (prefix) => {
|
|
776
|
+
try {
|
|
777
|
+
if (process && process.env) {
|
|
778
|
+
return Object.fromEntries(
|
|
779
|
+
Object.entries(process.env).filter(([key]) => key.startsWith(prefix))
|
|
780
|
+
);
|
|
781
|
+
} else {
|
|
782
|
+
return {};
|
|
783
|
+
}
|
|
784
|
+
} catch (error) {
|
|
785
|
+
return {};
|
|
786
|
+
}
|
|
787
|
+
};
|
|
772
788
|
|
|
773
789
|
// src/utils/constants.ts
|
|
774
790
|
var COMPOSIO_DIR = ".composio";
|
|
@@ -2508,13 +2524,26 @@ var FileToolModifier = class {
|
|
|
2508
2524
|
}
|
|
2509
2525
|
};
|
|
2510
2526
|
|
|
2527
|
+
// src/utils/toolkitVersion.ts
|
|
2528
|
+
var getToolkitVersion = (toolkitSlug, toolkitVersions) => {
|
|
2529
|
+
if (typeof toolkitVersions === "string") {
|
|
2530
|
+
return toolkitVersions;
|
|
2531
|
+
}
|
|
2532
|
+
const hasToolkitVersion = toolkitVersions && Object.keys(toolkitVersions).length > 0;
|
|
2533
|
+
if (hasToolkitVersion) {
|
|
2534
|
+
return toolkitVersions[toolkitSlug] ?? "latest";
|
|
2535
|
+
}
|
|
2536
|
+
return "latest";
|
|
2537
|
+
};
|
|
2538
|
+
|
|
2511
2539
|
// src/models/Tools.ts
|
|
2512
2540
|
var Tools = class {
|
|
2513
2541
|
client;
|
|
2514
2542
|
customTools;
|
|
2515
2543
|
provider;
|
|
2516
2544
|
autoUploadDownloadFiles;
|
|
2517
|
-
|
|
2545
|
+
toolkitVersions;
|
|
2546
|
+
constructor(client, provider, config) {
|
|
2518
2547
|
if (!client) {
|
|
2519
2548
|
throw new Error("ComposioClient is required");
|
|
2520
2549
|
}
|
|
@@ -2524,7 +2553,8 @@ var Tools = class {
|
|
|
2524
2553
|
this.client = client;
|
|
2525
2554
|
this.customTools = new CustomTools(client);
|
|
2526
2555
|
this.provider = provider;
|
|
2527
|
-
this.autoUploadDownloadFiles =
|
|
2556
|
+
this.autoUploadDownloadFiles = config?.autoUploadDownloadFiles ?? true;
|
|
2557
|
+
this.toolkitVersions = config?.toolkitVersions ?? "latest";
|
|
2528
2558
|
this.execute = this.execute.bind(this);
|
|
2529
2559
|
this.provider._setExecuteToolFn(this.execute);
|
|
2530
2560
|
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
@@ -2546,7 +2576,8 @@ var Tools = class {
|
|
|
2546
2576
|
return ToolSchema.parse({
|
|
2547
2577
|
...tool,
|
|
2548
2578
|
inputParameters: tool.input_parameters,
|
|
2549
|
-
outputParameters: tool.output_parameters
|
|
2579
|
+
outputParameters: tool.output_parameters,
|
|
2580
|
+
availableVersions: tool.available_versions
|
|
2550
2581
|
});
|
|
2551
2582
|
}
|
|
2552
2583
|
/**
|
|
@@ -2569,46 +2600,6 @@ var Tools = class {
|
|
|
2569
2600
|
sessionInfo: response.session_info
|
|
2570
2601
|
});
|
|
2571
2602
|
}
|
|
2572
|
-
/**
|
|
2573
|
-
* Check if the connected account exists for the given tools.
|
|
2574
|
-
* @param {string} userId - The user id.
|
|
2575
|
-
* @param {ToolList} tools - The tools to check.
|
|
2576
|
-
* @returns {Promise<boolean>} True if the connected account exists for the given tools, false otherwise.
|
|
2577
|
-
*/
|
|
2578
|
-
async checkIfConnectedAccountExistsForTools(userIds, tools) {
|
|
2579
|
-
if (!tools.length) {
|
|
2580
|
-
return true;
|
|
2581
|
-
}
|
|
2582
|
-
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
2583
|
-
user_ids: userIds
|
|
2584
|
-
});
|
|
2585
|
-
if (connectedAccounts.items.length === 0) {
|
|
2586
|
-
return false;
|
|
2587
|
-
}
|
|
2588
|
-
const connectedToolkitSlugs = connectedAccounts.items.reduce(
|
|
2589
|
-
(acc, account) => {
|
|
2590
|
-
if (account.toolkit.slug) {
|
|
2591
|
-
acc[account.toolkit.slug] = true;
|
|
2592
|
-
}
|
|
2593
|
-
return acc;
|
|
2594
|
-
},
|
|
2595
|
-
{}
|
|
2596
|
-
);
|
|
2597
|
-
const toolSlugs = tools.reduce(
|
|
2598
|
-
(acc, tool) => {
|
|
2599
|
-
acc[tool.slug] = true;
|
|
2600
|
-
return acc;
|
|
2601
|
-
},
|
|
2602
|
-
{}
|
|
2603
|
-
);
|
|
2604
|
-
for (const tool of Object.keys(toolSlugs)) {
|
|
2605
|
-
if (!connectedToolkitSlugs[tool]) {
|
|
2606
|
-
logger_default.warn(`Tool ${tool} requires a connected account but no connected account was found`);
|
|
2607
|
-
return false;
|
|
2608
|
-
}
|
|
2609
|
-
}
|
|
2610
|
-
return true;
|
|
2611
|
-
}
|
|
2612
2603
|
/**
|
|
2613
2604
|
* Get the connected account id for a given tool
|
|
2614
2605
|
* @param {string} userId - The user id
|
|
@@ -2734,32 +2725,59 @@ var Tools = class {
|
|
|
2734
2725
|
*
|
|
2735
2726
|
* This method fetches tools from the Composio API in raw format and combines them with
|
|
2736
2727
|
* any registered custom tools. The response can be filtered and modified as needed.
|
|
2728
|
+
* It provides access to the underlying tool data without provider-specific wrapping.
|
|
2737
2729
|
*
|
|
2738
|
-
* @param {ToolListParams}
|
|
2739
|
-
* @param {
|
|
2730
|
+
* @param {ToolListParams} query - Query parameters to filter the tools (required)
|
|
2731
|
+
* @param {GetRawComposioToolsOptions} [options] - Optional configuration for tool retrieval
|
|
2732
|
+
* @param {TransformToolSchemaModifier} [options.modifySchema] - Function to transform tool schemas
|
|
2740
2733
|
* @returns {Promise<ToolList>} List of tools matching the query criteria
|
|
2741
2734
|
*
|
|
2742
2735
|
* @example
|
|
2743
2736
|
* ```typescript
|
|
2744
|
-
* // Get
|
|
2745
|
-
* const
|
|
2737
|
+
* // Get tools from specific toolkits
|
|
2738
|
+
* const githubTools = await composio.tools.getRawComposioTools({
|
|
2739
|
+
* toolkits: ['github'],
|
|
2740
|
+
* limit: 10
|
|
2741
|
+
* });
|
|
2746
2742
|
*
|
|
2747
|
-
* // Get tools
|
|
2743
|
+
* // Get specific tools by slug
|
|
2744
|
+
* const specificTools = await composio.tools.getRawComposioTools({
|
|
2745
|
+
* tools: ['GITHUB_GET_REPOS', 'HACKERNEWS_GET_USER']
|
|
2746
|
+
* });
|
|
2747
|
+
*
|
|
2748
|
+
* // Get tools from specific toolkits
|
|
2748
2749
|
* const githubTools = await composio.tools.getRawComposioTools({
|
|
2749
2750
|
* toolkits: ['github'],
|
|
2750
2751
|
* limit: 10
|
|
2751
2752
|
* });
|
|
2752
2753
|
*
|
|
2753
2754
|
* // Get tools with schema transformation
|
|
2754
|
-
* const
|
|
2755
|
-
*
|
|
2755
|
+
* const customizedTools = await composio.tools.getRawComposioTools({
|
|
2756
|
+
* toolkits: ['github'],
|
|
2757
|
+
* limit: 5
|
|
2758
|
+
* }, {
|
|
2759
|
+
* modifySchema: ({ toolSlug, toolkitSlug, schema }) => {
|
|
2756
2760
|
* // Add custom properties to tool schema
|
|
2757
|
-
* return {
|
|
2761
|
+
* return {
|
|
2762
|
+
* ...schema,
|
|
2763
|
+
* customProperty: `Modified ${toolSlug} from ${toolkitSlug}`,
|
|
2764
|
+
* tags: [...(schema.tags || []), 'customized']
|
|
2765
|
+
* };
|
|
2758
2766
|
* }
|
|
2759
|
-
* );
|
|
2767
|
+
* });
|
|
2768
|
+
*
|
|
2769
|
+
* // Search for tools
|
|
2770
|
+
* const searchResults = await composio.tools.getRawComposioTools({
|
|
2771
|
+
* search: 'user management'
|
|
2772
|
+
* });
|
|
2773
|
+
*
|
|
2774
|
+
* // Get tools by authentication config
|
|
2775
|
+
* const authSpecificTools = await composio.tools.getRawComposioTools({
|
|
2776
|
+
* authConfigIds: ['auth_config_123']
|
|
2777
|
+
* });
|
|
2760
2778
|
* ```
|
|
2761
2779
|
*/
|
|
2762
|
-
async getRawComposioTools(query,
|
|
2780
|
+
async getRawComposioTools(query, options) {
|
|
2763
2781
|
if ("tools" in query && "toolkits" in query) {
|
|
2764
2782
|
throw new ValidationError(
|
|
2765
2783
|
"Invalid tool list parameters. You should not use tools and toolkits filter together."
|
|
@@ -2787,7 +2805,8 @@ var Tools = class {
|
|
|
2787
2805
|
..."tags" in queryParams.data ? { tags: queryParams.data.tags } : {},
|
|
2788
2806
|
..."scopes" in queryParams.data ? { scopes: queryParams.data.scopes } : {},
|
|
2789
2807
|
..."search" in queryParams.data ? { search: queryParams.data.search } : {},
|
|
2790
|
-
..."authConfigIds" in queryParams.data ? { auth_config_ids: queryParams.data.authConfigIds } : {}
|
|
2808
|
+
..."authConfigIds" in queryParams.data ? { auth_config_ids: queryParams.data.authConfigIds } : {},
|
|
2809
|
+
...{ toolkit_versions: this.toolkitVersions }
|
|
2791
2810
|
};
|
|
2792
2811
|
logger_default.debug(`Fetching tools with filters: ${JSON.stringify(filters, null, 2)}`);
|
|
2793
2812
|
const tools = await this.client.tools.list(filters);
|
|
@@ -2802,7 +2821,8 @@ var Tools = class {
|
|
|
2802
2821
|
...caseTransformedTools,
|
|
2803
2822
|
...customTools
|
|
2804
2823
|
]);
|
|
2805
|
-
if (
|
|
2824
|
+
if (options?.modifySchema) {
|
|
2825
|
+
const modifier = options.modifySchema;
|
|
2806
2826
|
if (typeof modifier === "function") {
|
|
2807
2827
|
const modifiedPromises = modifiedTools.map(
|
|
2808
2828
|
(tool) => modifier({
|
|
@@ -2819,17 +2839,56 @@ var Tools = class {
|
|
|
2819
2839
|
return modifiedTools;
|
|
2820
2840
|
}
|
|
2821
2841
|
/**
|
|
2822
|
-
* Retrieves a tool by its
|
|
2823
|
-
*
|
|
2824
|
-
*
|
|
2825
|
-
*
|
|
2842
|
+
* Retrieves a specific tool by its slug from the Composio API.
|
|
2843
|
+
*
|
|
2844
|
+
* This method fetches a single tool in raw format without provider-specific wrapping,
|
|
2845
|
+
* providing direct access to the tool's schema and metadata. Tool versions are controlled
|
|
2846
|
+
* at the Composio SDK initialization level through the `toolkitVersions` configuration.
|
|
2847
|
+
*
|
|
2848
|
+
* @param {string} slug - The unique identifier of the tool (e.g., 'GITHUB_GET_REPOS')
|
|
2849
|
+
* @param {GetRawComposioToolBySlugOptions} [options] - Optional configuration for tool retrieval
|
|
2850
|
+
* @param {TransformToolSchemaModifier} [options.modifySchema] - Function to transform the tool schema
|
|
2851
|
+
* @returns {Promise<Tool>} The requested tool with its complete schema and metadata
|
|
2826
2852
|
*
|
|
2827
2853
|
* @example
|
|
2828
|
-
* ```
|
|
2829
|
-
*
|
|
2854
|
+
* ```typescript
|
|
2855
|
+
* // Get a tool by slug
|
|
2856
|
+
* const tool = await composio.tools.getRawComposioToolBySlug('GITHUB_GET_REPOS');
|
|
2857
|
+
* console.log(tool.name, tool.description);
|
|
2858
|
+
*
|
|
2859
|
+
* // Get a tool with schema transformation
|
|
2860
|
+
* const customizedTool = await composio.tools.getRawComposioToolBySlug(
|
|
2861
|
+
* 'SLACK_SEND_MESSAGE',
|
|
2862
|
+
* {
|
|
2863
|
+
* modifySchema: ({ toolSlug, toolkitSlug, schema }) => {
|
|
2864
|
+
* return {
|
|
2865
|
+
* ...schema,
|
|
2866
|
+
* description: `Enhanced ${schema.description} with custom modifications`,
|
|
2867
|
+
* customMetadata: {
|
|
2868
|
+
* lastModified: new Date().toISOString(),
|
|
2869
|
+
* toolkit: toolkitSlug
|
|
2870
|
+
* }
|
|
2871
|
+
* };
|
|
2872
|
+
* }
|
|
2873
|
+
* }
|
|
2874
|
+
* );
|
|
2875
|
+
*
|
|
2876
|
+
* // Get a custom tool (will check custom tools first)
|
|
2877
|
+
* const customTool = await composio.tools.getRawComposioToolBySlug('MY_CUSTOM_TOOL');
|
|
2878
|
+
*
|
|
2879
|
+
* // Access tool properties
|
|
2880
|
+
* const githubTool = await composio.tools.getRawComposioToolBySlug('GITHUB_CREATE_ISSUE');
|
|
2881
|
+
* console.log({
|
|
2882
|
+
* slug: githubTool.slug,
|
|
2883
|
+
* name: githubTool.name,
|
|
2884
|
+
* toolkit: githubTool.toolkit?.name,
|
|
2885
|
+
* version: githubTool.version,
|
|
2886
|
+
* availableVersions: githubTool.availableVersions,
|
|
2887
|
+
* inputParameters: githubTool.inputParameters
|
|
2888
|
+
* });
|
|
2830
2889
|
* ```
|
|
2831
2890
|
*/
|
|
2832
|
-
async getRawComposioToolBySlug(slug,
|
|
2891
|
+
async getRawComposioToolBySlug(slug, options) {
|
|
2833
2892
|
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
2834
2893
|
if (customTool) {
|
|
2835
2894
|
logger_default.debug(`Found ${slug} to be a custom tool`, JSON.stringify(customTool, null, 2));
|
|
@@ -2839,14 +2898,17 @@ var Tools = class {
|
|
|
2839
2898
|
}
|
|
2840
2899
|
let tool;
|
|
2841
2900
|
try {
|
|
2842
|
-
tool = await this.client.tools.retrieve(slug
|
|
2901
|
+
tool = await this.client.tools.retrieve(slug, {
|
|
2902
|
+
toolkit_versions: this.toolkitVersions
|
|
2903
|
+
});
|
|
2843
2904
|
} catch (error) {
|
|
2844
2905
|
throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, {
|
|
2845
2906
|
cause: error
|
|
2846
2907
|
});
|
|
2847
2908
|
}
|
|
2848
2909
|
let [modifiedTool] = await this.applyDefaultSchemaModifiers([this.transformToolCases(tool)]);
|
|
2849
|
-
if (
|
|
2910
|
+
if (options?.modifySchema) {
|
|
2911
|
+
const modifier = options.modifySchema;
|
|
2850
2912
|
if (typeof modifier === "function") {
|
|
2851
2913
|
modifiedTool = await modifier({
|
|
2852
2914
|
toolSlug: slug,
|
|
@@ -2861,20 +2923,26 @@ var Tools = class {
|
|
|
2861
2923
|
}
|
|
2862
2924
|
/**
|
|
2863
2925
|
* Get a tool or list of tools based on the provided arguments.
|
|
2864
|
-
* This is an implementation method that handles
|
|
2926
|
+
* This is an implementation method that handles all overloads.
|
|
2865
2927
|
*
|
|
2866
2928
|
* @param {string} userId - The user id to get the tool(s) for
|
|
2867
2929
|
* @param {ToolListParams | string} arg2 - Either a slug string or filters object
|
|
2868
|
-
* @param {ProviderOptions<TProvider>} [
|
|
2930
|
+
* @param {ProviderOptions<TProvider> | ToolkitVersion} [arg3] - Optional provider options or version string
|
|
2931
|
+
* @param {ProviderOptions<TProvider>} [arg4] - Optional provider options (when arg3 is version)
|
|
2869
2932
|
* @returns {Promise<TToolCollection>} The tool collection
|
|
2870
2933
|
*/
|
|
2871
|
-
async get(userId, arg2,
|
|
2934
|
+
async get(userId, arg2, arg3) {
|
|
2935
|
+
const options = arg3;
|
|
2872
2936
|
const executeToolFn = this.createExecuteToolFn(userId, options);
|
|
2873
2937
|
if (typeof arg2 === "string") {
|
|
2874
|
-
const tool = await this.getRawComposioToolBySlug(arg2,
|
|
2938
|
+
const tool = await this.getRawComposioToolBySlug(arg2, {
|
|
2939
|
+
modifySchema: options?.modifySchema
|
|
2940
|
+
});
|
|
2875
2941
|
return this.provider.wrapTools([tool], executeToolFn);
|
|
2876
2942
|
} else {
|
|
2877
|
-
const tools = await this.getRawComposioTools(arg2,
|
|
2943
|
+
const tools = await this.getRawComposioTools(arg2, {
|
|
2944
|
+
modifySchema: options?.modifySchema
|
|
2945
|
+
});
|
|
2878
2946
|
return this.provider.wrapTools(tools, executeToolFn);
|
|
2879
2947
|
}
|
|
2880
2948
|
}
|
|
@@ -2964,7 +3032,7 @@ var Tools = class {
|
|
|
2964
3032
|
custom_connection_data: body.customConnectionData,
|
|
2965
3033
|
arguments: body.arguments,
|
|
2966
3034
|
user_id: body.userId,
|
|
2967
|
-
version: body.version,
|
|
3035
|
+
version: body.version ?? getToolkitVersion(tool.toolkit?.slug ?? "unknown", this.toolkitVersions),
|
|
2968
3036
|
text: body.text
|
|
2969
3037
|
});
|
|
2970
3038
|
result = this.transformToolExecuteResponse(result);
|
|
@@ -3024,25 +3092,34 @@ var Tools = class {
|
|
|
3024
3092
|
"CustomTools not initialized. Make sure Tools class is properly constructed."
|
|
3025
3093
|
);
|
|
3026
3094
|
}
|
|
3095
|
+
const executeParams = ToolExecuteParamsSchema.safeParse(body);
|
|
3096
|
+
if (!executeParams.success) {
|
|
3097
|
+
throw new ValidationError("Invalid tool execute parameters", { cause: executeParams.error });
|
|
3098
|
+
}
|
|
3027
3099
|
try {
|
|
3028
3100
|
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
3029
3101
|
if (customTool) {
|
|
3030
|
-
return this.handleCustomToolExecution(customTool,
|
|
3102
|
+
return this.handleCustomToolExecution(customTool, executeParams.data, modifiers);
|
|
3031
3103
|
} else {
|
|
3032
3104
|
const composioTool = await this.getRawComposioToolBySlug(slug);
|
|
3033
3105
|
if (!composioTool) {
|
|
3034
|
-
throw new ComposioToolNotFoundError(
|
|
3106
|
+
throw new ComposioToolNotFoundError(
|
|
3107
|
+
`Tool with slug ${slug} version:${executeParams.data.version} not found`
|
|
3108
|
+
);
|
|
3035
3109
|
}
|
|
3036
|
-
return this.handleComposioToolExecution(composioTool,
|
|
3110
|
+
return this.handleComposioToolExecution(composioTool, executeParams.data, modifiers);
|
|
3037
3111
|
}
|
|
3038
3112
|
} catch (error) {
|
|
3039
|
-
throw new ComposioToolExecutionError(
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3113
|
+
throw new ComposioToolExecutionError(
|
|
3114
|
+
`Error executing tool ${slug} version:${executeParams.data.version}`,
|
|
3115
|
+
{
|
|
3116
|
+
originalError: error,
|
|
3117
|
+
meta: {
|
|
3118
|
+
toolSlug: slug,
|
|
3119
|
+
body
|
|
3120
|
+
}
|
|
3044
3121
|
}
|
|
3045
|
-
|
|
3122
|
+
);
|
|
3046
3123
|
}
|
|
3047
3124
|
}
|
|
3048
3125
|
/**
|
|
@@ -3223,8 +3300,10 @@ var ToolKitItemSchema = z5.object({
|
|
|
3223
3300
|
});
|
|
3224
3301
|
var ToolKitListResponseSchema = z5.array(ToolKitItemSchema);
|
|
3225
3302
|
var ToolkitAuthFieldSchema = z5.object({
|
|
3226
|
-
|
|
3303
|
+
description: z5.string(),
|
|
3227
3304
|
displayName: z5.string(),
|
|
3305
|
+
required: z5.boolean(),
|
|
3306
|
+
name: z5.string(),
|
|
3228
3307
|
type: z5.string(),
|
|
3229
3308
|
default: z5.string().nullable().optional()
|
|
3230
3309
|
});
|
|
@@ -5094,24 +5173,506 @@ var Triggers = class {
|
|
|
5094
5173
|
}
|
|
5095
5174
|
};
|
|
5096
5175
|
|
|
5176
|
+
// src/types/mcp.experimental.types.ts
|
|
5177
|
+
import z8 from "zod";
|
|
5178
|
+
var MCPServerInstanceSchema = z8.object({
|
|
5179
|
+
id: z8.string(),
|
|
5180
|
+
name: z8.string(),
|
|
5181
|
+
type: z8.literal("streamable_http"),
|
|
5182
|
+
url: z8.string(),
|
|
5183
|
+
userId: z8.string(),
|
|
5184
|
+
allowedTools: z8.array(z8.string()),
|
|
5185
|
+
authConfigs: z8.array(z8.string())
|
|
5186
|
+
});
|
|
5187
|
+
var MCPConfigToolkitsSchema = z8.object({
|
|
5188
|
+
toolkit: z8.string().describe("Id of the toolkit").optional(),
|
|
5189
|
+
authConfigId: z8.string().describe("Id of the auth config").optional()
|
|
5190
|
+
});
|
|
5191
|
+
var MCPConfigCreationParamsSchema = z8.object({
|
|
5192
|
+
toolkits: z8.array(z8.union([MCPConfigToolkitsSchema, z8.string()])),
|
|
5193
|
+
allowedTools: z8.array(z8.string()).optional(),
|
|
5194
|
+
manuallyManageConnections: z8.boolean().default(false).optional().describe(
|
|
5195
|
+
`Whether to manually manage accounts. If true, you need to manage accounts manually connect user accounts.
|
|
5196
|
+
If set to false, composio will inject account maangement tools into your mcp server for agents to request and authenticate accounts.
|
|
5197
|
+
defaults to false`
|
|
5198
|
+
)
|
|
5199
|
+
});
|
|
5200
|
+
var MCPConfigResponseSchema = z8.object({
|
|
5201
|
+
/**
|
|
5202
|
+
* Unique identifier for the newly created custom MCP server
|
|
5203
|
+
*/
|
|
5204
|
+
id: z8.string(),
|
|
5205
|
+
/**
|
|
5206
|
+
* Human-readable name of the custom MCP server
|
|
5207
|
+
*/
|
|
5208
|
+
name: z8.string(),
|
|
5209
|
+
/**
|
|
5210
|
+
* List of tool identifiers that are enabled for this server
|
|
5211
|
+
*/
|
|
5212
|
+
allowedTools: z8.array(z8.string()),
|
|
5213
|
+
/**
|
|
5214
|
+
* ID references to the auth configurations used by this server
|
|
5215
|
+
*/
|
|
5216
|
+
authConfigIds: z8.array(z8.string()),
|
|
5217
|
+
/**
|
|
5218
|
+
* Set of command line instructions for connecting various clients to this MCP server
|
|
5219
|
+
*/
|
|
5220
|
+
commands: z8.object({
|
|
5221
|
+
/**
|
|
5222
|
+
* Command line instruction for Claude client setup
|
|
5223
|
+
*/
|
|
5224
|
+
claude: z8.string(),
|
|
5225
|
+
/**
|
|
5226
|
+
* Command line instruction for Cursor client setup
|
|
5227
|
+
*/
|
|
5228
|
+
cursor: z8.string(),
|
|
5229
|
+
/**
|
|
5230
|
+
* Command line instruction for Windsurf client setup
|
|
5231
|
+
*/
|
|
5232
|
+
windsurf: z8.string()
|
|
5233
|
+
}),
|
|
5234
|
+
/**
|
|
5235
|
+
* URL endpoint for establishing Server-Sent Events (SSE) connection to this MCP server
|
|
5236
|
+
*/
|
|
5237
|
+
MCPUrl: z8.string()
|
|
5238
|
+
});
|
|
5239
|
+
var MCPGetInstanceParamsSchema = z8.object({
|
|
5240
|
+
manuallyManageConnections: z8.boolean().default(false).optional().describe(
|
|
5241
|
+
`Whether to manually manage accounts. If true, you need to manage accounts manually connect user accounts.
|
|
5242
|
+
If set to false, composio will inject account maangement tools into your mcp server for agents to request and authenticate accounts.
|
|
5243
|
+
defaults to false`
|
|
5244
|
+
)
|
|
5245
|
+
});
|
|
5246
|
+
var MCPListParamsSchema = z8.object({
|
|
5247
|
+
page: z8.number().optional().default(1),
|
|
5248
|
+
limit: z8.number().optional().default(10),
|
|
5249
|
+
toolkits: z8.array(z8.string()).optional().default([]),
|
|
5250
|
+
authConfigs: z8.array(z8.string()).optional().default([]),
|
|
5251
|
+
name: z8.string().optional()
|
|
5252
|
+
});
|
|
5253
|
+
var MCPItemSchema = MCPConfigResponseSchema.extend({
|
|
5254
|
+
...z8.object({
|
|
5255
|
+
toolkitIcons: z8.record(z8.string(), z8.string()),
|
|
5256
|
+
serverInstanceCount: z8.number(),
|
|
5257
|
+
toolkits: z8.array(z8.string())
|
|
5258
|
+
}).shape
|
|
5259
|
+
});
|
|
5260
|
+
var MCPListResponseSchema = z8.object({
|
|
5261
|
+
items: z8.array(MCPItemSchema),
|
|
5262
|
+
currentPage: z8.number(),
|
|
5263
|
+
totalPages: z8.number()
|
|
5264
|
+
});
|
|
5265
|
+
var MCPUpdateParamsSchema = z8.object({
|
|
5266
|
+
name: z8.string().optional(),
|
|
5267
|
+
toolkits: z8.array(z8.union([MCPConfigToolkitsSchema, z8.string()])).optional(),
|
|
5268
|
+
allowedTools: z8.array(z8.string()).optional(),
|
|
5269
|
+
manuallyManageConnections: z8.boolean().optional().describe(
|
|
5270
|
+
`Whether to manually manage accounts. If true, you need to manage accounts manually connect user accounts.
|
|
5271
|
+
If set to false, composio will inject account maangement tools into your mcp server for agents to request and authenticate accounts.
|
|
5272
|
+
defaults to false`
|
|
5273
|
+
)
|
|
5274
|
+
});
|
|
5275
|
+
var MCPServerConnectionStatus = z8.object({
|
|
5276
|
+
connected: z8.boolean(),
|
|
5277
|
+
toolkit: z8.string(),
|
|
5278
|
+
connectedAccountId: z8.string()
|
|
5279
|
+
});
|
|
5280
|
+
var MCPServerConnectedAccountsSchema = z8.record(
|
|
5281
|
+
z8.string(),
|
|
5282
|
+
z8.array(
|
|
5283
|
+
z8.object({
|
|
5284
|
+
toolkit: z8.string(),
|
|
5285
|
+
authConfigId: z8.string(),
|
|
5286
|
+
connectedAccountId: z8.string()
|
|
5287
|
+
})
|
|
5288
|
+
)
|
|
5289
|
+
);
|
|
5290
|
+
|
|
5291
|
+
// src/models/MCP.experimental.ts
|
|
5292
|
+
function transformMCPItemResponse(response) {
|
|
5293
|
+
return transform(response).with(MCPItemSchema).using((raw) => ({
|
|
5294
|
+
name: raw.name,
|
|
5295
|
+
allowedTools: raw.allowed_tools,
|
|
5296
|
+
id: raw.id,
|
|
5297
|
+
authConfigIds: raw.auth_config_ids,
|
|
5298
|
+
commands: raw.commands,
|
|
5299
|
+
MCPUrl: raw.mcp_url,
|
|
5300
|
+
toolkitIcons: raw.toolkit_icons,
|
|
5301
|
+
serverInstanceCount: raw.server_instance_count,
|
|
5302
|
+
toolkits: raw.toolkits
|
|
5303
|
+
}));
|
|
5304
|
+
}
|
|
5305
|
+
var MCP = class {
|
|
5306
|
+
client;
|
|
5307
|
+
constructor(client) {
|
|
5308
|
+
this.client = client;
|
|
5309
|
+
telemetry.instrument(this);
|
|
5310
|
+
}
|
|
5311
|
+
/**
|
|
5312
|
+
* Create a new MCP configuration.
|
|
5313
|
+
* @param {Object} params - Parameters for creating the MCP configuration
|
|
5314
|
+
* @param {Array} params.authConfig - Array of auth configurations with id and allowed tools
|
|
5315
|
+
* @param {Object} params.options - Configuration options
|
|
5316
|
+
* @param {string} params.options.name - Unique name for the MCP configuration
|
|
5317
|
+
* @param {boolean} [params.options.manuallyManageConnections] - Whether to use chat-based authentication or manually connect accounts
|
|
5318
|
+
* @returns {Promise<McpServerCreateResponse<T>>} Created server details with instance getter
|
|
5319
|
+
*
|
|
5320
|
+
* @example
|
|
5321
|
+
* ```typescript
|
|
5322
|
+
* const server = await composio.mcpConfig.create("personal-mcp-server", {
|
|
5323
|
+
* toolkits: ["github", "slack"],
|
|
5324
|
+
* allowedTools: ["GMAIL_FETCH_EMAILS", "SLACK_SEND_MESSAGE"],
|
|
5325
|
+
* manuallyManageConnections: false
|
|
5326
|
+
* }
|
|
5327
|
+
* });
|
|
5328
|
+
*
|
|
5329
|
+
* const server = await composio.mcpConfig.create("personal-mcp-server", {
|
|
5330
|
+
* toolkits: [{ toolkit: "gmail", authConfigId: "ac_243434343" }],
|
|
5331
|
+
* allowedTools: ["GMAIL_FETCH_EMAILS"],
|
|
5332
|
+
* manuallyManageConnections: false
|
|
5333
|
+
* }
|
|
5334
|
+
* });
|
|
5335
|
+
* ```
|
|
5336
|
+
*/
|
|
5337
|
+
async create(name, mcpConfig) {
|
|
5338
|
+
const config = MCPConfigCreationParamsSchema.safeParse(mcpConfig);
|
|
5339
|
+
if (config.error) {
|
|
5340
|
+
throw new ValidationError("Invalid parameters passed to create mcp config", {
|
|
5341
|
+
cause: config.error
|
|
5342
|
+
});
|
|
5343
|
+
}
|
|
5344
|
+
const toolkits = [];
|
|
5345
|
+
const auth_config_ids = [];
|
|
5346
|
+
const custom_tools = config.data.allowedTools ?? [];
|
|
5347
|
+
config.data.toolkits.forEach((toolkit) => {
|
|
5348
|
+
if (typeof toolkit === "string") {
|
|
5349
|
+
toolkits.push(toolkit);
|
|
5350
|
+
} else if (toolkit.toolkit) {
|
|
5351
|
+
toolkits.push(toolkit.toolkit);
|
|
5352
|
+
} else if (toolkit.authConfigId) {
|
|
5353
|
+
auth_config_ids.push(toolkit.authConfigId);
|
|
5354
|
+
}
|
|
5355
|
+
});
|
|
5356
|
+
const server = await this.client.mcp.custom.create({
|
|
5357
|
+
name,
|
|
5358
|
+
toolkits,
|
|
5359
|
+
auth_config_ids,
|
|
5360
|
+
custom_tools,
|
|
5361
|
+
// if manually manage account is set to true, disable composio account management tools
|
|
5362
|
+
managed_auth_via_composio: config.data.manuallyManageConnections ? false : true
|
|
5363
|
+
});
|
|
5364
|
+
const camelCaseServer = transform(server).with(MCPConfigResponseSchema).using((raw) => ({
|
|
5365
|
+
name: raw.name,
|
|
5366
|
+
allowedTools: raw.allowed_tools,
|
|
5367
|
+
id: raw.id,
|
|
5368
|
+
authConfigIds: raw.auth_config_ids,
|
|
5369
|
+
commands: raw.commands,
|
|
5370
|
+
MCPUrl: raw.mcp_url
|
|
5371
|
+
}));
|
|
5372
|
+
return {
|
|
5373
|
+
...camelCaseServer,
|
|
5374
|
+
generate: async (userId) => {
|
|
5375
|
+
return await this.generate(userId, server.id, {
|
|
5376
|
+
manuallyManageConnections: config.data.manuallyManageConnections
|
|
5377
|
+
});
|
|
5378
|
+
}
|
|
5379
|
+
};
|
|
5380
|
+
}
|
|
5381
|
+
/**
|
|
5382
|
+
* List the MCP servers with optional filtering and pagination
|
|
5383
|
+
* @param {Object} options - Filtering and pagination options
|
|
5384
|
+
* @param {number} [options.page=1] - Page number for pagination (1-based)
|
|
5385
|
+
* @param {number} [options.limit=10] - Maximum number of items to return per page
|
|
5386
|
+
* @param {string[]} [options.toolkits=[]] - Array of toolkit names to filter by
|
|
5387
|
+
* @param {string[]} [options.authConfigs=[]] - Array of auth configuration IDs to filter by
|
|
5388
|
+
* @param {string} [options.name] - Filter by MCP server name (partial match)
|
|
5389
|
+
* @returns {Promise<MCPListResponse>} Paginated list of MCP servers with metadata
|
|
5390
|
+
*
|
|
5391
|
+
* @example
|
|
5392
|
+
* ```typescript
|
|
5393
|
+
* // List all MCP servers
|
|
5394
|
+
* const allServers = await composio.experimental.mcp.list({});
|
|
5395
|
+
*
|
|
5396
|
+
* // List with pagination
|
|
5397
|
+
* const pagedServers = await composio.experimental.mcp.list({
|
|
5398
|
+
* page: 2,
|
|
5399
|
+
* limit: 5
|
|
5400
|
+
* });
|
|
5401
|
+
*
|
|
5402
|
+
* // Filter by toolkit
|
|
5403
|
+
* const githubServers = await composio.experimental.mcp.list({
|
|
5404
|
+
* toolkits: ['github', 'slack']
|
|
5405
|
+
* });
|
|
5406
|
+
*
|
|
5407
|
+
* // Filter by name
|
|
5408
|
+
* const namedServers = await composio.experimental.mcp.list({
|
|
5409
|
+
* name: 'personal'
|
|
5410
|
+
* });
|
|
5411
|
+
* ```
|
|
5412
|
+
*/
|
|
5413
|
+
async list(options) {
|
|
5414
|
+
const { data: params, error } = MCPListParamsSchema.safeParse(options);
|
|
5415
|
+
if (error) {
|
|
5416
|
+
throw new ValidationError("Failed to validate list options", {
|
|
5417
|
+
cause: error
|
|
5418
|
+
});
|
|
5419
|
+
}
|
|
5420
|
+
const listResponse = await this.client.mcp.list({
|
|
5421
|
+
page_no: params.page,
|
|
5422
|
+
limit: params.limit,
|
|
5423
|
+
toolkits: params.toolkits?.length > 0 ? params.toolkits.join(",") : void 0,
|
|
5424
|
+
auth_config_ids: params.authConfigs?.length > 0 ? params.authConfigs.join(",") : void 0,
|
|
5425
|
+
name: params.name
|
|
5426
|
+
});
|
|
5427
|
+
const transformedListResponse = transform(listResponse).with(MCPListResponseSchema).using((raw) => ({
|
|
5428
|
+
currentPage: raw.current_page,
|
|
5429
|
+
totalPages: raw.total_pages,
|
|
5430
|
+
items: raw.items.map((item) => ({
|
|
5431
|
+
name: item.name,
|
|
5432
|
+
allowedTools: item.allowed_tools,
|
|
5433
|
+
id: item.id,
|
|
5434
|
+
authConfigIds: item.auth_config_ids,
|
|
5435
|
+
commands: item.commands,
|
|
5436
|
+
MCPUrl: item.mcp_url,
|
|
5437
|
+
toolkitIcons: item.toolkit_icons,
|
|
5438
|
+
serverInstanceCount: item.server_instance_count,
|
|
5439
|
+
toolkits: item.toolkits
|
|
5440
|
+
}))
|
|
5441
|
+
}));
|
|
5442
|
+
return transformedListResponse;
|
|
5443
|
+
}
|
|
5444
|
+
/**
|
|
5445
|
+
* Retrieve detailed information about a specific MCP server by its ID
|
|
5446
|
+
* @param {string} serverId - The unique identifier of the MCP server to retrieve
|
|
5447
|
+
* @returns {Promise<MCPItem>} Complete MCP server details including configuration, tools, and metadata
|
|
5448
|
+
*
|
|
5449
|
+
* @example
|
|
5450
|
+
* ```typescript
|
|
5451
|
+
* // Get a specific MCP server by ID
|
|
5452
|
+
* const server = await composio.experimental.mcp.get("mcp_12345");
|
|
5453
|
+
*
|
|
5454
|
+
* console.log(server.name); // "My Personal MCP Server"
|
|
5455
|
+
* console.log(server.allowedTools); // ["GITHUB_CREATE_ISSUE", "SLACK_SEND_MESSAGE"]
|
|
5456
|
+
* console.log(server.toolkits); // ["github", "slack"]
|
|
5457
|
+
* console.log(server.serverInstanceCount); // 3
|
|
5458
|
+
*
|
|
5459
|
+
* // Access setup commands for different clients
|
|
5460
|
+
* console.log(server.commands.claude); // Claude setup command
|
|
5461
|
+
* console.log(server.commands.cursor); // Cursor setup command
|
|
5462
|
+
* console.log(server.commands.windsurf); // Windsurf setup command
|
|
5463
|
+
*
|
|
5464
|
+
* // Use the MCP URL for direct connections
|
|
5465
|
+
* const mcpUrl = server.MCPUrl;
|
|
5466
|
+
* ```
|
|
5467
|
+
*
|
|
5468
|
+
* @throws {ValidationError} When the server ID is invalid or server not found
|
|
5469
|
+
*/
|
|
5470
|
+
async get(serverId) {
|
|
5471
|
+
const response = await this.client.mcp.retrieve(serverId);
|
|
5472
|
+
return transformMCPItemResponse(response);
|
|
5473
|
+
}
|
|
5474
|
+
/**
|
|
5475
|
+
* Delete an MCP server configuration permanently
|
|
5476
|
+
* @param {string} serverId - The unique identifier of the MCP server to delete
|
|
5477
|
+
* @returns {Promise<{id: string; deleted: boolean}>} Confirmation object with server ID and deletion status
|
|
5478
|
+
*
|
|
5479
|
+
* @example
|
|
5480
|
+
* ```typescript
|
|
5481
|
+
* // Delete an MCP server by ID
|
|
5482
|
+
* const result = await composio.experimental.mcp.delete("mcp_12345");
|
|
5483
|
+
*
|
|
5484
|
+
* if (result.deleted) {
|
|
5485
|
+
* console.log(`Server ${result.id} has been successfully deleted`);
|
|
5486
|
+
* } else {
|
|
5487
|
+
* console.log(`Failed to delete server ${result.id}`);
|
|
5488
|
+
* }
|
|
5489
|
+
*
|
|
5490
|
+
* // Example with error handling
|
|
5491
|
+
* try {
|
|
5492
|
+
* const result = await composio.experimental.mcp.delete("mcp_12345");
|
|
5493
|
+
* console.log("Deletion successful:", result);
|
|
5494
|
+
* } catch (error) {
|
|
5495
|
+
* console.error("Failed to delete MCP server:", error.message);
|
|
5496
|
+
* }
|
|
5497
|
+
*
|
|
5498
|
+
* // Delete and verify from list
|
|
5499
|
+
* await composio.experimental.mcp.delete("mcp_12345");
|
|
5500
|
+
* const servers = await composio.experimental.mcp.list({});
|
|
5501
|
+
* const serverExists = servers.items.some(server => server.id === "mcp_12345");
|
|
5502
|
+
* console.log("Server still exists:", serverExists); // Should be false
|
|
5503
|
+
* ```
|
|
5504
|
+
*
|
|
5505
|
+
* @throws {ValidationError} When the server ID is invalid or server not found
|
|
5506
|
+
* @throws {Error} When the server cannot be deleted due to active connections or other constraints
|
|
5507
|
+
*
|
|
5508
|
+
* @warning This operation is irreversible. Once deleted, the MCP server configuration and all its associated data will be permanently removed.
|
|
5509
|
+
*/
|
|
5510
|
+
async delete(serverId) {
|
|
5511
|
+
return await this.client.mcp.delete(serverId);
|
|
5512
|
+
}
|
|
5513
|
+
/**
|
|
5514
|
+
* Update an existing MCP server configuration with new settings
|
|
5515
|
+
* @param {string} serverId - The unique identifier of the MCP server to update
|
|
5516
|
+
* @param {Object} config - Update configuration parameters
|
|
5517
|
+
* @param {string} [config.name] - New name for the MCP server
|
|
5518
|
+
* @param {Array} [config.toolkits] - Updated toolkit configurations
|
|
5519
|
+
* @param {string} [config.toolkits[].toolkit] - Toolkit identifier (e.g., "github", "slack")
|
|
5520
|
+
* @param {string} [config.toolkits[].authConfigId] - Auth configuration ID for the toolkit
|
|
5521
|
+
* @param {string[]} [config.toolkits[].allowedTools] - Specific tools to enable for this toolkit
|
|
5522
|
+
* @param {boolean} [config.manuallyManageConnections] - Whether to manually manage account connections
|
|
5523
|
+
* @returns {Promise<MCPItem>} Updated MCP server configuration with all details
|
|
5524
|
+
*
|
|
5525
|
+
* @example
|
|
5526
|
+
* ```typescript
|
|
5527
|
+
* // Update server name only
|
|
5528
|
+
* const updatedServer = await composio.experimental.mcp.update("mcp_12345", {
|
|
5529
|
+
* name: "My Updated MCP Server"
|
|
5530
|
+
* });
|
|
5531
|
+
*
|
|
5532
|
+
* // Update toolkits and tools
|
|
5533
|
+
* const serverWithNewTools = await composio.experimental.mcp.update("mcp_12345", {
|
|
5534
|
+
* toolkits: [
|
|
5535
|
+
* {
|
|
5536
|
+
* toolkit: "github",
|
|
5537
|
+
* authConfigId: "auth_abc123",
|
|
5538
|
+
* allowedTools: ["GITHUB_CREATE_ISSUE", "GITHUB_LIST_REPOS"]
|
|
5539
|
+
* },
|
|
5540
|
+
* {
|
|
5541
|
+
* toolkit: "slack",
|
|
5542
|
+
* authConfigId: "auth_xyz789",
|
|
5543
|
+
* allowedTools: ["SLACK_SEND_MESSAGE", "SLACK_LIST_CHANNELS"]
|
|
5544
|
+
* }
|
|
5545
|
+
* ]
|
|
5546
|
+
* });
|
|
5547
|
+
*
|
|
5548
|
+
* // Update connection management setting
|
|
5549
|
+
* const serverWithManualAuth = await composio.experimental.mcp.update("mcp_12345", {
|
|
5550
|
+
* name: "Manual Auth Server",
|
|
5551
|
+
* manuallyManageConnections: true
|
|
5552
|
+
* });
|
|
5553
|
+
*
|
|
5554
|
+
* // Complete update example
|
|
5555
|
+
* const fullyUpdatedServer = await composio.experimental.mcp.update("mcp_12345", {
|
|
5556
|
+
* name: "Production MCP Server",
|
|
5557
|
+
* toolkits: [
|
|
5558
|
+
* {
|
|
5559
|
+
* toolkit: "gmail",
|
|
5560
|
+
* authConfigId: "auth_gmail_prod",
|
|
5561
|
+
* }
|
|
5562
|
+
* ],
|
|
5563
|
+
* allowedTools: ["GMAIL_SEND_EMAIL", "GMAIL_FETCH_EMAILS"]
|
|
5564
|
+
* manuallyManageConnections: false
|
|
5565
|
+
* });
|
|
5566
|
+
*
|
|
5567
|
+
* console.log("Updated server:", fullyUpdatedServer.name);
|
|
5568
|
+
* console.log("New tools:", fullyUpdatedServer.allowedTools);
|
|
5569
|
+
* ```
|
|
5570
|
+
*
|
|
5571
|
+
* @throws {ValidationError} When the update parameters are invalid or malformed
|
|
5572
|
+
* @throws {Error} When the server ID doesn't exist or update fails
|
|
5573
|
+
*
|
|
5574
|
+
* @note Only provided fields will be updated. Omitted fields will retain their current values.
|
|
5575
|
+
* @note When updating toolkits, the entire toolkit configuration is replaced, not merged.
|
|
5576
|
+
*/
|
|
5577
|
+
async update(serverId, config) {
|
|
5578
|
+
const { data: params, error } = MCPUpdateParamsSchema.safeParse(config);
|
|
5579
|
+
if (error) {
|
|
5580
|
+
throw new ValidationError("Failed to validate update params", {
|
|
5581
|
+
cause: error
|
|
5582
|
+
});
|
|
5583
|
+
}
|
|
5584
|
+
const toolkits = [];
|
|
5585
|
+
const auth_config_ids = [];
|
|
5586
|
+
const custom_tools = params.allowedTools ?? void 0;
|
|
5587
|
+
params.toolkits?.forEach((toolkit) => {
|
|
5588
|
+
if (typeof toolkit === "string") {
|
|
5589
|
+
toolkits.push(toolkit);
|
|
5590
|
+
} else if (toolkit.toolkit) {
|
|
5591
|
+
toolkits.push(toolkit.toolkit);
|
|
5592
|
+
} else if (toolkit.authConfigId) {
|
|
5593
|
+
auth_config_ids.push(toolkit.authConfigId);
|
|
5594
|
+
}
|
|
5595
|
+
});
|
|
5596
|
+
const response = await this.client.mcp.update(serverId, {
|
|
5597
|
+
...{ name: params.name ?? void 0 },
|
|
5598
|
+
...params.toolkits ? {
|
|
5599
|
+
custom_tools,
|
|
5600
|
+
toolkits,
|
|
5601
|
+
auth_config_ids
|
|
5602
|
+
} : {},
|
|
5603
|
+
...{ managed_auth_via_composio: params.manuallyManageConnections ?? void 0 }
|
|
5604
|
+
});
|
|
5605
|
+
return transformMCPItemResponse(response);
|
|
5606
|
+
}
|
|
5607
|
+
/**
|
|
5608
|
+
* Get server URLs for an existing MCP server.
|
|
5609
|
+
* The response is wrapped according to the provider's specifications.
|
|
5610
|
+
*
|
|
5611
|
+
* @example
|
|
5612
|
+
* ```typescript
|
|
5613
|
+
* import { Composio } from "@composio/code";
|
|
5614
|
+
*
|
|
5615
|
+
* const composio = new Composio();
|
|
5616
|
+
* const mcp = await composio.experimental.mcp.generate("default", "<mcp_config_id>");
|
|
5617
|
+
* ```
|
|
5618
|
+
*
|
|
5619
|
+
* @param userId {string} external user id from your database for whom you want the server for
|
|
5620
|
+
* @param mcpConfigId {string} config id of the MCPConfig for which you want to create a server for
|
|
5621
|
+
* @param options {object} additional options
|
|
5622
|
+
* @param options.isChatAuth {boolean} Authenticate the users via chat when they use the MCP Server
|
|
5623
|
+
*/
|
|
5624
|
+
async generate(userId, mcpConfigId, options) {
|
|
5625
|
+
const server = await this.client.mcp.retrieve(mcpConfigId);
|
|
5626
|
+
const params = MCPGetInstanceParamsSchema.safeParse(
|
|
5627
|
+
options ?? { manuallyManageConnections: false }
|
|
5628
|
+
);
|
|
5629
|
+
if (params.error) {
|
|
5630
|
+
throw new ValidationError("Invalid params passed for Get Instance Params", {
|
|
5631
|
+
cause: params.error
|
|
5632
|
+
});
|
|
5633
|
+
}
|
|
5634
|
+
const urlResponse = await this.client.mcp.generate.url({
|
|
5635
|
+
mcp_server_id: mcpConfigId,
|
|
5636
|
+
user_ids: [userId],
|
|
5637
|
+
managed_auth_by_composio: options?.manuallyManageConnections ? false : true
|
|
5638
|
+
});
|
|
5639
|
+
const userIdsURL = urlResponse.user_ids_url[0];
|
|
5640
|
+
const serverInstance = MCPServerInstanceSchema.safeParse({
|
|
5641
|
+
id: server.id,
|
|
5642
|
+
name: server.name,
|
|
5643
|
+
type: "streamable_http",
|
|
5644
|
+
url: userIdsURL,
|
|
5645
|
+
userId,
|
|
5646
|
+
allowedTools: server.allowed_tools,
|
|
5647
|
+
authConfigs: server.auth_config_ids
|
|
5648
|
+
});
|
|
5649
|
+
if (serverInstance.error) {
|
|
5650
|
+
throw new ValidationError("Failed to parse MCP server instance", {
|
|
5651
|
+
cause: serverInstance.error
|
|
5652
|
+
});
|
|
5653
|
+
}
|
|
5654
|
+
return serverInstance.data;
|
|
5655
|
+
}
|
|
5656
|
+
};
|
|
5657
|
+
|
|
5097
5658
|
// src/types/mcp.types.ts
|
|
5098
|
-
import { z as
|
|
5099
|
-
var MCPToolkitConfigSchema =
|
|
5100
|
-
toolkit:
|
|
5101
|
-
authConfigId:
|
|
5102
|
-
allowedTools:
|
|
5659
|
+
import { z as z9 } from "zod";
|
|
5660
|
+
var MCPToolkitConfigSchema = z9.object({
|
|
5661
|
+
toolkit: z9.string().min(1, "Toolkit name cannot be empty"),
|
|
5662
|
+
authConfigId: z9.string().min(1, "Auth config ID cannot be empty"),
|
|
5663
|
+
allowedTools: z9.array(z9.string().min(1, "Tool name cannot be empty")).min(1, "At least one tool must be specified")
|
|
5103
5664
|
});
|
|
5104
|
-
var MCPToolkitConfigsArraySchema =
|
|
5665
|
+
var MCPToolkitConfigsArraySchema = z9.array(MCPToolkitConfigSchema).min(1, "At least one toolkit configuration is required").refine((configs) => {
|
|
5105
5666
|
const toolkits = configs.map((config) => config.toolkit);
|
|
5106
5667
|
const uniqueToolkits = new Set(toolkits);
|
|
5107
5668
|
return uniqueToolkits.size === toolkits.length;
|
|
5108
5669
|
}, "Duplicate toolkits are not allowed. Each toolkit must be unique.");
|
|
5109
|
-
var MCPAuthOptionsSchema =
|
|
5110
|
-
isChatAuth:
|
|
5670
|
+
var MCPAuthOptionsSchema = z9.object({
|
|
5671
|
+
isChatAuth: z9.boolean().optional()
|
|
5111
5672
|
});
|
|
5112
|
-
var MCPGetServerParamsSchema =
|
|
5113
|
-
userId:
|
|
5114
|
-
connectedAccountIds:
|
|
5673
|
+
var MCPGetServerParamsSchema = z9.object({
|
|
5674
|
+
userId: z9.string().min(1, "User ID cannot be empty").optional(),
|
|
5675
|
+
connectedAccountIds: z9.record(z9.string(), z9.string().min(1, "Account ID cannot be empty")).optional()
|
|
5115
5676
|
}).refine(
|
|
5116
5677
|
(data) => {
|
|
5117
5678
|
const hasUserId = !!data.userId;
|
|
@@ -5122,61 +5683,61 @@ var MCPGetServerParamsSchema = z8.object({
|
|
|
5122
5683
|
message: "Must provide either userId or connectedAccountIds, but not both"
|
|
5123
5684
|
}
|
|
5124
5685
|
);
|
|
5125
|
-
var MCPGenerateURLParamsSchema =
|
|
5126
|
-
userIds:
|
|
5127
|
-
connectedAccountIds:
|
|
5128
|
-
isChatAuth:
|
|
5686
|
+
var MCPGenerateURLParamsSchema = z9.object({
|
|
5687
|
+
userIds: z9.array(z9.string()).optional(),
|
|
5688
|
+
connectedAccountIds: z9.array(z9.string()).optional(),
|
|
5689
|
+
isChatAuth: z9.boolean().optional()
|
|
5129
5690
|
});
|
|
5130
|
-
var ComposioGenerateURLParamsSchema =
|
|
5131
|
-
user_ids:
|
|
5132
|
-
connected_account_ids:
|
|
5133
|
-
mcp_server_id:
|
|
5134
|
-
managed_auth_by_composio:
|
|
5691
|
+
var ComposioGenerateURLParamsSchema = z9.object({
|
|
5692
|
+
user_ids: z9.array(z9.string()).optional(),
|
|
5693
|
+
connected_account_ids: z9.array(z9.string()).optional(),
|
|
5694
|
+
mcp_server_id: z9.string(),
|
|
5695
|
+
managed_auth_by_composio: z9.boolean().optional()
|
|
5135
5696
|
});
|
|
5136
|
-
var GenerateURLParamsSchema =
|
|
5137
|
-
userIds:
|
|
5138
|
-
connectedAccountIds:
|
|
5139
|
-
mcpServerId:
|
|
5140
|
-
composioManagedAuth:
|
|
5697
|
+
var GenerateURLParamsSchema = z9.object({
|
|
5698
|
+
userIds: z9.array(z9.string()).optional(),
|
|
5699
|
+
connectedAccountIds: z9.array(z9.string()).optional(),
|
|
5700
|
+
mcpServerId: z9.string(),
|
|
5701
|
+
composioManagedAuth: z9.boolean().optional()
|
|
5141
5702
|
});
|
|
5142
|
-
var GenerateURLResponseSchema =
|
|
5143
|
-
connectedAccountUrls:
|
|
5144
|
-
userIdsUrl:
|
|
5145
|
-
mcpUrl:
|
|
5703
|
+
var GenerateURLResponseSchema = z9.object({
|
|
5704
|
+
connectedAccountUrls: z9.array(z9.string()).optional(),
|
|
5705
|
+
userIdsUrl: z9.array(z9.string()).optional(),
|
|
5706
|
+
mcpUrl: z9.string().min(1, "MCP URL cannot be empty")
|
|
5146
5707
|
});
|
|
5147
|
-
var ComposioGenerateURLResponseSchema =
|
|
5148
|
-
connected_account_urls:
|
|
5149
|
-
user_ids_url:
|
|
5150
|
-
mcp_url:
|
|
5708
|
+
var ComposioGenerateURLResponseSchema = z9.object({
|
|
5709
|
+
connected_account_urls: z9.array(z9.string()).optional(),
|
|
5710
|
+
user_ids_url: z9.array(z9.string()).optional(),
|
|
5711
|
+
mcp_url: z9.string().min(1, "MCP URL cannot be empty")
|
|
5151
5712
|
});
|
|
5152
|
-
var MCPSingleAppServerSchema =
|
|
5153
|
-
name:
|
|
5154
|
-
tools:
|
|
5155
|
-
authConfigId:
|
|
5713
|
+
var MCPSingleAppServerSchema = z9.object({
|
|
5714
|
+
name: z9.string().describe("Name of the MCP server"),
|
|
5715
|
+
tools: z9.array(z9.string()).describe("List of allowed tools"),
|
|
5716
|
+
authConfigId: z9.string().optional().describe("Auth config ID for the server")
|
|
5156
5717
|
});
|
|
5157
|
-
var MCPMultiAppServerSchema =
|
|
5158
|
-
name:
|
|
5159
|
-
tools:
|
|
5160
|
-
toolkits:
|
|
5718
|
+
var MCPMultiAppServerSchema = z9.object({
|
|
5719
|
+
name: z9.string().describe("Name of the MCP server"),
|
|
5720
|
+
tools: z9.array(z9.string()).describe("List of allowed tools across toolkits"),
|
|
5721
|
+
toolkits: z9.array(z9.string()).describe("List of allowed toolkits")
|
|
5161
5722
|
});
|
|
5162
|
-
var MCPServerSchema =
|
|
5163
|
-
id:
|
|
5164
|
-
type:
|
|
5165
|
-
createdAt:
|
|
5166
|
-
updatedAt:
|
|
5167
|
-
status:
|
|
5168
|
-
config:
|
|
5723
|
+
var MCPServerSchema = z9.object({
|
|
5724
|
+
id: z9.string().describe("Unique identifier for the MCP server"),
|
|
5725
|
+
type: z9.enum(["single", "multi"]).describe("Type of MCP server"),
|
|
5726
|
+
createdAt: z9.string().describe("Creation timestamp"),
|
|
5727
|
+
updatedAt: z9.string().describe("Last update timestamp"),
|
|
5728
|
+
status: z9.enum(["active", "inactive", "error"]).default("active"),
|
|
5729
|
+
config: z9.union([MCPSingleAppServerSchema, MCPMultiAppServerSchema])
|
|
5169
5730
|
});
|
|
5170
|
-
var MCPServerListResponseSchema =
|
|
5171
|
-
items:
|
|
5172
|
-
total:
|
|
5173
|
-
page:
|
|
5174
|
-
pageSize:
|
|
5731
|
+
var MCPServerListResponseSchema = z9.object({
|
|
5732
|
+
items: z9.array(MCPServerSchema),
|
|
5733
|
+
total: z9.number(),
|
|
5734
|
+
page: z9.number(),
|
|
5735
|
+
pageSize: z9.number()
|
|
5175
5736
|
});
|
|
5176
|
-
var MCPServerUpdateParamsSchema =
|
|
5177
|
-
name:
|
|
5178
|
-
toolkits:
|
|
5179
|
-
allowedTools:
|
|
5737
|
+
var MCPServerUpdateParamsSchema = z9.object({
|
|
5738
|
+
name: z9.string().optional().describe("New name for the server"),
|
|
5739
|
+
toolkits: z9.array(z9.string()).optional().describe("Updated list of toolkits"),
|
|
5740
|
+
allowedTools: z9.array(z9.string()).optional().describe("Updated list of allowed tools")
|
|
5180
5741
|
});
|
|
5181
5742
|
var MCPServerCreateResponseSchema = MCPServerSchema;
|
|
5182
5743
|
var ConnectionStatus = /* @__PURE__ */ ((ConnectionStatus2) => {
|
|
@@ -5184,96 +5745,96 @@ var ConnectionStatus = /* @__PURE__ */ ((ConnectionStatus2) => {
|
|
|
5184
5745
|
ConnectionStatus2["DISCONNECTED"] = "DISCONNECTED";
|
|
5185
5746
|
return ConnectionStatus2;
|
|
5186
5747
|
})(ConnectionStatus || {});
|
|
5187
|
-
var CustomCreateResponseSchema =
|
|
5188
|
-
id:
|
|
5189
|
-
name:
|
|
5190
|
-
createdAt:
|
|
5191
|
-
updatedAt:
|
|
5192
|
-
status:
|
|
5748
|
+
var CustomCreateResponseSchema = z9.object({
|
|
5749
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5750
|
+
name: z9.string().min(1, "Server name cannot be empty"),
|
|
5751
|
+
createdAt: z9.string().nullish(),
|
|
5752
|
+
updatedAt: z9.string().nullish(),
|
|
5753
|
+
status: z9.string().nullish()
|
|
5193
5754
|
});
|
|
5194
|
-
var ComposioCustomCreateResponseSchema =
|
|
5195
|
-
id:
|
|
5196
|
-
name:
|
|
5197
|
-
created_at:
|
|
5198
|
-
updated_at:
|
|
5199
|
-
status:
|
|
5755
|
+
var ComposioCustomCreateResponseSchema = z9.object({
|
|
5756
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5757
|
+
name: z9.string().min(1, "Server name cannot be empty"),
|
|
5758
|
+
created_at: z9.string().nullish(),
|
|
5759
|
+
updated_at: z9.string().nullish(),
|
|
5760
|
+
status: z9.string().nullish()
|
|
5200
5761
|
});
|
|
5201
|
-
var McpListResponseSchema =
|
|
5202
|
-
items:
|
|
5203
|
-
|
|
5204
|
-
id:
|
|
5205
|
-
name:
|
|
5206
|
-
createdAt:
|
|
5207
|
-
updatedAt:
|
|
5208
|
-
status:
|
|
5762
|
+
var McpListResponseSchema = z9.object({
|
|
5763
|
+
items: z9.array(
|
|
5764
|
+
z9.object({
|
|
5765
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5766
|
+
name: z9.string().min(1, "Server name cannot be empty"),
|
|
5767
|
+
createdAt: z9.string().optional(),
|
|
5768
|
+
updatedAt: z9.string().optional(),
|
|
5769
|
+
status: z9.string().optional()
|
|
5209
5770
|
})
|
|
5210
5771
|
).optional()
|
|
5211
5772
|
});
|
|
5212
|
-
var ComposioMcpListResponseSchema =
|
|
5213
|
-
items:
|
|
5214
|
-
|
|
5215
|
-
id:
|
|
5216
|
-
name:
|
|
5217
|
-
created_at:
|
|
5218
|
-
updated_at:
|
|
5219
|
-
status:
|
|
5773
|
+
var ComposioMcpListResponseSchema = z9.object({
|
|
5774
|
+
items: z9.array(
|
|
5775
|
+
z9.object({
|
|
5776
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5777
|
+
name: z9.string().min(1, "Server name cannot be empty"),
|
|
5778
|
+
created_at: z9.string().optional(),
|
|
5779
|
+
updated_at: z9.string().optional(),
|
|
5780
|
+
status: z9.string().optional()
|
|
5220
5781
|
})
|
|
5221
5782
|
).optional()
|
|
5222
5783
|
});
|
|
5223
|
-
var McpRetrieveResponseSchema =
|
|
5224
|
-
id:
|
|
5225
|
-
name:
|
|
5226
|
-
createdAt:
|
|
5227
|
-
updatedAt:
|
|
5228
|
-
status:
|
|
5229
|
-
toolkits:
|
|
5230
|
-
tools:
|
|
5231
|
-
managedAuthViaComposio:
|
|
5232
|
-
authConfigIds:
|
|
5233
|
-
mcpUrl:
|
|
5234
|
-
commands:
|
|
5235
|
-
claude:
|
|
5236
|
-
cursor:
|
|
5237
|
-
windsurf:
|
|
5784
|
+
var McpRetrieveResponseSchema = z9.object({
|
|
5785
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5786
|
+
name: z9.string().min(1, "Server name cannot be empty"),
|
|
5787
|
+
createdAt: z9.string().optional(),
|
|
5788
|
+
updatedAt: z9.string().optional(),
|
|
5789
|
+
status: z9.string().optional(),
|
|
5790
|
+
toolkits: z9.array(z9.string()).optional(),
|
|
5791
|
+
tools: z9.array(z9.string()).optional(),
|
|
5792
|
+
managedAuthViaComposio: z9.boolean().optional(),
|
|
5793
|
+
authConfigIds: z9.array(z9.string()).optional(),
|
|
5794
|
+
mcpUrl: z9.string(),
|
|
5795
|
+
commands: z9.object({
|
|
5796
|
+
claude: z9.string(),
|
|
5797
|
+
cursor: z9.string(),
|
|
5798
|
+
windsurf: z9.string()
|
|
5238
5799
|
})
|
|
5239
5800
|
});
|
|
5240
|
-
var ComposioMcpRetrieveResponseSchema =
|
|
5241
|
-
id:
|
|
5242
|
-
name:
|
|
5243
|
-
created_at:
|
|
5244
|
-
updated_at:
|
|
5245
|
-
status:
|
|
5246
|
-
toolkits:
|
|
5247
|
-
tools:
|
|
5248
|
-
managed_auth_via_composio:
|
|
5801
|
+
var ComposioMcpRetrieveResponseSchema = z9.object({
|
|
5802
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5803
|
+
name: z9.string().min(1, "Server name cannot be empty"),
|
|
5804
|
+
created_at: z9.string().optional(),
|
|
5805
|
+
updated_at: z9.string().optional(),
|
|
5806
|
+
status: z9.string().optional(),
|
|
5807
|
+
toolkits: z9.array(z9.string()).optional(),
|
|
5808
|
+
tools: z9.array(z9.string()).optional(),
|
|
5809
|
+
managed_auth_via_composio: z9.boolean().optional()
|
|
5249
5810
|
});
|
|
5250
|
-
var McpDeleteResponseSchema =
|
|
5251
|
-
id:
|
|
5252
|
-
deleted:
|
|
5253
|
-
message:
|
|
5811
|
+
var McpDeleteResponseSchema = z9.object({
|
|
5812
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5813
|
+
deleted: z9.boolean().optional(),
|
|
5814
|
+
message: z9.string().optional()
|
|
5254
5815
|
});
|
|
5255
|
-
var ComposioMcpDeleteResponseSchema =
|
|
5256
|
-
id:
|
|
5257
|
-
deleted:
|
|
5258
|
-
message:
|
|
5816
|
+
var ComposioMcpDeleteResponseSchema = z9.object({
|
|
5817
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5818
|
+
deleted: z9.boolean().optional(),
|
|
5819
|
+
message: z9.string().optional()
|
|
5259
5820
|
});
|
|
5260
|
-
var McpUpdateResponseSchema =
|
|
5261
|
-
id:
|
|
5262
|
-
name:
|
|
5263
|
-
createdAt:
|
|
5264
|
-
updatedAt:
|
|
5265
|
-
status:
|
|
5266
|
-
toolkits:
|
|
5267
|
-
tools:
|
|
5821
|
+
var McpUpdateResponseSchema = z9.object({
|
|
5822
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5823
|
+
name: z9.string().min(1, "Server name cannot be empty"),
|
|
5824
|
+
createdAt: z9.string().optional(),
|
|
5825
|
+
updatedAt: z9.string().optional(),
|
|
5826
|
+
status: z9.string().optional(),
|
|
5827
|
+
toolkits: z9.array(z9.string()).optional(),
|
|
5828
|
+
tools: z9.array(z9.string()).optional()
|
|
5268
5829
|
});
|
|
5269
|
-
var ComposioMcpUpdateResponseSchema =
|
|
5270
|
-
id:
|
|
5271
|
-
name:
|
|
5272
|
-
created_at:
|
|
5273
|
-
updated_at:
|
|
5274
|
-
status:
|
|
5275
|
-
toolkits:
|
|
5276
|
-
tools:
|
|
5830
|
+
var ComposioMcpUpdateResponseSchema = z9.object({
|
|
5831
|
+
id: z9.string().min(1, "Server ID cannot be empty"),
|
|
5832
|
+
name: z9.string().min(1, "Server name cannot be empty"),
|
|
5833
|
+
created_at: z9.string().optional(),
|
|
5834
|
+
updated_at: z9.string().optional(),
|
|
5835
|
+
status: z9.string().optional(),
|
|
5836
|
+
toolkits: z9.array(z9.string()).optional(),
|
|
5837
|
+
tools: z9.array(z9.string()).optional()
|
|
5277
5838
|
});
|
|
5278
5839
|
|
|
5279
5840
|
// src/utils/transformers/mcp.ts
|
|
@@ -5376,10 +5937,10 @@ function transformMcpGenerateUrlResponse(response) {
|
|
|
5376
5937
|
}
|
|
5377
5938
|
|
|
5378
5939
|
// src/models/MCP.ts
|
|
5379
|
-
var
|
|
5940
|
+
var MCP2 = class {
|
|
5380
5941
|
client;
|
|
5381
|
-
provider;
|
|
5382
5942
|
toolkits;
|
|
5943
|
+
provider;
|
|
5383
5944
|
constructor(client, provider) {
|
|
5384
5945
|
this.client = client;
|
|
5385
5946
|
this.provider = provider;
|
|
@@ -5416,7 +5977,7 @@ var MCP = class {
|
|
|
5416
5977
|
* @param {Object} params.options - Server creation options
|
|
5417
5978
|
* @param {string} params.options.name - Unique name for the MCP server
|
|
5418
5979
|
* @param {boolean} [params.options.isChatAuth] - Whether to use chat-based authentication
|
|
5419
|
-
* @returns {Promise<McpServerCreateResponse<
|
|
5980
|
+
* @returns {Promise<McpServerCreateResponse<TMcpResponse>>} Created server details with instance getter
|
|
5420
5981
|
*
|
|
5421
5982
|
* @example
|
|
5422
5983
|
* ```typescript
|
|
@@ -5679,7 +6240,7 @@ var MCP = class {
|
|
|
5679
6240
|
* @param {Object} [options] - Additional options for server configuration
|
|
5680
6241
|
* @param {string[]} [options.limitTools] - Subset of tools to limit (from MCP config)
|
|
5681
6242
|
* @param {boolean} [options.isChatAuth] - Whether to use chat-based authentication
|
|
5682
|
-
* @returns {Promise<
|
|
6243
|
+
* @returns {Promise<TMcpResponse>} Transformed server URLs in provider-specific format
|
|
5683
6244
|
*
|
|
5684
6245
|
* @example
|
|
5685
6246
|
* ```typescript
|
|
@@ -5692,6 +6253,7 @@ var MCP = class {
|
|
|
5692
6253
|
* isChatAuth: true
|
|
5693
6254
|
* });
|
|
5694
6255
|
* ```
|
|
6256
|
+
*
|
|
5695
6257
|
*/
|
|
5696
6258
|
async getServer(serverId, userId, options) {
|
|
5697
6259
|
const serverDetails = await this.get(serverId);
|
|
@@ -5945,6 +6507,7 @@ var MCP = class {
|
|
|
5945
6507
|
* @param serverName - Name of the MCP server
|
|
5946
6508
|
|
|
5947
6509
|
* @returns Transformed response in appropriate format
|
|
6510
|
+
* @deprecated
|
|
5948
6511
|
*/
|
|
5949
6512
|
wrapMcpServerResponse(data, serverName, connectedAccountIds, userIds, toolkits) {
|
|
5950
6513
|
if (this.provider && typeof this.provider.wrapMcpServerResponse === "function") {
|
|
@@ -5970,6 +6533,7 @@ var MCP = class {
|
|
|
5970
6533
|
const transformed = this.provider.wrapMcpServerResponse(snakeCaseData);
|
|
5971
6534
|
return transformed;
|
|
5972
6535
|
}
|
|
6536
|
+
const self = this;
|
|
5973
6537
|
if (connectedAccountIds?.length && data.connectedAccountUrls) {
|
|
5974
6538
|
return data.connectedAccountUrls.map((url, index) => ({
|
|
5975
6539
|
url: new URL(url),
|
|
@@ -6067,6 +6631,31 @@ function getSDKConfig(baseUrl, apiKey) {
|
|
|
6067
6631
|
logger_default.debug("Environment", `Base URL: ${baseURLParsed}`);
|
|
6068
6632
|
return { baseURL: baseURLParsed, apiKey: apiKeyParsed };
|
|
6069
6633
|
}
|
|
6634
|
+
function getToolkitVersionsFromEnv(defaultVersions) {
|
|
6635
|
+
if (defaultVersions && typeof defaultVersions === "string") {
|
|
6636
|
+
return defaultVersions;
|
|
6637
|
+
}
|
|
6638
|
+
const envPrefixedVersions = getEnvsWithPrefix(`COMPOSIO_TOOLKIT_VERSION_`);
|
|
6639
|
+
const toolkitVersionsFromEnv = Object.entries(envPrefixedVersions).reduce((acc, [key, value]) => {
|
|
6640
|
+
const toolkitName = key.replace("COMPOSIO_TOOLKIT_VERSION_", "");
|
|
6641
|
+
acc[toolkitName.toLowerCase()] = value;
|
|
6642
|
+
return acc;
|
|
6643
|
+
}, {});
|
|
6644
|
+
let userProvidedToolkitVersions = {};
|
|
6645
|
+
if (defaultVersions && typeof defaultVersions === "object") {
|
|
6646
|
+
userProvidedToolkitVersions = Object.fromEntries(
|
|
6647
|
+
Object.entries(defaultVersions).map(([key, value]) => [key.toLowerCase(), value])
|
|
6648
|
+
);
|
|
6649
|
+
}
|
|
6650
|
+
const toolkitVersions = {
|
|
6651
|
+
...toolkitVersionsFromEnv,
|
|
6652
|
+
...userProvidedToolkitVersions
|
|
6653
|
+
};
|
|
6654
|
+
if (Object.keys(toolkitVersions).length === 0) {
|
|
6655
|
+
return "latest";
|
|
6656
|
+
}
|
|
6657
|
+
return toolkitVersions;
|
|
6658
|
+
}
|
|
6070
6659
|
|
|
6071
6660
|
// src/utils/version.ts
|
|
6072
6661
|
import semver from "semver";
|
|
@@ -6588,7 +7177,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
6588
7177
|
};
|
|
6589
7178
|
|
|
6590
7179
|
// package.json
|
|
6591
|
-
var version = "0.1.
|
|
7180
|
+
var version = "0.1.53";
|
|
6592
7181
|
|
|
6593
7182
|
// src/models/Files.ts
|
|
6594
7183
|
var Files = class {
|
|
@@ -6646,6 +7235,82 @@ var getDefaultHeaders = (headers, provider) => {
|
|
|
6646
7235
|
};
|
|
6647
7236
|
};
|
|
6648
7237
|
|
|
7238
|
+
// src/types/toolRouter.types.ts
|
|
7239
|
+
import z10 from "zod";
|
|
7240
|
+
var ToolRouterToolkitConfigSchema = z10.object({
|
|
7241
|
+
toolkit: z10.string(),
|
|
7242
|
+
authConfigId: z10.string().optional()
|
|
7243
|
+
});
|
|
7244
|
+
var ToolRouterConfigSchema = z10.object({
|
|
7245
|
+
toolkits: z10.array(z10.union([z10.string(), ToolRouterToolkitConfigSchema])).optional(),
|
|
7246
|
+
manuallyManageConnections: z10.boolean().optional()
|
|
7247
|
+
});
|
|
7248
|
+
var ToolRouterSessionSchema = z10.object({
|
|
7249
|
+
sessionId: z10.string(),
|
|
7250
|
+
url: z10.string()
|
|
7251
|
+
});
|
|
7252
|
+
|
|
7253
|
+
// src/models/ToolRouter.experimental.ts
|
|
7254
|
+
var ToolRouter = class {
|
|
7255
|
+
constructor(client) {
|
|
7256
|
+
this.client = client;
|
|
7257
|
+
this.client = client;
|
|
7258
|
+
telemetry.instrument(this);
|
|
7259
|
+
}
|
|
7260
|
+
/**
|
|
7261
|
+
* Creates a new Session for the tool router
|
|
7262
|
+
*
|
|
7263
|
+
* @param userId {string} The user id to create the session for
|
|
7264
|
+
* @param routerConfig {ToolRouterConfig} The router config to use
|
|
7265
|
+
* @returns {Promise<ToolRouterSession>} The tool router session
|
|
7266
|
+
*
|
|
7267
|
+
* @example
|
|
7268
|
+
* ```typescript
|
|
7269
|
+
* import { Composio } form "@composio/core"
|
|
7270
|
+
*
|
|
7271
|
+
* const composio = new Composio()
|
|
7272
|
+
* const userId = "xxx-ooo-xxxx"
|
|
7273
|
+
*
|
|
7274
|
+
* const mcpSession = await composio.experimental.toolRouter.createSession(userId, {
|
|
7275
|
+
* toolkits: ["github", "hackernews", "slack"]
|
|
7276
|
+
* })
|
|
7277
|
+
*
|
|
7278
|
+
* // with auth configs
|
|
7279
|
+
* const mcpSession = await composio.experimental.toolRouter.createSession(userId, {
|
|
7280
|
+
* toolkits: [{ toolkit: "github", authConfingId: "ac_123455344"}]
|
|
7281
|
+
* ```
|
|
7282
|
+
*/
|
|
7283
|
+
async createSession(userId, routerConfig) {
|
|
7284
|
+
const config = ToolRouterConfigSchema.safeParse(routerConfig ?? {});
|
|
7285
|
+
if (config.error) {
|
|
7286
|
+
throw new ValidationError("Failed to parse tool router config", {
|
|
7287
|
+
cause: config.error
|
|
7288
|
+
});
|
|
7289
|
+
}
|
|
7290
|
+
const toolkitConfig = config.data.toolkits?.map((config2) => {
|
|
7291
|
+
if (typeof config2 === "string") {
|
|
7292
|
+
return { toolkit: config2 };
|
|
7293
|
+
} else {
|
|
7294
|
+
return {
|
|
7295
|
+
toolkit: config2.toolkit,
|
|
7296
|
+
auth_config_id: config2.authConfigId
|
|
7297
|
+
};
|
|
7298
|
+
}
|
|
7299
|
+
});
|
|
7300
|
+
const session = await this.client.toolRouter.createSession({
|
|
7301
|
+
user_id: userId,
|
|
7302
|
+
config: {
|
|
7303
|
+
toolkits: toolkitConfig,
|
|
7304
|
+
manually_manage_connections: config.data.manuallyManageConnections
|
|
7305
|
+
}
|
|
7306
|
+
});
|
|
7307
|
+
return transform(session).with(ToolRouterSessionSchema).using((raw) => ({
|
|
7308
|
+
sessionId: raw.session_id,
|
|
7309
|
+
url: raw.chat_session_mcp_url
|
|
7310
|
+
}));
|
|
7311
|
+
}
|
|
7312
|
+
};
|
|
7313
|
+
|
|
6649
7314
|
// src/composio.ts
|
|
6650
7315
|
var Composio = class _Composio {
|
|
6651
7316
|
/**
|
|
@@ -6666,11 +7331,17 @@ var Composio = class _Composio {
|
|
|
6666
7331
|
triggers;
|
|
6667
7332
|
provider;
|
|
6668
7333
|
files;
|
|
6669
|
-
// auth configs
|
|
6670
7334
|
authConfigs;
|
|
6671
|
-
// connected accounts
|
|
6672
7335
|
connectedAccounts;
|
|
6673
7336
|
mcp;
|
|
7337
|
+
/**
|
|
7338
|
+
* Experimental features
|
|
7339
|
+
*/
|
|
7340
|
+
experimental;
|
|
7341
|
+
/**
|
|
7342
|
+
* Deprecated features
|
|
7343
|
+
*/
|
|
7344
|
+
deprecated;
|
|
6674
7345
|
/**
|
|
6675
7346
|
* Creates a new instance of the Composio SDK.
|
|
6676
7347
|
*
|
|
@@ -6711,7 +7382,11 @@ var Composio = class _Composio {
|
|
|
6711
7382
|
}
|
|
6712
7383
|
this.config = {
|
|
6713
7384
|
...config,
|
|
6714
|
-
|
|
7385
|
+
baseURL: baseURLParsed,
|
|
7386
|
+
apiKey: apiKeyParsed,
|
|
7387
|
+
toolkitVersions: getToolkitVersionsFromEnv(config?.toolkitVersions),
|
|
7388
|
+
allowTracking: config?.allowTracking ?? true,
|
|
7389
|
+
autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? true
|
|
6715
7390
|
};
|
|
6716
7391
|
this.provider = config?.provider ?? new OpenAIProvider();
|
|
6717
7392
|
const defaultHeaders = getDefaultHeaders(this.config.defaultHeaders, this.provider);
|
|
@@ -6721,15 +7396,28 @@ var Composio = class _Composio {
|
|
|
6721
7396
|
defaultHeaders,
|
|
6722
7397
|
logLevel: COMPOSIO_LOG_LEVEL
|
|
6723
7398
|
});
|
|
6724
|
-
this.tools = new Tools(this.client, this.provider,
|
|
6725
|
-
|
|
6726
|
-
});
|
|
6727
|
-
this.mcp = new MCP(this.client, this.provider);
|
|
7399
|
+
this.tools = new Tools(this.client, this.provider, this.config);
|
|
7400
|
+
this.mcp = new MCP(this.client);
|
|
6728
7401
|
this.toolkits = new Toolkits(this.client);
|
|
6729
7402
|
this.triggers = new Triggers(this.client);
|
|
6730
7403
|
this.authConfigs = new AuthConfigs(this.client);
|
|
6731
7404
|
this.files = new Files(this.client);
|
|
6732
7405
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
7406
|
+
this.experimental = {
|
|
7407
|
+
/**
|
|
7408
|
+
* Experimental tool router
|
|
7409
|
+
* Helps you create a single MCP server containing all the tools with smart routing.
|
|
7410
|
+
*
|
|
7411
|
+
* @description Allows you to create an isolated toolRouter MCP session for a user
|
|
7412
|
+
*/
|
|
7413
|
+
toolRouter: new ToolRouter(this.client)
|
|
7414
|
+
};
|
|
7415
|
+
this.deprecated = {
|
|
7416
|
+
/**
|
|
7417
|
+
* @deprecated this feature will be removed soon, use `composio.mcp`
|
|
7418
|
+
*/
|
|
7419
|
+
mcp: new MCP2(this.client, this.provider)
|
|
7420
|
+
};
|
|
6733
7421
|
if (this.config.allowTracking) {
|
|
6734
7422
|
telemetry.setup({
|
|
6735
7423
|
apiKey: apiKeyParsed ?? "",
|
|
@@ -6757,6 +7445,13 @@ var Composio = class _Composio {
|
|
|
6757
7445
|
}
|
|
6758
7446
|
return this.client;
|
|
6759
7447
|
}
|
|
7448
|
+
/**
|
|
7449
|
+
* Get the configuration SDK is initialized with
|
|
7450
|
+
* @returns {ComposioConfig<TProvider>} The configuration SDK is initialized with
|
|
7451
|
+
*/
|
|
7452
|
+
getConfig() {
|
|
7453
|
+
return this.config;
|
|
7454
|
+
}
|
|
6760
7455
|
/**
|
|
6761
7456
|
* Creates a new instance of the Composio SDK with custom request options while preserving the existing configuration.
|
|
6762
7457
|
* This method is particularly useful when you need to:
|
|
@@ -7061,7 +7756,7 @@ export {
|
|
|
7061
7756
|
IncomingTriggerPayloadSchema,
|
|
7062
7757
|
JSONSchemaPropertySchema,
|
|
7063
7758
|
JsonSchemaToZodError,
|
|
7064
|
-
MCP,
|
|
7759
|
+
MCP2 as MCP,
|
|
7065
7760
|
MCPAuthOptionsSchema,
|
|
7066
7761
|
MCPGenerateURLParamsSchema,
|
|
7067
7762
|
MCPGetServerParamsSchema,
|