Skip to content

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

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

Musthaq Ahamad09c4a2641ecc
diff --git a/.changeset/modern-lies-float.md b/.changeset/modern-lies-float.md
new file mode 100644
index 000000000..663ab256d
--- /dev/null
+++ b/.changeset/modern-lies-float.md
@@ -0,0 +1,13 @@
+---
+'@composio/core': patch
+'@composio/anthropic': patch
+'@composio/cloudflare': patch
+'@composio/google': patch
+'@composio/langchain': patch
+'@composio/mastra': patch
+'@composio/openai': patch
+'@composio/openai-agents': patch
+'@composio/vercel': patch
+---
+
+Fix issues with tools.execute requiring userId for no auth apps
diff --git a/ts/packages/core/src/models/CustomTools.ts b/ts/packages/core/src/models/CustomTools.ts
index 75a1a5efc..81573d053 100644
--- a/ts/packages/core/src/models/CustomTools.ts
+++ b/ts/packages/core/src/models/CustomTools.ts
@@ -32,6 +32,7 @@ import { ConnectedAccountRetrieveResponse } from '../types/connectedAccounts.typ
import { ValidationError } from '../errors';
import { transformConnectedAccountResponse } from '../utils/transformers/connectedAccounts';
import { ConnectionData } from '../types/connectedAccountAuthStates.types';
+import { AuthSchemeTypes } from '../types/authConfigs.types';
export class CustomTools {
private readonly client: ComposioClient;
@@ -189,9 +190,17 @@ export class CustomTools {
toolkitSlug: string,
userId: string,
connectedAccountId?: string
- ): Promise<ConnectedAccountRetrieveResponse> {
+ ): Promise<ConnectedAccountRetrieveResponse | null> {
try {
await this.client.toolkits.retrieve(toolkitSlug);
+ // check if the toolkit is a no auth toolkit
+ const toolkit = await this.client.toolkits.retrieve(toolkitSlug);
+ const isNoAuthToolkit = toolkit.auth_config_details?.some(
+ details => details.mode === AuthSchemeTypes.NO_AUTH
+ );
+ if (isNoAuthToolkit) {
+ return null;
+ }
} catch (error) {
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
cause: error,
@@ -243,8 +252,8 @@ export class CustomTools {
const { toolkitSlug, execute, inputParams } = tool.options;
// if a toolkit is used, get the connected account, and auth credentials
let connectedAccountId: string | undefined = body.connectedAccountId;
-
- if (toolkitSlug && toolkitSlug !== 'custom') {
+ // if a toolkit is used, and a userId is provided, get the connected account
+ if (toolkitSlug && toolkitSlug !== 'custom' && body.userId) {
const connectedAccount = await this.getConnectedAccountForToolkit(
toolkitSlug,
body.userId,
@@ -278,6 +287,7 @@ export class CustomTools {
}
// create a tool proxy request for users to execute in case of a toolkit being used
const executeToolRequest = async (data: ToolProxyParams): Promise<ToolExecuteResponse> => {
+ // if the toolkit is custom, throw an error while trying to execute the tool by user
if (toolkitSlug && toolkitSlug === 'custom') {
throw new ComposioInvalidExecuteFunctionError(
'Custom tools without a toolkit cannot be executed using the executeToolRequest function',
@@ -302,7 +312,7 @@ export class CustomTools {
method: data.method,
parameters: parameters,
body: data.body,
- connected_account_id: data.connectedAccountId ?? connectedAccountId,
+ connected_account_id: connectedAccountId,
custom_connection_data: data.customConnectionData,
});
diff --git a/ts/packages/core/src/models/Tools.ts b/ts/packages/core/src/models/Tools.ts
index beb68c535..333f41215 100644
--- a/ts/packages/core/src/models/Tools.ts
+++ b/ts/packages/core/src/models/Tools.ts
@@ -44,6 +44,8 @@ import {
import { ValidationError } from '../errors/ValidationErrors';
import { telemetry } from '../telemetry/Telemetry';
import { FileToolModifier } from '../utils/modifiers/FileToolModifier';
+import { CustomConnectionDataSchema } from '../types/connectedAccountAuthStates.types';
+import { AuthSchemeTypes } from '../types/authConfigs.types';
/**
* This class is used to manage tools in the Composio SDK.
* It provides methods to list, get, and execute tools.
@@ -204,7 +206,7 @@ export class Tools<
// check if the toolkit is a no auth app
const isNoAuthApp = toolkit.auth_config_details?.some(
- authConfigDetails => authConfigDetails.mode === 'NO_AUTH'
+ authConfigDetails => authConfigDetails.mode === AuthSchemeTypes.NO_AUTH
);
// if the toolkit is not a no auth app, fetch connected accounts
if (!isNoAuthApp) {
@@ -693,9 +695,9 @@ export class Tools<
modifiers?.beforeExecute
);
- // fetch connected accounts if doesn't exist
+ // fetch connected accounts if exists
let connectedAccountId = body.connectedAccountId;
- if (!connectedAccountId) {
+ if (!connectedAccountId && body.userId) {
connectedAccountId =
(await this.getConnectedAccountIdForTool(body.userId, tool.slug)) || undefined;
}
diff --git a/ts/packages/core/src/types/tool.types.ts b/ts/packages/core/src/types/tool.types.ts
index 9ed3b2157..d6e3a5e07 100644
--- a/ts/packages/core/src/types/tool.types.ts
+++ b/ts/packages/core/src/types/tool.types.ts
@@ -235,7 +235,7 @@ export const ToolExecuteParamsSchema = z.object({
customAuthParams: CustomAuthParamsSchema.optional(),
customConnectionData: CustomConnectionDataSchema.optional(),
arguments: z.record(z.string(), z.unknown()).optional(),
- userId: z.string(),
+ userId: z.string().optional(), //
version: z.string().optional(),
text: z.string().optional(),
});