25
import { ValidationError } from '../errors';
26
import { Tools } from './Tools';
27
import { ToolRouterSessionFilesMount } from './ToolRouterSessionFileMount';
28
-import type { LocalToolsMap, LocalToolsMapEntry, SessionContext } from '../types/customTool.types';
28
+import type { CustomToolsMap, CustomToolsMapEntry, SessionContext } from '../types/customTool.types';
29
import type { Tool, ToolExecuteResponse } from '../types/tool.types';
30
import { SessionContextImpl } from './SessionContext';
31
-import { findLocalTool, executeLocalTool } from './localToolExecution';
31
+import { findCustomTool, executeCustomTool } from './customToolExecution';
32
33
const COMPOSIO_MULTI_EXECUTE_TOOL = 'COMPOSIO_MULTI_EXECUTE_TOOL';
34
const COMPOSIO_EXECUTE_LOCAL_TOOL = 'COMPOSIO_EXECUTE_LOCAL_TOOL';
48
sessionId: string,
49
mcp: ToolRouterMCPServerConfig,
50
experimentalOverrides?: Pick<SessionExperimental, 'assistivePrompt'>,
51
- private readonly localToolsMap?: LocalToolsMap,
51
+ private readonly customToolsMap?: CustomToolsMap,
52
private readonly userId?: string
53
) {
54
- if (localToolsMap && !userId) {
54
+ if (customToolsMap && !userId) {
55
throw new Error('userId is required when custom tools are bound to a session.');
56
}
57
this.sessionId = sessionId;
77
modifiers?.modifySchema ? { modifySchema: modifiers.modifySchema } : undefined
78
);
79
80
- if (this.hasLocalTools()) {
80
+ if (this.hasCustomTools()) {
81
// Create an execute function that splits local/remote tools in COMPOSIO_MULTI_EXECUTE_TOOL
82
const routingExecuteFn = async (
83
toolSlug: string,
89
if (toolSlug === COMPOSIO_EXECUTE_LOCAL_TOOL) {
90
const slug = String(input.tool_slug ?? '');
91
const args = (input.arguments as Record<string, unknown> | undefined) ?? {};
92
- const entry = findLocalTool(this.localToolsMap, slug);
92
+ const entry = findCustomTool(this.customToolsMap, slug);
93
if (!entry) {
94
return {
95
data: {},
96
- error: `Local tool "${slug}" not found`,
96
+ error: `Custom tool "${slug}" not found. If this is a remote tool, execute it via COMPOSIO_MULTI_EXECUTE_TOOL.`,
97
successful: false,
98
};
99
}
100
- return executeLocalTool(entry, args, this.buildSessionContext());
100
+ return executeCustomTool(entry, args, this.buildSessionContext());
101
}
102
// Non-multi-execute meta tools always go to backend
103
return ToolsModel.executeMetaTool(
143
* ```
144
*/
145
async localTools(): Promise<ReturnType<TProvider['wrapTools']>> {
146
- if (!this.hasLocalTools()) {
146
+ if (!this.hasCustomTools()) {
147
throw new Error('No custom tools are bound to this session.');
148
}
149
if (!this.config?.provider) {
154
}
155
156
// Collect local tool slugs and descriptions for the schema
157
- const toolEntries = Array.from(this.localToolsMap!.byOriginal.entries());
157
+ const toolEntries = Array.from(this.customToolsMap!.byOriginal.entries());
158
const slugDescriptions = toolEntries
159
.map(([slug, entry]) => `- ${entry.prefixedSlug}: ${entry.handle.description}`)
160
.join('\n');
190
const slug = String(input.tool_slug ?? '');
191
const args = (input.arguments as Record<string, unknown> | undefined) ?? {};
192
193
- const entry = findLocalTool(this.localToolsMap, slug);
193
+ const entry = findCustomTool(this.customToolsMap, slug);
194
if (!entry) {
195
return {
196
data: {},
197
- error: `Local tool "${slug}" not found. Available: ${toolEntries.map(([, e]) => e.prefixedSlug).join(', ')}`,
197
+ error: `Custom tool "${slug}" not found. Available: ${toolEntries.map(([, e]) => e.prefixedSlug).join(', ')}. If this is a remote tool, execute it via COMPOSIO_MULTI_EXECUTE_TOOL.`,
198
successful: false,
199
};
200
}
201
202
- return executeLocalTool(entry, args, this.buildSessionContext());
202
+ return executeCustomTool(entry, args, this.buildSessionContext());
203
};
204
205
return this.config.provider.wrapTools([tool], executeFn) as ReturnType<
312
arguments_?: Record<string, unknown>
313
): Promise<ToolRouterSessionExecuteResponse> {
314
// Check if this is a local tool (by original or prefixed slug)
315
- const entry = findLocalTool(this.localToolsMap, toolSlug);
315
+ const entry = findCustomTool(this.customToolsMap, toolSlug);
316
if (entry) {
317
- const result = await executeLocalTool(entry, arguments_ ?? {}, this.buildSessionContext());
317
+ const result = await executeCustomTool(entry, arguments_ ?? {}, this.buildSessionContext());
318
return {
319
data: result.data,
320
error: result.error,
333
334
// ── Private helpers ──────────────────────────────────────────
335
336
- /** Check if this session has any local tools bound. */
337
- private hasLocalTools(): boolean {
338
- return (this.localToolsMap?.byPrefixed.size ?? 0) > 0;
336
+ /** Check if this session has any custom tools bound. */
337
+ private hasCustomTools(): boolean {
338
+ return (this.customToolsMap?.byPrefixed.size ?? 0) > 0;
339
}
340
341
/**
349
this.userId!,
350
this.sessionId,
351
(slug, args) => {
352
- const entry = findLocalTool(this.localToolsMap, slug);
352
+ const entry = findCustomTool(this.customToolsMap, slug);
353
if (!entry) return undefined;
354
- return executeLocalTool(entry, args, this.buildSessionContext());
354
+ return executeCustomTool(entry, args, this.buildSessionContext());
355
}
356
);
357
}
391
const parsed = toolItems.map(item => this.parseToolItem(item));
392
393
// Partition into local (with resolved entry) and remote
394
- const localItems: Array<{ index: number; entry: LocalToolsMapEntry }> = [];
394
+ const localItems: Array<{ index: number; entry: CustomToolsMapEntry }> = [];
395
const remoteIndices: number[] = [];
396
for (let i = 0; i < parsed.length; i++) {
397
- const entry = findLocalTool(this.localToolsMap, parsed[i].tool_slug);
397
+ const entry = findCustomTool(this.customToolsMap, parsed[i].tool_slug);
398
if (entry) {
399
localItems.push({ index: i, entry });
400
} else {
413
414
// Execute local tools in parallel
415
const localPromises = localItems.map(async ({ index, entry }) => {
416
- const result = await executeLocalTool(entry, parsed[index].arguments, this.buildSessionContext());
416
+ const result = await executeCustomTool(entry, parsed[index].arguments, this.buildSessionContext());
417
return { index, result };
418
});
419