@webhooks-cc/mcp 1.23.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.
@@ -501,6 +501,14 @@ ${JSON.stringify(result, null, 2)}`;
501
501
  if (typeof result.url === "string") {
502
502
  return `Approved. The share link is ${result.url} (anyone with it can read the copy until ${String(result.expiresAt)}).`;
503
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
+ }
504
512
  if (typeof result.removed === "string") {
505
513
  return `Approved. The domain ${result.removed} was removed; mail to it is refused now.`;
506
514
  }
@@ -575,6 +583,75 @@ function fitArrayField(value, key) {
575
583
  }
576
584
  return cut(low);
577
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
+ }
578
655
  function jsonContent(value) {
579
656
  return textContent(serializeJson(value));
580
657
  }
@@ -619,6 +696,13 @@ function serializeError(error) {
619
696
  } else if (error instanceof WebhooksCCError) {
620
697
  payload.code = error.statusCode >= 500 ? "server_error" : "validation_error";
621
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
+ }
622
706
  return JSON.stringify(payload, null, 2);
623
707
  }
624
708
  function withErrorHandling(handler) {
@@ -1070,6 +1154,124 @@ function registerTools(target, client, options = {}) {
1070
1154
  return jsonContent({ shared: false, slug, teamId });
1071
1155
  })
1072
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
+ );
1073
1275
  server.tool(
1074
1276
  "get_endpoint",
1075
1277
  "Get details for a specific webhook endpoint by slug.",
@@ -1163,6 +1365,35 @@ function registerTools(target, client, options = {}) {
1163
1365
  return jsonContent(holder);
1164
1366
  })
1165
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
+ );
1166
1397
  server.tool(
1167
1398
  "preview_response",
1168
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.",
@@ -1298,56 +1529,95 @@ function registerTools(target, client, options = {}) {
1298
1529
  );
1299
1530
  server.tool(
1300
1531
  "search_requests",
1301
- "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.",
1302
1533
  {
1303
1534
  slug: z.string().optional().describe("Filter to a specific endpoint slug"),
1304
1535
  method: z.string().optional().describe("Filter by HTTP method"),
1305
1536
  kind: kindSchema,
1306
- q: z.string().optional().describe("Free-text search across path, body, and headers"),
1307
- from: durationOrTimestampSchema.optional().describe('Start time as a timestamp or duration like "1h" or "7d"'),
1308
- 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
+ ),
1309
1546
  limit: z.number().int().min(1).max(200).default(50).describe("Max results to return"),
1310
- offset: z.number().int().min(0).max(1e4).default(0).describe("Result offset"),
1311
- 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
+ )
1312
1552
  },
1313
- withErrorHandling(async ({ slug, method, kind, q, from, to, limit, offset, order }) => {
1314
- const results = await client.requests.search({
1315
- slug,
1316
- method,
1317
- kind,
1318
- q,
1319
- from,
1320
- to,
1321
- limit,
1322
- offset,
1323
- order
1324
- });
1325
- 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));
1326
1578
  })
1327
1579
  );
1328
1580
  server.tool(
1329
1581
  "count_requests",
1330
- "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).",
1331
1583
  {
1332
1584
  slug: z.string().optional().describe("Filter to a specific endpoint slug"),
1333
1585
  method: z.string().optional().describe("Filter by HTTP method"),
1334
1586
  kind: kindSchema,
1335
- q: z.string().optional().describe("Free-text search across path, body, and headers"),
1336
- from: durationOrTimestampSchema.optional().describe('Start time as a timestamp or duration like "1h" or "7d"'),
1337
- 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
+ )
1338
1599
  },
1339
- withErrorHandling(async ({ slug, method, kind, q, from, to }) => {
1340
- const count = await client.requests.count({ slug, method, kind, q, from, to });
1341
- 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
+ });
1342
1612
  })
1343
1613
  );
1344
1614
  server.tool(
1345
1615
  "get_request",
1346
- "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.",
1347
1617
  getRequestShape,
1348
1618
  withErrorHandling(async ({ requestId }) => {
1349
1619
  const request = await client.requests.get(requestId);
1350
- return jsonContent(compactRequest(request));
1620
+ return requestContent(request);
1351
1621
  })
1352
1622
  );
1353
1623
  server.tool(
@@ -1356,7 +1626,7 @@ function registerTools(target, client, options = {}) {
1356
1626
  waitForRequestShape,
1357
1627
  withErrorHandling(async ({ endpointSlug, timeout, pollInterval }) => {
1358
1628
  const request = await client.requests.waitFor(endpointSlug, { timeout, pollInterval });
1359
- return jsonContent(compactRequest(request));
1629
+ return requestContent(request);
1360
1630
  })
1361
1631
  );
1362
1632
  server.tool(
@@ -2110,7 +2380,7 @@ function registerTools(target, client, options = {}) {
2110
2380
  );
2111
2381
  server.tool(
2112
2382
  "wait_for_approval",
2113
- "Wait for the account's owner to answer an approval (from create_api_key, create_share_link, remove_domain, rename_account, 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.",
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.",
2114
2384
  {
2115
2385
  id: z.string().describe("The approval id"),
2116
2386
  timeout: durationOrTimestampSchema.default("45s").describe('How long to wait for the person, for example "45s"')