@devries-cameron20 / composio Mirror · read-only / commits / 09c4a2641
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

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

Synced Nov 22, 22:00 UTC

Fix tools.execute requiring userId for noauth apps (#1784)

Musthaq Ahamad committed Jul 23, 2025 at 17:38 UTC 09c4a2641ecc4fece84c60fb3ec8e210d129c0cc
4 files changed +33 -8
.changeset/modern-lies-float.md new
+13
@@ -0,0 +1,13 @@
1 +---
2 +'@composio/core': patch
3 +'@composio/anthropic': patch
4 +'@composio/cloudflare': patch
5 +'@composio/google': patch
6 +'@composio/langchain': patch
7 +'@composio/mastra': patch
8 +'@composio/openai': patch
9 +'@composio/openai-agents': patch
10 +'@composio/vercel': patch
11 +---
12 +
13 +Fix issues with tools.execute requiring userId for no auth apps
ts/packages/core/src/models/CustomTools.ts
+14 -4
@@ -32,6 +32,7 @@ import { ConnectedAccountRetrieveResponse } from '../types/connectedAccounts.typ
32 import { ValidationError } from '../errors';
33 import { transformConnectedAccountResponse } from '../utils/transformers/connectedAccounts';
34 import { ConnectionData } from '../types/connectedAccountAuthStates.types';
35 +import { AuthSchemeTypes } from '../types/authConfigs.types';
36
37 export class CustomTools {
38 private readonly client: ComposioClient;
@@ -189,9 +190,17 @@ export class CustomTools {
190 toolkitSlug: string,
191 userId: string,
192 connectedAccountId?: string
192 - ): Promise<ConnectedAccountRetrieveResponse> {
193 + ): Promise<ConnectedAccountRetrieveResponse | null> {
194 try {
195 await this.client.toolkits.retrieve(toolkitSlug);
196 + // check if the toolkit is a no auth toolkit
197 + const toolkit = await this.client.toolkits.retrieve(toolkitSlug);
198 + const isNoAuthToolkit = toolkit.auth_config_details?.some(
199 + details => details.mode === AuthSchemeTypes.NO_AUTH
200 + );
201 + if (isNoAuthToolkit) {
202 + return null;
203 + }
204 } catch (error) {
205 throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
206 cause: error,
@@ -243,8 +252,8 @@ export class CustomTools {
252 const { toolkitSlug, execute, inputParams } = tool.options;
253 // if a toolkit is used, get the connected account, and auth credentials
254 let connectedAccountId: string | undefined = body.connectedAccountId;
246 -
247 - if (toolkitSlug && toolkitSlug !== 'custom') {
255 + // if a toolkit is used, and a userId is provided, get the connected account
256 + if (toolkitSlug && toolkitSlug !== 'custom' && body.userId) {
257 const connectedAccount = await this.getConnectedAccountForToolkit(
258 toolkitSlug,
259 body.userId,
@@ -278,6 +287,7 @@ export class CustomTools {
287 }
288 // create a tool proxy request for users to execute in case of a toolkit being used
289 const executeToolRequest = async (data: ToolProxyParams): Promise<ToolExecuteResponse> => {
290 + // if the toolkit is custom, throw an error while trying to execute the tool by user
291 if (toolkitSlug && toolkitSlug === 'custom') {
292 throw new ComposioInvalidExecuteFunctionError(
293 'Custom tools without a toolkit cannot be executed using the executeToolRequest function',
@@ -302,7 +312,7 @@ export class CustomTools {
312 method: data.method,
313 parameters: parameters,
314 body: data.body,
305 - connected_account_id: data.connectedAccountId ?? connectedAccountId,
315 + connected_account_id: connectedAccountId,
316 custom_connection_data: data.customConnectionData,
317 });
318
ts/packages/core/src/models/Tools.ts
+5 -3
@@ -44,6 +44,8 @@ import {
44 import { ValidationError } from '../errors/ValidationErrors';
45 import { telemetry } from '../telemetry/Telemetry';
46 import { FileToolModifier } from '../utils/modifiers/FileToolModifier';
47 +import { CustomConnectionDataSchema } from '../types/connectedAccountAuthStates.types';
48 +import { AuthSchemeTypes } from '../types/authConfigs.types';
49 /**
50 * This class is used to manage tools in the Composio SDK.
51 * It provides methods to list, get, and execute tools.
@@ -204,7 +206,7 @@ export class Tools<
206
207 // check if the toolkit is a no auth app
208 const isNoAuthApp = toolkit.auth_config_details?.some(
207 - authConfigDetails => authConfigDetails.mode === 'NO_AUTH'
209 + authConfigDetails => authConfigDetails.mode === AuthSchemeTypes.NO_AUTH
210 );
211 // if the toolkit is not a no auth app, fetch connected accounts
212 if (!isNoAuthApp) {
@@ -693,9 +695,9 @@ export class Tools<
695 modifiers?.beforeExecute
696 );
697
696 - // fetch connected accounts if doesn't exist
698 + // fetch connected accounts if exists
699 let connectedAccountId = body.connectedAccountId;
698 - if (!connectedAccountId) {
700 + if (!connectedAccountId && body.userId) {
701 connectedAccountId =
702 (await this.getConnectedAccountIdForTool(body.userId, tool.slug)) || undefined;
703 }
ts/packages/core/src/types/tool.types.ts
+1 -1
@@ -235,7 +235,7 @@ export const ToolExecuteParamsSchema = z.object({
235 customAuthParams: CustomAuthParamsSchema.optional(),
236 customConnectionData: CustomConnectionDataSchema.optional(),
237 arguments: z.record(z.string(), z.unknown()).optional(),
238 - userId: z.string(),
238 + userId: z.string().optional(), //
239 version: z.string().optional(),
240 text: z.string().optional(),
241 });