@dench.com/cli 3.11.70-staging.1221 → 3.12.0-staging.1224

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/mcp.ts ADDED
@@ -0,0 +1,251 @@
1
+ /**
2
+ * `dench mcp` — list and call custom MCP servers connected in Integrations → Custom MCP.
3
+ *
4
+ * Subcommands:
5
+ * dench mcp list [--json]
6
+ * dench mcp tools <server> [--json]
7
+ * dench mcp call <server> <tool> [--args '<json>'] [--json]
8
+ */
9
+
10
+ import type { ConvexHttpClient } from "convex/browser";
11
+ import { makeFunctionReference } from "convex/server";
12
+ import { PRODUCTION_API_URL } from "./host";
13
+ import {
14
+ assertNoUnknownFlags,
15
+ CliArgError,
16
+ getFlag,
17
+ hasFlag,
18
+ isHelpRequest,
19
+ parseJson,
20
+ shift,
21
+ } from "./lib/cli-args";
22
+
23
+ const listServersRef = makeFunctionReference<"query">(
24
+ "functions/customMcpServers:list",
25
+ );
26
+ const getToolsRef = makeFunctionReference<"query">(
27
+ "functions/customMcpServers:getTools",
28
+ );
29
+
30
+ export type McpCliOptions = {
31
+ convex?: ConvexHttpClient;
32
+ args: string[];
33
+ sessionToken?: string;
34
+ host?: string;
35
+ bearerToken?: string;
36
+ workspaceSlug?: string;
37
+ jsonOutput?: boolean;
38
+ };
39
+
40
+ /** Drops trailing "/" with a loop: a `/\/+$/` regex is slow on many slashes. */
41
+ function trimTrailingSlashes(value: string): string {
42
+ let end = value.length;
43
+ while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
44
+ return value.slice(0, end);
45
+ }
46
+
47
+ export function mcpHelpText(): string {
48
+ return `Usage: dench mcp <subcommand> [options]
49
+
50
+ Inspect and call custom MCP servers connected in Integrations → Custom MCP.
51
+
52
+ Subcommands:
53
+ list [--json]
54
+ List custom MCP servers you can use in this workspace.
55
+
56
+ tools <server> [--json]
57
+ List cached tools exposed by a custom MCP server (by slug, id, or "yc").
58
+
59
+ call <server> <tool> [--args '<json>'] [--json]
60
+ Call a tool on a connected custom MCP server.
61
+
62
+ Examples:
63
+ dench mcp list
64
+ dench mcp tools yc
65
+ dench mcp call yc find_intro --args '{"company":"Context.dev"}'
66
+ `;
67
+ }
68
+
69
+ type PublicMcpServerRow = {
70
+ _id: string;
71
+ name: string;
72
+ slug: string;
73
+ host: string;
74
+ preset?: string;
75
+ visibility: "private" | "shared";
76
+ status: "connected" | "reauth_required";
77
+ toolCount: number;
78
+ ownerName?: string;
79
+ isOwner: boolean;
80
+ };
81
+
82
+ type CachedMcpToolRow = {
83
+ name: string;
84
+ title: string;
85
+ description: string;
86
+ readOnly: boolean;
87
+ destructive?: boolean;
88
+ };
89
+
90
+ export async function runMcpCommand(opts: McpCliOptions): Promise<void> {
91
+ const args = [...opts.args];
92
+ const jsonOutput = hasFlag(args, "--json") || Boolean(opts.jsonOutput);
93
+
94
+ if (args.length === 0 || isHelpRequest(args)) {
95
+ console.log(mcpHelpText());
96
+ return;
97
+ }
98
+
99
+ const sub = shift(args, "subcommand (list | tools | call)");
100
+
101
+ if (sub === "list" || sub === "ls") {
102
+ assertNoUnknownFlags(args, "dench mcp list");
103
+ if (!opts.convex) {
104
+ throw new CliArgError("Not signed in. Run `dench signin` first.");
105
+ }
106
+ const rows = (await opts.convex.query(listServersRef, {
107
+ ...(opts.workspaceSlug ? { slug: opts.workspaceSlug } : {}),
108
+ ...(opts.sessionToken ? { sessionToken: opts.sessionToken } : {}),
109
+ } as never)) as PublicMcpServerRow[];
110
+
111
+ if (jsonOutput) {
112
+ console.log(JSON.stringify(rows, null, 2));
113
+ return;
114
+ }
115
+ if (!Array.isArray(rows) || rows.length === 0) {
116
+ console.log(
117
+ "No custom MCP servers connected. Add one in Integrations → Custom MCP.",
118
+ );
119
+ return;
120
+ }
121
+ console.log("Custom MCP servers:");
122
+ for (const row of rows) {
123
+ const statusLabel =
124
+ row.status === "reauth_required" ? "reauth_required" : "connected";
125
+ const visibilityLabel =
126
+ row.visibility === "private"
127
+ ? "private"
128
+ : row.isOwner
129
+ ? "shared"
130
+ : `shared · ${row.ownerName ?? "teammate"}`;
131
+ console.log(
132
+ ` - ${row.slug} (${row.name}) [${statusLabel}] · ${row.host} · ${row.toolCount} tools · ${visibilityLabel}`,
133
+ );
134
+ }
135
+ return;
136
+ }
137
+
138
+ if (sub === "tools") {
139
+ const server = shift(args, "<server>");
140
+ assertNoUnknownFlags(args, "dench mcp tools");
141
+ if (!opts.convex) {
142
+ throw new CliArgError("Not signed in. Run `dench signin` first.");
143
+ }
144
+ const result = (await opts.convex.query(getToolsRef, {
145
+ server,
146
+ ...(opts.workspaceSlug ? { slug: opts.workspaceSlug } : {}),
147
+ ...(opts.sessionToken ? { sessionToken: opts.sessionToken } : {}),
148
+ } as never)) as {
149
+ server: { name: string; slug: string; status: string };
150
+ tools: CachedMcpToolRow[];
151
+ };
152
+
153
+ if (jsonOutput) {
154
+ console.log(JSON.stringify(result, null, 2));
155
+ return;
156
+ }
157
+ console.log(
158
+ `Tools on ${result.server.name} (${result.server.slug}) [${result.server.status}]:`,
159
+ );
160
+ if (!result.tools.length) {
161
+ console.log(" (no tools cached)");
162
+ return;
163
+ }
164
+ for (const tool of result.tools) {
165
+ const mode = tool.readOnly
166
+ ? "read-only"
167
+ : tool.destructive
168
+ ? "destructive"
169
+ : "write";
170
+ console.log(` - ${tool.name} [${mode}] — ${tool.description}`);
171
+ }
172
+ return;
173
+ }
174
+
175
+ if (sub === "call" || sub === "run") {
176
+ const server = shift(args, "<server>");
177
+ const tool = shift(args, "<tool>");
178
+ const rawArgs = getFlag(args, "--args");
179
+ assertNoUnknownFlags(args, "dench mcp call");
180
+
181
+ let parsedArgs: Record<string, unknown> = {};
182
+ if (rawArgs !== undefined) {
183
+ const candidate = parseJson(rawArgs);
184
+ if (
185
+ !candidate ||
186
+ typeof candidate !== "object" ||
187
+ Array.isArray(candidate)
188
+ ) {
189
+ throw new CliArgError("--args must be a JSON object");
190
+ }
191
+ parsedArgs = candidate as Record<string, unknown>;
192
+ }
193
+
194
+ const bearer = opts.bearerToken?.trim() || opts.sessionToken?.trim();
195
+ if (!bearer) {
196
+ throw new CliArgError("Not signed in. Run `dench signin` first.");
197
+ }
198
+ const baseUrl = trimTrailingSlashes(
199
+ opts.host?.trim() || PRODUCTION_API_URL,
200
+ );
201
+ const response = await fetch(
202
+ `${baseUrl}/api/v1/mcp/servers/${encodeURIComponent(server)}/call`,
203
+ {
204
+ method: "POST",
205
+ headers: {
206
+ accept: "application/json",
207
+ "content-type": "application/json",
208
+ authorization: `Bearer ${bearer}`,
209
+ },
210
+ body: JSON.stringify({
211
+ tool,
212
+ arguments: parsedArgs,
213
+ ...(opts.workspaceSlug ? { slug: opts.workspaceSlug } : {}),
214
+ }),
215
+ },
216
+ );
217
+
218
+ const payload = (await response.json().catch(() => null)) as Record<
219
+ string,
220
+ unknown
221
+ > | null;
222
+ if (!response.ok) {
223
+ const errObj =
224
+ payload && typeof payload.error === "object" && payload.error !== null
225
+ ? (payload.error as Record<string, unknown>)
226
+ : null;
227
+ const message =
228
+ (typeof errObj?.message === "string" && errObj.message) ||
229
+ (typeof payload?.message === "string" && payload.message) ||
230
+ `MCP call failed with HTTP ${response.status}`;
231
+ throw new Error(message);
232
+ }
233
+
234
+ if (jsonOutput) {
235
+ console.log(JSON.stringify(payload, null, 2));
236
+ return;
237
+ }
238
+
239
+ const text = typeof payload?.text === "string" ? payload.text.trim() : "";
240
+ if (text) {
241
+ console.log(text);
242
+ } else {
243
+ console.log(JSON.stringify(payload, null, 2));
244
+ }
245
+ return;
246
+ }
247
+
248
+ throw new CliArgError(
249
+ `Unknown mcp subcommand "${sub}". Expected: list, tools, or call.`,
250
+ );
251
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dench.com/cli",
3
- "version": "3.11.70-staging.1221",
3
+ "version": "3.12.0-staging.1224",
4
4
  "description": "Dench agent workspace CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,6 +34,7 @@
34
34
  "crm-analytics.ts",
35
35
  "crm-detections.ts",
36
36
  "crm-privacy.ts",
37
+ "crm-warm-intros.ts",
37
38
  "meetings.ts",
38
39
  "email.ts",
39
40
  "email-inbox.ts",
@@ -50,6 +51,7 @@
50
51
  "image.ts",
51
52
  "leads.ts",
52
53
  "tools.ts",
54
+ "mcp.ts",
53
55
  "apps.ts",
54
56
  "agentKind.ts",
55
57
  "agent-config.ts",
package/tools.ts CHANGED
@@ -148,6 +148,9 @@ export async function runToolCommand(ctx: ToolCliContext): Promise<void> {
148
148
  const listUnipileConnectionsRef = makeFunctionReference<"query">(
149
149
  "functions/unipileConnections:listConnections",
150
150
  );
151
+ const listCustomMcpServersRef = makeFunctionReference<"query">(
152
+ "functions/customMcpServers:list",
153
+ );
151
154
  const listUnipileToolsRef = makeFunctionReference<"query">(
152
155
  "functions/unipileTools:listTools",
153
156
  );
@@ -213,6 +216,42 @@ export async function fetchUnipileConnections(
213
216
  }
214
217
  }
215
218
 
219
+ export async function fetchCustomMcpConnections(
220
+ ctx: UnipileAuthContext & Pick<ToolCliContext, "workspaceSlug">,
221
+ ): Promise<CompactConnection[]> {
222
+ if (!ctx.convex) return [];
223
+ try {
224
+ const rows = await ctx.convex.query(listCustomMcpServersRef, {
225
+ ...(ctx.workspaceSlug ? { slug: ctx.workspaceSlug } : {}),
226
+ ...(ctx.sessionToken ? { sessionToken: ctx.sessionToken } : {}),
227
+ } as never);
228
+ if (!Array.isArray(rows)) return [];
229
+ // A row without a slug is not a server this CLI can name or call.
230
+ return rows.flatMap((raw): CompactConnection[] => {
231
+ const row = asRecord(raw) ?? {};
232
+ const slug = stringField(row, "slug");
233
+ if (!slug) return [];
234
+ return [
235
+ {
236
+ source: "mcp" as const,
237
+ toolkit: slug,
238
+ status:
239
+ stringField(row, "status") === "reauth_required"
240
+ ? "reauth_required"
241
+ : "active",
242
+ connectedAccountId: null,
243
+ accountLabel: stringField(row, "name") ?? null,
244
+ isOwner: row.isOwner === true,
245
+ ownerName: stringField(row, "ownerName") ?? undefined,
246
+ visibility: row.visibility === "private" ? "private" : "shared",
247
+ },
248
+ ];
249
+ });
250
+ } catch {
251
+ return [];
252
+ }
253
+ }
254
+
216
255
  /**
217
256
  * Summarise the user's connected apps for `dench context` and friends.
218
257
  * Speaks straight to the gateway with either DENCH_API_KEY or a gateway
@@ -222,7 +261,9 @@ export async function fetchUnipileConnections(
222
261
  * existing parsers don't need to change.
223
262
  */
224
263
  export async function fetchConnectedAppsSummary(
225
- ctx: GatewayAuthContext & UnipileAuthContext = {},
264
+ ctx: GatewayAuthContext &
265
+ UnipileAuthContext &
266
+ Pick<ToolCliContext, "workspaceSlug"> = {},
226
267
  ): Promise<{
227
268
  available: boolean;
228
269
  count: number;
@@ -232,16 +273,20 @@ export async function fetchConnectedAppsSummary(
232
273
  error?: string;
233
274
  reason?: string;
234
275
  }> {
235
- const unipile = await fetchUnipileConnections(ctx);
276
+ const [unipile, mcpConnections] = await Promise.all([
277
+ fetchUnipileConnections(ctx),
278
+ fetchCustomMcpConnections(ctx),
279
+ ]);
236
280
  const unipileFields = {
237
281
  nativeAvailable: unipile.available,
238
282
  ...(unipile.error ? { nativeError: unipile.error } : {}),
239
283
  };
284
+ const firstPartyConnections = [...unipile.connections, ...mcpConnections];
240
285
  if (ctx.gatewayAuthError) {
241
286
  return {
242
287
  available: false,
243
- count: unipile.connections.length,
244
- connections: unipile.connections,
288
+ count: firstPartyConnections.length,
289
+ connections: firstPartyConnections,
245
290
  ...unipileFields,
246
291
  reason: ctx.gatewayAuthError,
247
292
  };
@@ -254,8 +299,8 @@ export async function fetchConnectedAppsSummary(
254
299
  // Unipile rows are still reported alongside the failure.
255
300
  const failure = {
256
301
  available: false,
257
- count: unipile.connections.length,
258
- connections: unipile.connections,
302
+ count: firstPartyConnections.length,
303
+ connections: firstPartyConnections,
259
304
  ...unipileFields,
260
305
  };
261
306
  return ctx.gatewayAuthError
@@ -268,7 +313,7 @@ export async function fetchConnectedAppsSummary(
268
313
  ...extractConnections(payload)
269
314
  .map(compactConnection)
270
315
  .filter((connection) => !nativeToolkit(connection.toolkit)),
271
- ...unipile.connections,
316
+ ...firstPartyConnections,
272
317
  ];
273
318
  return {
274
319
  available: true,
@@ -1185,11 +1230,16 @@ function formatConnectionLine(connection: CompactConnection): string {
1185
1230
  : "";
1186
1231
  // "via Dench" both names the broker and explains why the row has no
1187
1232
  // connected-account id to pass to `dench tool run`.
1188
- const via = connection.source === "dench" ? " via Dench" : "";
1233
+ const via =
1234
+ connection.source === "dench"
1235
+ ? " via Dench"
1236
+ : connection.source === "mcp"
1237
+ ? " via MCP"
1238
+ : "";
1189
1239
  // Whose mailbox/LinkedIn it is only matters when it is not this agent's —
1190
1240
  // `dench email --mailbox` picks between them.
1191
1241
  const owner =
1192
- connection.source === "dench" &&
1242
+ (connection.source === "dench" || connection.source === "mcp") &&
1193
1243
  connection.isOwner === false &&
1194
1244
  connection.ownerName
1195
1245
  ? ` · ${connection.ownerName}`