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, 05:45 UTC
fix(cli): skip misleading connection tips for meta tools, sync META_TOOL_SLUGS with API type
- toolkitFromToolSlug now returns undefined for COMPOSIO_* meta tool prefixes, preventing misleading tips like "link composio" when a meta tool execution fails with NoActiveConnection - Use `satisfies ReadonlyArray<SessionExecuteMetaParams['slug']>` on META_TOOL_SLUG_LIST to catch drift from the API type at compile time - Add justification comment for the `as any` cast in the test layer's ComposioClientSingleton mock
jkomyno committed
Feb 26, 2026 at 01:55 UTC
920f1aca7ec4dd97c31691b9d26ab4f7e5b50081
4 files changed
+53
-4
ts/packages/cli/src/commands/tools/commands/tools.execute.cmd.ts
+12
-2
@@ -83,14 +83,24 @@ const parseArguments = (raw: string) =>
83
/**
84
* Derive the toolkit slug from a tool slug.
85
* e.g. "GMAIL_CREATE_EMAIL_DRAFT" → "gmail", "GITHUB_GET_REPOS" → "github"
86
+ *
87
+ * Returns `undefined` for meta tool slugs (COMPOSIO_*) since they don't map
88
+ * to a real toolkit and would produce misleading connection tips.
89
*/
87
-const toolkitFromToolSlug = (toolSlug: string): string => {
90
+const toolkitFromToolSlug = (toolSlug: string): string | undefined => {
91
const idx = toolSlug.indexOf('_');
89
- return idx > 0 ? toolSlug.slice(0, idx).toLowerCase() : toolSlug.toLowerCase();
92
+ if (idx <= 0) return toolSlug.toLowerCase();
93
+ const prefix = toolSlug.slice(0, idx).toLowerCase();
94
+ // Meta tools (COMPOSIO_*) are internal and don't correspond to a real toolkit.
95
+ if (prefix === 'composio') return undefined;
96
+ return prefix;
97
};
98
99
const connectionTips = (toolSlug: string, userId: string) => {
100
const toolkit = toolkitFromToolSlug(toolSlug);
101
+ if (!toolkit) {
102
+ return `Retry: ${bold(`composio tools execute ${toolSlug} ...`)}`;
103
+ }
104
return [
105
`Link the toolkit first: ${bold(`composio connected-accounts link ${toolkit} --user-id ${userId}`)}`,
106
`Then retry: ${bold(`composio tools execute ${toolSlug} ...`)}`,
ts/packages/cli/src/services/tools-executor.ts
+8
-2
@@ -61,8 +61,12 @@ export const ToolsExecutor = Context.GenericTag<ToolsExecutor>('services/ToolsEx
61
62
/**
63
* Meta tool slugs handled by `session.executeMeta` instead of `session.execute`.
64
+ *
65
+ * The `satisfies` constraint ensures this list stays in sync with the API's
66
+ * `SessionExecuteMetaParams['slug']` union — a compile error will surface if
67
+ * a slug is misspelled or if the API adds/removes a meta tool.
68
*/
65
-const META_TOOL_SLUGS: ReadonlySet<string> = new Set([
69
+const META_TOOL_SLUG_LIST = [
70
'COMPOSIO_SEARCH_TOOLS',
71
'COMPOSIO_MULTI_EXECUTE_TOOL',
72
'COMPOSIO_MANAGE_CONNECTIONS',
@@ -72,7 +76,9 @@ const META_TOOL_SLUGS: ReadonlySet<string> = new Set([
76
'COMPOSIO_GET_TOOL_SCHEMAS',
77
'COMPOSIO_UPSERT_RECIPE',
78
'COMPOSIO_GET_RECIPE',
75
-] as const);
79
+] as const satisfies ReadonlyArray<SessionExecuteMetaParams['slug']>;
80
+
81
+const META_TOOL_SLUGS: ReadonlySet<string> = new Set(META_TOOL_SLUG_LIST);
82
83
const isMetaToolSlug = (slug: string): slug is SessionExecuteMetaParams['slug'] =>
84
META_TOOL_SLUGS.has(slug);
ts/packages/cli/test/__utils__/services/test-layer.ts
+4
@@ -821,6 +821,10 @@ export const TestLayer = (input?: TestLiveInput) =>
821
ComposioClientSingleton,
822
new ComposioClientSingleton({
823
get: Effect.fn(function* () {
824
+ // Partial mock: only implements `toolRouter.session.*` methods used by
825
+ // CLI commands under test. The full Composio client interface is too
826
+ // large to mock completely for unit tests.
827
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
828
return mockComposioClient as any;
829
}),
830
})
ts/packages/cli/test/src/commands/tools/tools.execute.cmd.test.ts
+29
@@ -316,6 +316,35 @@ describe('CLI: composio tools execute', () => {
316
);
317
});
318
319
+ // --- Meta tool error tests ---
320
+
321
+ layer(
322
+ TestLive({
323
+ baseConfigProvider: testConfigProvider,
324
+ stdin: { isTTY: true, data: '' },
325
+ toolsExecutor: {
326
+ failWith: new ActionExecuteConnectedAccountNotFoundError({
327
+ slug: 'ToolRouterV2_NoActiveConnection',
328
+ message: 'No active connection found for toolkit(s) in this session',
329
+ }),
330
+ },
331
+ })
332
+ )('[Given] meta tool NoActiveConnection error [Then] does not suggest "link composio"', it => {
333
+ it.scoped('omits connection tips for meta tool slugs', () =>
334
+ Effect.gen(function* () {
335
+ yield* cli(['tools', 'execute', 'COMPOSIO_SEARCH_TOOLS', '-d', '{"query":"email"}']).pipe(
336
+ Effect.catchAll(() => Effect.void)
337
+ );
338
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
339
+ const output = lines.join('\n');
340
+
341
+ expect(output).toContain('No active connection');
342
+ // Should NOT produce a misleading tip like "link composio"
343
+ expect(output).not.toContain('link composio');
344
+ })
345
+ );
346
+ });
347
+
348
// --- Edge case tests ---
349
350
layer(