@webhooks-cc/mcp 1.22.0 → 1.24.0

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.
@@ -487,9 +487,28 @@ function keyText(key) {
487
487
  }
488
488
  function approvalResultText(result) {
489
489
  if (typeof result.key === "string") return keyText(result);
490
+ if (typeof result.spreadsheetId === "string") {
491
+ const tabs = Array.isArray(result.tabs) ? result.tabs.join(", ") : "";
492
+ return `Approved. The chosen spreadsheet is ${String(result.spreadsheetId)} (${String(result.url)}), on connection ${String(result.connectionId)}${tabs ? `; its tabs: ${tabs}` : ""}. Use them in a Sheets destination's config.`;
493
+ }
494
+ if (Array.isArray(result.fields)) {
495
+ return `Approved. AI setup proposed (nothing is saved until you apply it):
496
+ ${JSON.stringify(result, null, 2)}`;
497
+ }
498
+ if (typeof result.connectionId === "string") {
499
+ return `Approved. The Google account ${result.email ? `${String(result.email)} ` : ""}is connected as ${result.connectionId}.`;
500
+ }
490
501
  if (typeof result.url === "string") {
491
502
  return `Approved. The share link is ${result.url} (anyone with it can read the copy until ${String(result.expiresAt)}).`;
492
503
  }
504
+ if (typeof result.invitedEmail === "string") {
505
+ const team = typeof result.teamName === "string" ? ` to "${result.teamName}"` : "";
506
+ const warning = typeof result.warning === "string" ? ` ${result.warning} Tell them to sign up with that address and accept from their Teams page.` : " They get an email; accepting claims one of the team's seats.";
507
+ return `Approved. Invited ${result.invitedEmail}${team} (invite ${String(result.id)}).${warning}`;
508
+ }
509
+ if (typeof result.deleted === "string" && typeof result.teamId === "string") {
510
+ return `Approved. The team ${result.deleted ? `"${result.deleted}" ` : ""}was deleted; its subscription has ended.`;
511
+ }
493
512
  if (typeof result.removed === "string") {
494
513
  return `Approved. The domain ${result.removed} was removed; mail to it is refused now.`;
495
514
  }
@@ -564,6 +583,75 @@ function fitArrayField(value, key) {
564
583
  }
565
584
  return cut(low);
566
585
  }
586
+ function isoTime(ms) {
587
+ if (ms === null || !Number.isFinite(ms)) return null;
588
+ const date = new Date(ms);
589
+ return Number.isNaN(date.getTime()) ? null : date.toISOString();
590
+ }
591
+ function searchStoppedNote(searchedUntil, order, hasCursor) {
592
+ const [direction, rest] = order === "asc" ? ["forward", "newer"] : ["back", "older"];
593
+ const reached = searchedUntil ? `Searched ${direction} to ${searchedUntil}; ${rest} requests were not searched yet.` : `The search stopped before it read everything; ${rest} requests were not searched yet.`;
594
+ return hasCursor ? `${reached} Call search_requests again with cursor to continue.` : reached;
595
+ }
596
+ var FULL_REQUEST_HINT = "The full request is available from the API (GET /api/requests/{id}), the SDKs (requests.get(id)) or the CLI (whk requests get <id>).";
597
+ var SEARCH_SHORTENED_NOTE = `Some requests were shortened to fit the output (bodyTruncated with bodySize, or shortened: true for a summary); get_request with the id returns as much of one request as fits. ${FULL_REQUEST_HINT}`;
598
+ var REQUEST_SHORTENED_NOTE = `This request was cut to fit the output: its body (bodyTruncated, with bodySize), or everything but a summary (shortened: true). ${FULL_REQUEST_HINT}`;
599
+ function clip(value, max) {
600
+ return typeof value === "string" ? sliceText(value, max) : void 0;
601
+ }
602
+ function listedSize(request) {
603
+ return jsonSize([[request]]) - 8;
604
+ }
605
+ function fitSearchRequests(requests, room) {
606
+ const share = Math.floor(room / Math.max(1, requests.length));
607
+ const fitted = requests.map(
608
+ (request) => shortenRequest(request, share, listedSize)
609
+ );
610
+ if (fitted.every((request) => listedSize(request) <= share)) return fitted;
611
+ return requests.map((request) => {
612
+ const { id, receivedAt } = request;
613
+ return { id, receivedAt, shortened: true };
614
+ });
615
+ }
616
+ function shortenRequest(request, share, sizeOf) {
617
+ if (sizeOf(request) <= share) return request;
618
+ if (typeof request.body === "string") {
619
+ const body = request.body;
620
+ let keep = body.length - (sizeOf(request) - share) - 96;
621
+ while (keep > 0) {
622
+ const cut = {
623
+ ...request,
624
+ body: sliceText(body, keep),
625
+ bodyTruncated: true,
626
+ bodySize: body.length
627
+ };
628
+ if (sizeOf(cut) <= share) return cut;
629
+ keep = Math.floor(keep / 2);
630
+ }
631
+ }
632
+ const email = request.email;
633
+ const summary = {
634
+ id: request.id,
635
+ slug: clip(request.slug, 64),
636
+ method: clip(request.method, 16),
637
+ path: clip(request.path, 200),
638
+ contentType: clip(request.contentType, 100),
639
+ size: request.size,
640
+ receivedAt: request.receivedAt,
641
+ kind: request.kind,
642
+ ...email ? { subject: clip(email.subject, 200) } : {},
643
+ shortened: true,
644
+ ...typeof request.note === "string" ? { note: request.note } : {}
645
+ };
646
+ return summary;
647
+ }
648
+ function requestContent(request) {
649
+ const compact = compactRequest(request);
650
+ if (jsonSize(compact) <= MAX_BODY_SIZE) return jsonContent(compact);
651
+ return jsonContent(
652
+ shortenRequest({ ...compact, note: REQUEST_SHORTENED_NOTE }, MAX_BODY_SIZE, jsonSize)
653
+ );
654
+ }
567
655
  function jsonContent(value) {
568
656
  return textContent(serializeJson(value));
569
657
  }
@@ -608,6 +696,13 @@ function serializeError(error) {
608
696
  } else if (error instanceof WebhooksCCError) {
609
697
  payload.code = error.statusCode >= 500 ? "server_error" : "validation_error";
610
698
  }
699
+ if (error instanceof WebhooksCCError && payload.hint === null) {
700
+ if (error.code === "invalid_cursor") {
701
+ payload.hint = "The cursor is not one this search returned, or the order changed since. Pass a cursor exactly as a result gave it, or search again without one.";
702
+ } else if (error.code === "search_busy") {
703
+ payload.hint = "The account's other searches are still running. Wait retryAfter seconds, then call again with the same inputs.";
704
+ }
705
+ }
611
706
  return JSON.stringify(payload, null, 2);
612
707
  }
613
708
  function withErrorHandling(handler) {
@@ -1059,6 +1154,124 @@ function registerTools(target, client, options = {}) {
1059
1154
  return jsonContent({ shared: false, slug, teamId });
1060
1155
  })
1061
1156
  );
1157
+ server.tool(
1158
+ "create_team",
1159
+ "Create a team you own, to share endpoints with its members under a pooled quota. It does nothing until it has a subscription, which the person starts in the browser (Account > Teams); until then it is suspended.",
1160
+ { name: z.string().trim().min(1).max(100).describe("The team's name") },
1161
+ withErrorHandling(async ({ name }) => jsonContent(await client.teams.create(name)))
1162
+ );
1163
+ server.tool(
1164
+ "rename_team",
1165
+ "Rename a team you own.",
1166
+ {
1167
+ teamId: z.string().min(1).describe("Team id (from list_teams)"),
1168
+ name: z.string().trim().min(1).max(100).describe("The new name")
1169
+ },
1170
+ withErrorHandling(async ({ teamId, name }) => {
1171
+ await client.teams.rename(teamId, name);
1172
+ return jsonContent({ renamed: true, teamId, name });
1173
+ })
1174
+ );
1175
+ server.tool(
1176
+ "delete_team",
1177
+ "Delete a team you own: its subscription ends at once, every member loses the endpoints shared with it, and it cannot be undone. Only when the person asks for it. The team's owner must approve it: this returns a link and a code to show them, then call wait_for_approval.",
1178
+ { teamId: z.string().min(1).describe("Team id (from list_teams)") },
1179
+ withErrorHandling(async ({ teamId }) => {
1180
+ const pending = await client.teams.delete(teamId);
1181
+ if (!pending.id) return textContent(`Deleted the team ${teamId}.`);
1182
+ return textContent(approvalAskText(pending));
1183
+ })
1184
+ );
1185
+ server.tool(
1186
+ "remove_team_member",
1187
+ "Remove a member from a team you own: the endpoints they shared with the team stop being shared, and their seat is free for someone else. Only when the person asks for it.",
1188
+ {
1189
+ teamId: z.string().min(1).describe("Team id (from list_teams)"),
1190
+ userId: z.string().min(1).describe("The member's userId (from list_team_members)")
1191
+ },
1192
+ withErrorHandling(async ({ teamId, userId }) => {
1193
+ await client.teams.removeMember(teamId, userId);
1194
+ return jsonContent({ removed: true, teamId, userId });
1195
+ })
1196
+ );
1197
+ server.tool(
1198
+ "leave_team",
1199
+ "Leave a team you belong to: the endpoints you shared with it stop being shared, and you lose access to the ones shared with you through it. An owner cannot leave; they delete the team instead (delete_team). Only when the person asks for it.",
1200
+ { teamId: z.string().min(1).describe("Team id (from list_teams)") },
1201
+ withErrorHandling(async ({ teamId }) => {
1202
+ await client.teams.leave(teamId);
1203
+ return jsonContent({ left: true, teamId });
1204
+ })
1205
+ );
1206
+ server.tool(
1207
+ "invite_to_team",
1208
+ "Invite an email address to a team you own. It emails that address, so the team's owner must approve it: this returns a link and a code to show them, then call wait_for_approval, which returns the invite. Accepting the invite claims one of the team's paid seats. Only when the person asks for it.",
1209
+ {
1210
+ teamId: z.string().min(1).describe("Team id (from list_teams)"),
1211
+ email: z.string().trim().email().describe("The address to invite")
1212
+ },
1213
+ withErrorHandling(async ({ teamId, email }) => {
1214
+ const pending = await client.teams.invite(teamId, email);
1215
+ if (!pending.id) return textContent(approvalResultText({ ...await pending.wait() }));
1216
+ return textContent(approvalAskText(pending));
1217
+ })
1218
+ );
1219
+ server.tool(
1220
+ "list_invites",
1221
+ "List the team invites waiting for you to answer: team, who invited you, when, and the invite id for answer_invite.",
1222
+ {},
1223
+ withErrorHandling(async () => jsonContent(await client.teams.invites.list()))
1224
+ );
1225
+ server.tool(
1226
+ "answer_invite",
1227
+ "Accept or decline a team invite waiting for you (from list_invites). Accepting claims one of the team's paid seats and you join the team, seeing the endpoints shared with it; it fails when the team is full or suspended. Only when the person says which.",
1228
+ {
1229
+ inviteId: z.string().min(1).describe("The invite's id, from list_invites"),
1230
+ answer: z.enum(["accept", "decline"]).describe("accept joins the team; decline turns it down")
1231
+ },
1232
+ withErrorHandling(async ({ inviteId, answer }) => {
1233
+ if (answer === "accept") {
1234
+ await client.teams.invites.accept(inviteId);
1235
+ return jsonContent({ accepted: true, inviteId });
1236
+ }
1237
+ await client.teams.invites.decline(inviteId);
1238
+ return jsonContent({ declined: true, inviteId });
1239
+ })
1240
+ );
1241
+ server.tool(
1242
+ "withdraw_invite",
1243
+ "Withdraw an invite to a team you own before it is answered (pending invites and their ids are in list_team_members). The invite link stops working.",
1244
+ {
1245
+ teamId: z.string().min(1).describe("Team id (from list_teams)"),
1246
+ inviteId: z.string().min(1).describe("The invite's id (from list_team_members' pendingInvites)")
1247
+ },
1248
+ withErrorHandling(async ({ teamId, inviteId }) => {
1249
+ await client.teams.withdrawInvite(teamId, inviteId);
1250
+ return jsonContent({ withdrawn: true, teamId, inviteId });
1251
+ })
1252
+ );
1253
+ server.tool(
1254
+ "quote_team_change",
1255
+ "What changing a team's seat count or plan would cost, read only (owner only): what is due now, any credit, and the price from the renewal. Give seats, or plan (with interval). The change itself is made by the person in the browser.",
1256
+ {
1257
+ teamId: z.string().min(1).describe("Team id (from list_teams)"),
1258
+ seats: z.number().int().min(1).optional().describe("Price this seat count"),
1259
+ plan: z.enum(["team", "team_business"]).optional().describe("Price a move to this plan: team (Teams) or team_business (Team Business)"),
1260
+ interval: z.enum(["month", "year"]).optional().describe("Billing interval for plan (default month; Teams is monthly only)")
1261
+ },
1262
+ withErrorHandling(async ({ teamId, seats, plan, interval }) => {
1263
+ if (seats === void 0 === (plan === void 0)) {
1264
+ throw new Error("Give seats or plan, not both.");
1265
+ }
1266
+ if (seats !== void 0) {
1267
+ if (interval !== void 0) throw new Error("interval goes with plan, not seats.");
1268
+ return jsonContent(await client.billing.quoteTeamSeats(teamId, seats));
1269
+ }
1270
+ return jsonContent(
1271
+ await client.billing.quoteTeamPlan(teamId, plan, interval)
1272
+ );
1273
+ })
1274
+ );
1062
1275
  server.tool(
1063
1276
  "get_endpoint",
1064
1277
  "Get details for a specific webhook endpoint by slug.",
@@ -1152,6 +1365,35 @@ function registerTools(target, client, options = {}) {
1152
1365
  return jsonContent(holder);
1153
1366
  })
1154
1367
  );
1368
+ server.tool(
1369
+ "list_layout_templates",
1370
+ "List the ready-made email layouts (order emails from Shopify, WooCommerce, Etsy and more, payments, bookings, attachments): each with its id, sender, kind, description, the fields it reads and whether it reads line items. Add one with add_layout_template.",
1371
+ { slug: z.string().describe("The endpoint slug") },
1372
+ withErrorHandling(async ({ slug }) => jsonContent(await client.endpoints.layoutTemplates(slug)))
1373
+ );
1374
+ server.tool(
1375
+ "add_layout_template",
1376
+ "Add a ready-made layout (an id from list_layout_templates) to the end of an endpoint's layouts. Emails it matches are parsed from the next one on; check it on a captured email with preview_layouts. Owner only.",
1377
+ {
1378
+ slug: z.string().describe("The endpoint slug"),
1379
+ template: z.string().min(1).describe("The template's id, from list_layout_templates")
1380
+ },
1381
+ withErrorHandling(
1382
+ async ({ slug, template }) => jsonContent(await client.endpoints.addLayoutTemplate(slug, template))
1383
+ )
1384
+ );
1385
+ server.tool(
1386
+ "preview_email_fields",
1387
+ "Dry run of an endpoint's named email fields on a captured email: each field's value (null where it finds nothing), and problems with fields you pass. Nothing is saved. Pass emailFields to try fields before saving them with update_endpoint. Owner only.",
1388
+ {
1389
+ slug: z.string().describe("The endpoint slug"),
1390
+ requestId: z.string().optional().describe("A captured email on the endpoint (default: the newest)"),
1391
+ emailFields: z.array(emailFieldSchema).max(20).optional().describe("Unsaved fields to try instead of the saved ones")
1392
+ },
1393
+ withErrorHandling(
1394
+ async ({ slug, requestId, emailFields }) => jsonContent(await client.endpoints.previewEmailFields(slug, { requestId, emailFields }))
1395
+ )
1396
+ );
1155
1397
  server.tool(
1156
1398
  "preview_response",
1157
1399
  "Dry run of an endpoint's responses: which response rule answers a captured request, and the response with its {{ placeholders }} filled in, exactly as the receiver would send it. Nothing is sent. Pass mockResponse or responseRules to try settings before saving them with update_endpoint.",
@@ -1287,56 +1529,95 @@ function registerTools(target, client, options = {}) {
1287
1529
  );
1288
1530
  server.tool(
1289
1531
  "search_requests",
1290
- "Search captured webhook requests across endpoints using retained full-text search.",
1532
+ "Search captured requests and emails across endpoints: a substring match on path, headers, body and decoded email fields. One call reads back through history for about 2 seconds and returns { requests, complete, searchedUntil, cursor }. When complete is false, older requests were not searched yet: call again with the cursor and the same filters to continue.",
1291
1533
  {
1292
1534
  slug: z.string().optional().describe("Filter to a specific endpoint slug"),
1293
1535
  method: z.string().optional().describe("Filter by HTTP method"),
1294
1536
  kind: kindSchema,
1295
- q: z.string().optional().describe("Free-text search across path, body, and headers"),
1296
- from: durationOrTimestampSchema.optional().describe('Start time as a timestamp or duration like "1h" or "7d"'),
1297
- to: durationOrTimestampSchema.optional().describe('End time as a timestamp or duration like "1h" or "7d"'),
1537
+ q: z.string().optional().describe(
1538
+ "Substring to find in the path, headers, body and decoded email fields (up to 1,000 characters)"
1539
+ ),
1540
+ from: durationOrTimestampSchema.optional().describe(
1541
+ 'Start time as a timestamp (Unix ms) or a duration back from now like "1h" or "7d". A duration is counted from each call, so when you continue with a cursor pass a timestamp to keep the same range.'
1542
+ ),
1543
+ to: durationOrTimestampSchema.optional().describe(
1544
+ 'End time as a timestamp (Unix ms) or a duration back from now like "1h" or "7d". A duration is counted from each call, so when you continue with a cursor pass a timestamp to keep the same range.'
1545
+ ),
1298
1546
  limit: z.number().int().min(1).max(200).default(50).describe("Max results to return"),
1299
- offset: z.number().int().min(0).max(1e4).default(0).describe("Result offset"),
1300
- order: z.enum(["asc", "desc"]).default("desc").describe("Sort order by received time")
1547
+ offset: z.number().int().min(0).max(1e4).default(0).describe("Matches to skip (first call only; a cursor carries what is left of it)"),
1548
+ order: z.enum(["asc", "desc"]).default("desc").describe("Sort order by received time"),
1549
+ cursor: z.string().optional().describe(
1550
+ "The cursor from a previous search_requests result, to continue that search. Keep the other inputs the same."
1551
+ )
1301
1552
  },
1302
- withErrorHandling(async ({ slug, method, kind, q, from, to, limit, offset, order }) => {
1303
- const results = await client.requests.search({
1304
- slug,
1305
- method,
1306
- kind,
1307
- q,
1308
- from,
1309
- to,
1310
- limit,
1311
- offset,
1312
- order
1313
- });
1314
- return jsonContent(results.map(compactRequest));
1553
+ withErrorHandling(async ({ slug, method, kind, q, from, to, limit, offset, order, cursor }) => {
1554
+ const page = await client.requests.searchPage(
1555
+ { slug, method, kind, q, from, to, limit, offset, order },
1556
+ { cursor }
1557
+ );
1558
+ const searchedUntil = isoTime(page.searchedUntil);
1559
+ const envelope = (requests2, shortened) => {
1560
+ const notes = [
1561
+ ...page.complete ? [] : [searchStoppedNote(searchedUntil, order, Boolean(page.cursor))],
1562
+ ...shortened ? [SEARCH_SHORTENED_NOTE] : []
1563
+ ];
1564
+ return {
1565
+ requests: requests2,
1566
+ complete: page.complete,
1567
+ searchedUntil,
1568
+ cursor: page.cursor,
1569
+ ...notes.length > 0 ? { note: notes.join(" ") } : {}
1570
+ };
1571
+ };
1572
+ const requests = page.requests.map(compactRequest);
1573
+ if (jsonSize(envelope(requests, false)) <= MAX_BODY_SIZE) {
1574
+ return jsonContent(envelope(requests, false));
1575
+ }
1576
+ const room = MAX_BODY_SIZE - jsonSize(envelope([], true)) - 8;
1577
+ return jsonContent(envelope(fitSearchRequests(requests, room), true));
1315
1578
  })
1316
1579
  );
1317
1580
  server.tool(
1318
1581
  "count_requests",
1319
- "Count captured webhook requests that match the given filters.",
1582
+ "Count captured requests and emails that match the given filters (q is a substring match on path, headers, body and decoded email fields). Returns { count, exact, searchedUntil, cursor }. With q or method a call counts back through history for about 2 seconds: when exact is false, count covers history back to searchedUntil only, and calling again with the cursor counts the next stretch (add the counts up).",
1320
1583
  {
1321
1584
  slug: z.string().optional().describe("Filter to a specific endpoint slug"),
1322
1585
  method: z.string().optional().describe("Filter by HTTP method"),
1323
1586
  kind: kindSchema,
1324
- q: z.string().optional().describe("Free-text search across path, body, and headers"),
1325
- from: durationOrTimestampSchema.optional().describe('Start time as a timestamp or duration like "1h" or "7d"'),
1326
- to: durationOrTimestampSchema.optional().describe('End time as a timestamp or duration like "1h" or "7d"')
1587
+ q: z.string().optional().describe(
1588
+ "Substring to find in the path, headers, body and decoded email fields (up to 1,000 characters)"
1589
+ ),
1590
+ from: durationOrTimestampSchema.optional().describe(
1591
+ 'Start time as a timestamp (Unix ms) or a duration back from now like "1h" or "7d". A duration is counted from each call, so when you continue with a cursor pass a timestamp to keep the same range.'
1592
+ ),
1593
+ to: durationOrTimestampSchema.optional().describe(
1594
+ 'End time as a timestamp (Unix ms) or a duration back from now like "1h" or "7d". A duration is counted from each call, so when you continue with a cursor pass a timestamp to keep the same range.'
1595
+ ),
1596
+ cursor: z.string().optional().describe(
1597
+ "The cursor from a previous count_requests result, to count the next stretch. Keep the other inputs the same."
1598
+ )
1327
1599
  },
1328
- withErrorHandling(async ({ slug, method, kind, q, from, to }) => {
1329
- const count = await client.requests.count({ slug, method, kind, q, from, to });
1330
- return jsonContent({ count });
1600
+ withErrorHandling(async ({ slug, method, kind, q, from, to, cursor }) => {
1601
+ const page = await client.requests.countPage({ slug, method, kind, q, from, to }, { cursor });
1602
+ const searchedUntil = isoTime(page.searchedUntil);
1603
+ return jsonContent({
1604
+ count: page.count,
1605
+ exact: page.exact,
1606
+ searchedUntil,
1607
+ cursor: page.cursor,
1608
+ ...page.exact ? {} : {
1609
+ note: `At least ${page.count}, counted ${searchedUntil ? `back to ${searchedUntil}` : "over part of the history"}; ${page.cursor ? "call count_requests again with cursor to count further (the counts add up)." : "there is no cursor to count further with."}`
1610
+ }
1611
+ });
1331
1612
  })
1332
1613
  );
1333
1614
  server.tool(
1334
1615
  "get_request",
1335
- "Get full details for a specific captured request by ID.",
1616
+ "Get the details of a captured request by ID: method, path, headers and body. A request larger than the tool output has its body cut (bodyTruncated, bodySize) and a note saying where the whole request is available.",
1336
1617
  getRequestShape,
1337
1618
  withErrorHandling(async ({ requestId }) => {
1338
1619
  const request = await client.requests.get(requestId);
1339
- return jsonContent(compactRequest(request));
1620
+ return requestContent(request);
1340
1621
  })
1341
1622
  );
1342
1623
  server.tool(
@@ -1345,7 +1626,7 @@ function registerTools(target, client, options = {}) {
1345
1626
  waitForRequestShape,
1346
1627
  withErrorHandling(async ({ endpointSlug, timeout, pollInterval }) => {
1347
1628
  const request = await client.requests.waitFor(endpointSlug, { timeout, pollInterval });
1348
- return jsonContent(compactRequest(request));
1629
+ return requestContent(request);
1349
1630
  })
1350
1631
  );
1351
1632
  server.tool(
@@ -2099,7 +2380,7 @@ function registerTools(target, client, options = {}) {
2099
2380
  );
2100
2381
  server.tool(
2101
2382
  "wait_for_approval",
2102
- "Wait for the account's owner to answer an approval (from create_api_key, create_share_link, remove_domain or rename_account) and collect what it grants or did, such as the new API key or the share link. If they have not answered yet, call it again.",
2383
+ "Wait for the account's owner to answer an approval (from create_api_key, create_share_link, remove_domain, rename_account, delete_team, invite_to_team, connect_google, pick_spreadsheet or ai_setup) and collect what it grants or did, such as the new API key, the share link or AI setup's proposals. If they have not answered yet, call it again.",
2103
2384
  {
2104
2385
  id: z.string().describe("The approval id"),
2105
2386
  timeout: durationOrTimestampSchema.default("45s").describe('How long to wait for the person, for example "45s"')
@@ -2267,6 +2548,109 @@ function registerTools(target, client, options = {}) {
2267
2548
  return textContent(approvalAskText(pending));
2268
2549
  })
2269
2550
  );
2551
+ server.tool(
2552
+ "list_google_connections",
2553
+ "List the Google accounts connected for Google Sheets destinations (id, email, when connected), and whether Google Sheets is set up on this server.",
2554
+ {},
2555
+ withErrorHandling(async () => jsonContent(await client.google.connections()))
2556
+ );
2557
+ server.tool(
2558
+ "connect_google",
2559
+ "Connect a Google account for Google Sheets destinations. The account's owner must approve it: this returns a link and a code to show them, and approving takes them to Google to choose the account. Then call wait_for_approval for the new connection's id.",
2560
+ {},
2561
+ withErrorHandling(async () => textContent(approvalAskText(await client.google.connect())))
2562
+ );
2563
+ server.tool(
2564
+ "pick_spreadsheet",
2565
+ "Have the account's owner choose an existing spreadsheet from Google Drive with a connected account (to add rows to it from a Sheets destination). Returns a link and a code to show them; the page opens Google's picker. Then call wait_for_approval for the spreadsheet's id and tabs. To use a new spreadsheet instead, call create_spreadsheet.",
2566
+ {
2567
+ connectionId: z.string().describe("The Google connection's id, from list_google_connections")
2568
+ },
2569
+ withErrorHandling(
2570
+ async ({ connectionId }) => textContent(approvalAskText(await client.google.pick(connectionId)))
2571
+ )
2572
+ );
2573
+ server.tool(
2574
+ "create_spreadsheet",
2575
+ "Create a new spreadsheet with a header row in a connected Google account, for a Sheets destination. Needs no approval: the app reaches only spreadsheets it created or that were chosen for it.",
2576
+ {
2577
+ connectionId: z.string().describe("The Google connection's id, from list_google_connections"),
2578
+ title: z.string().max(200).optional().describe("The spreadsheet's title"),
2579
+ sheet: z.string().max(100).optional().describe('The tab rows go to (default "Sheet1")'),
2580
+ headers: z.array(z.string().max(200)).max(50).describe("The header row, one per column")
2581
+ },
2582
+ withErrorHandling(
2583
+ async ({ connectionId, title, sheet, headers }) => jsonContent(await client.google.createSpreadsheet({ connectionId, title, sheet, headers }))
2584
+ )
2585
+ );
2586
+ server.tool(
2587
+ "list_sheet_tabs",
2588
+ "List a spreadsheet's tabs (one created by the app or chosen with pick_spreadsheet), to choose the one a Sheets destination writes to.",
2589
+ {
2590
+ connectionId: z.string().describe("The Google connection's id"),
2591
+ spreadsheetId: z.string().describe("The spreadsheet's id")
2592
+ },
2593
+ withErrorHandling(
2594
+ async ({ connectionId, spreadsheetId }) => jsonContent({ tabs: await client.google.tabs(connectionId, spreadsheetId) })
2595
+ )
2596
+ );
2597
+ server.tool(
2598
+ "disconnect_google",
2599
+ "Disconnect a Google account (id from list_google_connections) and revoke its access at Google. Sheets destinations using it fail until another account is chosen.",
2600
+ {
2601
+ connectionId: z.string().describe("The Google connection's id")
2602
+ },
2603
+ withErrorHandling(async ({ connectionId }) => {
2604
+ await client.google.disconnect(connectionId);
2605
+ return textContent(`Disconnected the Google account ${connectionId}.`);
2606
+ })
2607
+ );
2608
+ server.tool(
2609
+ "ai_setup_status",
2610
+ "Whether AI setup is offered for an endpoint, and how many AI assists the plan has left in a rolling 30 days.",
2611
+ {
2612
+ slug: z.string().describe("The endpoint's slug")
2613
+ },
2614
+ withErrorHandling(async ({ slug }) => jsonContent(await client.ai.status(slug)))
2615
+ );
2616
+ server.tool(
2617
+ "ai_setup",
2618
+ "Have AI propose email fields (or a layout, or a repaired field) from 1 to 5 of an endpoint's captured emails. It sends those emails (subject, sender, recipients, text, headers; never attachments) to Anthropic's model, so the account's owner must approve it: this returns a link and a code to show them, and the page lists the emails. Then call wait_for_approval for the proposals, each with the value it found in every email. Nothing is saved: apply the fields with update_endpoint. Uses one AI assist.",
2619
+ {
2620
+ slug: z.string().describe("The endpoint's slug"),
2621
+ requestIds: z.array(z.string()).min(1).max(5).describe("1 to 5 of the endpoint's email request ids, from list_emails"),
2622
+ ask: z.union([
2623
+ z.object({
2624
+ kind: z.literal("field"),
2625
+ name: z.string().describe("The field's name: letters, digits and _"),
2626
+ description: z.string().describe('What the field is, such as "the order number"')
2627
+ }),
2628
+ z.object({
2629
+ kind: z.literal("layout"),
2630
+ description: z.string().optional().describe("What these emails are")
2631
+ }),
2632
+ z.object({
2633
+ kind: z.literal("repair"),
2634
+ field: z.object({
2635
+ name: z.string(),
2636
+ from: z.string(),
2637
+ header: z.string().optional(),
2638
+ pattern: z.string()
2639
+ }).describe("The field to repair, as the endpoint has it")
2640
+ })
2641
+ ]).describe("What to propose")
2642
+ },
2643
+ withErrorHandling(
2644
+ async ({ slug, requestIds, ask }) => textContent(
2645
+ approvalAskText(
2646
+ await client.ai.setup(slug, {
2647
+ requestIds,
2648
+ ask
2649
+ })
2650
+ )
2651
+ )
2652
+ )
2653
+ );
2270
2654
  server.tool(
2271
2655
  "stop_share",
2272
2656
  "Stop a public preview or live tunnel by its id (from list_shares). The CLI running it is told why and exits.",