@webhooks-cc/mcp 1.10.0 → 1.11.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.
- package/README.md +7 -9
- package/dist/bin/mcp.js +417 -144
- package/dist/index.d.mts +21 -6
- package/dist/index.d.ts +21 -6
- package/dist/index.js +422 -144
- package/dist/index.mjs +424 -145
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { McpServer as McpServer2 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
-
import { WebhooksCC as
|
|
3
|
+
import { WebhooksCC as WebhooksCC3 } from "@webhooks-cc/sdk";
|
|
4
4
|
|
|
5
5
|
// src/prompts.ts
|
|
6
6
|
import { z } from "zod";
|
|
@@ -377,6 +377,13 @@ function registerResources(server, client) {
|
|
|
377
377
|
);
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
+
// src/sandbox-tools.ts
|
|
381
|
+
import { z as z3 } from "zod";
|
|
382
|
+
import {
|
|
383
|
+
AgentAuthError,
|
|
384
|
+
WebhooksCC as WebhooksCC2
|
|
385
|
+
} from "@webhooks-cc/sdk";
|
|
386
|
+
|
|
380
387
|
// src/tools.ts
|
|
381
388
|
import { z as z2 } from "zod";
|
|
382
389
|
import {
|
|
@@ -399,7 +406,6 @@ import {
|
|
|
399
406
|
UnauthorizedError,
|
|
400
407
|
VERIFY_PROVIDERS,
|
|
401
408
|
verifySignature,
|
|
402
|
-
WebhooksCC,
|
|
403
409
|
WebhooksCCError,
|
|
404
410
|
extractCode,
|
|
405
411
|
extractLink
|
|
@@ -460,6 +466,44 @@ var mockResponseSchema = z2.object({
|
|
|
460
466
|
`Response delay in milliseconds (${MOCK_RESPONSE_DELAY_MIN}-${MOCK_RESPONSE_DELAY_MAX}, default: none)`
|
|
461
467
|
)
|
|
462
468
|
});
|
|
469
|
+
var createEndpointShape = {
|
|
470
|
+
name: z2.string().optional().describe("Display name for the endpoint"),
|
|
471
|
+
ephemeral: z2.boolean().optional().describe("Create a temporary endpoint that auto-expires"),
|
|
472
|
+
expiresIn: durationOrTimestampSchema.optional().describe('Auto-expire after this duration, for example "12h"'),
|
|
473
|
+
mockResponse: mockResponseSchema.optional().describe("Optional mock response to return when the endpoint receives a request"),
|
|
474
|
+
responseRules: responseRulesSchema.optional().describe(
|
|
475
|
+
"Conditional response rules. Each rule has conditions and a response. First matching rule wins."
|
|
476
|
+
),
|
|
477
|
+
notificationUrl: z2.string().url().optional().describe(
|
|
478
|
+
"URL to POST a JSON summary to after each captured request (e.g. Slack/Discord webhook)"
|
|
479
|
+
),
|
|
480
|
+
signingProvider: z2.string().optional().describe(
|
|
481
|
+
"Signing provider for automatic signature verification (e.g. stripe, github, shopify)"
|
|
482
|
+
),
|
|
483
|
+
signingSecret: z2.string().optional().describe(
|
|
484
|
+
"Signing secret (encrypted server-side, never returned). Required when signingProvider is set."
|
|
485
|
+
),
|
|
486
|
+
signingHeader: z2.string().optional().describe("Custom signature header name. Only used with generic-hmac provider.")
|
|
487
|
+
};
|
|
488
|
+
var listEndpointsShape = {
|
|
489
|
+
team: z2.string().min(1).optional().describe(
|
|
490
|
+
"Team id or name (case-insensitive). Keeps endpoints shared with you from that team and endpoints you own that are shared with it."
|
|
491
|
+
)
|
|
492
|
+
};
|
|
493
|
+
var getEndpointShape = { slug: z2.string().describe("The endpoint slug") };
|
|
494
|
+
var deleteEndpointShape = { slug: z2.string().describe("The endpoint slug to delete") };
|
|
495
|
+
var listRequestsShape = {
|
|
496
|
+
endpointSlug: z2.string().describe("The endpoint slug"),
|
|
497
|
+
limit: z2.number().int().min(1).max(100).default(25).describe("Max requests to return"),
|
|
498
|
+
since: z2.number().optional().describe("Only return requests after this timestamp in ms"),
|
|
499
|
+
kind: kindSchema
|
|
500
|
+
};
|
|
501
|
+
var getRequestShape = { requestId: z2.string().describe("The request ID") };
|
|
502
|
+
var waitForRequestShape = {
|
|
503
|
+
endpointSlug: z2.string().describe("The endpoint slug to monitor"),
|
|
504
|
+
timeout: durationOrTimestampSchema.default("30s").describe('How long to wait, for example "30s"'),
|
|
505
|
+
pollInterval: durationOrTimestampSchema.optional().describe('Interval between polls, for example "500ms" or "1s"')
|
|
506
|
+
};
|
|
463
507
|
function textContent(text) {
|
|
464
508
|
return { content: [{ type: "text", text }] };
|
|
465
509
|
}
|
|
@@ -763,25 +807,7 @@ function registerTools(server, client) {
|
|
|
763
807
|
server.tool(
|
|
764
808
|
"create_endpoint",
|
|
765
809
|
"Create a webhook endpoint. Returns the endpoint slug, URL, and metadata.",
|
|
766
|
-
|
|
767
|
-
name: z2.string().optional().describe("Display name for the endpoint"),
|
|
768
|
-
ephemeral: z2.boolean().optional().describe("Create a temporary endpoint that auto-expires"),
|
|
769
|
-
expiresIn: durationOrTimestampSchema.optional().describe('Auto-expire after this duration, for example "12h"'),
|
|
770
|
-
mockResponse: mockResponseSchema.optional().describe("Optional mock response to return when the endpoint receives a request"),
|
|
771
|
-
responseRules: responseRulesSchema.optional().describe(
|
|
772
|
-
"Conditional response rules. Each rule has conditions and a response. First matching rule wins."
|
|
773
|
-
),
|
|
774
|
-
notificationUrl: z2.string().url().optional().describe(
|
|
775
|
-
"URL to POST a JSON summary to after each captured request (e.g. Slack/Discord webhook)"
|
|
776
|
-
),
|
|
777
|
-
signingProvider: z2.string().optional().describe(
|
|
778
|
-
"Signing provider for automatic signature verification (e.g. stripe, github, shopify)"
|
|
779
|
-
),
|
|
780
|
-
signingSecret: z2.string().optional().describe(
|
|
781
|
-
"Signing secret (encrypted server-side, never returned). Required when signingProvider is set."
|
|
782
|
-
),
|
|
783
|
-
signingHeader: z2.string().optional().describe("Custom signature header name. Only used with generic-hmac provider.")
|
|
784
|
-
},
|
|
810
|
+
createEndpointShape,
|
|
785
811
|
withErrorHandling(
|
|
786
812
|
async ({
|
|
787
813
|
name,
|
|
@@ -834,11 +860,7 @@ function registerTools(server, client) {
|
|
|
834
860
|
server.tool(
|
|
835
861
|
"list_endpoints",
|
|
836
862
|
"List webhook endpoints: those you own (with sharedWith) and those shared with you through teams (with fromTeam). Optionally keep only one team's endpoints.",
|
|
837
|
-
|
|
838
|
-
team: z2.string().min(1).optional().describe(
|
|
839
|
-
"Team id or name (case-insensitive). Keeps endpoints shared with you from that team and endpoints you own that are shared with it."
|
|
840
|
-
)
|
|
841
|
-
},
|
|
863
|
+
listEndpointsShape,
|
|
842
864
|
withErrorHandling(async ({ team }) => {
|
|
843
865
|
const endpoints = await client.endpoints.list({ team });
|
|
844
866
|
return jsonContent(endpoints);
|
|
@@ -894,7 +916,7 @@ function registerTools(server, client) {
|
|
|
894
916
|
server.tool(
|
|
895
917
|
"get_endpoint",
|
|
896
918
|
"Get details for a specific webhook endpoint by slug.",
|
|
897
|
-
|
|
919
|
+
getEndpointShape,
|
|
898
920
|
withErrorHandling(async ({ slug }) => {
|
|
899
921
|
const endpoint = await client.endpoints.get(slug);
|
|
900
922
|
return jsonContent(endpoint);
|
|
@@ -947,7 +969,7 @@ function registerTools(server, client) {
|
|
|
947
969
|
server.tool(
|
|
948
970
|
"delete_endpoint",
|
|
949
971
|
"Delete a webhook endpoint and all its captured requests.",
|
|
950
|
-
|
|
972
|
+
deleteEndpointShape,
|
|
951
973
|
withErrorHandling(async ({ slug }) => {
|
|
952
974
|
await client.endpoints.delete(slug);
|
|
953
975
|
return textContent(`Endpoint "${slug}" deleted.`);
|
|
@@ -1051,12 +1073,7 @@ function registerTools(server, client) {
|
|
|
1051
1073
|
server.tool(
|
|
1052
1074
|
"list_requests",
|
|
1053
1075
|
"List recent captured requests for an endpoint, HTTP requests and emails together (filter with kind). For emails, list_emails is shorter.",
|
|
1054
|
-
|
|
1055
|
-
endpointSlug: z2.string().describe("The endpoint slug"),
|
|
1056
|
-
limit: z2.number().int().min(1).max(100).default(25).describe("Max requests to return"),
|
|
1057
|
-
since: z2.number().optional().describe("Only return requests after this timestamp in ms"),
|
|
1058
|
-
kind: kindSchema
|
|
1059
|
-
},
|
|
1076
|
+
listRequestsShape,
|
|
1060
1077
|
withErrorHandling(async ({ endpointSlug, limit, since, kind }) => {
|
|
1061
1078
|
const requests = await client.requests.list(endpointSlug, { limit, since, kind });
|
|
1062
1079
|
return jsonContent(requests.map(compactRequest));
|
|
@@ -1110,7 +1127,7 @@ function registerTools(server, client) {
|
|
|
1110
1127
|
server.tool(
|
|
1111
1128
|
"get_request",
|
|
1112
1129
|
"Get full details for a specific captured request by ID.",
|
|
1113
|
-
|
|
1130
|
+
getRequestShape,
|
|
1114
1131
|
withErrorHandling(async ({ requestId }) => {
|
|
1115
1132
|
const request = await client.requests.get(requestId);
|
|
1116
1133
|
return jsonContent(compactRequest(request));
|
|
@@ -1119,11 +1136,7 @@ function registerTools(server, client) {
|
|
|
1119
1136
|
server.tool(
|
|
1120
1137
|
"wait_for_request",
|
|
1121
1138
|
"Wait for a request to arrive at an endpoint.",
|
|
1122
|
-
|
|
1123
|
-
endpointSlug: z2.string().describe("The endpoint slug to monitor"),
|
|
1124
|
-
timeout: durationOrTimestampSchema.default("30s").describe('How long to wait, for example "30s"'),
|
|
1125
|
-
pollInterval: durationOrTimestampSchema.optional().describe('Interval between polls, for example "500ms" or "1s"')
|
|
1126
|
-
},
|
|
1139
|
+
waitForRequestShape,
|
|
1127
1140
|
withErrorHandling(async ({ endpointSlug, timeout, pollInterval }) => {
|
|
1128
1141
|
const request = await client.requests.waitFor(endpointSlug, { timeout, pollInterval });
|
|
1129
1142
|
return jsonContent(compactRequest(request));
|
|
@@ -1614,127 +1627,392 @@ function registerTools(server, client) {
|
|
|
1614
1627
|
return jsonContent(description);
|
|
1615
1628
|
})
|
|
1616
1629
|
);
|
|
1617
|
-
registerAgentRegistrationTools(server);
|
|
1618
|
-
}
|
|
1619
|
-
function resolveBaseUrl() {
|
|
1620
|
-
return process.env.WHK_BASE_URL ?? "https://webhooks.cc";
|
|
1621
1630
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1631
|
+
|
|
1632
|
+
// src/sandbox-tools.ts
|
|
1633
|
+
var SANDBOX = {
|
|
1634
|
+
maxEndpoints: 3,
|
|
1635
|
+
requestsPerEndpoint: 25,
|
|
1636
|
+
requests: 100,
|
|
1637
|
+
lifetimeHours: 24
|
|
1638
|
+
};
|
|
1639
|
+
var DEFAULT_WAIT_SECONDS = 45;
|
|
1640
|
+
var MAX_WAIT_SECONDS = 600;
|
|
1641
|
+
var TOKEN_REFRESH_MARGIN_MS = 6e4;
|
|
1642
|
+
var DOCS_URL = "https://webhooks.cc/docs/agents";
|
|
1643
|
+
var ACCOUNT_ONLY_OPTIONS = [
|
|
1644
|
+
"mockResponse",
|
|
1645
|
+
"responseRules",
|
|
1646
|
+
"notificationUrl",
|
|
1647
|
+
"signingProvider",
|
|
1648
|
+
"signingSecret",
|
|
1649
|
+
"signingHeader"
|
|
1650
|
+
];
|
|
1651
|
+
var AgentSession = class {
|
|
1652
|
+
constructor(baseUrl, webhookUrl, clientName) {
|
|
1653
|
+
this.baseUrl = baseUrl;
|
|
1654
|
+
this.webhookUrl = webhookUrl;
|
|
1655
|
+
this.clientName = clientName;
|
|
1656
|
+
this.sandbox = null;
|
|
1657
|
+
this.claim = null;
|
|
1658
|
+
this.connected = false;
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* The sandbox, registered on first use and again after it expired. Tool
|
|
1662
|
+
* calls can run in parallel: this.sandbox is read again after every await,
|
|
1663
|
+
* and a new sandbox is assigned with no await in between, so parallel
|
|
1664
|
+
* calls share one registration. Calls waiting on a registration that fails
|
|
1665
|
+
* get its error (a 429 asks them to wait); the next call starts again.
|
|
1666
|
+
*/
|
|
1667
|
+
async sandboxClient() {
|
|
1668
|
+
while (this.sandbox) {
|
|
1669
|
+
const pending = this.sandbox;
|
|
1670
|
+
const sandbox = await pending;
|
|
1671
|
+
if (!this.expired(pending, sandbox)) return sandbox;
|
|
1672
|
+
}
|
|
1673
|
+
const created = WebhooksCC2.sandbox({
|
|
1674
|
+
baseUrl: this.baseUrl,
|
|
1675
|
+
webhookUrl: this.webhookUrl,
|
|
1676
|
+
clientName: this.clientName
|
|
1677
|
+
});
|
|
1678
|
+
this.sandbox = created;
|
|
1679
|
+
created.catch(() => {
|
|
1680
|
+
if (this.sandbox === created) this.sandbox = null;
|
|
1681
|
+
});
|
|
1682
|
+
return created;
|
|
1683
|
+
}
|
|
1684
|
+
/** The live sandbox, if one was registered; never registers one. */
|
|
1685
|
+
async existingSandbox() {
|
|
1686
|
+
const pending = this.sandbox;
|
|
1687
|
+
if (!pending) return null;
|
|
1688
|
+
let sandbox;
|
|
1689
|
+
try {
|
|
1690
|
+
sandbox = await pending;
|
|
1691
|
+
} catch {
|
|
1692
|
+
return null;
|
|
1693
|
+
}
|
|
1694
|
+
return this.expired(pending, sandbox) ? null : sandbox;
|
|
1695
|
+
}
|
|
1696
|
+
/** True when the sandbox is past its 24 hours; then it is dropped. */
|
|
1697
|
+
expired(pending, sandbox) {
|
|
1698
|
+
if (sandbox.expiresAt.getTime() > Date.now()) return false;
|
|
1699
|
+
if (this.sandbox === pending) this.sandbox = null;
|
|
1700
|
+
if (this.claim?.kind === "sandbox" && this.claim.claimToken === sandbox.registration.claimToken) {
|
|
1701
|
+
this.claim = null;
|
|
1702
|
+
}
|
|
1703
|
+
return true;
|
|
1704
|
+
}
|
|
1705
|
+
async requireSandbox() {
|
|
1706
|
+
const sandbox = await this.existingSandbox();
|
|
1707
|
+
if (!sandbox) {
|
|
1708
|
+
throw new Error("No sandbox yet: create_endpoint starts one.");
|
|
1709
|
+
}
|
|
1710
|
+
return sandbox;
|
|
1711
|
+
}
|
|
1712
|
+
forgetSandbox() {
|
|
1713
|
+
this.sandbox = null;
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
function claimedTokens(baseUrl, assertion, first) {
|
|
1717
|
+
let current = first;
|
|
1718
|
+
let pending = null;
|
|
1719
|
+
return async (options) => {
|
|
1720
|
+
if (!options?.forceRefresh && current.expiresAt.getTime() - Date.now() > TOKEN_REFRESH_MARGIN_MS) {
|
|
1721
|
+
return current.accessToken;
|
|
1722
|
+
}
|
|
1723
|
+
if (!pending) {
|
|
1724
|
+
pending = WebhooksCC2.agent.exchange({ baseUrl, assertion }).finally(() => {
|
|
1725
|
+
pending = null;
|
|
1635
1726
|
});
|
|
1636
|
-
}
|
|
1727
|
+
}
|
|
1728
|
+
current = await pending;
|
|
1729
|
+
return current.accessToken;
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
function minutesLeft(until) {
|
|
1733
|
+
return Math.max(1, Math.round((until.getTime() - Date.now()) / 6e4));
|
|
1734
|
+
}
|
|
1735
|
+
function onlyKind(requests, kind) {
|
|
1736
|
+
if (!kind) return requests;
|
|
1737
|
+
return requests.filter((request) => (request.kind ?? "http") === kind);
|
|
1738
|
+
}
|
|
1739
|
+
function registerSandboxTools(server, options = {}) {
|
|
1740
|
+
const baseUrl = options.baseUrl ?? process.env.WHK_BASE_URL ?? "https://webhooks.cc";
|
|
1741
|
+
const session = new AgentSession(
|
|
1742
|
+
baseUrl,
|
|
1743
|
+
options.webhookUrl ?? process.env.WHK_WEBHOOK_URL,
|
|
1744
|
+
options.clientName ?? "webhooks-cc-mcp"
|
|
1637
1745
|
);
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1746
|
+
const registered = [];
|
|
1747
|
+
const limits = `up to ${SANDBOX.maxEndpoints} endpoints at a time, ${SANDBOX.requestsPerEndpoint} captured requests each and ${SANDBOX.requests} in all, deleted ${SANDBOX.lifetimeHours} hours after the sandbox was created`;
|
|
1748
|
+
registered.push(
|
|
1749
|
+
server.tool(
|
|
1750
|
+
"create_endpoint",
|
|
1751
|
+
`Create a temporary webhook capture endpoint in the agent sandbox (no account needed): ${limits}. The first call registers the sandbox, which takes a few seconds of proof of work. Mock responses, notifications and signature verification need an account: see connect_account.`,
|
|
1752
|
+
createEndpointShape,
|
|
1753
|
+
withErrorHandling(async (args) => {
|
|
1754
|
+
const accountOnly = ACCOUNT_ONLY_OPTIONS.filter((key) => args[key] !== void 0);
|
|
1755
|
+
if (accountOnly.length > 0) {
|
|
1756
|
+
throw new Error(
|
|
1757
|
+
`${accountOnly.join(", ")} need an account; sandbox endpoints only capture and answer 200. Call connect_account to connect one.`
|
|
1758
|
+
);
|
|
1759
|
+
}
|
|
1760
|
+
const sandbox = await session.sandboxClient();
|
|
1761
|
+
const endpoint = await sandbox.endpoints.create();
|
|
1762
|
+
const ignored = args.name !== void 0 || args.expiresIn !== void 0;
|
|
1763
|
+
return jsonContent(
|
|
1764
|
+
ignored ? {
|
|
1765
|
+
...endpoint,
|
|
1766
|
+
note: "Sandbox endpoints have no name and expire with the sandbox."
|
|
1767
|
+
} : endpoint
|
|
1768
|
+
);
|
|
1769
|
+
})
|
|
1770
|
+
)
|
|
1659
1771
|
);
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1772
|
+
registered.push(
|
|
1773
|
+
server.tool(
|
|
1774
|
+
"list_endpoints",
|
|
1775
|
+
"List this agent's sandbox endpoints. Empty until create_endpoint starts the sandbox.",
|
|
1776
|
+
listEndpointsShape,
|
|
1777
|
+
withErrorHandling(async ({ team }) => {
|
|
1778
|
+
if (team !== void 0) {
|
|
1779
|
+
throw new Error("Teams need an account. Call connect_account to connect one.");
|
|
1780
|
+
}
|
|
1781
|
+
const sandbox = await session.existingSandbox();
|
|
1782
|
+
return jsonContent(sandbox ? await sandbox.endpoints.list() : []);
|
|
1783
|
+
})
|
|
1784
|
+
)
|
|
1670
1785
|
);
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
return jsonContent({
|
|
1681
|
-
claimToken: challenge.claimToken,
|
|
1682
|
-
expiresAt: challenge.claimTokenExpires,
|
|
1683
|
-
postClaimScopes: challenge.postClaimScopes,
|
|
1684
|
-
next_step: `A one-time code was emailed to ${email}. Ask the human for it, then call verify_agent_otp with this claimToken and the code.`
|
|
1685
|
-
});
|
|
1686
|
-
})
|
|
1786
|
+
registered.push(
|
|
1787
|
+
server.tool(
|
|
1788
|
+
"get_endpoint",
|
|
1789
|
+
"Get one of this agent's sandbox endpoints by slug, with its sandbox limits and usage.",
|
|
1790
|
+
getEndpointShape,
|
|
1791
|
+
withErrorHandling(async ({ slug }) => {
|
|
1792
|
+
return jsonContent(await (await session.requireSandbox()).endpoints.get(slug));
|
|
1793
|
+
})
|
|
1794
|
+
)
|
|
1687
1795
|
);
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
credential: issued.credential,
|
|
1699
|
-
scopes: issued.scopes,
|
|
1700
|
-
usage: "Set WHK_API_KEY to `credential` to use the authenticated tools."
|
|
1701
|
-
});
|
|
1702
|
-
})
|
|
1796
|
+
registered.push(
|
|
1797
|
+
server.tool(
|
|
1798
|
+
"delete_endpoint",
|
|
1799
|
+
"Delete one of this agent's sandbox endpoints and its captured requests. Frees a slot; the sandbox's request budget is not refunded.",
|
|
1800
|
+
deleteEndpointShape,
|
|
1801
|
+
withErrorHandling(async ({ slug }) => {
|
|
1802
|
+
await (await session.requireSandbox()).endpoints.delete(slug);
|
|
1803
|
+
return jsonContent({ deleted: slug });
|
|
1804
|
+
})
|
|
1805
|
+
)
|
|
1703
1806
|
);
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
usage: "Set WHK_API_KEY to `credential` to use the authenticated tools."
|
|
1716
|
-
});
|
|
1717
|
-
})
|
|
1807
|
+
registered.push(
|
|
1808
|
+
server.tool(
|
|
1809
|
+
"list_requests",
|
|
1810
|
+
"List recent requests captured by a sandbox endpoint, newest first.",
|
|
1811
|
+
listRequestsShape,
|
|
1812
|
+
withErrorHandling(async ({ endpointSlug, limit, since, kind }) => {
|
|
1813
|
+
const sandbox = await session.requireSandbox();
|
|
1814
|
+
const requests = await sandbox.requests.list(endpointSlug, { limit, since });
|
|
1815
|
+
return jsonContent(onlyKind(requests, kind).map(compactRequest));
|
|
1816
|
+
})
|
|
1817
|
+
)
|
|
1718
1818
|
);
|
|
1819
|
+
registered.push(
|
|
1820
|
+
server.tool(
|
|
1821
|
+
"get_request",
|
|
1822
|
+
"Get full details for a request captured by a sandbox endpoint.",
|
|
1823
|
+
getRequestShape,
|
|
1824
|
+
withErrorHandling(async ({ requestId }) => {
|
|
1825
|
+
const sandbox = await session.requireSandbox();
|
|
1826
|
+
return jsonContent(compactRequest(await sandbox.requests.get(requestId)));
|
|
1827
|
+
})
|
|
1828
|
+
)
|
|
1829
|
+
);
|
|
1830
|
+
registered.push(
|
|
1831
|
+
server.tool(
|
|
1832
|
+
"wait_for_request",
|
|
1833
|
+
"Wait for a request to arrive at a sandbox endpoint.",
|
|
1834
|
+
waitForRequestShape,
|
|
1835
|
+
withErrorHandling(async ({ endpointSlug, timeout, pollInterval }) => {
|
|
1836
|
+
const sandbox = await session.requireSandbox();
|
|
1837
|
+
const request = await sandbox.requests.waitFor(endpointSlug, { timeout, pollInterval });
|
|
1838
|
+
return jsonContent(compactRequest(request));
|
|
1839
|
+
})
|
|
1840
|
+
)
|
|
1841
|
+
);
|
|
1842
|
+
registered.push(
|
|
1843
|
+
server.tool(
|
|
1844
|
+
"connect_account",
|
|
1845
|
+
"Connect this agent to a human's webhooks.cc account, for the full tool set (mock responses, signatures, email, teams) and to keep the sandbox endpoints. Returns a link and a 6-digit code: show both to the human, who signs in or signs up with that email and enters the code. Then call wait_for_connection. Calling again gives a new code.",
|
|
1846
|
+
{
|
|
1847
|
+
email: z3.string().email({ message: "Invalid email address" }).describe("The human's email address; only someone signed in as it can connect")
|
|
1848
|
+
},
|
|
1849
|
+
withErrorHandling(async ({ email }) => {
|
|
1850
|
+
if (session.connected) {
|
|
1851
|
+
return jsonContent({ connected: true, message: "Already connected to an account." });
|
|
1852
|
+
}
|
|
1853
|
+
const normalized = email.trim().toLowerCase();
|
|
1854
|
+
const sandbox = await session.existingSandbox();
|
|
1855
|
+
let claim;
|
|
1856
|
+
if (sandbox) {
|
|
1857
|
+
claim = {
|
|
1858
|
+
kind: "sandbox",
|
|
1859
|
+
claimToken: sandbox.registration.claimToken,
|
|
1860
|
+
email: normalized,
|
|
1861
|
+
attempt: await sandbox.claim({ email: normalized }),
|
|
1862
|
+
claimExpires: sandbox.expiresAt
|
|
1863
|
+
};
|
|
1864
|
+
} else if (session.claim?.kind === "service_auth" && session.claim.email === normalized && session.claim.claimExpires.getTime() > Date.now()) {
|
|
1865
|
+
const attempt = await WebhooksCC2.agent.startClaim({
|
|
1866
|
+
baseUrl,
|
|
1867
|
+
claimToken: session.claim.claimToken
|
|
1868
|
+
});
|
|
1869
|
+
claim = { ...session.claim, attempt };
|
|
1870
|
+
} else {
|
|
1871
|
+
const registration = await WebhooksCC2.agent.registerServiceAuth({
|
|
1872
|
+
baseUrl,
|
|
1873
|
+
email: normalized,
|
|
1874
|
+
clientName: session.clientName
|
|
1875
|
+
});
|
|
1876
|
+
claim = {
|
|
1877
|
+
kind: "service_auth",
|
|
1878
|
+
claimToken: registration.claimToken,
|
|
1879
|
+
email: normalized,
|
|
1880
|
+
attempt: registration.claim,
|
|
1881
|
+
claimExpires: registration.claimTokenExpires
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
session.claim = claim;
|
|
1885
|
+
const { verificationUri, userCode, expiresAt } = claim.attempt;
|
|
1886
|
+
return jsonContent({
|
|
1887
|
+
verificationUri,
|
|
1888
|
+
userCode,
|
|
1889
|
+
expiresAt: expiresAt.toISOString(),
|
|
1890
|
+
tellTheHuman: `Open ${verificationUri}, sign in or sign up as ${normalized}, and enter the code ${userCode}.`,
|
|
1891
|
+
next: `Show the human that line, then call wait_for_connection. The code works for about ${minutesLeft(expiresAt)} minutes; connect_account gives a new one.`,
|
|
1892
|
+
...claim.kind === "sandbox" ? { endpoints: "The sandbox endpoints move into that account with what they captured." } : {}
|
|
1893
|
+
});
|
|
1894
|
+
})
|
|
1895
|
+
)
|
|
1896
|
+
);
|
|
1897
|
+
registered.push(
|
|
1898
|
+
server.tool(
|
|
1899
|
+
"wait_for_connection",
|
|
1900
|
+
`Wait for the human to enter the code from connect_account. On success the full webhooks.cc tools for their account replace these sandbox tools. Returns after timeoutSeconds (default ${DEFAULT_WAIT_SECONDS}) if they have not finished yet; call it again to keep waiting.`,
|
|
1901
|
+
{
|
|
1902
|
+
timeoutSeconds: z3.number().int().min(1).max(MAX_WAIT_SECONDS).optional().describe(`How long to wait, in seconds (default ${DEFAULT_WAIT_SECONDS})`)
|
|
1903
|
+
},
|
|
1904
|
+
withErrorHandling(async ({ timeoutSeconds }) => {
|
|
1905
|
+
if (session.connected) {
|
|
1906
|
+
return jsonContent({ connected: true, message: "Already connected to an account." });
|
|
1907
|
+
}
|
|
1908
|
+
const claim = session.claim;
|
|
1909
|
+
if (!claim) {
|
|
1910
|
+
throw new Error("Nothing to wait for: call connect_account first.");
|
|
1911
|
+
}
|
|
1912
|
+
let claimed;
|
|
1913
|
+
try {
|
|
1914
|
+
claimed = await WebhooksCC2.agent.waitForClaim({
|
|
1915
|
+
baseUrl,
|
|
1916
|
+
claimToken: claim.claimToken,
|
|
1917
|
+
interval: claim.attempt.interval,
|
|
1918
|
+
timeout: (timeoutSeconds ?? DEFAULT_WAIT_SECONDS) * 1e3
|
|
1919
|
+
});
|
|
1920
|
+
} catch (error) {
|
|
1921
|
+
if (!(error instanceof AgentAuthError)) throw error;
|
|
1922
|
+
if (error.code === "timeout") {
|
|
1923
|
+
return jsonContent({
|
|
1924
|
+
connected: false,
|
|
1925
|
+
status: "waiting",
|
|
1926
|
+
message: `Not connected yet. The code works until ${claim.attempt.expiresAt.toISOString()}; call wait_for_connection again.`
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
if (error.code === "expired_token") {
|
|
1930
|
+
return jsonContent({
|
|
1931
|
+
connected: false,
|
|
1932
|
+
status: "expired",
|
|
1933
|
+
message: "The code expired. Call connect_account for a new one."
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
if (error.code === "access_denied") {
|
|
1937
|
+
return jsonContent({
|
|
1938
|
+
connected: false,
|
|
1939
|
+
status: "declined",
|
|
1940
|
+
message: "The human declined. Call connect_account again only if they ask you to."
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
throw error;
|
|
1944
|
+
}
|
|
1945
|
+
const client = new WebhooksCC2({
|
|
1946
|
+
baseUrl,
|
|
1947
|
+
webhookUrl: session.webhookUrl,
|
|
1948
|
+
getAccessToken: claimedTokens(baseUrl, claimed.identityAssertion, claimed.token)
|
|
1949
|
+
});
|
|
1950
|
+
session.connected = true;
|
|
1951
|
+
session.claim = null;
|
|
1952
|
+
session.forgetSandbox();
|
|
1953
|
+
for (const tool of registered) tool.remove();
|
|
1954
|
+
registerTools(server, client);
|
|
1955
|
+
options.onConnected?.(client);
|
|
1956
|
+
return jsonContent({
|
|
1957
|
+
connected: true,
|
|
1958
|
+
email: claim.email,
|
|
1959
|
+
scope: claimed.token.scope,
|
|
1960
|
+
message: `Connected to the webhooks.cc account of ${claim.email}. The full tool set has replaced the sandbox tools (the tool list changed; if your client does not pick that up, ask the user to restart it).${claim.kind === "sandbox" ? " The sandbox endpoints are now that account's endpoints, with what they captured." : ""} This connection lasts while this MCP server runs; for a lasting setup, the human can create an API key under Account and set WHK_API_KEY.`
|
|
1961
|
+
});
|
|
1962
|
+
})
|
|
1963
|
+
)
|
|
1964
|
+
);
|
|
1965
|
+
registered.push(
|
|
1966
|
+
server.tool(
|
|
1967
|
+
"about_sandbox",
|
|
1968
|
+
"Explain what this agent can do without a webhooks.cc account, the sandbox limits, and how to connect an account. No network call.",
|
|
1969
|
+
{},
|
|
1970
|
+
withErrorHandling(async () => {
|
|
1971
|
+
return jsonContent({
|
|
1972
|
+
mode: "sandbox (no WHK_API_KEY)",
|
|
1973
|
+
sandbox: {
|
|
1974
|
+
maxEndpoints: SANDBOX.maxEndpoints,
|
|
1975
|
+
requestsPerEndpoint: SANDBOX.requestsPerEndpoint,
|
|
1976
|
+
requestsInAll: SANDBOX.requests,
|
|
1977
|
+
lifetimeHours: SANDBOX.lifetimeHours,
|
|
1978
|
+
startsWith: "create_endpoint (registers the sandbox; a few seconds of proof of work)",
|
|
1979
|
+
captures: "Endpoints answer every request with 200; only this agent can read what they capture.",
|
|
1980
|
+
notAvailable: "Mock responses, response rules, notifications, signature verification, email capture, forwarding, teams and sending webhooks."
|
|
1981
|
+
},
|
|
1982
|
+
connectAnAccount: [
|
|
1983
|
+
"Call connect_account with the human's email and show them the link and code it returns.",
|
|
1984
|
+
"Call wait_for_connection until it reports connected; the full tools for their account then replace the sandbox tools.",
|
|
1985
|
+
"Sandbox endpoints move into the account with their captured requests."
|
|
1986
|
+
],
|
|
1987
|
+
withAnApiKey: "Set WHK_API_KEY to a whcc_ key from the dashboard and restart for the full tools from the start.",
|
|
1988
|
+
docs: DOCS_URL,
|
|
1989
|
+
protocol: `${baseUrl}/auth.md`
|
|
1990
|
+
});
|
|
1991
|
+
})
|
|
1992
|
+
)
|
|
1993
|
+
);
|
|
1994
|
+
}
|
|
1995
|
+
function registerAgentRegistrationTools(server) {
|
|
1996
|
+
registerSandboxTools(server);
|
|
1719
1997
|
}
|
|
1720
1998
|
|
|
1721
1999
|
// src/index.ts
|
|
1722
|
-
var VERSION = true ? "1.
|
|
2000
|
+
var VERSION = true ? "1.11.0" : "0.0.0-dev";
|
|
1723
2001
|
function createServer(options = {}) {
|
|
1724
2002
|
const apiKey = options.apiKey ?? process.env.WHK_API_KEY;
|
|
1725
|
-
const
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
2003
|
+
const webhookUrl = options.webhookUrl ?? process.env.WHK_WEBHOOK_URL;
|
|
2004
|
+
const baseUrl = options.baseUrl ?? process.env.WHK_BASE_URL;
|
|
2005
|
+
const server = new McpServer2(
|
|
2006
|
+
{ name: "webhooks-cc", version: VERSION },
|
|
2007
|
+
// Connecting an account swaps every tool at once: one list_changed, not dozens.
|
|
2008
|
+
{ debouncedNotificationMethods: ["notifications/tools/list_changed"] }
|
|
2009
|
+
);
|
|
1729
2010
|
if (!apiKey) {
|
|
1730
|
-
|
|
2011
|
+
registerSandboxTools(server, { baseUrl, webhookUrl });
|
|
2012
|
+
registerPrompts(server);
|
|
1731
2013
|
return server;
|
|
1732
2014
|
}
|
|
1733
|
-
const client = new
|
|
1734
|
-
apiKey,
|
|
1735
|
-
webhookUrl: options.webhookUrl ?? process.env.WHK_WEBHOOK_URL,
|
|
1736
|
-
baseUrl: options.baseUrl ?? process.env.WHK_BASE_URL
|
|
1737
|
-
});
|
|
2015
|
+
const client = new WebhooksCC3({ apiKey, webhookUrl, baseUrl });
|
|
1738
2016
|
registerTools(server, client);
|
|
1739
2017
|
registerPrompts(server);
|
|
1740
2018
|
registerResources(server, client);
|
|
@@ -1745,5 +2023,6 @@ export {
|
|
|
1745
2023
|
registerAgentRegistrationTools,
|
|
1746
2024
|
registerPrompts,
|
|
1747
2025
|
registerResources,
|
|
2026
|
+
registerSandboxTools,
|
|
1748
2027
|
registerTools
|
|
1749
2028
|
};
|