@webhooks-cc/mcp 0.3.0 → 1.0.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 +126 -38
- package/dist/bin/mcp.js +817 -106
- package/dist/index.d.mts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +821 -106
- package/dist/index.mjs +827 -105
- package/package.json +4 -4
package/dist/bin/mcp.js
CHANGED
|
@@ -5,99 +5,584 @@
|
|
|
5
5
|
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
|
+
var import_mcp2 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
9
|
+
var import_sdk2 = require("@webhooks-cc/sdk");
|
|
10
|
+
|
|
11
|
+
// src/prompts.ts
|
|
12
|
+
var import_zod = require("zod");
|
|
13
|
+
function registerPrompts(server) {
|
|
14
|
+
server.registerPrompt(
|
|
15
|
+
"debug_webhook_delivery",
|
|
16
|
+
{
|
|
17
|
+
title: "Debug Webhook Delivery",
|
|
18
|
+
description: "Guide an agent through diagnosing why webhook delivery is failing or missing.",
|
|
19
|
+
argsSchema: {
|
|
20
|
+
provider: import_zod.z.string().optional().describe("Webhook provider, if known"),
|
|
21
|
+
endpointSlug: import_zod.z.string().optional().describe("Hosted endpoint slug, if known"),
|
|
22
|
+
targetUrl: import_zod.z.string().optional().describe("Your app's receiving URL, if known")
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
async ({ provider, endpointSlug, targetUrl }) => {
|
|
26
|
+
const scope = [
|
|
27
|
+
provider ? `Provider: ${provider}.` : null,
|
|
28
|
+
endpointSlug ? `Endpoint slug: ${endpointSlug}.` : null,
|
|
29
|
+
targetUrl ? `Target URL: ${targetUrl}.` : null
|
|
30
|
+
].filter(Boolean).join(" ");
|
|
31
|
+
return {
|
|
32
|
+
description: "Diagnose a missing or broken webhook delivery.",
|
|
33
|
+
messages: [
|
|
34
|
+
{
|
|
35
|
+
role: "user",
|
|
36
|
+
content: {
|
|
37
|
+
type: "text",
|
|
38
|
+
text: [
|
|
39
|
+
scope,
|
|
40
|
+
"Diagnose webhook delivery step by step.",
|
|
41
|
+
"Use list_endpoints or get_endpoint to confirm the endpoint and URL.",
|
|
42
|
+
"Use list_requests, wait_for_request, or wait_for_requests to check whether anything arrived.",
|
|
43
|
+
"If the provider is known, use preview_webhook or send_webhook to reproduce the webhook with realistic signing.",
|
|
44
|
+
"Use verify_signature when a secret is available.",
|
|
45
|
+
"Use compare_requests to compare retries or changed payloads.",
|
|
46
|
+
"Conclude with the most likely cause and the next concrete fix."
|
|
47
|
+
].filter(Boolean).join(" ")
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
server.registerPrompt(
|
|
55
|
+
"setup_provider_testing",
|
|
56
|
+
{
|
|
57
|
+
title: "Setup Provider Testing",
|
|
58
|
+
description: "Guide an agent through setting up webhook testing for a provider.",
|
|
59
|
+
argsSchema: {
|
|
60
|
+
provider: import_zod.z.string().describe("Webhook provider to test"),
|
|
61
|
+
targetUrl: import_zod.z.string().optional().describe("Optional local or remote target URL")
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
async ({ provider, targetUrl }) => {
|
|
65
|
+
return {
|
|
66
|
+
description: `Set up webhook testing for ${provider}.`,
|
|
67
|
+
messages: [
|
|
68
|
+
{
|
|
69
|
+
role: "user",
|
|
70
|
+
content: {
|
|
71
|
+
type: "text",
|
|
72
|
+
text: [
|
|
73
|
+
`Set up webhook testing for ${provider}.`,
|
|
74
|
+
"Use list_provider_templates to inspect supported templates and signing details first.",
|
|
75
|
+
"Create an endpoint with create_endpoint, preferably ephemeral.",
|
|
76
|
+
"If a target URL is provided, use preview_webhook before send_to so the request shape is visible.",
|
|
77
|
+
targetUrl ? `Target URL: ${targetUrl}.` : null,
|
|
78
|
+
"Send a realistic provider webhook, wait for capture, and verify the signature if a secret is available.",
|
|
79
|
+
"Return the endpoint URL, the exact tools used, and the next step for the developer."
|
|
80
|
+
].filter(Boolean).join(" ")
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
server.registerPrompt(
|
|
88
|
+
"compare_webhook_attempts",
|
|
89
|
+
{
|
|
90
|
+
title: "Compare Webhook Attempts",
|
|
91
|
+
description: "Guide an agent through comparing two webhook deliveries or retries.",
|
|
92
|
+
argsSchema: {
|
|
93
|
+
endpointSlug: import_zod.z.string().optional().describe("Endpoint slug to inspect for recent attempts"),
|
|
94
|
+
leftRequestId: import_zod.z.string().optional().describe("First request ID, if already known"),
|
|
95
|
+
rightRequestId: import_zod.z.string().optional().describe("Second request ID, if already known")
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
async ({ endpointSlug, leftRequestId, rightRequestId }) => {
|
|
99
|
+
return {
|
|
100
|
+
description: "Compare two webhook deliveries and explain the difference.",
|
|
101
|
+
messages: [
|
|
102
|
+
{
|
|
103
|
+
role: "user",
|
|
104
|
+
content: {
|
|
105
|
+
type: "text",
|
|
106
|
+
text: [
|
|
107
|
+
endpointSlug ? `Endpoint slug: ${endpointSlug}.` : null,
|
|
108
|
+
leftRequestId && rightRequestId ? `Compare request ${leftRequestId} against ${rightRequestId}.` : "Find the most relevant two webhook attempts first.",
|
|
109
|
+
"Use compare_requests for the structured diff.",
|
|
110
|
+
"If request IDs are not provided, use list_requests or the endpoint recent resource to find the last two attempts.",
|
|
111
|
+
"Explain what changed in the body, headers, or timing, and whether the difference looks expected, retried, or broken."
|
|
112
|
+
].filter(Boolean).join(" ")
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/resources.ts
|
|
8
122
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
9
|
-
var
|
|
123
|
+
var ENDPOINTS_RESOURCE_URI = "webhooks://endpoints";
|
|
124
|
+
var ENDPOINT_RECENT_TEMPLATE_URI = "webhooks://endpoint/{slug}/recent";
|
|
125
|
+
var REQUEST_TEMPLATE_URI = "webhooks://request/{id}";
|
|
126
|
+
var MAX_ENDPOINT_RESOURCE_ITEMS = 25;
|
|
127
|
+
var RECENT_REQUEST_LIMIT = 10;
|
|
128
|
+
function jsonResource(uri, value) {
|
|
129
|
+
return {
|
|
130
|
+
contents: [
|
|
131
|
+
{
|
|
132
|
+
uri,
|
|
133
|
+
mimeType: "application/json",
|
|
134
|
+
text: JSON.stringify(value, null, 2)
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function summarizeRequest(request) {
|
|
140
|
+
return {
|
|
141
|
+
id: request.id,
|
|
142
|
+
method: request.method,
|
|
143
|
+
path: request.path,
|
|
144
|
+
receivedAt: request.receivedAt,
|
|
145
|
+
contentType: request.contentType ?? null
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function variableToString(value, name) {
|
|
149
|
+
if (typeof value === "string" && value.length > 0) {
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`Missing resource variable "${name}"`);
|
|
153
|
+
}
|
|
154
|
+
async function listEndpointSummaries(client) {
|
|
155
|
+
const endpoints = (await client.endpoints.list()).slice().sort((left, right) => right.createdAt - left.createdAt);
|
|
156
|
+
const truncated = endpoints.length > MAX_ENDPOINT_RESOURCE_ITEMS;
|
|
157
|
+
const visible = endpoints.slice(0, MAX_ENDPOINT_RESOURCE_ITEMS);
|
|
158
|
+
const summaries = await Promise.all(
|
|
159
|
+
visible.map(async (endpoint) => {
|
|
160
|
+
const recent = await client.requests.list(endpoint.slug, { limit: 1 });
|
|
161
|
+
return {
|
|
162
|
+
...endpoint,
|
|
163
|
+
lastRequest: recent[0] ? summarizeRequest(recent[0]) : null
|
|
164
|
+
};
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
return {
|
|
168
|
+
endpoints: summaries,
|
|
169
|
+
total: endpoints.length,
|
|
170
|
+
truncated
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function registerResources(server, client) {
|
|
174
|
+
server.registerResource(
|
|
175
|
+
"endpoints-overview",
|
|
176
|
+
ENDPOINTS_RESOURCE_URI,
|
|
177
|
+
{
|
|
178
|
+
title: "Endpoints Overview",
|
|
179
|
+
description: "All endpoints with a summary of recent activity.",
|
|
180
|
+
mimeType: "application/json"
|
|
181
|
+
},
|
|
182
|
+
async () => {
|
|
183
|
+
return jsonResource(ENDPOINTS_RESOURCE_URI, await listEndpointSummaries(client));
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
server.registerResource(
|
|
187
|
+
"endpoint-recent-requests",
|
|
188
|
+
new import_mcp.ResourceTemplate(ENDPOINT_RECENT_TEMPLATE_URI, {
|
|
189
|
+
list: async () => {
|
|
190
|
+
const endpoints = await client.endpoints.list();
|
|
191
|
+
return {
|
|
192
|
+
resources: endpoints.map((endpoint) => ({
|
|
193
|
+
uri: `webhooks://endpoint/${endpoint.slug}/recent`,
|
|
194
|
+
name: `${endpoint.slug} recent requests`,
|
|
195
|
+
description: `Recent requests for endpoint ${endpoint.slug}`,
|
|
196
|
+
mimeType: "application/json"
|
|
197
|
+
}))
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
complete: {
|
|
201
|
+
slug: async (value) => {
|
|
202
|
+
const endpoints = await client.endpoints.list();
|
|
203
|
+
return endpoints.map((endpoint) => endpoint.slug).filter((slug) => slug.startsWith(value)).slice(0, 20);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}),
|
|
207
|
+
{
|
|
208
|
+
title: "Endpoint Recent Requests",
|
|
209
|
+
description: "Last 10 captured requests for an endpoint.",
|
|
210
|
+
mimeType: "application/json"
|
|
211
|
+
},
|
|
212
|
+
async (uri, variables) => {
|
|
213
|
+
const slug = variableToString(variables.slug, "slug");
|
|
214
|
+
const [endpoint, requests] = await Promise.all([
|
|
215
|
+
client.endpoints.get(slug),
|
|
216
|
+
client.requests.list(slug, { limit: RECENT_REQUEST_LIMIT })
|
|
217
|
+
]);
|
|
218
|
+
return jsonResource(uri.toString(), {
|
|
219
|
+
endpoint,
|
|
220
|
+
requests
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
);
|
|
224
|
+
server.registerResource(
|
|
225
|
+
"request-details",
|
|
226
|
+
new import_mcp.ResourceTemplate(REQUEST_TEMPLATE_URI, {
|
|
227
|
+
list: void 0,
|
|
228
|
+
complete: {}
|
|
229
|
+
}),
|
|
230
|
+
{
|
|
231
|
+
title: "Request Details",
|
|
232
|
+
description: "Full details for a captured request by ID.",
|
|
233
|
+
mimeType: "application/json"
|
|
234
|
+
},
|
|
235
|
+
async (uri, variables) => {
|
|
236
|
+
const id = variableToString(variables.id, "id");
|
|
237
|
+
const request = await client.requests.get(id);
|
|
238
|
+
return jsonResource(uri.toString(), request);
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
}
|
|
10
242
|
|
|
11
243
|
// src/tools.ts
|
|
12
|
-
var
|
|
244
|
+
var import_zod2 = require("zod");
|
|
245
|
+
var import_sdk = require("@webhooks-cc/sdk");
|
|
13
246
|
var MAX_BODY_SIZE = 32768;
|
|
247
|
+
var HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
248
|
+
var TEMPLATE_PROVIDER_VALUES = [
|
|
249
|
+
"stripe",
|
|
250
|
+
"github",
|
|
251
|
+
"shopify",
|
|
252
|
+
"twilio",
|
|
253
|
+
"slack",
|
|
254
|
+
"paddle",
|
|
255
|
+
"linear",
|
|
256
|
+
"standard-webhooks"
|
|
257
|
+
];
|
|
258
|
+
var VERIFY_PROVIDER_VALUES = [
|
|
259
|
+
...TEMPLATE_PROVIDER_VALUES,
|
|
260
|
+
"discord"
|
|
261
|
+
];
|
|
262
|
+
var TIME_SEPARATOR = " \u2014 ";
|
|
263
|
+
var httpUrlSchema = import_zod2.z.string().url().refine(
|
|
264
|
+
(value) => {
|
|
265
|
+
try {
|
|
266
|
+
const protocol = new URL(value).protocol;
|
|
267
|
+
return protocol === "http:" || protocol === "https:";
|
|
268
|
+
} catch {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{ message: "Only http and https URLs are supported" }
|
|
273
|
+
);
|
|
274
|
+
var methodSchema = import_zod2.z.enum(HTTP_METHODS).default("POST").describe("HTTP method (default: POST)");
|
|
275
|
+
var durationOrTimestampSchema = import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number()]);
|
|
276
|
+
var mockResponseSchema = import_zod2.z.object({
|
|
277
|
+
status: import_zod2.z.number().int().min(100).max(599).describe("HTTP status code (100-599)"),
|
|
278
|
+
body: import_zod2.z.string().default("").describe("Response body string (default: empty)"),
|
|
279
|
+
headers: import_zod2.z.record(import_zod2.z.string()).default({}).describe("Response headers (default: none)")
|
|
280
|
+
});
|
|
14
281
|
function textContent(text) {
|
|
15
282
|
return { content: [{ type: "text", text }] };
|
|
16
283
|
}
|
|
284
|
+
function serializeJson(value, limit = MAX_BODY_SIZE) {
|
|
285
|
+
const full = JSON.stringify(value, null, 2);
|
|
286
|
+
if (full.length <= limit) {
|
|
287
|
+
return full;
|
|
288
|
+
}
|
|
289
|
+
if (Array.isArray(value)) {
|
|
290
|
+
let low = 0;
|
|
291
|
+
let high = value.length;
|
|
292
|
+
let best = JSON.stringify(
|
|
293
|
+
{ items: [], truncated: true, total: value.length, returned: 0 },
|
|
294
|
+
null,
|
|
295
|
+
2
|
|
296
|
+
);
|
|
297
|
+
while (low <= high) {
|
|
298
|
+
const mid = Math.floor((low + high) / 2);
|
|
299
|
+
const candidate = JSON.stringify(
|
|
300
|
+
{
|
|
301
|
+
items: value.slice(0, mid),
|
|
302
|
+
truncated: true,
|
|
303
|
+
total: value.length,
|
|
304
|
+
returned: mid
|
|
305
|
+
},
|
|
306
|
+
null,
|
|
307
|
+
2
|
|
308
|
+
);
|
|
309
|
+
if (candidate.length <= limit) {
|
|
310
|
+
best = candidate;
|
|
311
|
+
low = mid + 1;
|
|
312
|
+
} else {
|
|
313
|
+
high = mid - 1;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return best;
|
|
317
|
+
}
|
|
318
|
+
return full.slice(0, limit) + `
|
|
319
|
+
... [truncated, ${full.length} chars total]`;
|
|
320
|
+
}
|
|
321
|
+
function jsonContent(value) {
|
|
322
|
+
return textContent(serializeJson(value));
|
|
323
|
+
}
|
|
17
324
|
async function readBodyTruncated(response, limit = MAX_BODY_SIZE) {
|
|
18
325
|
const text = await response.text();
|
|
19
326
|
if (text.length <= limit) return text;
|
|
20
327
|
return text.slice(0, limit) + `
|
|
21
328
|
... [truncated, ${text.length} chars total]`;
|
|
22
329
|
}
|
|
330
|
+
function sleep(ms) {
|
|
331
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
332
|
+
}
|
|
333
|
+
function splitHint(message) {
|
|
334
|
+
const separatorIndex = message.indexOf(TIME_SEPARATOR);
|
|
335
|
+
if (separatorIndex === -1) {
|
|
336
|
+
return { message, hint: null };
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
message: message.slice(0, separatorIndex),
|
|
340
|
+
hint: message.slice(separatorIndex + TIME_SEPARATOR.length) || null
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function serializeError(error) {
|
|
344
|
+
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
345
|
+
const { message, hint } = splitHint(rawMessage);
|
|
346
|
+
const payload = {
|
|
347
|
+
error: true,
|
|
348
|
+
code: "validation_error",
|
|
349
|
+
message,
|
|
350
|
+
hint,
|
|
351
|
+
retryAfter: null
|
|
352
|
+
};
|
|
353
|
+
if (error instanceof import_sdk.UnauthorizedError) {
|
|
354
|
+
payload.code = "unauthorized";
|
|
355
|
+
} else if (error instanceof import_sdk.NotFoundError) {
|
|
356
|
+
payload.code = "not_found";
|
|
357
|
+
} else if (error instanceof import_sdk.RateLimitError) {
|
|
358
|
+
payload.code = "rate_limited";
|
|
359
|
+
payload.retryAfter = error.retryAfter ?? null;
|
|
360
|
+
} else if (error instanceof import_sdk.TimeoutError) {
|
|
361
|
+
payload.code = "timeout";
|
|
362
|
+
} else if (error instanceof import_sdk.WebhooksCCError) {
|
|
363
|
+
payload.code = error.statusCode >= 500 ? "server_error" : "validation_error";
|
|
364
|
+
}
|
|
365
|
+
return JSON.stringify(payload, null, 2);
|
|
366
|
+
}
|
|
23
367
|
function withErrorHandling(handler) {
|
|
24
368
|
return async (args2) => {
|
|
25
369
|
try {
|
|
26
370
|
return await handler(args2);
|
|
27
371
|
} catch (error) {
|
|
28
|
-
|
|
29
|
-
return { ...textContent(`Error: ${message}`), isError: true };
|
|
372
|
+
return { ...textContent(serializeError(error)), isError: true };
|
|
30
373
|
}
|
|
31
374
|
};
|
|
32
375
|
}
|
|
376
|
+
function filterRequestsByMethod(requests, method) {
|
|
377
|
+
if (!method) {
|
|
378
|
+
return requests;
|
|
379
|
+
}
|
|
380
|
+
const target = method.toUpperCase();
|
|
381
|
+
return requests.filter((request) => request.method.toUpperCase() === target);
|
|
382
|
+
}
|
|
383
|
+
async function waitForMultipleRequests(client, endpointSlug, options) {
|
|
384
|
+
const timeoutMs = typeof options.timeout === "number" ? options.timeout : options.timeout ? Number.isNaN(Number(options.timeout)) ? parseDurationLike(options.timeout) : Number(options.timeout) : 3e4;
|
|
385
|
+
const pollIntervalMs = typeof options.pollInterval === "number" ? options.pollInterval : options.pollInterval ? Number.isNaN(Number(options.pollInterval)) ? parseDurationLike(options.pollInterval) : Number(options.pollInterval) : 500;
|
|
386
|
+
const startedAt = Date.now();
|
|
387
|
+
let since = startedAt;
|
|
388
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
389
|
+
const requests = [];
|
|
390
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
391
|
+
const checkTime = Date.now();
|
|
392
|
+
const page = await client.requests.list(endpointSlug, {
|
|
393
|
+
since,
|
|
394
|
+
limit: Math.max(100, options.count * 5)
|
|
395
|
+
});
|
|
396
|
+
since = checkTime;
|
|
397
|
+
const filtered = filterRequestsByMethod(page, options.method).slice().sort((left, right) => left.receivedAt - right.receivedAt);
|
|
398
|
+
for (const request of filtered) {
|
|
399
|
+
if (seenIds.has(request.id)) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
seenIds.add(request.id);
|
|
403
|
+
requests.push(request);
|
|
404
|
+
if (requests.length >= options.count) {
|
|
405
|
+
return {
|
|
406
|
+
requests,
|
|
407
|
+
complete: true,
|
|
408
|
+
timedOut: false,
|
|
409
|
+
expectedCount: options.count
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
await sleep(Math.max(10, pollIntervalMs));
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
requests,
|
|
417
|
+
complete: requests.length >= options.count,
|
|
418
|
+
timedOut: true,
|
|
419
|
+
expectedCount: options.count
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function parseDurationLike(value) {
|
|
423
|
+
const trimmed = value.trim();
|
|
424
|
+
if (trimmed.length === 0) {
|
|
425
|
+
throw new Error("Duration value cannot be empty");
|
|
426
|
+
}
|
|
427
|
+
const numeric = Number(trimmed);
|
|
428
|
+
if (!Number.isNaN(numeric)) {
|
|
429
|
+
return numeric;
|
|
430
|
+
}
|
|
431
|
+
const match = trimmed.match(/^(\d+)\s*(ms|s|m|h|d)$/i);
|
|
432
|
+
if (!match) {
|
|
433
|
+
throw new Error(`Invalid duration: "${value}"`);
|
|
434
|
+
}
|
|
435
|
+
const amount = Number(match[1]);
|
|
436
|
+
const unit = match[2].toLowerCase();
|
|
437
|
+
const multiplier = unit === "ms" ? 1 : unit === "s" ? 1e3 : unit === "m" ? 6e4 : unit === "h" ? 36e5 : 864e5;
|
|
438
|
+
return amount * multiplier;
|
|
439
|
+
}
|
|
440
|
+
function ensureVerifyArgs(args2) {
|
|
441
|
+
if (args2.provider === "discord") {
|
|
442
|
+
const publicKey = args2.publicKey?.trim();
|
|
443
|
+
if (!publicKey) {
|
|
444
|
+
throw new Error('verify_signature for provider "discord" requires publicKey');
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
provider: "discord",
|
|
448
|
+
publicKey
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
const secret = args2.secret?.trim();
|
|
452
|
+
if (!secret) {
|
|
453
|
+
throw new Error(`verify_signature for provider "${args2.provider}" requires secret`);
|
|
454
|
+
}
|
|
455
|
+
return {
|
|
456
|
+
provider: args2.provider,
|
|
457
|
+
secret,
|
|
458
|
+
...args2.url ? { url: args2.url } : {}
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
async function summarizeResponse(response) {
|
|
462
|
+
return {
|
|
463
|
+
status: response.status,
|
|
464
|
+
statusText: response.statusText,
|
|
465
|
+
body: await readBodyTruncated(response)
|
|
466
|
+
};
|
|
467
|
+
}
|
|
33
468
|
function registerTools(server, client) {
|
|
34
469
|
server.tool(
|
|
35
470
|
"create_endpoint",
|
|
36
|
-
"Create a
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
471
|
+
"Create a webhook endpoint. Returns the endpoint slug, URL, and metadata.",
|
|
472
|
+
{
|
|
473
|
+
name: import_zod2.z.string().optional().describe("Display name for the endpoint"),
|
|
474
|
+
ephemeral: import_zod2.z.boolean().optional().describe("Create a temporary endpoint that auto-expires"),
|
|
475
|
+
expiresIn: durationOrTimestampSchema.optional().describe('Auto-expire after this duration, for example "12h"'),
|
|
476
|
+
mockResponse: mockResponseSchema.optional().describe("Optional mock response to return when the endpoint receives a request")
|
|
477
|
+
},
|
|
478
|
+
withErrorHandling(async ({ name, ephemeral, expiresIn, mockResponse }) => {
|
|
479
|
+
const endpoint = await client.endpoints.create({ name, ephemeral, expiresIn, mockResponse });
|
|
480
|
+
return jsonContent(endpoint);
|
|
41
481
|
})
|
|
42
482
|
);
|
|
43
483
|
server.tool(
|
|
44
484
|
"list_endpoints",
|
|
45
|
-
"List all webhook endpoints for the authenticated user.
|
|
485
|
+
"List all webhook endpoints for the authenticated user.",
|
|
46
486
|
{},
|
|
47
487
|
withErrorHandling(async () => {
|
|
48
488
|
const endpoints = await client.endpoints.list();
|
|
49
|
-
return
|
|
489
|
+
return jsonContent(endpoints);
|
|
50
490
|
})
|
|
51
491
|
);
|
|
52
492
|
server.tool(
|
|
53
493
|
"get_endpoint",
|
|
54
|
-
"Get details for a specific webhook endpoint by
|
|
55
|
-
{ slug:
|
|
494
|
+
"Get details for a specific webhook endpoint by slug.",
|
|
495
|
+
{ slug: import_zod2.z.string().describe("The endpoint slug") },
|
|
56
496
|
withErrorHandling(async ({ slug }) => {
|
|
57
497
|
const endpoint = await client.endpoints.get(slug);
|
|
58
|
-
return
|
|
498
|
+
return jsonContent(endpoint);
|
|
59
499
|
})
|
|
60
500
|
);
|
|
61
501
|
server.tool(
|
|
62
502
|
"update_endpoint",
|
|
63
|
-
"Update an endpoint
|
|
503
|
+
"Update an endpoint name or mock response configuration.",
|
|
64
504
|
{
|
|
65
|
-
slug:
|
|
66
|
-
name:
|
|
67
|
-
mockResponse:
|
|
68
|
-
status: import_zod.z.number().min(100).max(599).describe("HTTP status code (100-599)"),
|
|
69
|
-
body: import_zod.z.string().default("").describe("Response body string (default: empty)"),
|
|
70
|
-
headers: import_zod.z.record(import_zod.z.string()).default({}).describe("Response headers (default: none)")
|
|
71
|
-
}).nullable().optional().describe("Mock response config, or null to clear it")
|
|
505
|
+
slug: import_zod2.z.string().describe("The endpoint slug to update"),
|
|
506
|
+
name: import_zod2.z.string().optional().describe("New display name"),
|
|
507
|
+
mockResponse: mockResponseSchema.nullable().optional().describe("Mock response config, or null to clear it")
|
|
72
508
|
},
|
|
73
509
|
withErrorHandling(async ({ slug, name, mockResponse }) => {
|
|
74
510
|
const endpoint = await client.endpoints.update(slug, { name, mockResponse });
|
|
75
|
-
return
|
|
511
|
+
return jsonContent(endpoint);
|
|
76
512
|
})
|
|
77
513
|
);
|
|
78
514
|
server.tool(
|
|
79
515
|
"delete_endpoint",
|
|
80
516
|
"Delete a webhook endpoint and all its captured requests.",
|
|
81
|
-
{ slug:
|
|
517
|
+
{ slug: import_zod2.z.string().describe("The endpoint slug to delete") },
|
|
82
518
|
withErrorHandling(async ({ slug }) => {
|
|
83
519
|
await client.endpoints.delete(slug);
|
|
84
520
|
return textContent(`Endpoint "${slug}" deleted.`);
|
|
85
521
|
})
|
|
86
522
|
);
|
|
523
|
+
server.tool(
|
|
524
|
+
"create_endpoints",
|
|
525
|
+
"Create multiple webhook endpoints in one call.",
|
|
526
|
+
{
|
|
527
|
+
count: import_zod2.z.number().int().min(1).max(20).describe("Number of endpoints to create"),
|
|
528
|
+
namePrefix: import_zod2.z.string().optional().describe("Optional prefix for endpoint names"),
|
|
529
|
+
ephemeral: import_zod2.z.boolean().optional().describe("Create temporary endpoints that auto-expire"),
|
|
530
|
+
expiresIn: durationOrTimestampSchema.optional().describe('Auto-expire after this duration, for example "12h"')
|
|
531
|
+
},
|
|
532
|
+
withErrorHandling(async ({ count, namePrefix, ephemeral, expiresIn }) => {
|
|
533
|
+
const endpoints = await Promise.all(
|
|
534
|
+
Array.from(
|
|
535
|
+
{ length: count },
|
|
536
|
+
(_, index) => client.endpoints.create({
|
|
537
|
+
name: namePrefix ? `${namePrefix}-${index + 1}` : void 0,
|
|
538
|
+
ephemeral,
|
|
539
|
+
expiresIn
|
|
540
|
+
})
|
|
541
|
+
)
|
|
542
|
+
);
|
|
543
|
+
return jsonContent({ endpoints });
|
|
544
|
+
})
|
|
545
|
+
);
|
|
546
|
+
server.tool(
|
|
547
|
+
"delete_endpoints",
|
|
548
|
+
"Delete multiple webhook endpoints in one call.",
|
|
549
|
+
{
|
|
550
|
+
slugs: import_zod2.z.array(import_zod2.z.string()).min(1).max(100).describe("Endpoint slugs to delete")
|
|
551
|
+
},
|
|
552
|
+
withErrorHandling(async ({ slugs }) => {
|
|
553
|
+
const settled = await Promise.allSettled(
|
|
554
|
+
slugs.map(async (slug) => {
|
|
555
|
+
await client.endpoints.delete(slug);
|
|
556
|
+
return slug;
|
|
557
|
+
})
|
|
558
|
+
);
|
|
559
|
+
return jsonContent({
|
|
560
|
+
deleted: settled.filter(
|
|
561
|
+
(result) => result.status === "fulfilled"
|
|
562
|
+
).map((result) => result.value),
|
|
563
|
+
failed: settled.flatMap(
|
|
564
|
+
(result, index) => result.status === "rejected" ? [
|
|
565
|
+
{
|
|
566
|
+
slug: slugs[index],
|
|
567
|
+
message: result.reason instanceof Error ? result.reason.message : String(result.reason)
|
|
568
|
+
}
|
|
569
|
+
] : []
|
|
570
|
+
)
|
|
571
|
+
});
|
|
572
|
+
})
|
|
573
|
+
);
|
|
87
574
|
server.tool(
|
|
88
575
|
"send_webhook",
|
|
89
|
-
"Send a test webhook to
|
|
576
|
+
"Send a test webhook to a hosted endpoint. Supports provider templates and signing.",
|
|
90
577
|
{
|
|
91
|
-
slug:
|
|
92
|
-
method:
|
|
93
|
-
headers:
|
|
94
|
-
body:
|
|
95
|
-
provider:
|
|
96
|
-
template:
|
|
97
|
-
event:
|
|
98
|
-
secret:
|
|
99
|
-
"Shared secret for provider signature generation (required when provider is set)"
|
|
100
|
-
)
|
|
578
|
+
slug: import_zod2.z.string().describe("The endpoint slug to send to"),
|
|
579
|
+
method: methodSchema,
|
|
580
|
+
headers: import_zod2.z.record(import_zod2.z.string()).optional().describe("HTTP headers to include"),
|
|
581
|
+
body: import_zod2.z.unknown().optional().describe("Request body"),
|
|
582
|
+
provider: import_zod2.z.enum(TEMPLATE_PROVIDER_VALUES).optional().describe("Optional provider template to send with signed headers"),
|
|
583
|
+
template: import_zod2.z.string().optional().describe("Provider-specific template preset"),
|
|
584
|
+
event: import_zod2.z.string().optional().describe("Provider event or topic name"),
|
|
585
|
+
secret: import_zod2.z.string().optional().describe("Signing secret. Required when provider is set.")
|
|
101
586
|
},
|
|
102
587
|
withErrorHandling(
|
|
103
588
|
async ({ slug, method, headers, body, provider, template, event, secret }) => {
|
|
@@ -120,104 +605,204 @@ function registerTools(server, client) {
|
|
|
120
605
|
response = await client.endpoints.send(slug, { method, headers, body });
|
|
121
606
|
}
|
|
122
607
|
const responseBody = await readBodyTruncated(response);
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
)
|
|
129
|
-
);
|
|
608
|
+
return jsonContent({
|
|
609
|
+
status: response.status,
|
|
610
|
+
statusText: response.statusText,
|
|
611
|
+
body: responseBody
|
|
612
|
+
});
|
|
130
613
|
}
|
|
131
614
|
)
|
|
132
615
|
);
|
|
133
616
|
server.tool(
|
|
134
617
|
"list_requests",
|
|
135
|
-
"List captured
|
|
618
|
+
"List recent captured requests for an endpoint.",
|
|
136
619
|
{
|
|
137
|
-
endpointSlug:
|
|
138
|
-
limit:
|
|
139
|
-
since:
|
|
620
|
+
endpointSlug: import_zod2.z.string().describe("The endpoint slug"),
|
|
621
|
+
limit: import_zod2.z.number().int().min(1).max(100).default(25).describe("Max requests to return"),
|
|
622
|
+
since: import_zod2.z.number().optional().describe("Only return requests after this timestamp in ms")
|
|
140
623
|
},
|
|
141
624
|
withErrorHandling(async ({ endpointSlug, limit, since }) => {
|
|
142
625
|
const requests = await client.requests.list(endpointSlug, { limit, since });
|
|
143
|
-
return
|
|
626
|
+
return jsonContent(requests);
|
|
627
|
+
})
|
|
628
|
+
);
|
|
629
|
+
server.tool(
|
|
630
|
+
"search_requests",
|
|
631
|
+
"Search captured webhook requests across endpoints using retained full-text search.",
|
|
632
|
+
{
|
|
633
|
+
slug: import_zod2.z.string().optional().describe("Filter to a specific endpoint slug"),
|
|
634
|
+
method: import_zod2.z.string().optional().describe("Filter by HTTP method"),
|
|
635
|
+
q: import_zod2.z.string().optional().describe("Free-text search across path, body, and headers"),
|
|
636
|
+
from: durationOrTimestampSchema.optional().describe('Start time as a timestamp or duration like "1h" or "7d"'),
|
|
637
|
+
to: durationOrTimestampSchema.optional().describe('End time as a timestamp or duration like "1h" or "7d"'),
|
|
638
|
+
limit: import_zod2.z.number().int().min(1).max(200).default(50).describe("Max results to return"),
|
|
639
|
+
offset: import_zod2.z.number().int().min(0).max(1e4).default(0).describe("Result offset"),
|
|
640
|
+
order: import_zod2.z.enum(["asc", "desc"]).default("desc").describe("Sort order by received time")
|
|
641
|
+
},
|
|
642
|
+
withErrorHandling(async ({ slug, method, q, from, to, limit, offset, order }) => {
|
|
643
|
+
const results = await client.requests.search({
|
|
644
|
+
slug,
|
|
645
|
+
method,
|
|
646
|
+
q,
|
|
647
|
+
from,
|
|
648
|
+
to,
|
|
649
|
+
limit,
|
|
650
|
+
offset,
|
|
651
|
+
order
|
|
652
|
+
});
|
|
653
|
+
return jsonContent(results);
|
|
654
|
+
})
|
|
655
|
+
);
|
|
656
|
+
server.tool(
|
|
657
|
+
"count_requests",
|
|
658
|
+
"Count captured webhook requests that match the given filters.",
|
|
659
|
+
{
|
|
660
|
+
slug: import_zod2.z.string().optional().describe("Filter to a specific endpoint slug"),
|
|
661
|
+
method: import_zod2.z.string().optional().describe("Filter by HTTP method"),
|
|
662
|
+
q: import_zod2.z.string().optional().describe("Free-text search across path, body, and headers"),
|
|
663
|
+
from: durationOrTimestampSchema.optional().describe('Start time as a timestamp or duration like "1h" or "7d"'),
|
|
664
|
+
to: durationOrTimestampSchema.optional().describe('End time as a timestamp or duration like "1h" or "7d"')
|
|
665
|
+
},
|
|
666
|
+
withErrorHandling(async ({ slug, method, q, from, to }) => {
|
|
667
|
+
const count = await client.requests.count({ slug, method, q, from, to });
|
|
668
|
+
return jsonContent({ count });
|
|
144
669
|
})
|
|
145
670
|
);
|
|
146
671
|
server.tool(
|
|
147
672
|
"get_request",
|
|
148
|
-
"Get full details
|
|
149
|
-
{ requestId:
|
|
673
|
+
"Get full details for a specific captured request by ID.",
|
|
674
|
+
{ requestId: import_zod2.z.string().describe("The request ID") },
|
|
150
675
|
withErrorHandling(async ({ requestId }) => {
|
|
151
676
|
const request = await client.requests.get(requestId);
|
|
152
|
-
return
|
|
677
|
+
return jsonContent(request);
|
|
153
678
|
})
|
|
154
679
|
);
|
|
155
680
|
server.tool(
|
|
156
681
|
"wait_for_request",
|
|
157
|
-
"Wait for a
|
|
682
|
+
"Wait for a request to arrive at an endpoint.",
|
|
158
683
|
{
|
|
159
|
-
endpointSlug:
|
|
160
|
-
timeout:
|
|
161
|
-
pollInterval:
|
|
684
|
+
endpointSlug: import_zod2.z.string().describe("The endpoint slug to monitor"),
|
|
685
|
+
timeout: durationOrTimestampSchema.default("30s").describe('How long to wait, for example "30s"'),
|
|
686
|
+
pollInterval: durationOrTimestampSchema.optional().describe('Interval between polls, for example "500ms" or "1s"')
|
|
162
687
|
},
|
|
163
688
|
withErrorHandling(async ({ endpointSlug, timeout, pollInterval }) => {
|
|
164
689
|
const request = await client.requests.waitFor(endpointSlug, { timeout, pollInterval });
|
|
165
|
-
return
|
|
690
|
+
return jsonContent(request);
|
|
691
|
+
})
|
|
692
|
+
);
|
|
693
|
+
server.tool(
|
|
694
|
+
"wait_for_requests",
|
|
695
|
+
"Wait for multiple requests to arrive at an endpoint.",
|
|
696
|
+
{
|
|
697
|
+
endpointSlug: import_zod2.z.string().describe("The endpoint slug to monitor"),
|
|
698
|
+
count: import_zod2.z.number().int().min(1).max(20).describe("Number of requests to collect"),
|
|
699
|
+
timeout: durationOrTimestampSchema.default("30s").describe('How long to wait, for example "30s"'),
|
|
700
|
+
pollInterval: durationOrTimestampSchema.optional().describe('Interval between polls, for example "500ms" or "1s"'),
|
|
701
|
+
method: import_zod2.z.string().optional().describe("Only collect requests with this HTTP method")
|
|
702
|
+
},
|
|
703
|
+
withErrorHandling(async ({ endpointSlug, count, timeout, pollInterval, method }) => {
|
|
704
|
+
const result = await waitForMultipleRequests(client, endpointSlug, {
|
|
705
|
+
count,
|
|
706
|
+
timeout,
|
|
707
|
+
pollInterval,
|
|
708
|
+
method
|
|
709
|
+
});
|
|
710
|
+
return jsonContent(result);
|
|
166
711
|
})
|
|
167
712
|
);
|
|
168
713
|
server.tool(
|
|
169
714
|
"replay_request",
|
|
170
|
-
"Replay a previously captured
|
|
715
|
+
"Replay a previously captured request to a target URL.",
|
|
171
716
|
{
|
|
172
|
-
requestId:
|
|
173
|
-
targetUrl:
|
|
174
|
-
(u) => {
|
|
175
|
-
try {
|
|
176
|
-
const p = new URL(u).protocol;
|
|
177
|
-
return p === "http:" || p === "https:";
|
|
178
|
-
} catch {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
{ message: "Only http and https URLs are supported" }
|
|
183
|
-
).describe("The URL to send the replayed request to (http or https only)")
|
|
717
|
+
requestId: import_zod2.z.string().describe("The captured request ID"),
|
|
718
|
+
targetUrl: httpUrlSchema.describe("The URL to replay the request to")
|
|
184
719
|
},
|
|
185
720
|
withErrorHandling(async ({ requestId, targetUrl }) => {
|
|
186
721
|
const response = await client.requests.replay(requestId, targetUrl);
|
|
187
722
|
const responseBody = await readBodyTruncated(response);
|
|
188
|
-
return
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
723
|
+
return jsonContent({
|
|
724
|
+
status: response.status,
|
|
725
|
+
statusText: response.statusText,
|
|
726
|
+
body: responseBody
|
|
727
|
+
});
|
|
728
|
+
})
|
|
729
|
+
);
|
|
730
|
+
server.tool(
|
|
731
|
+
"compare_requests",
|
|
732
|
+
"Compare two captured requests and show the structured differences.",
|
|
733
|
+
{
|
|
734
|
+
leftRequestId: import_zod2.z.string().describe("The first request ID"),
|
|
735
|
+
rightRequestId: import_zod2.z.string().describe("The second request ID"),
|
|
736
|
+
ignoreHeaders: import_zod2.z.array(import_zod2.z.string()).optional().describe("Headers to ignore during comparison")
|
|
737
|
+
},
|
|
738
|
+
withErrorHandling(async ({ leftRequestId, rightRequestId, ignoreHeaders }) => {
|
|
739
|
+
const [leftRequest, rightRequest] = await Promise.all([
|
|
740
|
+
client.requests.get(leftRequestId),
|
|
741
|
+
client.requests.get(rightRequestId)
|
|
742
|
+
]);
|
|
743
|
+
const diff = (0, import_sdk.diffRequests)(leftRequest, rightRequest, { ignoreHeaders });
|
|
744
|
+
return jsonContent(diff);
|
|
745
|
+
})
|
|
746
|
+
);
|
|
747
|
+
server.tool(
|
|
748
|
+
"extract_from_request",
|
|
749
|
+
"Extract specific JSON fields from a captured request body.",
|
|
750
|
+
{
|
|
751
|
+
requestId: import_zod2.z.string().describe("The request ID"),
|
|
752
|
+
jsonPaths: import_zod2.z.array(import_zod2.z.string()).min(1).max(50).describe("Dot-notation JSON paths to extract")
|
|
753
|
+
},
|
|
754
|
+
withErrorHandling(async ({ requestId, jsonPaths }) => {
|
|
755
|
+
const request = await client.requests.get(requestId);
|
|
756
|
+
const extracted = Object.fromEntries(
|
|
757
|
+
jsonPaths.map((path) => [path, (0, import_sdk.extractJsonField)(request, path) ?? null])
|
|
194
758
|
);
|
|
759
|
+
return jsonContent(extracted);
|
|
760
|
+
})
|
|
761
|
+
);
|
|
762
|
+
server.tool(
|
|
763
|
+
"verify_signature",
|
|
764
|
+
"Verify the webhook signature on a captured request.",
|
|
765
|
+
{
|
|
766
|
+
requestId: import_zod2.z.string().describe("The captured request ID"),
|
|
767
|
+
provider: import_zod2.z.enum(VERIFY_PROVIDER_VALUES).describe("Provider whose signature scheme should be verified"),
|
|
768
|
+
secret: import_zod2.z.string().optional().describe("Shared signing secret. Required for non-Discord providers."),
|
|
769
|
+
publicKey: import_zod2.z.string().optional().describe("Discord application public key. Required for provider=discord."),
|
|
770
|
+
url: httpUrlSchema.optional().describe("Original signed URL. Required for Twilio verification.")
|
|
771
|
+
},
|
|
772
|
+
withErrorHandling(async ({ requestId, provider, secret, publicKey, url }) => {
|
|
773
|
+
const request = await client.requests.get(requestId);
|
|
774
|
+
const verificationOptions = ensureVerifyArgs({ provider, secret, publicKey, url });
|
|
775
|
+
const result = await (0, import_sdk.verifySignature)(request, verificationOptions);
|
|
776
|
+
return jsonContent({
|
|
777
|
+
valid: result.valid,
|
|
778
|
+
details: result.valid ? "Signature is valid." : "Signature did not match."
|
|
779
|
+
});
|
|
780
|
+
})
|
|
781
|
+
);
|
|
782
|
+
server.tool(
|
|
783
|
+
"clear_requests",
|
|
784
|
+
"Delete captured requests for an endpoint without deleting the endpoint itself.",
|
|
785
|
+
{
|
|
786
|
+
slug: import_zod2.z.string().describe("The endpoint slug to clear"),
|
|
787
|
+
before: durationOrTimestampSchema.optional().describe('Only clear requests older than this timestamp or duration like "1h"')
|
|
788
|
+
},
|
|
789
|
+
withErrorHandling(async ({ slug, before }) => {
|
|
790
|
+
await client.requests.clear(slug, { before });
|
|
791
|
+
return jsonContent({ slug, cleared: true, before: before ?? null });
|
|
195
792
|
})
|
|
196
793
|
);
|
|
197
794
|
server.tool(
|
|
198
795
|
"send_to",
|
|
199
|
-
"Send a webhook directly to any URL with optional provider signing.
|
|
796
|
+
"Send a webhook directly to any URL with optional provider signing.",
|
|
200
797
|
{
|
|
201
|
-
url:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
},
|
|
210
|
-
{ message: "Only http and https URLs are supported" }
|
|
211
|
-
).describe("Target URL to send the webhook to"),
|
|
212
|
-
method: import_zod.z.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]).default("POST").describe("HTTP method (default: POST)"),
|
|
213
|
-
headers: import_zod.z.record(import_zod.z.string()).optional().describe("HTTP headers to include"),
|
|
214
|
-
body: import_zod.z.unknown().optional().describe("Request body (will be JSON-serialized)"),
|
|
215
|
-
provider: import_zod.z.enum(["stripe", "github", "shopify", "twilio", "standard-webhooks"]).optional().describe("Optional provider template for signing"),
|
|
216
|
-
template: import_zod.z.string().optional().describe("Provider-specific template preset (not used for standard-webhooks)"),
|
|
217
|
-
event: import_zod.z.string().optional().describe("Provider event/topic name"),
|
|
218
|
-
secret: import_zod.z.string().optional().describe(
|
|
219
|
-
"Shared secret for provider signature generation (required when provider is set)"
|
|
220
|
-
)
|
|
798
|
+
url: httpUrlSchema.describe("Target URL"),
|
|
799
|
+
method: methodSchema,
|
|
800
|
+
headers: import_zod2.z.record(import_zod2.z.string()).optional().describe("HTTP headers to include"),
|
|
801
|
+
body: import_zod2.z.unknown().optional().describe("Request body"),
|
|
802
|
+
provider: import_zod2.z.enum(TEMPLATE_PROVIDER_VALUES).optional().describe("Optional provider template for signing"),
|
|
803
|
+
template: import_zod2.z.string().optional().describe("Provider-specific template preset"),
|
|
804
|
+
event: import_zod2.z.string().optional().describe("Provider event or topic name"),
|
|
805
|
+
secret: import_zod2.z.string().optional().describe("Signing secret. Required when provider is set.")
|
|
221
806
|
},
|
|
222
807
|
withErrorHandling(async ({ url, method, headers, body, provider, template, event, secret }) => {
|
|
223
808
|
const response = await client.sendTo(url, {
|
|
@@ -230,43 +815,169 @@ function registerTools(server, client) {
|
|
|
230
815
|
secret
|
|
231
816
|
});
|
|
232
817
|
const responseBody = await readBodyTruncated(response);
|
|
233
|
-
return
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
818
|
+
return jsonContent({
|
|
819
|
+
status: response.status,
|
|
820
|
+
statusText: response.statusText,
|
|
821
|
+
body: responseBody
|
|
822
|
+
});
|
|
823
|
+
})
|
|
824
|
+
);
|
|
825
|
+
server.tool(
|
|
826
|
+
"preview_webhook",
|
|
827
|
+
"Preview a webhook request without sending it. Returns the exact URL, method, headers, and body.",
|
|
828
|
+
{
|
|
829
|
+
url: httpUrlSchema.describe("Target URL"),
|
|
830
|
+
method: methodSchema,
|
|
831
|
+
headers: import_zod2.z.record(import_zod2.z.string()).optional().describe("HTTP headers to include"),
|
|
832
|
+
body: import_zod2.z.unknown().optional().describe("Request body"),
|
|
833
|
+
provider: import_zod2.z.enum(TEMPLATE_PROVIDER_VALUES).optional().describe("Optional provider template for signing"),
|
|
834
|
+
template: import_zod2.z.string().optional().describe("Provider-specific template preset"),
|
|
835
|
+
event: import_zod2.z.string().optional().describe("Provider event or topic name"),
|
|
836
|
+
secret: import_zod2.z.string().optional().describe("Signing secret. Required when provider is set.")
|
|
837
|
+
},
|
|
838
|
+
withErrorHandling(async ({ url, method, headers, body, provider, template, event, secret }) => {
|
|
839
|
+
const preview = await client.buildRequest(url, {
|
|
840
|
+
method,
|
|
841
|
+
headers,
|
|
842
|
+
body,
|
|
843
|
+
provider,
|
|
844
|
+
template,
|
|
845
|
+
event,
|
|
846
|
+
secret
|
|
847
|
+
});
|
|
848
|
+
return jsonContent(preview);
|
|
849
|
+
})
|
|
850
|
+
);
|
|
851
|
+
server.tool(
|
|
852
|
+
"list_provider_templates",
|
|
853
|
+
"List supported webhook providers, templates, and signing metadata.",
|
|
854
|
+
{
|
|
855
|
+
provider: import_zod2.z.enum(TEMPLATE_PROVIDER_VALUES).optional().describe("Filter to a single provider")
|
|
856
|
+
},
|
|
857
|
+
withErrorHandling(async ({ provider }) => {
|
|
858
|
+
if (provider) {
|
|
859
|
+
return jsonContent([client.templates.get(provider)]);
|
|
860
|
+
}
|
|
861
|
+
return jsonContent(
|
|
862
|
+
client.templates.listProviders().map((name) => client.templates.get(name))
|
|
239
863
|
);
|
|
240
864
|
})
|
|
241
865
|
);
|
|
866
|
+
server.tool(
|
|
867
|
+
"get_usage",
|
|
868
|
+
"Check current request usage, remaining quota, plan, and period end.",
|
|
869
|
+
{},
|
|
870
|
+
withErrorHandling(async () => {
|
|
871
|
+
const usage = await client.usage();
|
|
872
|
+
return jsonContent({
|
|
873
|
+
...usage,
|
|
874
|
+
periodEnd: usage.periodEnd ? new Date(usage.periodEnd).toISOString() : null
|
|
875
|
+
});
|
|
876
|
+
})
|
|
877
|
+
);
|
|
878
|
+
server.tool(
|
|
879
|
+
"test_webhook_flow",
|
|
880
|
+
"Run a full webhook test flow: create endpoint, optionally mock, send, wait, verify, replay, and clean up.",
|
|
881
|
+
{
|
|
882
|
+
provider: import_zod2.z.enum(TEMPLATE_PROVIDER_VALUES).optional().describe("Optional provider template to use when sending the webhook"),
|
|
883
|
+
event: import_zod2.z.string().optional().describe("Optional provider event or topic name"),
|
|
884
|
+
secret: import_zod2.z.string().optional().describe(
|
|
885
|
+
"Signing secret. Required when provider is set or signature verification is enabled."
|
|
886
|
+
),
|
|
887
|
+
mockStatus: import_zod2.z.number().int().min(100).max(599).optional().describe("Optional mock response status to configure before sending"),
|
|
888
|
+
targetUrl: httpUrlSchema.optional().describe("Optional URL to replay the captured request to after capture"),
|
|
889
|
+
verifySignature: import_zod2.z.boolean().default(false).describe("Verify the captured request signature after capture"),
|
|
890
|
+
cleanup: import_zod2.z.boolean().default(true).describe("Delete the created endpoint after the flow completes")
|
|
891
|
+
},
|
|
892
|
+
withErrorHandling(
|
|
893
|
+
async ({
|
|
894
|
+
provider,
|
|
895
|
+
event,
|
|
896
|
+
secret,
|
|
897
|
+
mockStatus,
|
|
898
|
+
targetUrl,
|
|
899
|
+
verifySignature: shouldVerify,
|
|
900
|
+
cleanup
|
|
901
|
+
}) => {
|
|
902
|
+
const flow = client.flow().createEndpoint({ expiresIn: "1h" }).waitForCapture({ timeout: "30s" });
|
|
903
|
+
if (mockStatus !== void 0) {
|
|
904
|
+
flow.setMock({
|
|
905
|
+
status: mockStatus,
|
|
906
|
+
body: "",
|
|
907
|
+
headers: {}
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
if (provider) {
|
|
911
|
+
const templateSecret = secret?.trim();
|
|
912
|
+
if (!templateSecret) {
|
|
913
|
+
throw new Error(
|
|
914
|
+
"test_webhook_flow with provider templates requires a non-empty secret"
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
flow.sendTemplate({
|
|
918
|
+
provider,
|
|
919
|
+
event,
|
|
920
|
+
secret: templateSecret
|
|
921
|
+
});
|
|
922
|
+
if (shouldVerify) {
|
|
923
|
+
flow.verifySignature({
|
|
924
|
+
provider,
|
|
925
|
+
secret: templateSecret
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
} else {
|
|
929
|
+
if (shouldVerify) {
|
|
930
|
+
throw new Error("test_webhook_flow cannot verify signatures without a provider");
|
|
931
|
+
}
|
|
932
|
+
flow.send();
|
|
933
|
+
}
|
|
934
|
+
if (targetUrl) {
|
|
935
|
+
flow.replayTo(targetUrl);
|
|
936
|
+
}
|
|
937
|
+
if (cleanup) {
|
|
938
|
+
flow.cleanup();
|
|
939
|
+
}
|
|
940
|
+
const result = await flow.run();
|
|
941
|
+
return jsonContent({
|
|
942
|
+
endpoint: result.endpoint,
|
|
943
|
+
request: result.request ?? null,
|
|
944
|
+
verification: result.verification ?? null,
|
|
945
|
+
replayResponse: result.replayResponse ? await summarizeResponse(result.replayResponse) : null,
|
|
946
|
+
cleanedUp: result.cleanedUp
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
)
|
|
950
|
+
);
|
|
242
951
|
server.tool(
|
|
243
952
|
"describe",
|
|
244
|
-
"Describe all available SDK operations,
|
|
953
|
+
"Describe all available SDK operations, parameters, and types.",
|
|
245
954
|
{},
|
|
246
955
|
withErrorHandling(async () => {
|
|
247
956
|
const description = client.describe();
|
|
248
|
-
return
|
|
957
|
+
return jsonContent(description);
|
|
249
958
|
})
|
|
250
959
|
);
|
|
251
960
|
}
|
|
252
961
|
|
|
253
962
|
// src/index.ts
|
|
254
|
-
var VERSION = true ? "0.
|
|
963
|
+
var VERSION = true ? "1.0.0" : "0.0.0-dev";
|
|
255
964
|
function createServer(options = {}) {
|
|
256
965
|
const apiKey = options.apiKey ?? process.env.WHK_API_KEY;
|
|
257
966
|
if (!apiKey) {
|
|
258
967
|
throw new Error("Missing API key. Set WHK_API_KEY environment variable or pass apiKey option.");
|
|
259
968
|
}
|
|
260
|
-
const client = new
|
|
969
|
+
const client = new import_sdk2.WebhooksCC({
|
|
261
970
|
apiKey,
|
|
262
971
|
webhookUrl: options.webhookUrl ?? process.env.WHK_WEBHOOK_URL,
|
|
263
972
|
baseUrl: options.baseUrl ?? process.env.WHK_BASE_URL
|
|
264
973
|
});
|
|
265
|
-
const server = new
|
|
974
|
+
const server = new import_mcp2.McpServer({
|
|
266
975
|
name: "webhooks-cc",
|
|
267
976
|
version: VERSION
|
|
268
977
|
});
|
|
269
978
|
registerTools(server, client);
|
|
979
|
+
registerPrompts(server);
|
|
980
|
+
registerResources(server, client);
|
|
270
981
|
return server;
|
|
271
982
|
}
|
|
272
983
|
|