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, 04:30 UTC
fix(cli): valid CTA payload, lowercase link, and JSON output for link command (#2844)
Musthaq Ahamad committed
Mar 5, 2026 at 21:31 UTC
ecb455c853698998624d3ae740f0d8dbfc737029
8 files changed
+303
-35
.changeset/forty-aliens-listen.md
new
+5
@@ -0,0 +1,5 @@
1
+---
2
+'@composio/cli': patch
3
+---
4
+
5
+Fix CTAs and Link commands
ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
+16
-4
@@ -32,6 +32,7 @@ const noBrowser = Options.boolean('no-browser').pipe(
32
33
/**
34
* Open the browser and poll until the connected account becomes ACTIVE.
35
+ * On success, outputs valid JSON to stdout for piping (e.g. to jq).
36
*/
37
const waitForActiveConnection = (
38
ui: TerminalUI,
@@ -41,9 +42,8 @@ const waitForActiveConnection = (
42
noBrowser: boolean
43
) =>
44
Effect.gen(function* () {
44
- // Display the redirect URL
45
+ // Display the redirect URL (interactive only)
46
yield* ui.note(redirectUrl, 'Redirect URL');
46
- yield* ui.output(redirectUrl);
47
48
if (!noBrowser) {
49
// Validate URL scheme before opening — prevent non-HTTPS redirects
@@ -92,10 +92,22 @@ const waitForActiveConnection = (
92
)
93
).pipe(
94
Effect.tap(account => {
95
+ const message = `Connected account "${account.id}" is now ACTIVE (toolkit: ${account.toolkit.slug}).`;
96
return Effect.all([
97
spinner.stop('Connection successful'),
97
- ui.log.success(
98
- `Connected account "${account.id}" is now ACTIVE (toolkit: ${account.toolkit.slug}).`
98
+ ui.log.success(message),
99
+ ui.output(
100
+ JSON.stringify(
101
+ {
102
+ status: 'success',
103
+ message,
104
+ connected_account_id: account.id,
105
+ toolkit: account.toolkit.slug,
106
+ redirect_url: redirectUrl,
107
+ },
108
+ null,
109
+ 2
110
+ )
111
),
112
]);
113
}),
ts/packages/cli/src/commands/root-help.ts
+2
-1
@@ -54,10 +54,11 @@ const BASIC_COMMANDS: ReadonlyArray<BasicCommand> = [
54
{
55
name: 'search',
56
description: 'Search tools by use case across toolkits/apps.',
57
- usage: 'search <query> [--toolkits text] [--limit integer]',
57
+ usage: 'search <query> [--toolkits text] [--user-id text] [--limit integer]',
58
options: [
59
{ name: '<query>', description: 'Semantic use-case query (e.g. "send emails")' },
60
{ name: '--toolkits', description: 'Filter by toolkit slugs, comma-separated' },
61
+ { name: '--user-id', description: 'User ID (falls back to project/global test_user_id)' },
62
{ name: '--limit', description: 'Number of results per page (1-1000)' },
63
],
64
},
ts/packages/cli/src/commands/tools/commands/tools.search.cmd.ts
+67
-5
@@ -4,8 +4,11 @@ import { TerminalUI } from 'src/services/terminal-ui';
4
import { requireAuth } from 'src/effects/require-auth';
5
import { clampLimit } from 'src/ui/clamp-limit';
6
import { resolveToolRouterSession } from 'src/effects/create-tool-router-session';
7
+import { buildMinimalPayloadFromSchema } from 'src/ui/build-minimal-payload';
8
import { formatToolsTable } from '../format';
9
import type { Tool } from 'src/models/tools';
10
+import { ProjectContext } from 'src/services/project-context';
11
+import { ComposioUserContext } from 'src/services/user-context';
12
13
const query = Args.text({ name: 'query' }).pipe(
14
Args.withDescription(
@@ -18,6 +21,11 @@ const toolkits = Options.text('toolkits').pipe(
21
Options.optional
22
);
23
24
+const userId = Options.text('user-id').pipe(
25
+ Options.optional,
26
+ Options.withDescription('User ID for the session (falls back to project/global test_user_id)')
27
+);
28
+
29
const limit = Options.integer('limit').pipe(
30
Options.withDefault(10),
31
Options.withDescription('Number of results per page (1-1000)')
@@ -39,12 +47,38 @@ const limit = Options.integer('limit').pipe(
47
*/
48
export const toolsCmd$Search = Command.make(
49
'search',
42
- { query, toolkits, limit },
43
- ({ query, toolkits, limit }) =>
50
+ { query, toolkits, userId, limit },
51
+ ({ query, toolkits, userId, limit }) =>
52
Effect.gen(function* () {
53
if (!(yield* requireAuth)) return;
54
55
const ui = yield* TerminalUI;
56
+ const projectContext = yield* ProjectContext;
57
+ const userContext = yield* ComposioUserContext;
58
+ const resolvedProjectContext = yield* projectContext.resolve.pipe(
59
+ Effect.catchAll(() => Effect.succeed(Option.none()))
60
+ );
61
+ const testUserId = Option.flatMap(resolvedProjectContext, keys => keys.testUserId);
62
+ const globalTestUserId = userContext.data.testUserId;
63
+ const resolvedUserId = Option.match(userId, {
64
+ onSome: value => Option.some(value),
65
+ onNone: () => Option.orElse(testUserId, () => globalTestUserId),
66
+ });
67
+
68
+ if (Option.isNone(resolvedUserId)) {
69
+ return yield* Effect.fail(
70
+ new Error(
71
+ 'Missing user id. Provide --user-id or run composio init to set test_user_id, or composio login to set global test_user_id.'
72
+ )
73
+ );
74
+ }
75
+
76
+ if (Option.isNone(userId) && Option.isSome(testUserId)) {
77
+ yield* ui.log.warn(`Using test user id "${testUserId.value}"`);
78
+ } else if (Option.isNone(userId) && Option.isSome(globalTestUserId)) {
79
+ yield* ui.log.warn(`Using global test user id "${globalTestUserId.value}"`);
80
+ }
81
+
82
const clampedLimit = clampLimit(limit);
83
const toolkitFilter = Option.getOrUndefined(toolkits);
84
const toolkitList =
@@ -58,7 +92,7 @@ export const toolsCmd$Search = Command.make(
92
const searchResponse = yield* ui.withSpinner(
93
`Searching tools for "${query}"...`,
94
Effect.gen(function* () {
61
- const { client, sessionId } = yield* resolveToolRouterSession('default-cli', {
95
+ const { client, sessionId } = yield* resolveToolRouterSession(resolvedUserId.value, {
96
toolkits: toolkitList,
97
});
98
return yield* Effect.tryPromise(() =>
@@ -138,8 +172,36 @@ export const toolsCmd$Search = Command.make(
172
yield* ui.log.warn(searchResponse.error);
173
}
174
141
- // For machine-readable output (e.g. piping to jq), expose the full API payload.
142
- yield* ui.output(JSON.stringify(searchResponse, null, 2));
175
+ // For machine-readable output (e.g. piping to jq), expose the full API payload with CTA.
176
+ const firstSchema =
177
+ firstSlug && searchResponse.tool_schemas[firstSlug]
178
+ ? searchResponse.tool_schemas[firstSlug]
179
+ : undefined;
180
+ const firstToolkit = firstSchema?.toolkit;
181
+
182
+ const cta: Array<{ action: string; command: string }> = [];
183
+ if (firstSlug) {
184
+ const payload = buildMinimalPayloadFromSchema(
185
+ firstSchema?.input_schema as Record<string, unknown>
186
+ );
187
+ const payloadJson = JSON.stringify(payload);
188
+ cta.push({
189
+ action: 'Execute a tool',
190
+ command: `composio execute "${firstSlug}" -d '${payloadJson}'`,
191
+ });
192
+ }
193
+ if (firstToolkit) {
194
+ cta.push({
195
+ action: 'Connect a user account',
196
+ command: `composio link ${String(firstToolkit).toLowerCase()}`,
197
+ });
198
+ }
199
+
200
+ const outputForJq = {
201
+ ...searchResponse,
202
+ CTA: cta,
203
+ };
204
+ yield* ui.output(JSON.stringify(outputForJq, null, 2));
205
})
206
).pipe(
207
Command.withDescription(
ts/packages/cli/src/ui/build-minimal-payload.ts
new
+45
@@ -0,0 +1,45 @@
1
+import { extractSchemaProperties } from './extract-schema-properties';
2
+
3
+/**
4
+ * Builds a minimal valid JSON payload from a JSON Schema input_schema.
5
+ * Used for CTA examples (e.g. composio execute "TOOL" -d '...').
6
+ */
7
+export function buildMinimalPayloadFromSchema(
8
+ schema: Record<string, unknown> | null | undefined
9
+): Record<string, unknown> {
10
+ if (!schema || typeof schema !== 'object') {
11
+ return {};
12
+ }
13
+
14
+ const entries = extractSchemaProperties(schema);
15
+ if (entries.length === 0) {
16
+ return {};
17
+ }
18
+
19
+ const result: Record<string, unknown> = {};
20
+ for (const entry of entries) {
21
+ result[entry.name] = defaultForType(entry.type, entry.defaultValue);
22
+ }
23
+ return result;
24
+}
25
+
26
+function defaultForType(type: string, schemaDefault: unknown): unknown {
27
+ if (schemaDefault !== undefined) {
28
+ return schemaDefault;
29
+ }
30
+ switch (type) {
31
+ case 'string':
32
+ return '';
33
+ case 'number':
34
+ case 'integer':
35
+ return 0;
36
+ case 'boolean':
37
+ return false;
38
+ case 'array':
39
+ return [];
40
+ case 'object':
41
+ return {};
42
+ default:
43
+ return '';
44
+ }
45
+}
ts/packages/cli/test/src/commands/__snapshots__/$default.cmd.test.ts.snap
+2
-1
@@ -44,10 +44,11 @@ BASIC COMMANDS
44
45
search
46
Search tools by use case across toolkits/apps.
47
- Usage: composio search <query> [--toolkits text] [--limit integer]
47
+ Usage: composio search <query> [--toolkits text] [--user-id text] [--limit integer]
48
Options:
49
<query> Semantic use-case query (e.g. "send emails")
50
--toolkits Filter by toolkit slugs, comma-separated
51
+ --user-id User ID (falls back to project/global test_user_id)
52
--limit Number of results per page (1-1000)
53
54
execute
ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.link.cmd.test.ts
+34
@@ -143,4 +143,38 @@ describe('CLI: composio connected-accounts link', () => {
143
);
144
}
145
);
146
+
147
+ layer(TestLive({ baseConfigProvider: testConfigProvider, connectedAccountsData }))(
148
+ '[Given] successful link [Then] outputs valid JSON with success message for jq',
149
+ it => {
150
+ it.scoped(
151
+ 'prints JSON with status, message, connected_account_id, toolkit, redirect_url',
152
+ () =>
153
+ Effect.gen(function* () {
154
+ yield* cli([
155
+ 'connected-accounts',
156
+ 'link',
157
+ '--auth-config',
158
+ 'ac_gmail_oauth',
159
+ '--user-id',
160
+ 'default',
161
+ '--no-browser',
162
+ ]);
163
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
164
+ const output = lines.join('\n');
165
+
166
+ expect(output).toContain('"status"');
167
+ expect(output).toContain('"success"');
168
+ expect(output).toContain('"message"');
169
+ expect(output).toContain('ACTIVE');
170
+ expect(output).toContain('"connected_account_id"');
171
+ expect(output).toContain('con_test_link');
172
+ expect(output).toContain('"toolkit"');
173
+ expect(output).toContain('"gmail"');
174
+ expect(output).toContain('"redirect_url"');
175
+ expect(output).toContain('https://app.composio.dev/link');
176
+ })
177
+ );
178
+ }
179
+ );
180
});
ts/packages/cli/test/src/commands/tools/tools.search.cmd.test.ts
+132
-24
@@ -47,26 +47,29 @@ const testConfigProvider = ConfigProvider.fromMap(
47
new Map([['COMPOSIO_USER_API_KEY', 'test_api_key']])
48
).pipe(extendConfigProvider);
49
50
+const testLiveOptions = {
51
+ baseConfigProvider: testConfigProvider,
52
+ toolkitsData,
53
+ fixture: 'global-test-user-id' as const,
54
+};
55
+
56
describe('CLI: composio tools search', () => {
51
- layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
52
- '[Given] query "send" [Then] returns matching tools',
53
- it => {
54
- it.scoped('returns matching tools', () =>
55
- Effect.gen(function* () {
56
- yield* cli(['tools', 'search', 'send']);
57
- const lines = yield* MockConsole.getLines({ stripAnsi: true });
58
- const output = lines.join('\n');
57
+ layer(TestLive(testLiveOptions))('[Given] query "send" [Then] returns matching tools', it => {
58
+ it.scoped('returns matching tools', () =>
59
+ Effect.gen(function* () {
60
+ yield* cli(['tools', 'search', 'send']);
61
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
62
+ const output = lines.join('\n');
63
60
- expect(output).toContain('GMAIL_SEND_EMAIL');
61
- expect(output).toContain('SLACK_SEND_MESSAGE');
62
- expect(output).not.toContain('GITHUB_CREATE_ISSUE');
63
- expect(output).toContain('Found 2 tools');
64
- })
65
- );
66
- }
67
- );
64
+ expect(output).toContain('GMAIL_SEND_EMAIL');
65
+ expect(output).toContain('SLACK_SEND_MESSAGE');
66
+ expect(output).not.toContain('GITHUB_CREATE_ISSUE');
67
+ expect(output).toContain('Found 2 tools');
68
+ })
69
+ );
70
+ });
71
69
- layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
72
+ layer(TestLive(testLiveOptions))(
73
'[Given] query with no results [Then] shows not found message',
74
it => {
75
it.scoped('shows not found message', () =>
@@ -81,7 +84,7 @@ describe('CLI: composio tools search', () => {
84
}
85
);
86
84
- layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
87
+ layer(TestLive(testLiveOptions))(
88
'[Given] query "send" --toolkits "gmail" [Then] scopes to toolkit',
89
it => {
90
it.scoped('scopes search to toolkit', () =>
@@ -99,10 +102,10 @@ describe('CLI: composio tools search', () => {
102
}
103
);
104
102
- layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
103
- '[Given] tools search [Then] JSON output includes full tool-router payload',
105
+ layer(TestLive(testLiveOptions))(
106
+ '[Given] tools search [Then] JSON output includes full tool-router payload and CTA',
107
it => {
105
- it.scoped('prints full search response for jq', () =>
108
+ it.scoped('prints full search response with CTA for jq', () =>
109
Effect.gen(function* () {
110
yield* cli(['tools', 'search', 'send']);
111
const lines = yield* MockConsole.getLines({ stripAnsi: true });
@@ -113,12 +116,70 @@ describe('CLI: composio tools search', () => {
116
expect(output).toContain('"toolkit_connection_statuses"');
117
expect(output).toContain('"session"');
118
expect(output).toContain('"time_info"');
119
+ expect(output).toContain('"CTA"');
120
+ expect(output).toContain('"Execute a tool"');
121
+ expect(output).toContain('"Connect a user account"');
122
+ expect(output).toContain('composio execute');
123
+ expect(output).toContain('composio link gmail');
124
})
125
);
126
}
127
);
128
121
- layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
129
+ layer(TestLive({ baseConfigProvider: testConfigProvider, fixture: 'global-test-user-id' }))(
130
+ '[Given] search with schema properties [Then] CTA has valid payload and lowercase link',
131
+ it => {
132
+ it.scoped('CTA uses valid payload from input_schema and lowercase toolkit', () =>
133
+ Effect.gen(function* () {
134
+ const live = TestLive({
135
+ baseConfigProvider: testConfigProvider,
136
+ fixture: 'global-test-user-id',
137
+ toolkitsData: {
138
+ tools: [
139
+ {
140
+ name: 'Send Email',
141
+ slug: 'GMAIL_SEND_EMAIL',
142
+ description: 'Sends an email',
143
+ tags: [],
144
+ available_versions: [],
145
+ input_parameters: {
146
+ type: 'object',
147
+ properties: {
148
+ to: { type: 'string' },
149
+ subject: { type: 'string' },
150
+ body: { type: 'string' },
151
+ },
152
+ required: ['to'],
153
+ },
154
+ output_parameters: { type: 'object', properties: {} },
155
+ },
156
+ ],
157
+ },
158
+ });
159
+
160
+ yield* cli(['tools', 'search', 'send']).pipe(Effect.provide(live));
161
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
162
+ const output = lines.join('\n');
163
+
164
+ const ctaMatch = output.match(/"CTA":\s*\[([\s\S]*?)\]/);
165
+ expect(ctaMatch).toBeTruthy();
166
+ const ctaJson = `[${ctaMatch![1]}]`;
167
+ const cta = JSON.parse(ctaJson) as Array<{ action: string; command: string }>;
168
+
169
+ const executeCta = cta.find(c => c.action === 'Execute a tool');
170
+ expect(executeCta).toBeTruthy();
171
+ expect(executeCta!.command).toContain('composio execute "GMAIL_SEND_EMAIL"');
172
+ expect(executeCta!.command).toMatch(/-d '\{"to":"","subject":"","body":""\}'/);
173
+
174
+ const linkCta = cta.find(c => c.action === 'Connect a user account');
175
+ expect(linkCta).toBeTruthy();
176
+ expect(linkCta!.command).toBe('composio link gmail');
177
+ })
178
+ );
179
+ }
180
+ );
181
+
182
+ layer(TestLive(testLiveOptions))(
183
'[Given] --toolkits filter [Then] it is passed to session create as enabled toolkits',
184
it => {
185
it.scoped('passes toolkit filter into tool router session', () =>
@@ -129,6 +190,7 @@ describe('CLI: composio tools search', () => {
190
const live = TestLive({
191
baseConfigProvider: testConfigProvider,
192
toolkitsData,
193
+ fixture: 'global-test-user-id',
194
toolRouter: {
195
create: async params => {
196
createParams = params;
@@ -198,7 +260,7 @@ describe('CLI: composio tools search', () => {
260
}
261
);
262
201
- layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
263
+ layer(TestLive(testLiveOptions))(
264
'[Given] search response with recommended plan [Then] it prints plan and execute hint',
265
it => {
266
it.scoped('prints plan and command hints', () =>
@@ -206,6 +268,7 @@ describe('CLI: composio tools search', () => {
268
const live = TestLive({
269
baseConfigProvider: testConfigProvider,
270
toolkitsData,
271
+ fixture: 'global-test-user-id',
272
toolRouter: {
273
search: async (_sessionId, params) => ({
274
success: true,
@@ -281,7 +344,52 @@ describe('CLI: composio tools search', () => {
344
);
345
});
346
284
- layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
347
+ layer(TestLive(testLiveOptions))(
348
+ '[Given] explicit --user-id [Then] uses that user id for session',
349
+ it => {
350
+ it.scoped('passes user-id to session create', () =>
351
+ Effect.gen(function* () {
352
+ let createParams: SessionCreateParams | undefined;
353
+ const live = TestLive({
354
+ ...testLiveOptions,
355
+ toolRouter: {
356
+ create: async params => {
357
+ createParams = params;
358
+ return {
359
+ session_id: 'trs_test_session',
360
+ config: { user_id: params.user_id },
361
+ mcp: { type: 'http', url: 'https://mcp.test.composio.dev' },
362
+ tool_router_tools: ['COMPOSIO_SEARCH_TOOLS'],
363
+ };
364
+ },
365
+ },
366
+ });
367
+
368
+ yield* cli(['tools', 'search', 'send', '--user-id', 'alice']).pipe(Effect.provide(live));
369
+
370
+ expect(createParams?.user_id).toBe('alice');
371
+ })
372
+ );
373
+ }
374
+ );
375
+
376
+ layer(TestLive({ baseConfigProvider: testConfigProvider }))(
377
+ '[Given] no test_user_id and no --user-id [Then] fails with missing user id message',
378
+ it => {
379
+ it.scoped('fails when user id cannot be resolved', () =>
380
+ Effect.gen(function* () {
381
+ const err = yield* cli(['tools', 'search', 'send']).pipe(Effect.flip);
382
+ const message = err instanceof Error ? err.message : String(err);
383
+
384
+ expect(message).toContain('Missing user id');
385
+ expect(message).toContain('--user-id');
386
+ expect(message).toContain('composio init');
387
+ })
388
+ );
389
+ }
390
+ );
391
+
392
+ layer(TestLive(testLiveOptions))(
393
'[Given] composio search alias [Then] works like composio tools search',
394
it => {
395
it.scoped('alias expands to tools search', () =>