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.

refactor(core): simplify custom tool DX and fix multi-execute routing

Dhawal Upadhyay20e8e3a16d1b
diff --git a/ts/packages/core/src/experimental/index.ts b/ts/packages/core/src/experimental/index.ts
index c26db2526..e526e9a3f 100644
--- a/ts/packages/core/src/experimental/index.ts
+++ b/ts/packages/core/src/experimental/index.ts
@@ -13,6 +13,5 @@ export type {
CustomToolHandle,
NewCustomToolOptions,
CustomToolExecuteFn,
- CustomToolExecuteResponse,
SessionContext,
} from '../types/customTool.types';
diff --git a/ts/packages/core/src/models/CustomTool.ts b/ts/packages/core/src/models/CustomTool.ts
index 0aae19854..5da532e1e 100644
--- a/ts/packages/core/src/models/CustomTool.ts
+++ b/ts/packages/core/src/models/CustomTool.ts
@@ -10,7 +10,7 @@
* name: 'Get user context',
* description: 'Retrieve what we know about a user',
* inputParams: z.object({ category: z.string() }),
- * execute: async (input) => ({ data: { ... }, error: null, successful: true }),
+ * execute: async (input) => ({ preferences: await db.find(input.category) }),
* });
* ```
*/
@@ -36,48 +36,63 @@ export const LOCAL_TOOL_PREFIX = 'LOCAL_';
* and execute function. Pass it to `composio.create(userId, { customTools: [...] })`
* to bind it to a session.
*
+ * Just return the result data from `execute`, or throw an error.
+ * The SDK wraps it into the standard response format internally.
+ *
* @param options - Tool definition including slug, schema, and execute function
* @returns A CustomToolHandle to pass to session creation
*
- * @example No-auth tool
+ * @example No-auth tool (no session needed)
* ```typescript
* const getUserContext = CustomTool({
* slug: 'GET_USER_CONTEXT',
* name: 'Get user context',
* description: 'Retrieve user preferences and history',
* inputParams: z.object({ category: z.string().default('all') }),
- * execute: async (input) => ({
- * data: await db.userContext.find(input.category),
- * error: null,
- * successful: true,
- * }),
+ * execute: async (input) => {
+ * const prefs = await db.userContext.find(input.category);
+ * return { preferences: prefs };
+ * },
+ * });
+ * ```
+ *
+ * @example No-auth tool using session to call other tools
+ * ```typescript
+ * const enrichedSearch = CustomTool({
+ * slug: 'ENRICHED_SEARCH',
+ * name: 'Enriched search',
+ * description: 'Search and enrich results with user context',
+ * inputParams: z.object({ query: z.string() }),
+ * execute: async (input, session) => {
+ * const results = await session.execute('GOOGLE_SEARCH', { query: input.query });
+ * return { enriched: results.data, userId: session.userId };
+ * },
* });
* ```
*
- * @example Auth tool with session context
+ * @example Auth tool with connectedToolkit (requires Composio connection)
* ```typescript
* const getAdAccounts = CustomTool({
* slug: 'GET_AD_ACCOUNTS',
* name: 'Get ad accounts',
* description: 'Get Meta ad account IDs for the authenticated user',
- * toolkit: 'meta_ads',
+ * connectedToolkit: 'meta_ads',
* inputParams: z.object({ fields: z.string().default('id,name') }),
- * execute: async (input, session) => ({
- * data: await session.proxyExecute({
+ * execute: async (input, session) => {
+ * const result = await session.proxyExecute({
* endpoint: '/v21.0/me/adaccounts',
* method: 'GET',
* parameters: [{ in: 'query', name: 'fields', value: input.fields }],
- * }),
- * error: null,
- * successful: true,
- * }),
+ * });
+ * return result.data;
+ * },
* });
* ```
*/
export function CustomTool<T extends z.ZodType>(
options: NewCustomToolOptions<T>
): CustomToolHandle {
- const { slug, name, description, inputParams, execute, toolkit } = options;
+ const { slug, name, description, inputParams, execute, connectedToolkit } = options;
if (!slug) {
throw new Error('CustomTool: slug is required');
@@ -111,7 +126,7 @@ export function CustomTool<T extends z.ZodType>(
slug,
name,
description,
- toolkit,
+ connectedToolkit,
inputSchema,
inputParams,
execute: execute as CustomToolExecuteFn<z.ZodType>,
@@ -162,6 +177,6 @@ export function serializeLocalTools(
name: handle.name,
description: handle.description,
input_schema: handle.inputSchema,
- ...(handle.toolkit ? { toolkit: handle.toolkit } : {}),
+ ...(handle.connectedToolkit ? { toolkit: handle.connectedToolkit } : {}),
}));
}
diff --git a/ts/packages/core/src/models/ToolRouterSession.ts b/ts/packages/core/src/models/ToolRouterSession.ts
index 1cc2af510..817917c6b 100644
--- a/ts/packages/core/src/models/ToolRouterSession.ts
+++ b/ts/packages/core/src/models/ToolRouterSession.ts
@@ -73,21 +73,15 @@ export class ToolRouterSession<
);
if (this.hasLocalTools()) {
- // Create an execute function that routes between local and remote execution
+ // Create an execute function that splits local/remote tools in COMPOSIO_MULTI_EXECUTE_TOOL
const routingExecuteFn = async (
toolSlug: string,
input: Record<string, unknown>
): Promise<ToolExecuteResponse> => {
- // Intercept COMPOSIO_MULTI_EXECUTE_TOOL and check if the inner tool is local
if (toolSlug === COMPOSIO_MULTI_EXECUTE_TOOL) {
- const innerSlug = String(input.tool_slug ?? '');
- const entry = this.findLocalTool(innerSlug);
- if (entry) {
- const innerArgs = (input.arguments as Record<string, unknown> | undefined) ?? {};
- return this.executeLocalTool(entry, innerArgs);
- }
+ return this.routeMultiExecute(input, ToolsModel, modifiers);
}
- // Default: send to backend
+ // Non-multi-execute meta tools always go to backend
return ToolsModel.executeMetaTool(
toolSlug,
{ sessionId: this.sessionId, arguments: input },
@@ -246,9 +240,111 @@ export class ToolRouterSession<
return this.localToolsMap.byPrefixed.get(upper) ?? this.localToolsMap.byOriginal.get(upper);
}
+ /** Parse an individual tool item from COMPOSIO_MULTI_EXECUTE_TOOL's tools array */
+ private parseToolItem(item: unknown): { tool_slug: string; arguments: Record<string, unknown> } {
+ const obj = item as Record<string, unknown>;
+ return {
+ tool_slug: String(obj.tool_slug ?? ''),
+ arguments: (obj.arguments as Record<string, unknown> | undefined) ?? {},
+ };
+ }
+
+ /**
+ * Route a COMPOSIO_MULTI_EXECUTE_TOOL call.
+ * Splits the tools[] array into local and remote, executes each appropriately,
+ * and merges results preserving original order.
+ */
+ private async routeMultiExecute(
+ input: Record<string, unknown>,
+ ToolsModel: Tools<TToolCollection, TTool, TProvider>,
+ modifiers?: SessionMetaToolOptions
+ ): Promise<ToolExecuteResponse> {
+ const toolItems = input.tools as unknown[];
+ if (!Array.isArray(toolItems) || toolItems.length === 0) {
+ // Fallback: send to backend as-is
+ return ToolsModel.executeMetaTool(
+ COMPOSIO_MULTI_EXECUTE_TOOL,
+ { sessionId: this.sessionId, arguments: input },
+ modifiers
+ );
+ }
+
+ const parsed = toolItems.map(item => this.parseToolItem(item));
+
+ // Partition into local and remote
+ const localIndices: number[] = [];
+ const remoteIndices: number[] = [];
+ for (let i = 0; i < parsed.length; i++) {
+ const entry = this.findLocalTool(parsed[i].tool_slug);
+ if (entry) {
+ localIndices.push(i);
+ } else {
+ remoteIndices.push(i);
+ }
+ }
+
+ // All remote — just forward entire payload
+ if (localIndices.length === 0) {
+ return ToolsModel.executeMetaTool(
+ COMPOSIO_MULTI_EXECUTE_TOOL,
+ { sessionId: this.sessionId, arguments: input },
+ modifiers
+ );
+ }
+
+ // Execute local tools in parallel
+ const results: Array<{ index: number; result: ToolExecuteResponse }> = [];
+
+ const localPromises = localIndices.map(async i => {
+ const entry = this.findLocalTool(parsed[i].tool_slug)!;
+ const result = await this.executeLocalTool(entry, parsed[i].arguments);
+ results.push({ index: i, result });
+ });
+
+ // Execute remote tools via backend (if any)
+ let remotePromise: Promise<void> | undefined;
+ if (remoteIndices.length > 0) {
+ const remoteToolItems = remoteIndices.map(i => toolItems[i]);
+ const remoteInput = { ...input, tools: remoteToolItems };
+ remotePromise = ToolsModel.executeMetaTool(
+ COMPOSIO_MULTI_EXECUTE_TOOL,
+ { sessionId: this.sessionId, arguments: remoteInput },
+ modifiers
+ ).then(remoteResult => {
+ // The backend returns a single merged response for all remote tools.
+ // We assign it to the first remote index and mark it as the remote batch result.
+ for (const i of remoteIndices) {
+ results.push({ index: i, result: remoteResult });
+ }
+ });
+ }
+
+ await Promise.all([...localPromises, ...(remotePromise ? [remotePromise] : [])]);
+
+ // If only local tools, return the single/first result
+ if (remoteIndices.length === 0 && results.length === 1) {
+ return results[0].result;
+ }
+
+ // Merge: collect all data keyed by tool slug
+ const mergedData: Record<string, unknown> = {};
+ for (const { index, result } of results) {
+ mergedData[parsed[index].tool_slug] = result.data;
+ }
+ const anyError = results.find(r => r.result.error)?.result.error ?? null;
+ return {
+ data: mergedData,
+ error: anyError,
+ successful: !anyError,
+ };
+ }
+
/**
* Execute a local tool in-process.
- * Builds a SessionContext, validates input, and calls the user's execute function.
+ * Builds a SessionContext, validates input, calls the user's execute function,
+ * and wraps the result into the standard response format.
+ *
+ * Users just return data or throw — we wrap it here.
*/
private async executeLocalTool(
entry: LocalToolsMapEntry,
@@ -275,11 +371,12 @@ export class ToolRouterSession<
);
try {
- const result = await handle.execute(parsed.data, sessionContext);
+ // User's execute returns data directly — we wrap into { data, error, successful }
+ const data = await handle.execute(parsed.data, sessionContext);
return {
- data: result.data,
- error: result.error,
- successful: result.successful,
+ data: data ?? {},
+ error: null,
+ successful: true,
};
} catch (err: unknown) {
const message = err instanceof Error ? err.message : String(err);
diff --git a/ts/packages/core/src/types/customTool.types.ts b/ts/packages/core/src/types/customTool.types.ts
index ce3e51f8b..b93d77324 100644
--- a/ts/packages/core/src/types/customTool.types.ts
+++ b/ts/packages/core/src/types/customTool.types.ts
@@ -80,23 +80,18 @@ export interface SessionContext {
proxyExecute(params: ToolProxyParams): Promise<SdkToolExecuteResponse>;
}
-/** Response shape returned by custom tool execute functions. */
-export type CustomToolExecuteResponse = {
- data: Record<string, unknown>;
- error: string | null;
- successful: boolean;
-};
-
/**
* Execute function for custom tools.
+ * Just return the result data, or throw an error. The SDK wraps it internally.
+ *
* Supports two call patterns:
- * - `(input) => result` — for tools that don't need session context
- * - `(input, session) => result` — for tools that need to call other tools or proxy APIs
+ * - `(input) => data` — for tools that don't need session context
+ * - `(input, session) => data` — for tools that need to call other tools or proxy APIs
*/
export type CustomToolExecuteFn<T extends z.ZodType> = (
input: z.infer<T>,
session: SessionContext
-) => Promise<CustomToolExecuteResponse>;
+) => Promise<Record<string, unknown>>;
/** Options for creating a custom local tool via `CustomTool()`. */
export type NewCustomToolOptions<T extends z.ZodType> = {
@@ -108,8 +103,11 @@ export type NewCustomToolOptions<T extends z.ZodType> = {
description: string;
/** Zod schema for input parameters */
inputParams: T;
- /** Optional toolkit slug for auth-based tools (e.g. 'meta_ads') */
- toolkit?: string;
+ /**
+ * Composio toolkit slug requiring an active connection (e.g. 'meta_ads').
+ * If not provided, the tool does not need Composio auth.
+ */
+ connectedToolkit?: string;
/** The function that executes the tool */
execute: CustomToolExecuteFn<T>;
};
@@ -122,7 +120,11 @@ export interface CustomToolHandle {
readonly slug: string;
readonly name: string;
readonly description: string;
- readonly toolkit?: string;
+ /**
+ * Composio toolkit slug requiring an active connection.
+ * Undefined means the tool does not need Composio auth.
+ */
+ readonly connectedToolkit?: string;
readonly inputSchema: Record<string, unknown>;
/** @internal Original Zod schema — used for runtime input validation (defaults, coercions, transforms) */
readonly inputParams: z.ZodType;
@@ -136,6 +138,7 @@ export interface LocalToolDefinition {
name: string;
description: string;
input_schema: Record<string, unknown>;
+ /** Maps connectedToolkit → toolkit in the backend payload */
toolkit?: string;
}
diff --git a/ts/packages/core/test/models/customTool.test.ts b/ts/packages/core/test/models/customTool.test.ts
index 15ce50fc9..0b053f9b9 100644
--- a/ts/packages/core/test/models/customTool.test.ts
+++ b/ts/packages/core/test/models/customTool.test.ts
@@ -16,11 +16,7 @@ describe('CustomTool', () => {
inputParams: z.object({
category: z.string().describe('The category'),
}),
- execute: vi.fn().mockResolvedValue({
- data: { result: 'ok' },
- error: null,
- successful: true,
- }),
+ execute: vi.fn().mockResolvedValue({ result: 'ok' }),
};
it('should return a valid handle with correct fields', () => {
@@ -29,7 +25,7 @@ describe('CustomTool', () => {
expect(handle.slug).toBe('GET_USER_CONTEXT');
expect(handle.name).toBe('Get user context');
expect(handle.description).toBe('Retrieve what we know about a user');
- expect(handle.toolkit).toBeUndefined();
+ expect(handle.connectedToolkit).toBeUndefined();
expect(handle.execute).toBe(baseOptions.execute);
expect(handle.inputSchema).toMatchObject({
type: 'object',
@@ -41,9 +37,9 @@ describe('CustomTool', () => {
expect(handle.inputParams).toBe(baseOptions.inputParams);
});
- it('should include toolkit when provided', () => {
- const handle = CustomTool({ ...baseOptions, toolkit: 'meta_ads' });
- expect(handle.toolkit).toBe('meta_ads');
+ it('should include connectedToolkit when provided', () => {
+ const handle = CustomTool({ ...baseOptions, connectedToolkit: 'meta_ads' });
+ expect(handle.connectedToolkit).toBe('meta_ads');
});
it('should convert Zod schema with optional fields correctly', () => {
@@ -111,11 +107,7 @@ describe('CustomTool', () => {
describe('execute function signatures', () => {
it('should allow no-session execute (input only)', async () => {
- const noSessionExecute = vi.fn().mockResolvedValue({
- data: { result: 42 },
- error: null,
- successful: true,
- });
+ const noSessionExecute = vi.fn().mockResolvedValue({ result: 42 });
const handle = CustomTool({
...baseOptions,
@@ -124,16 +116,12 @@ describe('CustomTool', () => {
// Call without session — JS ignores extra params
const result = await handle.execute({ category: 'test' } as any);
- expect(result.data.result).toBe(42);
+ expect(result.result).toBe(42);
expect(noSessionExecute).toHaveBeenCalledWith({ category: 'test' });
});
it('should allow session-based execute (input + session)', async () => {
- const sessionExecute = vi.fn().mockResolvedValue({
- data: { userId: 'u1' },
- error: null,
- successful: true,
- });
+ const sessionExecute = vi.fn().mockResolvedValue({ userId: 'u1' });
const handle = CustomTool({
...baseOptions,
@@ -148,7 +136,7 @@ describe('CustomTool', () => {
};
const result = await handle.execute({ category: 'test' }, mockSession);
- expect(result.data.userId).toBe('u1');
+ expect(result.userId).toBe('u1');
expect(sessionExecute).toHaveBeenCalledWith({ category: 'test' }, mockSession);
});
});
@@ -223,7 +211,7 @@ describe('serializeLocalTools', () => {
slug: 'GET_DATA',
name: 'Get Data',
description: 'Gets some data',
- toolkit: 'my_toolkit',
+ connectedToolkit: 'my_toolkit',
inputSchema: { type: 'object', properties: { id: { type: 'string' } } },
inputParams: z.object({ id: z.string() }),
execute: vi.fn(),
@@ -242,7 +230,7 @@ describe('serializeLocalTools', () => {
]);
});
- it('should omit toolkit when not provided', () => {
+ it('should omit toolkit when connectedToolkit not provided', () => {
const handle: CustomToolHandle = {
slug: 'NO_TOOLKIT',
name: 'No Toolkit',
diff --git a/ts/packages/core/test/models/customToolRouting.test.ts b/ts/packages/core/test/models/customToolRouting.test.ts
index bcdbf2f74..e9b211815 100644
--- a/ts/packages/core/test/models/customToolRouting.test.ts
+++ b/ts/packages/core/test/models/customToolRouting.test.ts
@@ -62,11 +62,8 @@ const createMockClient = () => ({
},
});
-const localExecute = vi.fn().mockResolvedValue({
- data: { local_result: true },
- error: null,
- successful: true,
-});
+// Execute returns data directly (simplified API)
+const localExecute = vi.fn().mockResolvedValue({ local_result: true });
const customToolHandle = CustomTool({
slug: 'GET_USER_CONTEXT',
@@ -77,16 +74,14 @@ const customToolHandle = CustomTool({
});
const sessionExecute = vi.fn().mockImplementation(async (input: any, session: any) => ({
- data: { userId: session.userId },
- error: null,
- successful: true,
+ userId: session.userId,
}));
const sessionToolHandle = CustomTool({
slug: 'GET_AD_ACCOUNTS',
name: 'Get ad accounts',
description: 'Get ad account IDs',
- toolkit: 'meta_ads',
+ connectedToolkit: 'meta_ads',
inputParams: z.object({ fields: z.string() }),
execute: sessionExecute,
});
@@ -125,7 +120,7 @@ describe('ToolRouter.create() with customTools', () => {
]);
});
- it('should include toolkit in local_tools when present', async () => {
+ it('should include toolkit in local_tools when connectedToolkit is present', async () => {
await router.create('user_1', {
customTools: [sessionToolHandle],
});
@@ -194,6 +189,7 @@ describe('ToolRouterSession execution routing', () => {
const result = await session.execute('GET_USER_CONTEXT', { category: 'prefs' });
+ // User returns data directly, SDK wraps it
expect(result.data).toEqual({ local_result: true });
expect(result.logId).toBe('local');
expect(localExecute).toHaveBeenCalledWith(
@@ -263,7 +259,7 @@ describe('ToolRouterSession execution routing', () => {
// Tool that calls another tool via session.execute()
const chainedExecute = vi.fn().mockImplementation(async (input: any, session: any) => {
const inner = await session.execute('GMAIL_SEND_EMAIL', { to: input.to });
- return { data: { inner_result: inner.data }, error: null, successful: true };
+ return { inner_result: inner.data };
});
const chainedTool = CustomTool({
@@ -306,9 +302,7 @@ describe('ToolRouterSession execution routing', () => {
it('should apply Zod defaults when input is missing optional fields', async () => {
const defaultExecute = vi.fn().mockImplementation(async (input: any) => ({
- data: { category: input.category },
- error: null,
- successful: true,
+ category: input.category,
}));
const toolWithDefaults = CustomTool({
@@ -364,35 +358,43 @@ describe('ToolRouterSession execution routing', () => {
});
});
- describe('session.tools() — COMPOSIO_MULTI_EXECUTE_TOOL routing', () => {
- it('should route local tools via COMPOSIO_MULTI_EXECUTE_TOOL to in-process execution', async () => {
- const provider = new MockProvider();
- // Mock wrapTools to capture the execute function and call it
- provider.wrapTools.mockImplementation((tools: any, executeFn: any) => {
- // Store executeFn so we can call it
- (provider as any)._capturedExecuteFn = executeFn;
- return 'wrapped-tools-with-routing';
- });
-
- const session = new ToolRouterSession(
- mockClient as unknown as ComposioClient,
+ describe('session.tools() — COMPOSIO_MULTI_EXECUTE_TOOL routing with tools[] array', () => {
+ const createSessionWithProvider = (
+ client: ReturnType<typeof createMockClient>,
+ provider: MockProvider,
+ customTools: CustomToolHandle[]
+ ) => {
+ return new ToolRouterSession(
+ client as unknown as ComposioClient,
{ apiKey: 'key', provider },
'sess_123',
{ type: 'http' as const, url: 'https://mcp.example.com/sess_123' },
undefined,
- buildLocalToolsMap([customToolHandle]),
+ buildLocalToolsMap(customTools),
'user_1'
);
+ };
- await session.tools();
+ const captureExecuteFn = (provider: MockProvider) => {
+ provider.wrapTools.mockImplementation((tools: any, executeFn: any) => {
+ (provider as any)._capturedExecuteFn = executeFn;
+ return 'wrapped-tools-with-routing';
+ });
+ };
- // Now simulate the LLM calling COMPOSIO_MULTI_EXECUTE_TOOL with a local tool
+ it('should route all-local tools[] to in-process execution', async () => {
+ const provider = new MockProvider();
+ captureExecuteFn(provider);
+ const session = createSessionWithProvider(mockClient, provider, [customToolHandle]);
+
+ await session.tools();
const executeFn = (provider as any)._capturedExecuteFn;
- expect(executeFn).toBeDefined();
const result = await executeFn('COMPOSIO_MULTI_EXECUTE_TOOL', {
- tool_slug: 'LOCAL_GET_USER_CONTEXT',
- arguments: { category: 'test' },
+ tools: [
+ { tool_slug: 'LOCAL_GET_USER_CONTEXT', arguments: { category: 'test' } },
+ ],
+ sync_response_to_workbench: false,
});
expect(result.data).toEqual({ local_result: true });
@@ -402,56 +404,57 @@ describe('ToolRouterSession execution routing', () => {
);
});
- it('should route remote tools via COMPOSIO_MULTI_EXECUTE_TOOL to backend', async () => {
+ it('should route all-remote tools[] to backend', async () => {
const provider = new MockProvider();
- provider.wrapTools.mockImplementation((tools: any, executeFn: any) => {
- (provider as any)._capturedExecuteFn = executeFn;
- return 'wrapped';
- });
-
- const session = new ToolRouterSession(
- mockClient as unknown as ComposioClient,
- { apiKey: 'key', provider },
- 'sess_123',
- { type: 'http' as const, url: 'https://mcp.example.com/sess_123' },
- undefined,
- buildLocalToolsMap([customToolHandle]),
- 'user_1'
- );
+ captureExecuteFn(provider);
+ const session = createSessionWithProvider(mockClient, provider, [customToolHandle]);
await session.tools();
-
const executeFn = (provider as any)._capturedExecuteFn;
+
const result = await executeFn('COMPOSIO_MULTI_EXECUTE_TOOL', {
- tool_slug: 'GMAIL_SEND_EMAIL',
- arguments: { to: '[email protected]' },
+ tools: [
+ { tool_slug: 'GMAIL_SEND_EMAIL', arguments: { to: '[email protected]' } },
+ ],
+ sync_response_to_workbench: false,
});
- // Should have gone to remote via executeMetaTool
+ // All remote — goes to executeMetaTool
expect(result.data).toEqual({ remote: true });
expect(localExecute).not.toHaveBeenCalled();
});
- it('should route non-MULTI_EXECUTE meta tools to backend', async () => {
+ it('should split mixed local+remote tools and merge results', async () => {
const provider = new MockProvider();
- provider.wrapTools.mockImplementation((tools: any, executeFn: any) => {
- (provider as any)._capturedExecuteFn = executeFn;
- return 'wrapped';
+ captureExecuteFn(provider);
+ const session = createSessionWithProvider(mockClient, provider, [customToolHandle]);
+
+ await session.tools();
+ const executeFn = (provider as any)._capturedExecuteFn;
+
+ const result = await executeFn('COMPOSIO_MULTI_EXECUTE_TOOL', {
+ tools: [
+ { tool_slug: 'LOCAL_GET_USER_CONTEXT', arguments: { category: 'prefs' } },
+ { tool_slug: 'GMAIL_SEND_EMAIL', arguments: { to: '[email protected]' } },
+ ],
+ sync_response_to_workbench: false,
});
- const session = new ToolRouterSession(
- mockClient as unknown as ComposioClient,
- { apiKey: 'key', provider },
- 'sess_123',
- { type: 'http' as const, url: 'https://mcp.example.com/sess_123' },
- undefined,
- buildLocalToolsMap([customToolHandle]),
- 'user_1'
- );
+ // Both should have been called
+ expect(localExecute).toHaveBeenCalled();
+ // Remote goes to backend — merged results keyed by slug
+ expect(result.data).toHaveProperty('LOCAL_GET_USER_CONTEXT');
+ expect(result.data).toHaveProperty('GMAIL_SEND_EMAIL');
+ });
- await session.tools();
+ it('should route non-MULTI_EXECUTE meta tools to backend', async () => {
+ const provider = new MockProvider();
+ captureExecuteFn(provider);
+ const session = createSessionWithProvider(mockClient, provider, [customToolHandle]);
+ await session.tools();
const executeFn = (provider as any)._capturedExecuteFn;
+
const result = await executeFn('COMPOSIO_SEARCH_TOOLS', {
queries: [{ use_case: 'send email' }],
});