Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Add connection removal CLI (#3259)
## Summary - Add interactive `composio connections remove <account>` support for consumer connections. - Resolve the account selector by toolkit slug, alias, word_id, or connected account ID, with ambiguity handling. - Require explicit confirmation before deleting a connection, defaulting to No. - Update CLI help/README and add tests for confirmed removal, declined removal, and ambiguous selectors. ## Testing - `pnpm --filter @composio/cli test -- test/src/commands/connections/connections.list.cmd.test.ts` - `pnpm typecheck`
Rahul Tarak committed
Apr 23, 2026 at 14:54 UTC
d80e109e264193ed6ca3c6ed321ddd7bf926be43
6 files changed
+301
-3
ts/packages/cli/README.md
+1
@@ -39,6 +39,7 @@ composio [--log-level all|trace|debug|info|warning|error|fatal|none]
39
- `composio tools list|info`: Inspect available tools and their cached schemas.
40
- `composio triggers list <toolkit>|info`: Inspect toolkit-scoped trigger types and their schemas.
41
- `composio connections list [--toolkit <toolkit>]`: Print toolkit connection statuses as JSON.
42
+- `composio connections remove <account>`: Interactively remove a toolkit connection after confirmation.
43
- `composio artifacts cwd`: Print the cwd-scoped CLI session artifacts directory.
44
- `composio dev <subcommand>`: Developer workflows for init, playground execution, logs, toolkits, auth configs, accounts, triggers, orgs, and projects.
45
- `composio generate [-o, --output-dir <directory>] [--toolkits <toolkit>] [--type-tools]`: Auto-detect the project language (Python or TypeScript) and generate type stubs for toolkits, tools, and triggers.
ts/packages/cli/src/commands/connections/commands/connections.remove.cmd.ts
new
+146
@@ -0,0 +1,146 @@
1
+import { Args, Command } from '@effect/cli';
2
+import { Effect, Schema } from 'effect';
3
+import { requireAuth } from 'src/effects/require-auth';
4
+import type { ConnectedAccountItem } from 'src/models/connected-accounts';
5
+import {
6
+ ComposioClientSingleton,
7
+ ConnectedAccountListResponse,
8
+} from 'src/services/composio-clients';
9
+import {
10
+ formatResolveCommandProjectError,
11
+ resolveCommandProject,
12
+} from 'src/services/command-project';
13
+import { TerminalUI } from 'src/services/terminal-ui';
14
+import { bold } from 'src/ui/colors';
15
+import { redact } from 'src/ui/redact';
16
+
17
+const account = Args.text({ name: 'account' }).pipe(
18
+ Args.withDescription('Connection selector: toolkit slug, alias, word_id, or connected account ID')
19
+);
20
+
21
+const normalizeSelector = (value: string): string => value.trim().toLowerCase();
22
+
23
+const selectorMatches = (item: ConnectedAccountItem, selector: string): boolean => {
24
+ const normalized = normalizeSelector(selector);
25
+ return (
26
+ normalizeSelector(item.id) === normalized ||
27
+ normalizeSelector(item.alias ?? '') === normalized ||
28
+ normalizeSelector(item.word_id ?? '') === normalized ||
29
+ normalizeSelector(item.toolkit.slug) === normalized
30
+ );
31
+};
32
+
33
+const formatAccountSummary = (item: ConnectedAccountItem): string =>
34
+ [
35
+ `${bold('Toolkit:')} ${item.toolkit.slug}`,
36
+ `${bold('Alias:')} ${item.alias || '-'}`,
37
+ `${bold('Word Id:')} ${item.word_id || '-'}`,
38
+ `${bold('Connected Account:')} ${redact({ value: item.id, prefix: 'con_' })}`,
39
+ `${bold('Status:')} ${item.status}`,
40
+ ].join('\n');
41
+
42
+const formatAccountChoice = (item: ConnectedAccountItem): string => {
43
+ const labels = [item.alias, item.word_id].filter(
44
+ (value): value is string => typeof value === 'string' && value.trim().length > 0
45
+ );
46
+ const selectors = labels.length > 0 ? ` (${labels.join(' / ')})` : '';
47
+ return `${item.toolkit.slug}${selectors}: ${redact({ value: item.id, prefix: 'con_' })}`;
48
+};
49
+
50
+const resolveAccount = (params: {
51
+ readonly accounts: ReadonlyArray<ConnectedAccountItem>;
52
+ readonly selector: string;
53
+}): ConnectedAccountItem | { readonly error: string } => {
54
+ const matches = params.accounts.filter(item => selectorMatches(item, params.selector));
55
+
56
+ if (matches.length === 0) {
57
+ return {
58
+ error: `No connection matched "${params.selector}". Run \`composio connections list\` to inspect available connections.`,
59
+ };
60
+ }
61
+
62
+ const idMatches = matches.filter(
63
+ item => normalizeSelector(item.id) === normalizeSelector(params.selector)
64
+ );
65
+ if (idMatches.length === 1) {
66
+ return idMatches[0]!;
67
+ }
68
+
69
+ if (matches.length === 1) {
70
+ return matches[0]!;
71
+ }
72
+
73
+ return {
74
+ error: [
75
+ `Multiple connections matched "${params.selector}". Use a unique alias, word_id, or connected account ID.`,
76
+ '',
77
+ ...matches.map(item => `- ${formatAccountChoice(item)}`),
78
+ ].join('\n'),
79
+ };
80
+};
81
+
82
+export const connectionsCmd$Remove = Command.make('remove', { account }, ({ account }) =>
83
+ Effect.gen(function* () {
84
+ if (!(yield* requireAuth)) return;
85
+
86
+ const ui = yield* TerminalUI;
87
+ const clientSingleton = yield* ComposioClientSingleton;
88
+ const resolvedProject = yield* resolveCommandProject({
89
+ mode: 'consumer',
90
+ }).pipe(Effect.mapError(formatResolveCommandProjectError));
91
+
92
+ const consumerUserId = resolvedProject.consumerUserId;
93
+ if (!consumerUserId) {
94
+ return yield* Effect.fail(
95
+ new Error('Missing consumer user id. Run `composio login` and try again.')
96
+ );
97
+ }
98
+
99
+ const client = yield* clientSingleton.getFor({
100
+ orgId: resolvedProject.orgId,
101
+ projectId: resolvedProject.projectId,
102
+ });
103
+ const rawResult = yield* ui.withSpinner(
104
+ 'Fetching connections...',
105
+ Effect.tryPromise(() =>
106
+ client.connectedAccounts.list({
107
+ user_ids: [consumerUserId],
108
+ limit: 1000,
109
+ })
110
+ )
111
+ );
112
+ const result = yield* Schema.decodeUnknown(ConnectedAccountListResponse)(rawResult);
113
+ const resolved = resolveAccount({ accounts: result.items, selector: account });
114
+
115
+ if ('error' in resolved) {
116
+ yield* ui.log.warn(resolved.error);
117
+ return;
118
+ }
119
+
120
+ yield* ui.note(
121
+ `${formatAccountSummary(resolved)}\n\nThis will remove the connection from Composio and tools will no longer be able to use it.`,
122
+ 'Remove Connection'
123
+ );
124
+
125
+ const confirmed = yield* ui.confirm(`Remove ${resolved.toolkit.slug} connection?`, {
126
+ defaultValue: false,
127
+ });
128
+ if (!confirmed) {
129
+ yield* ui.log.warn('No connection removed.');
130
+ return;
131
+ }
132
+
133
+ yield* ui.withSpinner(
134
+ `Removing ${resolved.toolkit.slug} connection...`,
135
+ Effect.tryPromise(() => client.connectedAccounts.delete(resolved.id)),
136
+ {
137
+ successMessage: `Removed ${resolved.toolkit.slug} connection.`,
138
+ errorMessage: `Failed to remove ${resolved.toolkit.slug} connection.`,
139
+ }
140
+ );
141
+ })
142
+).pipe(
143
+ Command.withDescription(
144
+ 'Interactively remove a connection by toolkit slug, alias, word_id, or connected account ID.'
145
+ )
146
+);
ts/packages/cli/src/commands/connections/connections.cmd.ts
+3
-2
@@ -1,7 +1,8 @@
1
import { Command } from '@effect/cli';
2
import { connectionsCmd$List } from './commands/connections.list.cmd';
3
+import { connectionsCmd$Remove } from './commands/connections.remove.cmd';
4
5
export const rootConnectionsCmd = Command.make('connections').pipe(
5
- Command.withDescription('Inspect connected toolkit accounts in a script-friendly format.'),
6
- Command.withSubcommands([connectionsCmd$List])
6
+ Command.withDescription('Inspect and remove connected toolkit accounts.'),
7
+ Command.withSubcommands([connectionsCmd$List, connectionsCmd$Remove])
8
);
ts/packages/cli/src/commands/root-help.ts
+21
@@ -181,6 +181,7 @@ const FULL_COMMANDS: ReadonlyArray<TaggedValue<CompactCommand>> = [
181
full({ name: 'triggers list', description: 'List trigger types for a toolkit' }),
182
full({ name: 'triggers info', description: 'Inspect a trigger type and schema summary' }),
183
full({ name: 'connections list', description: 'Print toolkit connection statuses as JSON' }),
184
+ full({ name: 'connections remove', description: 'Interactively remove a toolkit connection' }),
185
full({ name: 'generate ts', description: 'Generate TypeScript stubs for selected toolkits' }),
186
full({ name: 'generate py', description: 'Generate Python stubs for selected toolkits' }),
187
full({
@@ -551,6 +552,26 @@ const SUBCOMMAND_HELP: Record<string, SubcommandHelp | TaggedValue<SubcommandHel
552
'composio dev connected-accounts list Inspect the full connected-account table',
553
],
554
},
555
+ 'connections remove': {
556
+ usage: 'composio connections remove <account>',
557
+ description:
558
+ 'Interactively remove a connected toolkit account. The command prompts for confirmation and defaults to No.',
559
+ args: [
560
+ {
561
+ name: '<account>',
562
+ description: 'Toolkit slug, alias, word_id, or connected account ID',
563
+ },
564
+ ],
565
+ examples: [
566
+ 'composio connections remove gmail',
567
+ 'composio connections remove work',
568
+ 'composio connections remove castle',
569
+ ],
570
+ seeAlso: [
571
+ 'composio connections list Find connection selectors',
572
+ 'composio link <toolkit> Reconnect a toolkit account',
573
+ ],
574
+ },
575
run: {
576
usage: 'composio run <code> [-- ...args] | run -f <file> [-- ...args]',
577
description:
ts/packages/cli/test/__utils__/services/test-layer.ts
+9
@@ -109,6 +109,7 @@ export interface TestLiveInput {
109
items?: ConnectedAccountItem[];
110
linkResponse?: LinkCreateResponse;
111
onPatch?: (params: { path: string; body: Record<string, unknown> | undefined }) => void;
112
+ onDelete?: (nanoid: string) => void;
113
};
114
115
/**
@@ -1058,6 +1059,14 @@ export const TestLayer = (input?: TestLiveInput) =>
1059
}
1060
return found;
1061
},
1062
+ delete: async (nanoid: string) => {
1063
+ const found = connectedAccountsData.items.find(item => item.id === nanoid);
1064
+ if (!found) {
1065
+ throw new Error(`Connected account "${nanoid}" not found`);
1066
+ }
1067
+ connectedAccountsData.onDelete?.(nanoid);
1068
+ return {};
1069
+ },
1070
},
1071
triggerInstances: {
1072
upsert: async (
ts/packages/cli/test/src/commands/connections/connections.list.cmd.test.ts
+121
-1
@@ -1,7 +1,8 @@
1
import { describe, expect, layer } from '@effect/vitest';
2
-import { ConfigProvider, Effect } from 'effect';
2
+import { ConfigProvider, Console, Effect } from 'effect';
3
import type { ConnectedAccountItem } from 'src/models/connected-accounts';
4
import { extendConfigProvider } from 'src/services/config';
5
+import { TerminalUI } from 'src/services/terminal-ui';
6
import { ComposioUserContext } from 'src/services/user-context';
7
import { cli, TestLive, MockConsole } from 'test/__utils__';
8
import type { TestLiveInput } from 'test/__utils__/services/test-layer';
@@ -87,6 +88,40 @@ const testConfigProvider = ConfigProvider.fromMap(
88
new Map([['COMPOSIO_USER_API_KEY', 'test_api_key']])
89
).pipe(extendConfigProvider);
90
91
+const terminalUIWithConfirm = (confirmed: boolean) =>
92
+ TerminalUI.of({
93
+ output: data => Console.log(data),
94
+ intro: title => Console.log(`-- ${title} --`),
95
+ outro: message => Console.log(`-- ${message} --`),
96
+ log: {
97
+ info: message => Console.log(message),
98
+ success: message => Console.log(message),
99
+ warn: message => Console.warn(message),
100
+ error: message => Console.error(message),
101
+ step: message => Console.log(message),
102
+ message: message => Console.log(message),
103
+ },
104
+ note: (message, title) => Console.log(title ? `[${title}] ${message}` : message),
105
+ select: (_message, options) => Effect.succeed(options[0]!.value),
106
+ confirm: () => Effect.succeed(confirmed),
107
+ withSpinner: (message, effect, options) =>
108
+ Effect.gen(function* () {
109
+ const result = yield* effect;
110
+ const successMsg =
111
+ typeof options?.successMessage === 'function'
112
+ ? options.successMessage(result)
113
+ : (options?.successMessage ?? message);
114
+ yield* Console.log(successMsg);
115
+ return result;
116
+ }),
117
+ useMakeSpinner: (_message, use) =>
118
+ use({
119
+ message: (_msg: string) => Effect.void,
120
+ stop: (msg?: string) => (msg ? Console.log(msg) : Effect.void),
121
+ error: (msg?: string) => (msg ? Console.error(msg) : Effect.void),
122
+ }),
123
+ });
124
+
125
describe('CLI: composio connections list', () => {
126
layer(TestLive({ baseConfigProvider: testConfigProvider, connectedAccountsData }))(it => {
127
it.scoped('[Given] no filter [Then] prints connection JSON with aliases for duplicates', () =>
@@ -199,3 +234,88 @@ describe('CLI: composio connections list', () => {
234
);
235
});
236
});
237
+
238
+describe('CLI: composio connections remove', () => {
239
+ const confirmedDeleteCalls: string[] = [];
240
+ layer(
241
+ TestLive({
242
+ baseConfigProvider: testConfigProvider,
243
+ connectedAccountsData: {
244
+ items: testConnections,
245
+ onDelete: nanoid => confirmedDeleteCalls.push(nanoid),
246
+ },
247
+ terminalUI: terminalUIWithConfirm(true),
248
+ })
249
+ )(it => {
250
+ it.scoped('[Given] a unique toolkit selector and consent [Then] removes that connection', () =>
251
+ Effect.gen(function* () {
252
+ confirmedDeleteCalls.length = 0;
253
+
254
+ const userContext = yield* ComposioUserContext;
255
+ yield* userContext.login('test_api_key', 'org_test');
256
+ yield* cli(['connections', 'remove', 'gmail']);
257
+
258
+ expect(confirmedDeleteCalls).toEqual(['con_gmail_active']);
259
+
260
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
261
+ expect(lines.join('\n')).toContain('Removed gmail connection.');
262
+ })
263
+ );
264
+ });
265
+
266
+ const deniedDeleteCalls: string[] = [];
267
+ layer(
268
+ TestLive({
269
+ baseConfigProvider: testConfigProvider,
270
+ connectedAccountsData: {
271
+ items: testConnections,
272
+ onDelete: nanoid => deniedDeleteCalls.push(nanoid),
273
+ },
274
+ terminalUI: terminalUIWithConfirm(false),
275
+ })
276
+ )(it => {
277
+ it.scoped('[Given] consent is denied [Then] does not remove the connection', () =>
278
+ Effect.gen(function* () {
279
+ deniedDeleteCalls.length = 0;
280
+
281
+ const userContext = yield* ComposioUserContext;
282
+ yield* userContext.login('test_api_key', 'org_test');
283
+ yield* cli(['connections', 'remove', 'work']);
284
+
285
+ expect(deniedDeleteCalls).toEqual([]);
286
+
287
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
288
+ expect(lines.join('\n')).toContain('No connection removed.');
289
+ })
290
+ );
291
+ });
292
+
293
+ const ambiguousDeleteCalls: string[] = [];
294
+ layer(
295
+ TestLive({
296
+ baseConfigProvider: testConfigProvider,
297
+ connectedAccountsData: {
298
+ items: testConnections,
299
+ onDelete: nanoid => ambiguousDeleteCalls.push(nanoid),
300
+ },
301
+ terminalUI: terminalUIWithConfirm(true),
302
+ })
303
+ )(it => {
304
+ it.scoped(
305
+ '[Given] a selector matches multiple accounts [Then] asks for a unique selector',
306
+ () =>
307
+ Effect.gen(function* () {
308
+ ambiguousDeleteCalls.length = 0;
309
+
310
+ const userContext = yield* ComposioUserContext;
311
+ yield* userContext.login('test_api_key', 'org_test');
312
+ yield* cli(['connections', 'remove', 'github']);
313
+
314
+ expect(ambiguousDeleteCalls).toEqual([]);
315
+
316
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
317
+ expect(lines.join('\n')).toContain('Multiple connections matched "github"');
318
+ })
319
+ );
320
+ });
321
+});