@usethrottle/mcp 0.1.1 → 0.2.1
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 +9 -2
- package/dist/contract-index.json +1 -1
- package/dist/docs-index.json +1 -1
- package/dist/lib.cjs +3328 -0
- package/dist/lib.cjs.map +1 -0
- package/dist/lib.d.cts +219 -0
- package/dist/lib.d.ts +219 -0
- package/dist/lib.js +3294 -0
- package/dist/lib.js.map +1 -0
- package/dist/mcp.js +2053 -142
- package/dist/mcp.js.map +1 -1
- package/package.json +11 -1
package/dist/lib.js
ADDED
|
@@ -0,0 +1,3294 @@
|
|
|
1
|
+
// src/server.ts
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
|
|
5
|
+
// ../core-scopes/src/scopes.ts
|
|
6
|
+
function hasScope(granted, required) {
|
|
7
|
+
if (granted.includes("*")) return true;
|
|
8
|
+
if (granted.includes(required)) return true;
|
|
9
|
+
const sep = required.lastIndexOf(":");
|
|
10
|
+
if (sep === -1) return false;
|
|
11
|
+
const resource = required.slice(0, sep);
|
|
12
|
+
const action = required.slice(sep + 1);
|
|
13
|
+
if (action === "read" && granted.includes(`${resource}:write`)) return true;
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
var REG = {};
|
|
17
|
+
function add(group, resource, actions, labels, opts = {}) {
|
|
18
|
+
const hasRead = actions.includes("read");
|
|
19
|
+
for (const action of actions) {
|
|
20
|
+
const id = `${resource}:${action}`;
|
|
21
|
+
const implies = action === "write" && hasRead ? [`${resource}:read`] : [];
|
|
22
|
+
REG[id] = {
|
|
23
|
+
id,
|
|
24
|
+
resource,
|
|
25
|
+
action,
|
|
26
|
+
group,
|
|
27
|
+
label: (action === "read" ? labels.read : labels.write) ?? `${action} ${resource}`,
|
|
28
|
+
sensitive: opts.sensitive ?? false,
|
|
29
|
+
staffOnly: opts.staffOnly ?? false,
|
|
30
|
+
// publishable defaults false; only the curated set below is true
|
|
31
|
+
publishableAllowed: opts.publishableAllowed ?? false,
|
|
32
|
+
// publishableOnly defaults false; only customer_accounts:write sets it
|
|
33
|
+
publishableOnly: opts.publishableOnly ?? false,
|
|
34
|
+
// extension default true for commerce scopes; Taxonomy B passes false
|
|
35
|
+
extensionAllowed: opts.extensionAllowed ?? true,
|
|
36
|
+
implies
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
add("Orders", "orders", ["read", "write"], { read: "View orders", write: "Manage orders" });
|
|
41
|
+
add("Quotes", "quotes", ["read", "write"], { read: "View quotes", write: "Manage quotes" });
|
|
42
|
+
add("Orders", "order_cancellations", ["write"], { write: "Cancel orders" });
|
|
43
|
+
add("Orders", "order_returns", ["read", "write"], { read: "View returns", write: "Process returns" });
|
|
44
|
+
add("Orders", "order_comps", ["write"], { write: "Comp orders (write off the balance)" }, { sensitive: true });
|
|
45
|
+
add("Orders", "order_holds", ["write"], { write: "Freeze and unfreeze orders" });
|
|
46
|
+
add(
|
|
47
|
+
"Imports",
|
|
48
|
+
"imports",
|
|
49
|
+
["read", "write"],
|
|
50
|
+
{ read: "View data imports", write: "Run and undo data imports" },
|
|
51
|
+
{ extensionAllowed: false }
|
|
52
|
+
);
|
|
53
|
+
add("Payments", "payments", ["read", "write"], { read: "View payments", write: "Create payments" });
|
|
54
|
+
add("Payments", "payment_authorizations", ["write"], { write: "Authorize payments" });
|
|
55
|
+
add("Payments", "payment_captures", ["write"], { write: "Capture payments" });
|
|
56
|
+
add("Payments", "payment_refunds", ["read", "write"], { read: "View refunds", write: "Refund payments" }, { sensitive: true });
|
|
57
|
+
add("Payments", "payment_voids", ["write"], { write: "Void payments" }, { sensitive: true });
|
|
58
|
+
add("Payments", "payment_records", ["write"], { write: "Record payments received outside Throttle" }, { sensitive: true });
|
|
59
|
+
add("Payments", "payment_disputes", ["read", "write"], { read: "View disputes", write: "Handle disputes" }, { sensitive: true });
|
|
60
|
+
add("Payments", "payment_methods", ["read", "write"], { read: "View payment methods", write: "Tokenize payment methods" }, { sensitive: true });
|
|
61
|
+
add("Customers", "customers", ["read", "write"], { read: "View customers", write: "Manage customers" });
|
|
62
|
+
add("Customers", "customer_pii", ["read"], { read: "View customer PII" }, { sensitive: true });
|
|
63
|
+
add("Customers", "customer_addresses", ["read", "write"], { read: "View addresses", write: "Manage addresses" });
|
|
64
|
+
add("Customers", "customer_payment_methods", ["read", "write"], { read: "View stored cards", write: "Manage stored cards" }, { sensitive: true });
|
|
65
|
+
add(
|
|
66
|
+
"Customer accounts",
|
|
67
|
+
"customer_accounts",
|
|
68
|
+
["write"],
|
|
69
|
+
{ write: "Let shoppers register, sign in and manage their account" },
|
|
70
|
+
{ publishableAllowed: true, publishableOnly: true, extensionAllowed: false }
|
|
71
|
+
);
|
|
72
|
+
add("Carts", "carts", ["read", "write"], { read: "View carts", write: "Manage carts" });
|
|
73
|
+
add("Carts", "cart_items", ["write"], { write: "Manage line items" });
|
|
74
|
+
add("Carts", "checkout_sessions", ["read", "write"], { read: "View checkout sessions", write: "Manage checkout sessions" });
|
|
75
|
+
add("Discounts", "discounts", ["read", "write"], { read: "View discounts", write: "Manage discounts" });
|
|
76
|
+
add("Subscriptions", "subscriptions", ["read", "write"], { read: "View subscriptions", write: "Manage subscriptions" });
|
|
77
|
+
add("Subscriptions", "subscription_pauses", ["write"], { write: "Pause/resume subscriptions" });
|
|
78
|
+
add("Subscriptions", "subscription_cancellations", ["write"], { write: "Cancel subscriptions" });
|
|
79
|
+
add("Subscriptions", "subscription_usage", ["read", "write"], { read: "View subscription usage", write: "Report subscription usage" }, { extensionAllowed: false });
|
|
80
|
+
add("Fulfillments", "fulfillments", ["read", "write"], { read: "View fulfillments", write: "Manage fulfillments" });
|
|
81
|
+
add("Fulfillments", "fulfillment_shipments", ["write"], { write: "Update shipments" });
|
|
82
|
+
add("Fulfillments", "fulfillment_digital", ["read", "write"], { read: "View digital delivery", write: "Manage digital delivery" });
|
|
83
|
+
add("Fulfillments", "fulfillment_access", ["write"], { write: "Manage access credentials" });
|
|
84
|
+
add("Fulfillments", "fulfillment_services", ["write"], { write: "Manage service fulfillment" });
|
|
85
|
+
add("Invoices / AR", "invoices", ["read"], { read: "View invoices & aging" });
|
|
86
|
+
add("Invoices / AR", "invoice_payments", ["write"], { write: "Mark invoices paid" }, { sensitive: true });
|
|
87
|
+
add("Invoices / AR", "invoice_dunning", ["write"], { write: "Send dunning notices" });
|
|
88
|
+
add("Shipping & Tax", "shipping_tax", ["read", "write"], { read: "View shipping/tax config", write: "Edit shipping/tax config" });
|
|
89
|
+
add("Shipping & Tax", "shipping_tax_publications", ["write"], { write: "Publish shipping/tax config" });
|
|
90
|
+
add("Shipping & Tax", "shipping_quotes", ["write"], { write: "Request shipping quotes" }, { publishableAllowed: true });
|
|
91
|
+
add("Shipping & Tax", "tax_calculations", ["write"], { write: "Calculate tax" }, { publishableAllowed: true });
|
|
92
|
+
add("Shipping & Tax", "shipping_tax_quote_tokens", ["read", "write"], { read: "View quote tokens", write: "Manage quote tokens" });
|
|
93
|
+
add("Shipping & Tax", "shipping_tax_snapshots", ["write"], { write: "Accept external snapshots" });
|
|
94
|
+
add(
|
|
95
|
+
"Scripts",
|
|
96
|
+
"storefront_scripts",
|
|
97
|
+
["read", "write"],
|
|
98
|
+
{
|
|
99
|
+
read: "Load storefront scripts",
|
|
100
|
+
// `write` covers exactly one thing: reporting a script's own load outcome
|
|
101
|
+
// from the merchant's storefront, so the health panel stops being
|
|
102
|
+
// hosted-checkout-only. On checkout the session id in the URL is the
|
|
103
|
+
// capability that scopes that write; a storefront page has no session, so
|
|
104
|
+
// the pk it already holds is what scopes it instead. It writes nothing but
|
|
105
|
+
// load telemetry — authoring stays on `application_scripts:write`, which
|
|
106
|
+
// is not publishable-allowed.
|
|
107
|
+
write: "Report storefront script load outcomes"
|
|
108
|
+
},
|
|
109
|
+
{ publishableAllowed: true }
|
|
110
|
+
);
|
|
111
|
+
add("Scripts", "application_scripts", ["read", "write"], {
|
|
112
|
+
read: "View merchant-authored scripts",
|
|
113
|
+
write: "Create, edit and disable merchant-authored scripts"
|
|
114
|
+
}, { extensionAllowed: false });
|
|
115
|
+
add("Scripts", "extension_scripts", ["read", "write"], {
|
|
116
|
+
read: "View an extension's buyer-facing scripts",
|
|
117
|
+
write: "Create, edit and delete an extension's buyer-facing scripts"
|
|
118
|
+
}, { extensionAllowed: false });
|
|
119
|
+
add("Connectors", "connectors", ["read", "write"], { read: "View connectors", write: "Manage connectors" });
|
|
120
|
+
add("Webhooks & Events", "webhooks", ["read", "write"], { read: "View webhooks", write: "Manage webhooks" });
|
|
121
|
+
add("Webhooks & Events", "webhook_deliveries", ["read", "write"], { read: "View deliveries", write: "Retry deliveries" });
|
|
122
|
+
add("Webhooks & Events", "events", ["read"], { read: "View events" });
|
|
123
|
+
add("Webhooks & Events", "audit_logs", ["read"], { read: "View audit log" });
|
|
124
|
+
add("Applications", "applications", ["read", "write"], { read: "View applications", write: "Manage applications" });
|
|
125
|
+
add("Workspace", "merchant", ["read", "write"], { read: "View workspace settings", write: "Edit workspace settings" });
|
|
126
|
+
add("Workspace", "embed_config", ["read", "write"], { read: "View embed config", write: "Edit embed config" });
|
|
127
|
+
add("Workspace", "branding", ["write"], { write: "Upload branding assets" });
|
|
128
|
+
var HUMAN = { extensionAllowed: false };
|
|
129
|
+
add("Team", "team_members", ["read", "write"], { read: "View members", write: "Manage members" }, HUMAN);
|
|
130
|
+
add("Team", "team_invites", ["read", "write"], { read: "View invites", write: "Manage invites" }, HUMAN);
|
|
131
|
+
add("Platform billing", "billing", ["read", "write"], { read: "View billing", write: "Manage subscription" }, HUMAN);
|
|
132
|
+
add("Platform billing", "billing_payment_methods", ["read", "write"], { read: "View billing cards", write: "Manage billing cards" }, HUMAN);
|
|
133
|
+
add("Email", "email_templates", ["read", "write"], { read: "View email templates", write: "Edit email templates" }, HUMAN);
|
|
134
|
+
add("Email", "email_settings", ["read", "write"], { read: "View email settings", write: "Edit email settings" }, HUMAN);
|
|
135
|
+
add("Go-live", "go_live", ["write"], { write: "Submit go-live" }, HUMAN);
|
|
136
|
+
add("Partner", "partner", ["read", "write"], { read: "View partner profile", write: "Edit partner profile" }, HUMAN);
|
|
137
|
+
add("Partner", "affiliates", ["read", "write"], { read: "View affiliates", write: "Manage affiliates" }, HUMAN);
|
|
138
|
+
add("Notifications", "notifications", ["write"], { write: "Send notifications" }, HUMAN);
|
|
139
|
+
add("Notifications", "preferences", ["read", "write"], { read: "View preferences", write: "Edit preferences" }, HUMAN);
|
|
140
|
+
add("Integrations", "integrations", ["read", "write"], { read: "View integrations", write: "Manage integrations" }, HUMAN);
|
|
141
|
+
add("Support", "support", ["read", "write"], { read: "View support tickets", write: "Manage support tickets" }, HUMAN);
|
|
142
|
+
add("Admin (staff)", "admin", ["read", "write"], { read: "View admin data", write: "Perform admin actions" }, { sensitive: true, staffOnly: true, extensionAllowed: false });
|
|
143
|
+
add(
|
|
144
|
+
"Extensions",
|
|
145
|
+
"extensions",
|
|
146
|
+
["read", "write"],
|
|
147
|
+
{ read: "View extensions & installs", write: "Author, version & publish extensions" },
|
|
148
|
+
HUMAN
|
|
149
|
+
);
|
|
150
|
+
REG["extensions:install"] = {
|
|
151
|
+
id: "extensions:install",
|
|
152
|
+
resource: "extensions",
|
|
153
|
+
action: "install",
|
|
154
|
+
group: "Extensions",
|
|
155
|
+
label: "Install, configure & manage extensions",
|
|
156
|
+
sensitive: false,
|
|
157
|
+
staffOnly: false,
|
|
158
|
+
publishableAllowed: false,
|
|
159
|
+
publishableOnly: false,
|
|
160
|
+
extensionAllowed: false,
|
|
161
|
+
implies: []
|
|
162
|
+
};
|
|
163
|
+
REG["*"] = {
|
|
164
|
+
id: "*",
|
|
165
|
+
resource: "*",
|
|
166
|
+
action: "write",
|
|
167
|
+
group: "Global",
|
|
168
|
+
label: "Full access",
|
|
169
|
+
sensitive: true,
|
|
170
|
+
staffOnly: false,
|
|
171
|
+
publishableAllowed: false,
|
|
172
|
+
publishableOnly: false,
|
|
173
|
+
extensionAllowed: false,
|
|
174
|
+
implies: []
|
|
175
|
+
};
|
|
176
|
+
var SCOPE_REGISTRY = REG;
|
|
177
|
+
var ALL_SCOPE_IDS = Object.keys(REG);
|
|
178
|
+
var SCOPE_GROUPS = (() => {
|
|
179
|
+
const out = {};
|
|
180
|
+
for (const def of Object.values(REG)) {
|
|
181
|
+
if (def.id === "*") continue;
|
|
182
|
+
(out[def.group] ??= []).push(def.id);
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
})();
|
|
186
|
+
|
|
187
|
+
// ../core-scopes/src/events.ts
|
|
188
|
+
var EVENT_SCOPE_OVERRIDES = {
|
|
189
|
+
"payment.refunded": "payment_refunds:read",
|
|
190
|
+
"payment.partially_refunded": "payment_refunds:read",
|
|
191
|
+
"payment.refund_failed": "payment_refunds:read",
|
|
192
|
+
// Money returned, so it belongs with the other refund events rather than
|
|
193
|
+
// behind the broad subscriptions:read the `subscription.` prefix would give.
|
|
194
|
+
"subscription.invoice_refunded": "payment_refunds:read",
|
|
195
|
+
"payment.disputed": "payment_disputes:read",
|
|
196
|
+
"payment.dispute_cleared": "payment_disputes:read",
|
|
197
|
+
"fulfillment.digital.delivered": "fulfillment_digital:read"
|
|
198
|
+
};
|
|
199
|
+
var PREFIX_RULES = [
|
|
200
|
+
["checkout.session.", "carts:read"],
|
|
201
|
+
["cart.", "carts:read"],
|
|
202
|
+
["order.", "orders:read"],
|
|
203
|
+
["quote.", "quotes:read"],
|
|
204
|
+
["return.", "order_returns:read"],
|
|
205
|
+
["payment.", "payments:read"],
|
|
206
|
+
["customer.", "customers:read"],
|
|
207
|
+
["subscription.", "subscriptions:read"],
|
|
208
|
+
["fulfillment.", "fulfillments:read"],
|
|
209
|
+
["discount.", "discounts:read"],
|
|
210
|
+
["invoice.", "invoices:read"],
|
|
211
|
+
["import.", "imports:read"],
|
|
212
|
+
["shipping_tax.", "shipping_tax:read"],
|
|
213
|
+
["workspace.", "billing:read"],
|
|
214
|
+
// `extensions:read` is a human scope (extensions must never watch other
|
|
215
|
+
// extensions), so only a workspace endpoint can SUBSCRIBE to this family.
|
|
216
|
+
// The uninstalled installation's own endpoint is addressed directly by the
|
|
217
|
+
// uninstall path and needs no subscription at all.
|
|
218
|
+
["extension.", "extensions:read"],
|
|
219
|
+
// Subscribing to script outcomes needs script read — the payload names the
|
|
220
|
+
// script key and its hash, which is the merchant's script inventory.
|
|
221
|
+
["script.", "application_scripts:read"]
|
|
222
|
+
];
|
|
223
|
+
function eventReadScope(type) {
|
|
224
|
+
if (EVENT_SCOPE_OVERRIDES[type]) return EVENT_SCOPE_OVERRIDES[type];
|
|
225
|
+
for (const [prefix, scope] of PREFIX_RULES) {
|
|
226
|
+
if (type.startsWith(prefix)) return scope;
|
|
227
|
+
}
|
|
228
|
+
throw new Error(`Unknown event type: ${type}`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ../core-scopes/src/issuance.ts
|
|
232
|
+
var PUBLISHABLE_SCOPES = Object.values(SCOPE_REGISTRY).filter((d) => d.publishableAllowed).map((d) => d.id);
|
|
233
|
+
var CONNECTOR_GRANTABLE_SENSITIVE_SCOPES = ["customer_pii:read"];
|
|
234
|
+
function validateScopesForOAuth(scopes, opts = {}) {
|
|
235
|
+
const invalid = [];
|
|
236
|
+
for (const id of scopes) {
|
|
237
|
+
if (id === "*") {
|
|
238
|
+
invalid.push(id);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const def = SCOPE_REGISTRY[id];
|
|
242
|
+
if (!def || def.staffOnly) {
|
|
243
|
+
invalid.push(id);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (def.sensitive && !(opts.connector && CONNECTOR_GRANTABLE_SENSITIVE_SCOPES.includes(id))) invalid.push(id);
|
|
247
|
+
}
|
|
248
|
+
return { ok: invalid.length === 0, invalid };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// ../core-scopes/src/shopper-pii.ts
|
|
252
|
+
var PERSON_KEYS = /* @__PURE__ */ new Set([
|
|
253
|
+
"email",
|
|
254
|
+
"customerEmail",
|
|
255
|
+
"billingEmail",
|
|
256
|
+
"buyerEmail",
|
|
257
|
+
"authorEmail",
|
|
258
|
+
"authorName",
|
|
259
|
+
"phone",
|
|
260
|
+
"firstName",
|
|
261
|
+
"lastName",
|
|
262
|
+
"addressLine1",
|
|
263
|
+
"addressLine2",
|
|
264
|
+
"billingAddressLines",
|
|
265
|
+
"processorResponse",
|
|
266
|
+
"shareToken",
|
|
267
|
+
"company",
|
|
268
|
+
"externalId",
|
|
269
|
+
"externalCustomerId",
|
|
270
|
+
// Free-form: contents cannot be inspected for a person, so the field goes.
|
|
271
|
+
"metadata",
|
|
272
|
+
"notes",
|
|
273
|
+
"internalNotes",
|
|
274
|
+
"buyerNote",
|
|
275
|
+
"buyerReference",
|
|
276
|
+
"changeSummary",
|
|
277
|
+
"declinedReason",
|
|
278
|
+
"compReason",
|
|
279
|
+
"holdReason",
|
|
280
|
+
"body",
|
|
281
|
+
"acceptance",
|
|
282
|
+
"acceptanceSelections",
|
|
283
|
+
"clientContext",
|
|
284
|
+
"ipAddress",
|
|
285
|
+
"userAgent",
|
|
286
|
+
"vatNumber",
|
|
287
|
+
"buyerVatNumber",
|
|
288
|
+
"taxExemptionNumber"
|
|
289
|
+
]);
|
|
290
|
+
var PERSON_CONTAINERS = /* @__PURE__ */ new Set(["customer", "buyer"]);
|
|
291
|
+
function isPlainObject(value) {
|
|
292
|
+
if (value === null || typeof value !== "object") return false;
|
|
293
|
+
const proto = Object.getPrototypeOf(value);
|
|
294
|
+
return proto === Object.prototype || proto === null;
|
|
295
|
+
}
|
|
296
|
+
function walk(value, parentKey, depth) {
|
|
297
|
+
if (depth > 32) return value;
|
|
298
|
+
if (Array.isArray(value)) return value.map((item) => walk(item, parentKey, depth + 1));
|
|
299
|
+
if (!isPlainObject(value)) return value;
|
|
300
|
+
const out = {};
|
|
301
|
+
const isPerson = parentKey !== null && PERSON_CONTAINERS.has(parentKey);
|
|
302
|
+
for (const [key, child] of Object.entries(value)) {
|
|
303
|
+
if (PERSON_KEYS.has(key) || isPerson && key === "name") {
|
|
304
|
+
out[key] = child === void 0 ? child : null;
|
|
305
|
+
} else {
|
|
306
|
+
out[key] = walk(child, key, depth + 1);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
311
|
+
function redactShopperPii(value) {
|
|
312
|
+
return walk(value, null, 0);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ../action-catalog/src/actions.ts
|
|
316
|
+
var OAUTH_WITHHELD = "Over an OAuth connection (ChatGPT, Claude) these are withheld, because a buyer can type them: line-item and quote-item names, SKUs and reference ids; company; every address line except the country; the merchant's external ids; notes, messages, reasons and metadata. Describe items by quantity and amount, and say the rest is withheld rather than missing.";
|
|
317
|
+
var ACTIONS = [
|
|
318
|
+
// ---------------------------------------------------------------- identity
|
|
319
|
+
{
|
|
320
|
+
id: "whoami",
|
|
321
|
+
title: "Identify the connected credential",
|
|
322
|
+
description: "Report which workspace, application and environment this credential is pinned to, and what it is allowed to do. Call this first when you need to know whether you are talking to production or a sandbox.",
|
|
323
|
+
kind: "read",
|
|
324
|
+
scopes: [],
|
|
325
|
+
input: [],
|
|
326
|
+
requests: [{ method: "GET", path: "/api/v1/whoami" }],
|
|
327
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
328
|
+
},
|
|
329
|
+
// ------------------------------------------------------- local (no API call)
|
|
330
|
+
{
|
|
331
|
+
id: "search_docs",
|
|
332
|
+
title: "Search the Throttle developer docs",
|
|
333
|
+
description: "Full-text search over the Throttle developer documentation. Returns titles, canonical usethrottle.dev/docs URLs, and matching excerpts. Prefer this over recalling API details from memory.",
|
|
334
|
+
kind: "read",
|
|
335
|
+
scopes: [],
|
|
336
|
+
input: [
|
|
337
|
+
{ name: "query", type: "string", required: true, description: "What to search for." },
|
|
338
|
+
{ name: "limit", type: "number", required: false, description: "Maximum results." }
|
|
339
|
+
],
|
|
340
|
+
requests: [],
|
|
341
|
+
channels: ["mcp"]
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
id: "describe_endpoint",
|
|
345
|
+
title: "Describe an API endpoint",
|
|
346
|
+
description: "Return the canonical request and response shape of a Throttle API endpoint from the published OpenAPI contract: path parameters, request body fields, required scope. Use before writing any integration code.",
|
|
347
|
+
kind: "read",
|
|
348
|
+
scopes: [],
|
|
349
|
+
input: [
|
|
350
|
+
{
|
|
351
|
+
name: "path",
|
|
352
|
+
type: "string",
|
|
353
|
+
required: true,
|
|
354
|
+
description: 'Endpoint path or fragment, e.g. "/api/v1/carts" or "carts".'
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
name: "method",
|
|
358
|
+
type: "string",
|
|
359
|
+
required: false,
|
|
360
|
+
description: "Narrow to one HTTP method.",
|
|
361
|
+
enum: ["GET", "POST", "PATCH", "PUT", "DELETE"]
|
|
362
|
+
}
|
|
363
|
+
],
|
|
364
|
+
requests: [],
|
|
365
|
+
channels: ["mcp"]
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
id: "validate_payload",
|
|
369
|
+
title: "Validate a request body against the API contract",
|
|
370
|
+
description: "Check a request body against the published contract before sending it. Names every unsupported field and gives its canonical replacement \u2014 Throttle is strict camelCase and rejects retired aliases such as line_items, unit_price, customer_id and storeId. Full reference: https://usethrottle.dev/docs/developers/api-reference.",
|
|
371
|
+
kind: "read",
|
|
372
|
+
scopes: [],
|
|
373
|
+
input: [
|
|
374
|
+
{ name: "method", type: "string", required: true, description: "HTTP method." },
|
|
375
|
+
{ name: "path", type: "string", required: true, description: "Endpoint path." },
|
|
376
|
+
{ name: "body", type: "object", required: true, description: "The request body to check." }
|
|
377
|
+
],
|
|
378
|
+
requests: [],
|
|
379
|
+
channels: ["mcp"]
|
|
380
|
+
},
|
|
381
|
+
// ------------------------------------------------------------ generic reads
|
|
382
|
+
{
|
|
383
|
+
id: "api_get",
|
|
384
|
+
title: "Read any Throttle API endpoint",
|
|
385
|
+
description: "Escape hatch for reads the curated tools do not cover: performs a GET against any /api/v1 path and returns the response. Cannot write. Confirm the path with describe_endpoint first if unsure. Full reference: https://usethrottle.dev/docs/developers/api-reference.",
|
|
386
|
+
kind: "read",
|
|
387
|
+
scopes: [],
|
|
388
|
+
credentialScoped: true,
|
|
389
|
+
input: [
|
|
390
|
+
{
|
|
391
|
+
name: "path",
|
|
392
|
+
type: "string",
|
|
393
|
+
required: true,
|
|
394
|
+
description: "Path beginning with /api/v1, query string included."
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
name: "applicationId",
|
|
398
|
+
type: "string",
|
|
399
|
+
required: false,
|
|
400
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
401
|
+
}
|
|
402
|
+
],
|
|
403
|
+
requests: [],
|
|
404
|
+
channels: ["mcp"],
|
|
405
|
+
guardrails: [
|
|
406
|
+
"GET only \u2014 reject any other method.",
|
|
407
|
+
"Reject paths outside /api/v1 so the tool cannot be pointed at another host or a non-versioned surface.",
|
|
408
|
+
"Server-side scope enforcement still applies; surface a 403 insufficient_scopes verbatim rather than retrying."
|
|
409
|
+
]
|
|
410
|
+
},
|
|
411
|
+
// ------------------------------------------------------------------- orders
|
|
412
|
+
{
|
|
413
|
+
id: "search_orders",
|
|
414
|
+
title: "Search orders",
|
|
415
|
+
description: "List orders, newest first, with optional free-text and status filters.",
|
|
416
|
+
kind: "read",
|
|
417
|
+
scopes: ["orders:read"],
|
|
418
|
+
input: [
|
|
419
|
+
{ name: "q", type: "string", required: false, description: "Free-text search." },
|
|
420
|
+
{ name: "status", type: "string", required: false, description: "Order status filter." },
|
|
421
|
+
{ name: "paymentStatus", type: "string", required: false, description: "Payment status filter." },
|
|
422
|
+
{
|
|
423
|
+
name: "createdAfter",
|
|
424
|
+
type: "string",
|
|
425
|
+
required: false,
|
|
426
|
+
description: "ISO 8601 lower bound on creation time, exclusive. For a single day, pass that day's midnight and the next day's midnight."
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
name: "createdBefore",
|
|
430
|
+
type: "string",
|
|
431
|
+
required: false,
|
|
432
|
+
description: "ISO 8601 upper bound on creation time, exclusive."
|
|
433
|
+
},
|
|
434
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
435
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
436
|
+
{
|
|
437
|
+
name: "applicationId",
|
|
438
|
+
type: "string",
|
|
439
|
+
required: false,
|
|
440
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
441
|
+
}
|
|
442
|
+
],
|
|
443
|
+
requests: [{ method: "GET", path: "/api/v1/orders" }],
|
|
444
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
445
|
+
guardrails: [
|
|
446
|
+
OAUTH_WITHHELD,
|
|
447
|
+
"Over an OAuth connection, q matches the order id, order number and status fields only."
|
|
448
|
+
]
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
id: "get_order",
|
|
452
|
+
title: "Get one order with its returns and fulfillments",
|
|
453
|
+
description: "Full picture of a single order: the order itself plus its payments, returns and fulfillments in one response.",
|
|
454
|
+
kind: "read",
|
|
455
|
+
scopes: ["orders:read"],
|
|
456
|
+
sectionScopes: ["payments:read", "order_returns:read", "fulfillments:read"],
|
|
457
|
+
input: [
|
|
458
|
+
{ name: "id", type: "string", required: true, description: "Order id." },
|
|
459
|
+
{
|
|
460
|
+
name: "applicationId",
|
|
461
|
+
type: "string",
|
|
462
|
+
required: false,
|
|
463
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
464
|
+
}
|
|
465
|
+
],
|
|
466
|
+
requests: [
|
|
467
|
+
{ method: "GET", path: "/api/v1/orders/:id" },
|
|
468
|
+
{ method: "GET", path: "/api/v1/orders/:id/payments" },
|
|
469
|
+
{ method: "GET", path: "/api/v1/orders/:id/returns" },
|
|
470
|
+
{ method: "GET", path: "/api/v1/orders/:orderId/fulfillments" }
|
|
471
|
+
],
|
|
472
|
+
channels: ["mcp"],
|
|
473
|
+
guardrails: [
|
|
474
|
+
"Sub-reads need their own scopes (payments:read, order_returns:read, fulfillments:read). Skip a section the credential cannot read and say so in the result rather than failing the whole call.",
|
|
475
|
+
OAUTH_WITHHELD
|
|
476
|
+
]
|
|
477
|
+
},
|
|
478
|
+
// ---------------------------------------------------------------- customers
|
|
479
|
+
{
|
|
480
|
+
id: "search_customers",
|
|
481
|
+
title: "Search customers",
|
|
482
|
+
description: "Find customers by name, email or external id, or list them by creation date. Over an OAuth connection (ChatGPT, Claude) text search is not available \u2014 list by date instead \u2014 because every field it could match is withheld there.",
|
|
483
|
+
kind: "read",
|
|
484
|
+
scopes: ["customers:read"],
|
|
485
|
+
input: [
|
|
486
|
+
{ name: "q", type: "string", required: false, description: "Free-text search." },
|
|
487
|
+
{
|
|
488
|
+
name: "createdAfter",
|
|
489
|
+
type: "string",
|
|
490
|
+
required: false,
|
|
491
|
+
description: "ISO 8601 lower bound on creation time, exclusive. For a single day, pass that day's midnight and the next day's midnight."
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
name: "createdBefore",
|
|
495
|
+
type: "string",
|
|
496
|
+
required: false,
|
|
497
|
+
description: "ISO 8601 upper bound on creation time, exclusive."
|
|
498
|
+
},
|
|
499
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
500
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
501
|
+
{
|
|
502
|
+
name: "applicationId",
|
|
503
|
+
type: "string",
|
|
504
|
+
required: false,
|
|
505
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
506
|
+
}
|
|
507
|
+
],
|
|
508
|
+
requests: [{ method: "GET", path: "/api/v1/customers" }],
|
|
509
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
510
|
+
guardrails: [
|
|
511
|
+
'email, phone, firstName, lastName, name and metadata are withheld (null, or absent from the result) unless the credential holds customer_pii:read, which OAuth connections cannot hold. Over an OAuth connection company, externalId and externalCustomerId are withheld too, and q is refused. Do not describe a missing name/email as "no name on file"; say it is withheld.'
|
|
512
|
+
]
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
id: "get_customer",
|
|
516
|
+
title: "Get one customer with subscriptions and addresses",
|
|
517
|
+
description: "Full picture of a single customer: the record plus their subscriptions and addresses in one response.",
|
|
518
|
+
kind: "read",
|
|
519
|
+
scopes: ["customers:read"],
|
|
520
|
+
sectionScopes: ["customer_addresses:read", "subscriptions:read"],
|
|
521
|
+
input: [
|
|
522
|
+
{ name: "id", type: "string", required: true, description: "Customer id." },
|
|
523
|
+
{
|
|
524
|
+
name: "applicationId",
|
|
525
|
+
type: "string",
|
|
526
|
+
required: false,
|
|
527
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
528
|
+
}
|
|
529
|
+
],
|
|
530
|
+
requests: [
|
|
531
|
+
{ method: "GET", path: "/api/v1/customers/:id" },
|
|
532
|
+
{ method: "GET", path: "/api/v1/customers/:id/addresses" },
|
|
533
|
+
{ method: "GET", path: "/api/v1/subscriptions" }
|
|
534
|
+
],
|
|
535
|
+
channels: ["mcp"],
|
|
536
|
+
guardrails: [
|
|
537
|
+
"Sub-reads need customer_addresses:read / subscriptions:read. Omit a section the credential cannot read instead of failing.",
|
|
538
|
+
"email, phone, firstName, lastName, name and metadata on the customer record are withheld (null, or absent from the result) unless the credential holds customer_pii:read, which OAuth connections cannot hold. Say PII is redacted rather than reporting the buyer as anonymous.",
|
|
539
|
+
OAUTH_WITHHELD
|
|
540
|
+
]
|
|
541
|
+
},
|
|
542
|
+
// ------------------------------------------------------------- subscriptions
|
|
543
|
+
{
|
|
544
|
+
id: "list_subscriptions",
|
|
545
|
+
title: "List subscriptions",
|
|
546
|
+
description: "List subscriptions with optional customer and status filters.",
|
|
547
|
+
kind: "read",
|
|
548
|
+
scopes: ["subscriptions:read"],
|
|
549
|
+
input: [
|
|
550
|
+
{ name: "customerId", type: "string", required: false, description: "Filter by customer." },
|
|
551
|
+
{ name: "status", type: "string", required: false, description: "Filter by status." },
|
|
552
|
+
{
|
|
553
|
+
name: "createdAfter",
|
|
554
|
+
type: "string",
|
|
555
|
+
required: false,
|
|
556
|
+
description: "ISO 8601 lower bound on creation time, exclusive. For a single day, pass that day's midnight and the next day's midnight."
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
name: "createdBefore",
|
|
560
|
+
type: "string",
|
|
561
|
+
required: false,
|
|
562
|
+
description: "ISO 8601 upper bound on creation time, exclusive."
|
|
563
|
+
},
|
|
564
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
565
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
566
|
+
{
|
|
567
|
+
name: "applicationId",
|
|
568
|
+
type: "string",
|
|
569
|
+
required: false,
|
|
570
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
571
|
+
}
|
|
572
|
+
],
|
|
573
|
+
requests: [{ method: "GET", path: "/api/v1/subscriptions" }],
|
|
574
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
id: "get_subscription",
|
|
578
|
+
title: "Get one subscription",
|
|
579
|
+
description: "Read a single subscription including its current period and pending changes.",
|
|
580
|
+
kind: "read",
|
|
581
|
+
scopes: ["subscriptions:read"],
|
|
582
|
+
input: [
|
|
583
|
+
{ name: "id", type: "string", required: true, description: "Subscription id." },
|
|
584
|
+
{
|
|
585
|
+
name: "applicationId",
|
|
586
|
+
type: "string",
|
|
587
|
+
required: false,
|
|
588
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
589
|
+
}
|
|
590
|
+
],
|
|
591
|
+
requests: [{ method: "GET", path: "/api/v1/subscriptions/:id" }],
|
|
592
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
593
|
+
},
|
|
594
|
+
// ------------------------------------------------------------------- quotes
|
|
595
|
+
{
|
|
596
|
+
id: "search_quotes",
|
|
597
|
+
title: "Search quotes",
|
|
598
|
+
description: 'List quotes with optional status filter \u2014 useful for "which quotes expire soon".',
|
|
599
|
+
kind: "read",
|
|
600
|
+
scopes: ["quotes:read"],
|
|
601
|
+
input: [
|
|
602
|
+
{ name: "status", type: "string", required: false, description: "Filter by quote status." },
|
|
603
|
+
{
|
|
604
|
+
name: "createdAfter",
|
|
605
|
+
type: "string",
|
|
606
|
+
required: false,
|
|
607
|
+
description: "ISO 8601 lower bound on creation time, exclusive. For a single day, pass that day's midnight and the next day's midnight."
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
name: "createdBefore",
|
|
611
|
+
type: "string",
|
|
612
|
+
required: false,
|
|
613
|
+
description: "ISO 8601 upper bound on creation time, exclusive."
|
|
614
|
+
},
|
|
615
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
616
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
617
|
+
{
|
|
618
|
+
name: "applicationId",
|
|
619
|
+
type: "string",
|
|
620
|
+
required: false,
|
|
621
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
622
|
+
}
|
|
623
|
+
],
|
|
624
|
+
requests: [{ method: "GET", path: "/api/v1/quotes" }],
|
|
625
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
id: "get_quote",
|
|
629
|
+
title: "Get one quote",
|
|
630
|
+
description: "Read a single quote: status, totals, and each revision with its line items and payment terms.",
|
|
631
|
+
kind: "read",
|
|
632
|
+
scopes: ["quotes:read"],
|
|
633
|
+
input: [
|
|
634
|
+
{ name: "id", type: "string", required: true, description: "Quote id." },
|
|
635
|
+
{
|
|
636
|
+
name: "applicationId",
|
|
637
|
+
type: "string",
|
|
638
|
+
required: false,
|
|
639
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
640
|
+
}
|
|
641
|
+
],
|
|
642
|
+
requests: [{ method: "GET", path: "/api/v1/quotes/:id" }],
|
|
643
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
644
|
+
guardrails: [OAUTH_WITHHELD]
|
|
645
|
+
},
|
|
646
|
+
// ----------------------------------------------------------------- invoices
|
|
647
|
+
{
|
|
648
|
+
id: "list_invoices",
|
|
649
|
+
title: "List invoices",
|
|
650
|
+
description: "List issued invoices with optional status filter.",
|
|
651
|
+
kind: "read",
|
|
652
|
+
scopes: ["invoices:read"],
|
|
653
|
+
input: [
|
|
654
|
+
{ name: "status", type: "string", required: false, description: "Filter by invoice status." },
|
|
655
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
656
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
657
|
+
{
|
|
658
|
+
name: "applicationId",
|
|
659
|
+
type: "string",
|
|
660
|
+
required: false,
|
|
661
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
662
|
+
}
|
|
663
|
+
],
|
|
664
|
+
requests: [{ method: "GET", path: "/api/v1/invoices" }],
|
|
665
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
666
|
+
guardrails: [OAUTH_WITHHELD]
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
id: "receivables_aging",
|
|
670
|
+
title: "Receivables aging",
|
|
671
|
+
description: 'Outstanding receivables bucketed by age \u2014 answers "what is overdue and by how long".',
|
|
672
|
+
kind: "read",
|
|
673
|
+
scopes: ["invoices:read"],
|
|
674
|
+
input: [
|
|
675
|
+
{
|
|
676
|
+
name: "applicationId",
|
|
677
|
+
type: "string",
|
|
678
|
+
required: false,
|
|
679
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
680
|
+
}
|
|
681
|
+
],
|
|
682
|
+
requests: [{ method: "GET", path: "/api/v1/invoices/aging" }],
|
|
683
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
684
|
+
},
|
|
685
|
+
// --------------------------------------------------------------- discounts
|
|
686
|
+
{
|
|
687
|
+
id: "search_discounts",
|
|
688
|
+
title: "Search discounts",
|
|
689
|
+
description: "List discount codes with optional filters \u2014 type, active state, and creation date range.",
|
|
690
|
+
kind: "read",
|
|
691
|
+
scopes: ["discounts:read"],
|
|
692
|
+
input: [
|
|
693
|
+
{ name: "q", type: "string", required: false, description: "Free-text search." },
|
|
694
|
+
{ name: "code", type: "string", required: false, description: "Exact code match." },
|
|
695
|
+
{
|
|
696
|
+
name: "type",
|
|
697
|
+
type: "string",
|
|
698
|
+
required: false,
|
|
699
|
+
description: "Filter by discount type.",
|
|
700
|
+
enum: ["percentage", "fixed_amount"]
|
|
701
|
+
},
|
|
702
|
+
{ name: "isActive", type: "boolean", required: false, description: "Filter by active state." },
|
|
703
|
+
{ name: "createdAfter", type: "string", required: false, description: "ISO 8601 date lower bound." },
|
|
704
|
+
{ name: "createdBefore", type: "string", required: false, description: "ISO 8601 date upper bound." },
|
|
705
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
706
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
707
|
+
{
|
|
708
|
+
name: "applicationId",
|
|
709
|
+
type: "string",
|
|
710
|
+
required: false,
|
|
711
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
712
|
+
}
|
|
713
|
+
],
|
|
714
|
+
requests: [{ method: "GET", path: "/api/v1/discounts" }],
|
|
715
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
id: "get_discount",
|
|
719
|
+
title: "Get one discount",
|
|
720
|
+
description: "Read a single discount code: value, conditions, usage limits and redemption count.",
|
|
721
|
+
kind: "read",
|
|
722
|
+
scopes: ["discounts:read"],
|
|
723
|
+
input: [
|
|
724
|
+
{ name: "id", type: "string", required: true, description: "Discount id." },
|
|
725
|
+
{
|
|
726
|
+
name: "applicationId",
|
|
727
|
+
type: "string",
|
|
728
|
+
required: false,
|
|
729
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
730
|
+
}
|
|
731
|
+
],
|
|
732
|
+
requests: [{ method: "GET", path: "/api/v1/discounts/:id" }],
|
|
733
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
734
|
+
},
|
|
735
|
+
// ---------------------------------------------------------------- payments
|
|
736
|
+
{
|
|
737
|
+
id: "search_payments",
|
|
738
|
+
title: "Search payments",
|
|
739
|
+
description: "List payments with optional filters \u2014 method, status, order, amount range, or a Net-N overdue bucket. Today payments are only reachable nested inside get_order; this is the standalone entry point.",
|
|
740
|
+
kind: "read",
|
|
741
|
+
scopes: ["payments:read"],
|
|
742
|
+
input: [
|
|
743
|
+
{ name: "method", type: "string", required: false, description: "Filter by payment method." },
|
|
744
|
+
{ name: "status", type: "string", required: false, description: "Filter by payment status." },
|
|
745
|
+
{ name: "orderId", type: "string", required: false, description: "Filter to one order." },
|
|
746
|
+
{
|
|
747
|
+
name: "aging",
|
|
748
|
+
type: "string",
|
|
749
|
+
required: false,
|
|
750
|
+
description: "Overdue bucket filter, Net-N payments only.",
|
|
751
|
+
enum: ["0_30", "31_60", "61_90", "90_plus"]
|
|
752
|
+
},
|
|
753
|
+
{ name: "dueFrom", type: "string", required: false, description: "Due-date range start, YYYY-MM-DD." },
|
|
754
|
+
{ name: "dueTo", type: "string", required: false, description: "Due-date range end, YYYY-MM-DD." },
|
|
755
|
+
{ name: "amountMin", type: "number", required: false, description: "Minimum amount, minor units." },
|
|
756
|
+
{ name: "amountMax", type: "number", required: false, description: "Maximum amount, minor units." },
|
|
757
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
758
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
759
|
+
{
|
|
760
|
+
name: "applicationId",
|
|
761
|
+
type: "string",
|
|
762
|
+
required: false,
|
|
763
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
764
|
+
}
|
|
765
|
+
],
|
|
766
|
+
requests: [{ method: "GET", path: "/api/v1/payments" }],
|
|
767
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
id: "get_payment",
|
|
771
|
+
title: "Get one payment with its transactions",
|
|
772
|
+
description: "Read a single payment plus its full transaction history (authorize/capture/refund/void attempts).",
|
|
773
|
+
kind: "read",
|
|
774
|
+
scopes: ["payments:read"],
|
|
775
|
+
input: [
|
|
776
|
+
{ name: "id", type: "string", required: true, description: "Payment id." },
|
|
777
|
+
{
|
|
778
|
+
name: "applicationId",
|
|
779
|
+
type: "string",
|
|
780
|
+
required: false,
|
|
781
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
782
|
+
}
|
|
783
|
+
],
|
|
784
|
+
requests: [
|
|
785
|
+
{ method: "GET", path: "/api/v1/payments/:id" },
|
|
786
|
+
{ method: "GET", path: "/api/v1/payments/:id/transactions" }
|
|
787
|
+
],
|
|
788
|
+
channels: ["mcp"],
|
|
789
|
+
guardrails: [
|
|
790
|
+
"The transactions sub-read needs its own read of the same payment scope; report it as unavailable rather than failing the whole call if the underlying request errors."
|
|
791
|
+
]
|
|
792
|
+
},
|
|
793
|
+
// ---------------------------------------------------------------- invoices
|
|
794
|
+
{
|
|
795
|
+
id: "get_invoice",
|
|
796
|
+
title: "Get one invoice",
|
|
797
|
+
description: "Read a single issued invoice: line items, totals, status and the billing snapshot at issue time.",
|
|
798
|
+
kind: "read",
|
|
799
|
+
scopes: ["invoices:read"],
|
|
800
|
+
input: [
|
|
801
|
+
{ name: "id", type: "string", required: true, description: "Invoice id." },
|
|
802
|
+
{
|
|
803
|
+
name: "applicationId",
|
|
804
|
+
type: "string",
|
|
805
|
+
required: false,
|
|
806
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
807
|
+
}
|
|
808
|
+
],
|
|
809
|
+
requests: [{ method: "GET", path: "/api/v1/invoices/:id" }],
|
|
810
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
811
|
+
guardrails: [OAUTH_WITHHELD]
|
|
812
|
+
},
|
|
813
|
+
// ------------------------------------------------------------------ carts
|
|
814
|
+
{
|
|
815
|
+
id: "list_abandoned_carts",
|
|
816
|
+
title: "List abandoned carts",
|
|
817
|
+
description: "Carts that were started but never finalized, with recovery status \u2014 the abandoned-cart recovery list.",
|
|
818
|
+
kind: "read",
|
|
819
|
+
scopes: ["carts:read"],
|
|
820
|
+
input: [
|
|
821
|
+
{ name: "sinceDays", type: "number", required: false, description: "How many days back to look." },
|
|
822
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
823
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
824
|
+
{
|
|
825
|
+
name: "applicationId",
|
|
826
|
+
type: "string",
|
|
827
|
+
required: false,
|
|
828
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
829
|
+
}
|
|
830
|
+
],
|
|
831
|
+
requests: [
|
|
832
|
+
{ method: "GET", path: "/api/v1/abandoned-carts" },
|
|
833
|
+
{ method: "GET", path: "/api/v1/abandoned-carts/summary" }
|
|
834
|
+
],
|
|
835
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
836
|
+
guardrails: ["Report the summary as unavailable rather than failing the whole call if that sub-read errors."]
|
|
837
|
+
},
|
|
838
|
+
// ---------------------------------------------------------------- debugging
|
|
839
|
+
{
|
|
840
|
+
id: "search_events",
|
|
841
|
+
title: "Search the event log",
|
|
842
|
+
description: "Search the immutable event log by type or entity. The first stop when asking what actually happened to an order, cart or subscription.",
|
|
843
|
+
kind: "read",
|
|
844
|
+
scopes: ["events:read"],
|
|
845
|
+
input: [
|
|
846
|
+
{ name: "type", type: "string", required: false, description: "Event type, e.g. order.created." },
|
|
847
|
+
{ name: "entityType", type: "string", required: false, description: "Entity type filter." },
|
|
848
|
+
{ name: "entityId", type: "string", required: false, description: "Entity id filter." },
|
|
849
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
850
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
851
|
+
{
|
|
852
|
+
name: "applicationId",
|
|
853
|
+
type: "string",
|
|
854
|
+
required: false,
|
|
855
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
856
|
+
}
|
|
857
|
+
],
|
|
858
|
+
requests: [{ method: "GET", path: "/api/v1/events" }],
|
|
859
|
+
channels: ["mcp", "n8n"]
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
id: "list_webhook_deliveries",
|
|
863
|
+
title: "List webhook deliveries",
|
|
864
|
+
description: "Recent outbound webhook deliveries, filterable by endpoint, status and event type.",
|
|
865
|
+
kind: "read",
|
|
866
|
+
scopes: ["webhook_deliveries:read"],
|
|
867
|
+
input: [
|
|
868
|
+
{ name: "endpointId", type: "string", required: false, description: "Filter by endpoint." },
|
|
869
|
+
{
|
|
870
|
+
name: "status",
|
|
871
|
+
type: "string",
|
|
872
|
+
required: false,
|
|
873
|
+
description: "Filter by delivery status: pending, delivered, failed or dead_letter."
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
name: "eventType",
|
|
877
|
+
type: "string",
|
|
878
|
+
required: false,
|
|
879
|
+
description: "Filter by exact event type, e.g. payment.failed."
|
|
880
|
+
},
|
|
881
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
882
|
+
{
|
|
883
|
+
name: "applicationId",
|
|
884
|
+
type: "string",
|
|
885
|
+
required: false,
|
|
886
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
887
|
+
}
|
|
888
|
+
],
|
|
889
|
+
requests: [{ method: "GET", path: "/api/v1/webhook-deliveries" }],
|
|
890
|
+
channels: ["mcp", "n8n"]
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
id: "get_webhook_delivery",
|
|
894
|
+
title: "Get one webhook delivery",
|
|
895
|
+
description: "Full delivery record: the signed payload we sent, the response we got back, and every attempt.",
|
|
896
|
+
kind: "read",
|
|
897
|
+
scopes: ["webhook_deliveries:read"],
|
|
898
|
+
input: [
|
|
899
|
+
{ name: "id", type: "string", required: true, description: "Delivery id." },
|
|
900
|
+
{
|
|
901
|
+
name: "applicationId",
|
|
902
|
+
type: "string",
|
|
903
|
+
required: false,
|
|
904
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
905
|
+
}
|
|
906
|
+
],
|
|
907
|
+
requests: [{ method: "GET", path: "/api/v1/webhook-deliveries/:id" }],
|
|
908
|
+
channels: ["mcp", "n8n"]
|
|
909
|
+
},
|
|
910
|
+
{
|
|
911
|
+
id: "explain_checkout_failure",
|
|
912
|
+
title: "Explain why a checkout failed",
|
|
913
|
+
description: "Diagnose a failing checkout in one call: session state, its cart, the events it emitted, and any webhook deliveries that followed. Use this before asking the user to reproduce anything.",
|
|
914
|
+
kind: "read",
|
|
915
|
+
scopes: ["checkout_sessions:read"],
|
|
916
|
+
sectionScopes: ["events:read", "webhook_deliveries:read"],
|
|
917
|
+
input: [
|
|
918
|
+
{
|
|
919
|
+
name: "id",
|
|
920
|
+
type: "string",
|
|
921
|
+
required: true,
|
|
922
|
+
description: "Checkout session id (or cart id \u2014 the tool resolves the session)."
|
|
923
|
+
},
|
|
924
|
+
{
|
|
925
|
+
name: "applicationId",
|
|
926
|
+
type: "string",
|
|
927
|
+
required: false,
|
|
928
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
929
|
+
}
|
|
930
|
+
],
|
|
931
|
+
requests: [
|
|
932
|
+
{ method: "GET", path: "/api/v1/checkout-sessions/:id" },
|
|
933
|
+
{ method: "GET", path: "/api/v1/checkout-sessions/:id/cart" },
|
|
934
|
+
{ method: "GET", path: "/api/v1/events" },
|
|
935
|
+
{ method: "GET", path: "/api/v1/webhook-deliveries" }
|
|
936
|
+
],
|
|
937
|
+
channels: ["mcp"],
|
|
938
|
+
guardrails: [
|
|
939
|
+
"Report which sections were unavailable rather than failing the call when a sub-read is unscoped.",
|
|
940
|
+
OAUTH_WITHHELD
|
|
941
|
+
]
|
|
942
|
+
},
|
|
943
|
+
// ------------------------------------------------------------- extensions
|
|
944
|
+
{
|
|
945
|
+
id: "list_extension_installations",
|
|
946
|
+
title: "List installed extensions",
|
|
947
|
+
description: "Extensions installed on this application, with status and configuration.",
|
|
948
|
+
kind: "read",
|
|
949
|
+
scopes: ["extensions:read"],
|
|
950
|
+
input: [
|
|
951
|
+
{
|
|
952
|
+
name: "status",
|
|
953
|
+
type: "string",
|
|
954
|
+
required: false,
|
|
955
|
+
description: "Filter by installation status.",
|
|
956
|
+
enum: ["active", "suspended", "uninstalled"]
|
|
957
|
+
},
|
|
958
|
+
{ name: "limit", type: "number", required: false, description: "Page size." },
|
|
959
|
+
{ name: "cursor", type: "string", required: false, description: "Pagination cursor." },
|
|
960
|
+
{
|
|
961
|
+
name: "applicationId",
|
|
962
|
+
type: "string",
|
|
963
|
+
required: false,
|
|
964
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
965
|
+
}
|
|
966
|
+
],
|
|
967
|
+
requests: [{ method: "GET", path: "/api/v1/installations" }],
|
|
968
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
969
|
+
},
|
|
970
|
+
// ------------------------------------------------------------- connectors
|
|
971
|
+
{
|
|
972
|
+
id: "get_connector_routing",
|
|
973
|
+
title: "Payment routing and decline rules",
|
|
974
|
+
description: "Read the payment-routing cascade, active routing connectors, and card/other decline rules \u2014 what determines which processor handles a payment and what happens on a decline.",
|
|
975
|
+
kind: "read",
|
|
976
|
+
scopes: ["connectors:read"],
|
|
977
|
+
input: [
|
|
978
|
+
{
|
|
979
|
+
name: "applicationId",
|
|
980
|
+
type: "string",
|
|
981
|
+
required: false,
|
|
982
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
983
|
+
}
|
|
984
|
+
],
|
|
985
|
+
requests: [
|
|
986
|
+
{ method: "GET", path: "/api/v1/payment-routing" },
|
|
987
|
+
{ method: "GET", path: "/api/v1/routing-connectors" },
|
|
988
|
+
{ method: "GET", path: "/api/v1/card-decline" },
|
|
989
|
+
{ method: "GET", path: "/api/v1/other-decline" }
|
|
990
|
+
],
|
|
991
|
+
channels: ["mcp"],
|
|
992
|
+
guardrails: [
|
|
993
|
+
"Every sub-read proxies live to the payment provider's routing API and none are guaranteed to succeed together; report any that fail as unavailable rather than failing the whole call."
|
|
994
|
+
]
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
id: "get_integration_status",
|
|
998
|
+
title: "Integration readiness",
|
|
999
|
+
description: 'Answers "am I ready to go live?" \u2014 active connectors, webhook endpoints and their recent delivery health, and the environment this credential is pinned to.',
|
|
1000
|
+
kind: "read",
|
|
1001
|
+
scopes: [],
|
|
1002
|
+
sectionScopes: ["connectors:read", "webhooks:read"],
|
|
1003
|
+
input: [
|
|
1004
|
+
{
|
|
1005
|
+
name: "applicationId",
|
|
1006
|
+
type: "string",
|
|
1007
|
+
required: false,
|
|
1008
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1009
|
+
}
|
|
1010
|
+
],
|
|
1011
|
+
requests: [
|
|
1012
|
+
{ method: "GET", path: "/api/v1/whoami" },
|
|
1013
|
+
{ method: "GET", path: "/api/v1/connectors" },
|
|
1014
|
+
{ method: "GET", path: "/api/v1/webhook-endpoints" },
|
|
1015
|
+
{ method: "GET", path: "/api/v1/webhook-endpoints/coverage" }
|
|
1016
|
+
],
|
|
1017
|
+
channels: ["mcp"],
|
|
1018
|
+
guardrails: [
|
|
1019
|
+
'Each section needs its own scope (connectors:read, webhooks:read). Report a section as "not readable with this credential" instead of failing.'
|
|
1020
|
+
]
|
|
1021
|
+
},
|
|
1022
|
+
// --------------------------------------------------------------- workspace
|
|
1023
|
+
{
|
|
1024
|
+
id: "get_workspace_settings",
|
|
1025
|
+
title: "Get workspace settings",
|
|
1026
|
+
description: "Read this workspace's identity: name, slug, branding and onboarding state. Payment terms are set per application and environment, not here.",
|
|
1027
|
+
kind: "read",
|
|
1028
|
+
scopes: ["merchant:read"],
|
|
1029
|
+
input: [],
|
|
1030
|
+
requests: [{ method: "GET", path: "/api/v1/merchants/me" }],
|
|
1031
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
1032
|
+
},
|
|
1033
|
+
{
|
|
1034
|
+
id: "get_audit_log",
|
|
1035
|
+
title: "Get the workspace audit log",
|
|
1036
|
+
description: "Recent admin actions taken on this workspace \u2014 invites, billing changes, key rotation, suspensions.",
|
|
1037
|
+
kind: "read",
|
|
1038
|
+
scopes: ["audit_logs:read"],
|
|
1039
|
+
input: [
|
|
1040
|
+
{ name: "limit", type: "number", required: false, description: "Maximum entries (1-200).", default: 100 }
|
|
1041
|
+
],
|
|
1042
|
+
requests: [{ method: "GET", path: "/api/v1/audit-log" }],
|
|
1043
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
id: "list_applications",
|
|
1047
|
+
title: "List applications in this workspace",
|
|
1048
|
+
description: 'List every application in this workspace you have access to, so you can pass one of their ids as applicationId on other read and analytics tools. Note: the underlying route is the legacy-named /v1/stores (kept for contract stability) \u2014 the resource it returns is applications, not a separate "stores" concept.',
|
|
1049
|
+
kind: "read",
|
|
1050
|
+
scopes: ["applications:read"],
|
|
1051
|
+
input: [],
|
|
1052
|
+
requests: [{ method: "GET", path: "/api/v1/stores" }],
|
|
1053
|
+
channels: ["mcp", "zapier", "make", "n8n"]
|
|
1054
|
+
},
|
|
1055
|
+
{
|
|
1056
|
+
id: "get_sales_timeseries",
|
|
1057
|
+
title: "Sales over time",
|
|
1058
|
+
description: `Order count and gross revenue bucketed by day, week or month over any date range, in the merchant's timezone, optionally compared to the previous period or the same range last year. Use this for "how much did we sell on/last/between\u2026" instead of paging search_orders and adding it up.`,
|
|
1059
|
+
kind: "read",
|
|
1060
|
+
scopes: ["orders:read"],
|
|
1061
|
+
input: [
|
|
1062
|
+
{ name: "from", type: "string", required: false, description: 'ISO 8601 start of range, exclusive. Defaults to 30 days before "to".' },
|
|
1063
|
+
{ name: "to", type: "string", required: false, description: "ISO 8601 end of range, exclusive. Defaults to now." },
|
|
1064
|
+
{ name: "groupBy", type: "string", required: false, description: "Bucket size.", enum: ["day", "week", "month"], default: "day" },
|
|
1065
|
+
{ name: "timezone", type: "string", required: false, description: "IANA timezone for bucket boundaries, e.g. America/New_York. Defaults to UTC \u2014 ask the user rather than assuming UTC when the answer depends on day boundaries." },
|
|
1066
|
+
{ name: "compareTo", type: "string", required: false, description: "Add a comparison total.", enum: ["previous_period", "previous_year", "none"], default: "none" },
|
|
1067
|
+
{
|
|
1068
|
+
name: "applicationId",
|
|
1069
|
+
type: "string",
|
|
1070
|
+
required: false,
|
|
1071
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1072
|
+
}
|
|
1073
|
+
],
|
|
1074
|
+
requests: [{ method: "GET", path: "/api/v1/analytics/orders-timeseries" }],
|
|
1075
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1076
|
+
guardrails: [
|
|
1077
|
+
"Revenue is GROSS. Refunds are not deducted, because that needs payment_refunds:read, which OAuth connections cannot hold. Never describe the figure as net."
|
|
1078
|
+
]
|
|
1079
|
+
},
|
|
1080
|
+
{
|
|
1081
|
+
id: "get_business_summary",
|
|
1082
|
+
title: "Business summary",
|
|
1083
|
+
description: "How are we doing? Orders/revenue, subscription MRR, receivables and quotes pipeline over a date range, compared to the immediately preceding window of equal length. Note: period=week|month|quarter means the TRAILING 7/30/90 days, not a calendar period \u2014 pass from/to for calendar months.",
|
|
1084
|
+
kind: "read",
|
|
1085
|
+
scopes: [],
|
|
1086
|
+
sectionScopes: ["orders:read", "subscriptions:read", "invoices:read", "quotes:read"],
|
|
1087
|
+
input: [
|
|
1088
|
+
{
|
|
1089
|
+
name: "period",
|
|
1090
|
+
type: "string",
|
|
1091
|
+
required: false,
|
|
1092
|
+
description: "Reporting window.",
|
|
1093
|
+
enum: ["week", "month", "quarter"],
|
|
1094
|
+
default: "month"
|
|
1095
|
+
},
|
|
1096
|
+
{ name: "from", type: "string", required: false, description: "ISO 8601 start of range. Overrides period." },
|
|
1097
|
+
{ name: "to", type: "string", required: false, description: "ISO 8601 end of range. Defaults to now." },
|
|
1098
|
+
{ name: "timezone", type: "string", required: false, description: "IANA timezone for period boundaries. Defaults to UTC." },
|
|
1099
|
+
{
|
|
1100
|
+
name: "applicationId",
|
|
1101
|
+
type: "string",
|
|
1102
|
+
required: false,
|
|
1103
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1104
|
+
}
|
|
1105
|
+
],
|
|
1106
|
+
requests: [{ method: "GET", path: "/api/v1/analytics/business-summary" }],
|
|
1107
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1108
|
+
guardrails: [
|
|
1109
|
+
"Each section needs its own scope (orders:read, subscriptions:read, invoices:read, quotes:read). A section without its scope is reported as omitted rather than failing the whole call."
|
|
1110
|
+
]
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
id: "get_top_products",
|
|
1114
|
+
title: "Top products",
|
|
1115
|
+
description: "Best-selling products over a date range, by revenue or units sold. Line items come from the merchant's own cart payload, so a product is identified by its external reference id when present and by name otherwise. The response carries both the top-N rows (by the chosen sort) and range-wide totals across every matching product, so you can compute what share of total revenue/units the top N represent.",
|
|
1116
|
+
kind: "read",
|
|
1117
|
+
scopes: ["orders:read"],
|
|
1118
|
+
input: [
|
|
1119
|
+
{ name: "from", type: "string", required: false, description: 'ISO 8601 start of range, exclusive. Defaults to 30 days before "to".' },
|
|
1120
|
+
{ name: "to", type: "string", required: false, description: "ISO 8601 end of range, exclusive. Defaults to now." },
|
|
1121
|
+
{ name: "timezone", type: "string", required: false, description: "IANA timezone for range boundaries. Defaults to UTC." },
|
|
1122
|
+
{ name: "by", type: "string", required: false, description: "Sort key.", enum: ["revenue", "units"], default: "revenue" },
|
|
1123
|
+
{ name: "limit", type: "number", required: false, description: "Max rows to return (1-100). Defaults to 20." },
|
|
1124
|
+
{
|
|
1125
|
+
name: "applicationId",
|
|
1126
|
+
type: "string",
|
|
1127
|
+
required: false,
|
|
1128
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1129
|
+
}
|
|
1130
|
+
],
|
|
1131
|
+
requests: [{ method: "GET", path: "/api/v1/analytics/products" }],
|
|
1132
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1133
|
+
guardrails: [
|
|
1134
|
+
"Revenue is GROSS. Refunds are not deducted, because that needs payment_refunds:read, which OAuth connections cannot hold. Never describe the figure as net."
|
|
1135
|
+
]
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
id: "get_attention_digest",
|
|
1139
|
+
title: "Attention digest",
|
|
1140
|
+
description: "What needs attention right now? Open disputes, subscriptions in dunning, overdue Net-N invoices, and webhooks with degraded delivery health \u2014 a point-in-time snapshot, not a time range.",
|
|
1141
|
+
kind: "read",
|
|
1142
|
+
scopes: [],
|
|
1143
|
+
sectionScopes: ["payment_disputes:read", "subscriptions:read", "invoices:read", "webhook_deliveries:read"],
|
|
1144
|
+
input: [
|
|
1145
|
+
{
|
|
1146
|
+
name: "applicationId",
|
|
1147
|
+
type: "string",
|
|
1148
|
+
required: false,
|
|
1149
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1150
|
+
}
|
|
1151
|
+
],
|
|
1152
|
+
requests: [{ method: "GET", path: "/api/v1/analytics/attention-digest" }],
|
|
1153
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1154
|
+
guardrails: [
|
|
1155
|
+
"Each section needs its own scope (payment_disputes:read, subscriptions:read, invoices:read, webhook_deliveries:read). A section without its scope is reported as omitted rather than failing the whole call."
|
|
1156
|
+
]
|
|
1157
|
+
},
|
|
1158
|
+
{
|
|
1159
|
+
id: "get_customer_growth",
|
|
1160
|
+
title: "Customer growth",
|
|
1161
|
+
description: "Customer growth over a date range: signups per day/week/month, how many orders came from first-time versus returning customers, and the highest-value customers in the window.",
|
|
1162
|
+
kind: "read",
|
|
1163
|
+
scopes: ["customers:read"],
|
|
1164
|
+
input: [
|
|
1165
|
+
{ name: "from", type: "string", required: false, description: 'ISO 8601 start of range, exclusive. Defaults to 30 days before "to".' },
|
|
1166
|
+
{ name: "to", type: "string", required: false, description: "ISO 8601 end of range, exclusive. Defaults to now." },
|
|
1167
|
+
{ name: "groupBy", type: "string", required: false, description: "Signup series bucket size.", enum: ["day", "week", "month"], default: "day" },
|
|
1168
|
+
{ name: "timezone", type: "string", required: false, description: "IANA timezone for bucket boundaries. Defaults to UTC." },
|
|
1169
|
+
{ name: "topBy", type: "string", required: false, description: "Sort key for top customers.", enum: ["revenue", "orders"], default: "revenue" },
|
|
1170
|
+
{ name: "topLimit", type: "number", required: false, description: "Max top-customers rows to return (1-50). Defaults to 10." },
|
|
1171
|
+
{
|
|
1172
|
+
name: "applicationId",
|
|
1173
|
+
type: "string",
|
|
1174
|
+
required: false,
|
|
1175
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1176
|
+
}
|
|
1177
|
+
],
|
|
1178
|
+
requests: [{ method: "GET", path: "/api/v1/analytics/customers" }],
|
|
1179
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1180
|
+
guardrails: [
|
|
1181
|
+
"Revenue is GROSS. Refunds are not deducted, because that needs payment_refunds:read, which OAuth connections cannot hold. Never describe the figure as net.",
|
|
1182
|
+
"topCustomers is a top-N list; use the accompanying totals for range-wide customer/order/revenue counts instead of summing the returned rows.",
|
|
1183
|
+
"topCustomers[].email and .name come back null unless the credential holds customer_pii:read, which OAuth connections cannot hold. Identify a top customer by id, not by a null name."
|
|
1184
|
+
]
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
id: "get_revenue_breakdown",
|
|
1188
|
+
title: "Revenue breakdown",
|
|
1189
|
+
description: "Revenue split by one dimension over a date range \u2014 payment method, order source, or currency. Amounts are gross; refunds are not deducted.",
|
|
1190
|
+
kind: "read",
|
|
1191
|
+
scopes: ["orders:read"],
|
|
1192
|
+
input: [
|
|
1193
|
+
{
|
|
1194
|
+
name: "dimension",
|
|
1195
|
+
type: "string",
|
|
1196
|
+
required: true,
|
|
1197
|
+
description: "Breakdown dimension.",
|
|
1198
|
+
enum: ["paymentMethod", "source", "currency"]
|
|
1199
|
+
},
|
|
1200
|
+
{ name: "from", type: "string", required: false, description: 'ISO 8601 start of range, exclusive. Defaults to 30 days before "to".' },
|
|
1201
|
+
{ name: "to", type: "string", required: false, description: "ISO 8601 end of range, exclusive. Defaults to now." },
|
|
1202
|
+
{ name: "timezone", type: "string", required: false, description: "IANA timezone for range boundaries. Defaults to UTC." },
|
|
1203
|
+
{
|
|
1204
|
+
name: "applicationId",
|
|
1205
|
+
type: "string",
|
|
1206
|
+
required: false,
|
|
1207
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1208
|
+
}
|
|
1209
|
+
],
|
|
1210
|
+
requests: [{ method: "GET", path: "/api/v1/analytics/revenue-breakdown" }],
|
|
1211
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1212
|
+
guardrails: [
|
|
1213
|
+
"Revenue is GROSS. Refunds are not deducted, because that needs payment_refunds:read, which OAuth connections cannot hold. Never describe the figure as net.",
|
|
1214
|
+
"dimension is required; it is never defaulted, so omitting it fails the call instead of silently picking a dimension.",
|
|
1215
|
+
"For dimension=paymentMethod, an order paid via more than one method can appear in more than one row, so rows can sum to more than totals (a separate whole-range aggregate over orders alone)."
|
|
1216
|
+
]
|
|
1217
|
+
},
|
|
1218
|
+
{
|
|
1219
|
+
id: "get_funnel_conversion",
|
|
1220
|
+
title: "Checkout funnel",
|
|
1221
|
+
description: "Checkout funnel over a date range: carts created, checkout sessions started, orders completed, with the drop-off between each stage.",
|
|
1222
|
+
kind: "read",
|
|
1223
|
+
scopes: ["carts:read"],
|
|
1224
|
+
input: [
|
|
1225
|
+
{ name: "from", type: "string", required: false, description: 'ISO 8601 start of range, exclusive. Defaults to 30 days before "to".' },
|
|
1226
|
+
{ name: "to", type: "string", required: false, description: "ISO 8601 end of range, exclusive. Defaults to now." },
|
|
1227
|
+
{ name: "timezone", type: "string", required: false, description: "IANA timezone for range boundaries. Defaults to UTC." },
|
|
1228
|
+
{
|
|
1229
|
+
name: "applicationId",
|
|
1230
|
+
type: "string",
|
|
1231
|
+
required: false,
|
|
1232
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1233
|
+
}
|
|
1234
|
+
],
|
|
1235
|
+
requests: [{ method: "GET", path: "/api/v1/analytics/funnel" }],
|
|
1236
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1237
|
+
guardrails: [
|
|
1238
|
+
"Each stage needs its own scope (carts:read, checkout_sessions:read, orders:read), checked independently \u2014 an OAuth grant carries literal scopes with no legacy expansion, so a credential can hold carts:read without the other two. An omitted stage is reported as such rather than failing the whole call.",
|
|
1239
|
+
"conversionRate and dropOff[].ratePct are null (unknown) when a stage they depend on is omitted, and 0 only when the stage was readable with a true zero count. Never treat a null here as 0.",
|
|
1240
|
+
'dropOff[].ratePct is the percentage of "from" that did NOT reach "to" (loss), not a conversion rate. The step-conversion rate is 100 - ratePct.'
|
|
1241
|
+
]
|
|
1242
|
+
},
|
|
1243
|
+
{
|
|
1244
|
+
id: "get_subscription_movement",
|
|
1245
|
+
title: "Subscription movement",
|
|
1246
|
+
description: "Subscription movement over a date range: new subscriptions, cancellations and net MRR change per day/week/month. Figures are reconstructed from subscription timestamps, not a stored historical snapshot.",
|
|
1247
|
+
kind: "read",
|
|
1248
|
+
scopes: ["subscriptions:read"],
|
|
1249
|
+
input: [
|
|
1250
|
+
{ name: "from", type: "string", required: false, description: 'ISO 8601 start of range, exclusive. Defaults to 30 days before "to".' },
|
|
1251
|
+
{ name: "to", type: "string", required: false, description: "ISO 8601 end of range, exclusive. Defaults to now." },
|
|
1252
|
+
{ name: "timezone", type: "string", required: false, description: "IANA timezone for bucket boundaries. Defaults to UTC." },
|
|
1253
|
+
{ name: "groupBy", type: "string", required: false, description: "Bucket size.", enum: ["day", "week", "month"], default: "day" },
|
|
1254
|
+
{
|
|
1255
|
+
name: "applicationId",
|
|
1256
|
+
type: "string",
|
|
1257
|
+
required: false,
|
|
1258
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1259
|
+
}
|
|
1260
|
+
],
|
|
1261
|
+
requests: [{ method: "GET", path: "/api/v1/analytics/subscriptions" }],
|
|
1262
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1263
|
+
guardrails: [
|
|
1264
|
+
"newSubscriptions, churnedSubscriptions and mrrDeltaCents are reconstructed per bucket from subscription created_at/cancelled_at timestamps, not a stored historical MRR snapshot \u2014 never present this series as an audited historical MRR ledger.",
|
|
1265
|
+
"mrrDeltaCents for a bucket only credits subscriptions created in that bucket that are still active right now, and only debits subscriptions cancelled in that bucket that already existed when it started. A subscription created AND cancelled inside the same bucket still counts toward both newSubscriptions and churnedSubscriptions but contributes 0 to mrrDeltaCents.",
|
|
1266
|
+
"totals is the sum over the full series (the series is never truncated), so totals.newSubscriptions/.churnedSubscriptions/.netMrrDeltaCents always equal the corresponding sums of series[]."
|
|
1267
|
+
]
|
|
1268
|
+
},
|
|
1269
|
+
{
|
|
1270
|
+
id: "get_discount_performance",
|
|
1271
|
+
title: "Discount performance",
|
|
1272
|
+
description: "Discount code performance over a date range: redemption count, revenue on discounted orders, and total discount given per code.",
|
|
1273
|
+
kind: "read",
|
|
1274
|
+
scopes: ["discounts:read"],
|
|
1275
|
+
input: [
|
|
1276
|
+
{ name: "from", type: "string", required: false, description: 'ISO 8601 start of range, exclusive. Defaults to 30 days before "to".' },
|
|
1277
|
+
{ name: "to", type: "string", required: false, description: "ISO 8601 end of range, exclusive. Defaults to now." },
|
|
1278
|
+
{ name: "timezone", type: "string", required: false, description: "IANA timezone for range boundaries. Defaults to UTC." },
|
|
1279
|
+
{ name: "limit", type: "number", required: false, description: "Max rows to return. Defaults to 20." },
|
|
1280
|
+
{
|
|
1281
|
+
name: "applicationId",
|
|
1282
|
+
type: "string",
|
|
1283
|
+
required: false,
|
|
1284
|
+
description: "Application to read from. Defaults to the one this connection was authorized for. Call list_applications to see the others."
|
|
1285
|
+
}
|
|
1286
|
+
],
|
|
1287
|
+
requests: [{ method: "GET", path: "/api/v1/analytics/discounts" }],
|
|
1288
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1289
|
+
guardrails: [
|
|
1290
|
+
'discountedRevenueCents and discountGivenCents are DIFFERENT measures: discountedRevenueCents is the gross order total on orders that redeemed the code; discountGivenCents is the discount amount taken off those same orders. Never describe discountedRevenueCents as "given away" or discountGivenCents as revenue.',
|
|
1291
|
+
"Only orders with status <> draft and a gross-eligible payment_status are counted; refunds are not deducted from discountedRevenueCents, because that needs payment_refunds:read.",
|
|
1292
|
+
"rows are the top N codes by discount given; totals is a SEPARATE whole-range aggregate (not a reduction over rows), so totals.redemptions / totals.discountGivenCents stay valid even when rows is truncated by limit."
|
|
1293
|
+
]
|
|
1294
|
+
},
|
|
1295
|
+
// ------------------------------------------------------------ sandbox write
|
|
1296
|
+
{
|
|
1297
|
+
id: "seed_test_data",
|
|
1298
|
+
title: "Seed test data (non-production only)",
|
|
1299
|
+
description: "Create a realistic customer, cart, line items and a finalized draft order so an integration has something to read. Refuses to run against production.",
|
|
1300
|
+
kind: "write",
|
|
1301
|
+
scopes: ["customers:write", "carts:write", "cart_items:write"],
|
|
1302
|
+
input: [
|
|
1303
|
+
{ name: "customerEmail", type: "string", required: false, description: "Email for the seeded customer." },
|
|
1304
|
+
{ name: "lineItems", type: "array", required: false, description: "Line items; a sensible default set is used when omitted." }
|
|
1305
|
+
],
|
|
1306
|
+
requests: [
|
|
1307
|
+
{ method: "POST", path: "/api/v1/customers" },
|
|
1308
|
+
{ method: "POST", path: "/api/v1/carts" },
|
|
1309
|
+
{ method: "POST", path: "/api/v1/carts/:id/items" },
|
|
1310
|
+
{ method: "POST", path: "/api/v1/carts/:id/finalize" }
|
|
1311
|
+
],
|
|
1312
|
+
channels: ["mcp"],
|
|
1313
|
+
sandboxOnly: true,
|
|
1314
|
+
idempotent: true,
|
|
1315
|
+
guardrails: [
|
|
1316
|
+
"Hard-refuse when the credential resolves to a production environment, regardless of any allow-writes flag.",
|
|
1317
|
+
"Seeds a finalized DRAFT order \u2014 it does not capture a payment, which needs a browser-side tokenised payment method."
|
|
1318
|
+
]
|
|
1319
|
+
},
|
|
1320
|
+
// ---------------------------------------------------------- inbound writes
|
|
1321
|
+
// The no-code channels are mostly used in the "something happened elsewhere,
|
|
1322
|
+
// put it into Throttle" direction — a form submission, a new CRM contact, a
|
|
1323
|
+
// spreadsheet row. These three are that direction.
|
|
1324
|
+
{
|
|
1325
|
+
id: "create_customer",
|
|
1326
|
+
title: "Create a customer",
|
|
1327
|
+
description: "Create a customer record. Use search_customers first if the buyer may already exist \u2014 this does not de-duplicate by email.",
|
|
1328
|
+
kind: "write",
|
|
1329
|
+
scopes: ["customers:write"],
|
|
1330
|
+
input: [
|
|
1331
|
+
{ name: "email", type: "string", required: true, description: "The buyer's email address." },
|
|
1332
|
+
{ name: "firstName", type: "string", required: false, description: "Given name." },
|
|
1333
|
+
{ name: "lastName", type: "string", required: false, description: "Family name." },
|
|
1334
|
+
{ name: "phone", type: "string", required: false, description: "Contact phone number." },
|
|
1335
|
+
{ name: "company", type: "string", required: false, description: "The buyer's company." },
|
|
1336
|
+
{
|
|
1337
|
+
name: "externalId",
|
|
1338
|
+
type: "string",
|
|
1339
|
+
required: false,
|
|
1340
|
+
description: "This customer's id in your own system. Resolvable later via get_customer."
|
|
1341
|
+
},
|
|
1342
|
+
{
|
|
1343
|
+
name: "netN",
|
|
1344
|
+
type: "number",
|
|
1345
|
+
required: false,
|
|
1346
|
+
description: "Invoice terms in days for this customer specifically, 0-365. Omit to use the workspace default; 0 means due on issue."
|
|
1347
|
+
},
|
|
1348
|
+
{
|
|
1349
|
+
name: "acceptsMarketing",
|
|
1350
|
+
type: "boolean",
|
|
1351
|
+
required: false,
|
|
1352
|
+
description: "Whether the buyer opted into marketing email.",
|
|
1353
|
+
default: false
|
|
1354
|
+
}
|
|
1355
|
+
],
|
|
1356
|
+
requests: [{ method: "POST", path: "/api/v1/customers" }],
|
|
1357
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1358
|
+
idempotent: true,
|
|
1359
|
+
guardrails: [
|
|
1360
|
+
"The created record is echoed back with email, phone, firstName, lastName and name nulled unless the credential holds customer_pii:read, which OAuth connections cannot hold \u2014 the customer is still created with the values sent, only the response is redacted."
|
|
1361
|
+
]
|
|
1362
|
+
},
|
|
1363
|
+
{
|
|
1364
|
+
id: "update_customer",
|
|
1365
|
+
title: "Update a customer",
|
|
1366
|
+
description: "Change fields on an existing customer. Only the fields supplied are touched; everything else is left alone.",
|
|
1367
|
+
kind: "write",
|
|
1368
|
+
scopes: ["customers:write"],
|
|
1369
|
+
input: [
|
|
1370
|
+
{ name: "id", type: "string", required: true, description: "Customer id." },
|
|
1371
|
+
{ name: "email", type: "string", required: false, description: "The buyer's email address." },
|
|
1372
|
+
{ name: "firstName", type: "string", required: false, description: "Given name." },
|
|
1373
|
+
{ name: "lastName", type: "string", required: false, description: "Family name." },
|
|
1374
|
+
{ name: "phone", type: "string", required: false, description: "Contact phone number." },
|
|
1375
|
+
{ name: "company", type: "string", required: false, description: "The buyer's company." },
|
|
1376
|
+
{
|
|
1377
|
+
name: "externalId",
|
|
1378
|
+
type: "string",
|
|
1379
|
+
required: false,
|
|
1380
|
+
description: "This customer's id in your own system. Pass null to clear it."
|
|
1381
|
+
},
|
|
1382
|
+
{
|
|
1383
|
+
name: "netN",
|
|
1384
|
+
type: "number",
|
|
1385
|
+
required: false,
|
|
1386
|
+
description: "Invoice terms in days for this customer specifically, 0-365."
|
|
1387
|
+
},
|
|
1388
|
+
{
|
|
1389
|
+
name: "acceptsMarketing",
|
|
1390
|
+
type: "boolean",
|
|
1391
|
+
required: false,
|
|
1392
|
+
description: "Whether the buyer opted into marketing email."
|
|
1393
|
+
}
|
|
1394
|
+
],
|
|
1395
|
+
requests: [{ method: "PATCH", path: "/api/v1/customers/:id" }],
|
|
1396
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1397
|
+
idempotent: true,
|
|
1398
|
+
guardrails: [
|
|
1399
|
+
"The updated record is echoed back with email, phone, firstName, lastName and name nulled unless the credential holds customer_pii:read, which OAuth connections cannot hold \u2014 the update still applied, only the response is redacted."
|
|
1400
|
+
]
|
|
1401
|
+
},
|
|
1402
|
+
{
|
|
1403
|
+
id: "create_checkout_link",
|
|
1404
|
+
title: "Create a checkout link",
|
|
1405
|
+
description: "Build a cart from line items and return a hosted checkout URL the buyer can pay at. Prices are in minor units (2500 = $25.00).",
|
|
1406
|
+
kind: "write",
|
|
1407
|
+
scopes: ["carts:write", "cart_items:write", "checkout_sessions:write"],
|
|
1408
|
+
input: [
|
|
1409
|
+
{
|
|
1410
|
+
name: "lineItems",
|
|
1411
|
+
type: "array",
|
|
1412
|
+
required: true,
|
|
1413
|
+
description: "What the buyer is paying for: { name, unitPrice, quantity }. unitPrice is an integer in minor units."
|
|
1414
|
+
},
|
|
1415
|
+
{
|
|
1416
|
+
name: "returnUrl",
|
|
1417
|
+
type: "string",
|
|
1418
|
+
required: true,
|
|
1419
|
+
description: "Absolute URL the buyer lands on after paying."
|
|
1420
|
+
},
|
|
1421
|
+
{
|
|
1422
|
+
name: "cancelUrl",
|
|
1423
|
+
type: "string",
|
|
1424
|
+
required: true,
|
|
1425
|
+
description: "Absolute URL the buyer lands on if they abandon checkout."
|
|
1426
|
+
},
|
|
1427
|
+
{
|
|
1428
|
+
name: "customerId",
|
|
1429
|
+
type: "string",
|
|
1430
|
+
required: false,
|
|
1431
|
+
description: "Attach the cart to an existing customer."
|
|
1432
|
+
},
|
|
1433
|
+
{
|
|
1434
|
+
name: "customerEmail",
|
|
1435
|
+
type: "string",
|
|
1436
|
+
required: false,
|
|
1437
|
+
description: "Pre-fill the buyer email without needing a customer record."
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
name: "discountCode",
|
|
1441
|
+
type: "string",
|
|
1442
|
+
required: false,
|
|
1443
|
+
description: "Discount code to apply to the session."
|
|
1444
|
+
},
|
|
1445
|
+
{
|
|
1446
|
+
name: "netN",
|
|
1447
|
+
type: "number",
|
|
1448
|
+
required: false,
|
|
1449
|
+
description: "Invoice terms in days for this cart, 0-365. Omit to pay in full at checkout."
|
|
1450
|
+
}
|
|
1451
|
+
],
|
|
1452
|
+
// Three calls: the API has no single "checkout link" endpoint, and a
|
|
1453
|
+
// checkout session requires a cart that already holds its line items.
|
|
1454
|
+
requests: [
|
|
1455
|
+
{ method: "POST", path: "/api/v1/carts" },
|
|
1456
|
+
{ method: "POST", path: "/api/v1/carts/:id/items" },
|
|
1457
|
+
{ method: "POST", path: "/api/v1/checkout/sessions" }
|
|
1458
|
+
],
|
|
1459
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1460
|
+
idempotent: true,
|
|
1461
|
+
guardrails: [
|
|
1462
|
+
"The returned URL is buyer-facing and takes real payment in a production environment."
|
|
1463
|
+
]
|
|
1464
|
+
},
|
|
1465
|
+
// -------------------------------------------------------------- money/mail
|
|
1466
|
+
{
|
|
1467
|
+
id: "create_quote",
|
|
1468
|
+
title: "Create a quote",
|
|
1469
|
+
description: "Draft a quote for a customer with line items and terms. Does not send it \u2014 use send_quote.",
|
|
1470
|
+
kind: "write",
|
|
1471
|
+
scopes: ["quotes:write"],
|
|
1472
|
+
input: [
|
|
1473
|
+
{ name: "customerId", type: "string", required: true, description: "Customer the quote is for." },
|
|
1474
|
+
{ name: "items", type: "array", required: true, description: "Quote line items: { name, unitPrice, quantity }." },
|
|
1475
|
+
{ name: "expiresAt", type: "string", required: false, description: "ISO 8601 expiry." },
|
|
1476
|
+
{ name: "netN", type: "number", required: false, description: "Payment terms in days. Omit for pay-in-full." },
|
|
1477
|
+
{ name: "notes", type: "string", required: false, description: "Buyer-visible notes." }
|
|
1478
|
+
],
|
|
1479
|
+
requests: [{ method: "POST", path: "/api/v1/quotes" }],
|
|
1480
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1481
|
+
idempotent: true
|
|
1482
|
+
},
|
|
1483
|
+
{
|
|
1484
|
+
id: "send_quote",
|
|
1485
|
+
title: "Issue and send a quote",
|
|
1486
|
+
description: "Issue a draft quote and email the buyer their quote link. This is buyer-visible \u2014 confirm with the user before calling it.",
|
|
1487
|
+
kind: "write",
|
|
1488
|
+
scopes: ["quotes:write"],
|
|
1489
|
+
input: [{ name: "id", type: "string", required: true, description: "Quote id." }],
|
|
1490
|
+
requests: [{ method: "POST", path: "/api/v1/quotes/:id/issue" }],
|
|
1491
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1492
|
+
idempotent: true,
|
|
1493
|
+
guardrails: ['Sends mail to a real buyer. Never call it speculatively or to "check" a quote.'],
|
|
1494
|
+
destructive: true
|
|
1495
|
+
},
|
|
1496
|
+
{
|
|
1497
|
+
id: "refund_payment",
|
|
1498
|
+
title: "Refund a payment",
|
|
1499
|
+
description: "Refund a captured payment. The amount is required \u2014 never infer a full refund from an unspecified amount.",
|
|
1500
|
+
kind: "write",
|
|
1501
|
+
scopes: ["payment_refunds:write"],
|
|
1502
|
+
input: [
|
|
1503
|
+
{ name: "id", type: "string", required: true, description: "Payment id." },
|
|
1504
|
+
{
|
|
1505
|
+
name: "amount",
|
|
1506
|
+
type: "number",
|
|
1507
|
+
required: true,
|
|
1508
|
+
description: "Amount to refund in minor units. Required \u2014 omitting it would refund the whole payment."
|
|
1509
|
+
},
|
|
1510
|
+
{ name: "reason", type: "string", required: false, description: "Reason recorded on the refund." }
|
|
1511
|
+
],
|
|
1512
|
+
requests: [{ method: "POST", path: "/api/v1/payments/:id/refund" }],
|
|
1513
|
+
// NOT zapier/make. `payment_refunds:write` is `sensitive` in the scope
|
|
1514
|
+
// registry, and `validateScopesForOAuth` rejects every sensitive scope — so
|
|
1515
|
+
// an OAuth grant, which is the only credential a public Zapier or Make app
|
|
1516
|
+
// can hold, can never carry it. Listing the action on those channels would
|
|
1517
|
+
// ship a connector action that 403s on every call. MCP and n8n keep it:
|
|
1518
|
+
// both authenticate with an `sk_` key, which CAN hold the scope.
|
|
1519
|
+
// `oauth-grantable-scopes` in the catalog tests enforces this.
|
|
1520
|
+
channels: ["mcp", "n8n"],
|
|
1521
|
+
idempotent: true,
|
|
1522
|
+
guardrails: [
|
|
1523
|
+
"Moves money and is irreversible. Confirm with the user first.",
|
|
1524
|
+
"The API treats an omitted amount as a FULL refund, so this action requires it explicitly."
|
|
1525
|
+
],
|
|
1526
|
+
destructive: true
|
|
1527
|
+
},
|
|
1528
|
+
{
|
|
1529
|
+
id: "manage_subscription",
|
|
1530
|
+
title: "Pause or resume a subscription",
|
|
1531
|
+
description: "Pause or resume an active subscription.",
|
|
1532
|
+
kind: "write",
|
|
1533
|
+
scopes: ["subscription_pauses:write"],
|
|
1534
|
+
input: [
|
|
1535
|
+
{ name: "id", type: "string", required: true, description: "Subscription id." },
|
|
1536
|
+
{
|
|
1537
|
+
name: "action",
|
|
1538
|
+
type: "string",
|
|
1539
|
+
required: true,
|
|
1540
|
+
description: "What to do.",
|
|
1541
|
+
enum: ["pause", "resume"]
|
|
1542
|
+
}
|
|
1543
|
+
],
|
|
1544
|
+
requests: [
|
|
1545
|
+
{ method: "POST", path: "/api/v1/subscriptions/:id/pause" },
|
|
1546
|
+
{ method: "POST", path: "/api/v1/subscriptions/:id/resume" }
|
|
1547
|
+
],
|
|
1548
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1549
|
+
idempotent: true
|
|
1550
|
+
},
|
|
1551
|
+
{
|
|
1552
|
+
id: "cancel_subscription",
|
|
1553
|
+
title: "Cancel a subscription",
|
|
1554
|
+
description: "Cancel a subscription. Separate from pause/resume because it needs its own scope.",
|
|
1555
|
+
kind: "write",
|
|
1556
|
+
scopes: ["subscription_cancellations:write"],
|
|
1557
|
+
input: [
|
|
1558
|
+
{ name: "id", type: "string", required: true, description: "Subscription id." },
|
|
1559
|
+
{
|
|
1560
|
+
name: "atPeriodEnd",
|
|
1561
|
+
type: "boolean",
|
|
1562
|
+
required: false,
|
|
1563
|
+
description: "Cancel at the end of the current period instead of immediately."
|
|
1564
|
+
}
|
|
1565
|
+
],
|
|
1566
|
+
requests: [{ method: "POST", path: "/api/v1/subscriptions/:id/cancel" }],
|
|
1567
|
+
channels: ["mcp", "zapier", "make", "n8n"],
|
|
1568
|
+
idempotent: true,
|
|
1569
|
+
guardrails: ["Ends billing for a paying customer. Confirm with the user first."],
|
|
1570
|
+
destructive: true
|
|
1571
|
+
},
|
|
1572
|
+
{
|
|
1573
|
+
id: "replay_webhook_delivery",
|
|
1574
|
+
title: "Replay a webhook delivery",
|
|
1575
|
+
description: "Re-send a past webhook delivery to its endpoint \u2014 useful after fixing a broken handler.",
|
|
1576
|
+
kind: "write",
|
|
1577
|
+
scopes: ["webhook_deliveries:write"],
|
|
1578
|
+
input: [{ name: "id", type: "string", required: true, description: "Delivery id." }],
|
|
1579
|
+
requests: [{ method: "POST", path: "/api/v1/webhook-deliveries/:id/replay" }],
|
|
1580
|
+
channels: ["mcp", "n8n"],
|
|
1581
|
+
idempotent: true,
|
|
1582
|
+
guardrails: ["The receiving system will process the event again. Confirm it is idempotent first."],
|
|
1583
|
+
destructive: true
|
|
1584
|
+
},
|
|
1585
|
+
{
|
|
1586
|
+
id: "send_test_webhook",
|
|
1587
|
+
title: "Send a test webhook",
|
|
1588
|
+
description: "Send a synthetic signed event to a webhook endpoint to verify signature handling and reachability.",
|
|
1589
|
+
kind: "write",
|
|
1590
|
+
scopes: ["webhooks:write"],
|
|
1591
|
+
input: [
|
|
1592
|
+
{ name: "id", type: "string", required: true, description: "Endpoint id." },
|
|
1593
|
+
{ name: "eventType", type: "string", required: false, description: "Event type to simulate." }
|
|
1594
|
+
],
|
|
1595
|
+
requests: [{ method: "POST", path: "/api/v1/webhook-endpoints/:id/test" }],
|
|
1596
|
+
channels: ["mcp", "n8n"],
|
|
1597
|
+
idempotent: true,
|
|
1598
|
+
destructive: true
|
|
1599
|
+
}
|
|
1600
|
+
];
|
|
1601
|
+
|
|
1602
|
+
// ../action-catalog/src/triggers.ts
|
|
1603
|
+
var NO_CODE = ["zapier", "make", "n8n"];
|
|
1604
|
+
function trigger(id, title, eventType, description) {
|
|
1605
|
+
return { id, title, eventType, description, scope: eventReadScope(eventType), channels: NO_CODE };
|
|
1606
|
+
}
|
|
1607
|
+
var TRIGGERS = [
|
|
1608
|
+
trigger("new_order", "New order", "order.created", "Fires when an order is created."),
|
|
1609
|
+
trigger(
|
|
1610
|
+
"payment_captured",
|
|
1611
|
+
"Payment captured",
|
|
1612
|
+
"payment.captured",
|
|
1613
|
+
"Fires when a payment is successfully captured."
|
|
1614
|
+
),
|
|
1615
|
+
trigger(
|
|
1616
|
+
"payment_failed",
|
|
1617
|
+
"Payment failed",
|
|
1618
|
+
"payment.failed",
|
|
1619
|
+
"Fires when a payment attempt fails."
|
|
1620
|
+
),
|
|
1621
|
+
trigger(
|
|
1622
|
+
"new_subscription",
|
|
1623
|
+
"New subscription",
|
|
1624
|
+
"subscription.created",
|
|
1625
|
+
"Fires when a subscription is created."
|
|
1626
|
+
),
|
|
1627
|
+
trigger(
|
|
1628
|
+
"subscription_cancelled",
|
|
1629
|
+
"Subscription cancelled",
|
|
1630
|
+
"subscription.cancelled",
|
|
1631
|
+
"Fires when a subscription is cancelled."
|
|
1632
|
+
),
|
|
1633
|
+
trigger(
|
|
1634
|
+
"quote_accepted",
|
|
1635
|
+
"Quote accepted",
|
|
1636
|
+
"quote.accepted",
|
|
1637
|
+
"Fires when a buyer accepts a quote."
|
|
1638
|
+
),
|
|
1639
|
+
trigger(
|
|
1640
|
+
"cart_abandoned",
|
|
1641
|
+
"Cart abandoned",
|
|
1642
|
+
"cart.abandoned",
|
|
1643
|
+
"Fires when a cart is marked abandoned."
|
|
1644
|
+
),
|
|
1645
|
+
trigger(
|
|
1646
|
+
"invoice_past_due",
|
|
1647
|
+
"Invoice past due",
|
|
1648
|
+
"invoice.past_due",
|
|
1649
|
+
"Fires when an invoice passes its due date unpaid."
|
|
1650
|
+
)
|
|
1651
|
+
];
|
|
1652
|
+
|
|
1653
|
+
// ../action-catalog/src/index.ts
|
|
1654
|
+
function actionsForChannel(channel) {
|
|
1655
|
+
return ACTIONS.filter((a) => a.channels.includes(channel));
|
|
1656
|
+
}
|
|
1657
|
+
function canRunAction(granted, action) {
|
|
1658
|
+
return action.scopes.every((required) => hasScope(granted, required));
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
// src/format.ts
|
|
1662
|
+
var MAX_CHARS = 24e3;
|
|
1663
|
+
function prune(value) {
|
|
1664
|
+
if (Array.isArray(value)) return value.map(prune);
|
|
1665
|
+
if (value && typeof value === "object") {
|
|
1666
|
+
const out = {};
|
|
1667
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
1668
|
+
if (inner === void 0 || inner === null) continue;
|
|
1669
|
+
out[key] = prune(inner);
|
|
1670
|
+
}
|
|
1671
|
+
return out;
|
|
1672
|
+
}
|
|
1673
|
+
return value;
|
|
1674
|
+
}
|
|
1675
|
+
function formatResult(value) {
|
|
1676
|
+
const text = JSON.stringify(prune(value), null, 2) ?? "null";
|
|
1677
|
+
if (text.length <= MAX_CHARS) return text;
|
|
1678
|
+
return `${text.slice(0, MAX_CHARS)}
|
|
1679
|
+
|
|
1680
|
+
\u2026 truncated at ${MAX_CHARS} characters. Narrow the query (lower "limit", add a filter) or fetch a single record.`;
|
|
1681
|
+
}
|
|
1682
|
+
function formatError(error) {
|
|
1683
|
+
const e = error;
|
|
1684
|
+
if (e?.code && e?.message) {
|
|
1685
|
+
const detail = e.details ? `
|
|
1686
|
+
|
|
1687
|
+
details: ${JSON.stringify(e.details)}` : "";
|
|
1688
|
+
return `Throttle API error ${e.code}${e.statusCode ? ` (HTTP ${e.statusCode})` : ""}: ${e.message}${detail}`;
|
|
1689
|
+
}
|
|
1690
|
+
return `Error: ${e?.message ?? String(error)}`;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
// ../errors/dist/index.js
|
|
1694
|
+
var ThrottleError = class extends Error {
|
|
1695
|
+
code;
|
|
1696
|
+
statusCode;
|
|
1697
|
+
details;
|
|
1698
|
+
body;
|
|
1699
|
+
constructor(args) {
|
|
1700
|
+
super(args.message);
|
|
1701
|
+
this.name = "ThrottleError";
|
|
1702
|
+
this.code = args.code;
|
|
1703
|
+
this.statusCode = args.statusCode;
|
|
1704
|
+
this.details = args.details;
|
|
1705
|
+
this.body = args.body;
|
|
1706
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
|
|
1710
|
+
// src/client.ts
|
|
1711
|
+
var ThrottleApiError = class extends ThrottleError {
|
|
1712
|
+
constructor(code, message, statusCode, details) {
|
|
1713
|
+
super({ code, message, statusCode, details });
|
|
1714
|
+
this.name = "ThrottleApiError";
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
function buildQuery(query) {
|
|
1718
|
+
if (!query) return "";
|
|
1719
|
+
const params = new URLSearchParams();
|
|
1720
|
+
for (const [key, value] of Object.entries(query)) {
|
|
1721
|
+
if (value === void 0 || value === null || value === "") continue;
|
|
1722
|
+
params.set(key, String(value));
|
|
1723
|
+
}
|
|
1724
|
+
const qs = params.toString();
|
|
1725
|
+
return qs ? `?${qs}` : "";
|
|
1726
|
+
}
|
|
1727
|
+
var API_KEY_PREFIX_RE = /^(sk_|pk_)/;
|
|
1728
|
+
var ThrottleClient = class {
|
|
1729
|
+
constructor(auth, fetchImpl = fetch) {
|
|
1730
|
+
this.auth = auth;
|
|
1731
|
+
this.fetchImpl = fetchImpl;
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Swap the credential every later request is sent with. The hosted remote
|
|
1735
|
+
* server builds one client per MCP session at `initialize`, but an OAuth
|
|
1736
|
+
* access token lives one hour and the MCP client refreshes it underneath
|
|
1737
|
+
* the session — each request then arrives with a newer bearer than the one
|
|
1738
|
+
* the session was opened with. Without this, the session keeps calling the
|
|
1739
|
+
* REST API with the token it was born with and every tool fails with a 401
|
|
1740
|
+
* the moment that first token expires, even though the caller is still
|
|
1741
|
+
* perfectly authenticated.
|
|
1742
|
+
*/
|
|
1743
|
+
setApiKey(apiKey) {
|
|
1744
|
+
this.auth = { ...this.auth, apiKey };
|
|
1745
|
+
}
|
|
1746
|
+
async requestJson(method, path, options = {}) {
|
|
1747
|
+
const url = `${this.auth.apiBaseUrl.replace(/\/$/, "")}${path}${buildQuery(options.query)}`;
|
|
1748
|
+
const headers = {
|
|
1749
|
+
"content-type": "application/json",
|
|
1750
|
+
"x-api-key": this.auth.apiKey,
|
|
1751
|
+
// Also sent as Authorization: Bearer — required for an OAuth access
|
|
1752
|
+
// token (the remote server's oauth_token sessions), which the auth
|
|
1753
|
+
// middleware only ever recognizes via this header (peeked by issuer),
|
|
1754
|
+
// never via x-api-key. For an sk_/pk_ key this is a no-op: the
|
|
1755
|
+
// middleware already treats `Authorization: Bearer sk_.../pk_...`
|
|
1756
|
+
// identically to `X-API-Key`, so existing stdio-CLI callers are
|
|
1757
|
+
// unaffected.
|
|
1758
|
+
Authorization: `Bearer ${this.auth.apiKey}`
|
|
1759
|
+
};
|
|
1760
|
+
if (options.idempotencyKey) headers["idempotency-key"] = options.idempotencyKey;
|
|
1761
|
+
if (options.applicationId && !API_KEY_PREFIX_RE.test(this.auth.apiKey)) {
|
|
1762
|
+
headers["x-throttle-application-id"] = options.applicationId;
|
|
1763
|
+
}
|
|
1764
|
+
const sendsBody = method === "POST" || method === "PATCH" || method === "PUT";
|
|
1765
|
+
const body = options.body !== void 0 ? JSON.stringify(options.body) : sendsBody ? "{}" : void 0;
|
|
1766
|
+
const res = await this.fetchImpl(url, { method, headers, body });
|
|
1767
|
+
const text = await res.text();
|
|
1768
|
+
let parsed = {};
|
|
1769
|
+
try {
|
|
1770
|
+
parsed = text ? JSON.parse(text) : {};
|
|
1771
|
+
} catch {
|
|
1772
|
+
}
|
|
1773
|
+
if (!res.ok) {
|
|
1774
|
+
const err = parsed.error;
|
|
1775
|
+
throw new ThrottleApiError(
|
|
1776
|
+
err?.code ?? `http_${res.status}`,
|
|
1777
|
+
err?.message ?? `Request failed (${res.status}): ${text.slice(0, 200)}`,
|
|
1778
|
+
res.status,
|
|
1779
|
+
err?.details
|
|
1780
|
+
);
|
|
1781
|
+
}
|
|
1782
|
+
return parsed;
|
|
1783
|
+
}
|
|
1784
|
+
/** Unwraps the `{ data }` envelope. Key presence, not `??` — `{data: null}` unwraps to null. */
|
|
1785
|
+
async get(path, query, options) {
|
|
1786
|
+
const body = await this.requestJson("GET", path, { query, applicationId: options?.applicationId });
|
|
1787
|
+
return body && typeof body === "object" && "data" in body ? body.data : body;
|
|
1788
|
+
}
|
|
1789
|
+
async list(path, query, options) {
|
|
1790
|
+
const body = await this.requestJson("GET", path, { query, applicationId: options?.applicationId });
|
|
1791
|
+
const data = "data" in body ? body.data : body;
|
|
1792
|
+
const meta = body.meta;
|
|
1793
|
+
return { data: Array.isArray(data) ? data : [], pagination: meta?.pagination ?? null };
|
|
1794
|
+
}
|
|
1795
|
+
async post(path, options = {}) {
|
|
1796
|
+
const body = await this.requestJson("POST", path, options);
|
|
1797
|
+
return body && typeof body === "object" && "data" in body ? body.data : body;
|
|
1798
|
+
}
|
|
1799
|
+
async patch(path, options = {}) {
|
|
1800
|
+
const body = await this.requestJson("PATCH", path, options);
|
|
1801
|
+
return body && typeof body === "object" && "data" in body ? body.data : body;
|
|
1802
|
+
}
|
|
1803
|
+
};
|
|
1804
|
+
async function optional(load) {
|
|
1805
|
+
try {
|
|
1806
|
+
return { ok: true, value: await load() };
|
|
1807
|
+
} catch (error) {
|
|
1808
|
+
const e = error;
|
|
1809
|
+
const code = e?.code ?? "error";
|
|
1810
|
+
const reason = code === "insufficient_scopes" ? "not readable with this credential (missing scope)" : code === "not_found" ? "not found" : `unavailable (${code})`;
|
|
1811
|
+
return { ok: false, unavailable: reason };
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
// src/contract.ts
|
|
1816
|
+
var RETIRED_FIELDS = {
|
|
1817
|
+
storeId: "applicationId",
|
|
1818
|
+
store_id: "applicationId",
|
|
1819
|
+
merchantId: "workspaceId",
|
|
1820
|
+
merchant_id: "workspaceId",
|
|
1821
|
+
customer_id: "customerId",
|
|
1822
|
+
line_items: "lineItems",
|
|
1823
|
+
unit_price: "unitPrice",
|
|
1824
|
+
external_id: "externalId",
|
|
1825
|
+
payment_method_id: "paymentMethodId",
|
|
1826
|
+
first_name: "firstName",
|
|
1827
|
+
last_name: "lastName",
|
|
1828
|
+
net_n: "netN",
|
|
1829
|
+
hosted_url: "hostedUrl",
|
|
1830
|
+
embed_url: "embedUrl",
|
|
1831
|
+
checkout_url: "checkoutUrl",
|
|
1832
|
+
order_number: "orderNumber",
|
|
1833
|
+
payment_status: "paymentStatus",
|
|
1834
|
+
allowed_origins: "allowedOrigins",
|
|
1835
|
+
enabled_events: "enabledEvents",
|
|
1836
|
+
template_key: "templateKey",
|
|
1837
|
+
request_id: "requestId",
|
|
1838
|
+
signing_secret: "signingSecret (returned once at creation; not accepted as input)"
|
|
1839
|
+
};
|
|
1840
|
+
function snakeToCamel(name) {
|
|
1841
|
+
return name.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
1842
|
+
}
|
|
1843
|
+
function normalizePath(path) {
|
|
1844
|
+
return path.replace(/\{[^}]+\}/g, "{}").replace(/:[A-Za-z0-9_]+/g, "{}").replace(/\/$/, "");
|
|
1845
|
+
}
|
|
1846
|
+
function segmentsOf(path) {
|
|
1847
|
+
return path.split("?")[0].replace(/\/$/, "").split("/").filter(Boolean);
|
|
1848
|
+
}
|
|
1849
|
+
function isParamSegment(segment) {
|
|
1850
|
+
return /^\{[^}]+\}$/.test(segment) || /^:[A-Za-z0-9_]+$/.test(segment);
|
|
1851
|
+
}
|
|
1852
|
+
function pathMatches(template, candidate) {
|
|
1853
|
+
const t = segmentsOf(template);
|
|
1854
|
+
const c = segmentsOf(candidate);
|
|
1855
|
+
if (t.length !== c.length) return false;
|
|
1856
|
+
return t.every((segment, i) => isParamSegment(segment) || isParamSegment(c[i]) || segment === c[i]);
|
|
1857
|
+
}
|
|
1858
|
+
function paramCount(path) {
|
|
1859
|
+
return segmentsOf(path).filter(isParamSegment).length;
|
|
1860
|
+
}
|
|
1861
|
+
function findOperations(index, query) {
|
|
1862
|
+
const method = query.method?.toUpperCase();
|
|
1863
|
+
const wanted = query.path.trim();
|
|
1864
|
+
const byMethod = (op) => !method || op.method === method;
|
|
1865
|
+
const matched = index.operations.filter((op) => byMethod(op) && pathMatches(op.path, wanted)).sort((a, b) => paramCount(a.path) - paramCount(b.path));
|
|
1866
|
+
if (matched.length > 0) return matched;
|
|
1867
|
+
const needle = normalizePath(wanted).replace(/^\/+/, "");
|
|
1868
|
+
return index.operations.filter((op) => byMethod(op) && normalizePath(op.path).includes(needle));
|
|
1869
|
+
}
|
|
1870
|
+
function validatePayload(index, input) {
|
|
1871
|
+
const errors = [];
|
|
1872
|
+
const warnings = [];
|
|
1873
|
+
const keys = Object.keys(input.body ?? {});
|
|
1874
|
+
for (const key of keys) {
|
|
1875
|
+
const retired = RETIRED_FIELDS[key];
|
|
1876
|
+
if (retired) {
|
|
1877
|
+
errors.push({
|
|
1878
|
+
field: key,
|
|
1879
|
+
problem: "retired public field name \u2014 the API rejects it",
|
|
1880
|
+
suggestion: `use "${retired}"`
|
|
1881
|
+
});
|
|
1882
|
+
continue;
|
|
1883
|
+
}
|
|
1884
|
+
if (key.includes("_")) {
|
|
1885
|
+
errors.push({
|
|
1886
|
+
field: key,
|
|
1887
|
+
problem: "snake_case is not accepted on public request bodies",
|
|
1888
|
+
suggestion: `use "${snakeToCamel(key)}"`
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
const matches = findOperations(index, { path: input.path, method: input.method });
|
|
1893
|
+
const operation = matches[0];
|
|
1894
|
+
if (!operation) {
|
|
1895
|
+
return {
|
|
1896
|
+
ok: false,
|
|
1897
|
+
matched: null,
|
|
1898
|
+
errors: [
|
|
1899
|
+
...errors,
|
|
1900
|
+
{
|
|
1901
|
+
field: input.path,
|
|
1902
|
+
problem: `no ${input.method.toUpperCase()} operation matches this path in the published contract`,
|
|
1903
|
+
suggestion: "call describe_endpoint to find the right path"
|
|
1904
|
+
}
|
|
1905
|
+
],
|
|
1906
|
+
warnings
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
if (!operation.bodyFields) {
|
|
1910
|
+
return {
|
|
1911
|
+
ok: errors.length === 0,
|
|
1912
|
+
matched: `${operation.method} ${operation.path}`,
|
|
1913
|
+
errors,
|
|
1914
|
+
warnings,
|
|
1915
|
+
note: "The contract publishes no request-body schema for this operation, so field-level checks beyond naming could not run."
|
|
1916
|
+
};
|
|
1917
|
+
}
|
|
1918
|
+
const known = new Map(operation.bodyFields.map((f) => [f.name, f]));
|
|
1919
|
+
for (const key of keys) {
|
|
1920
|
+
if (RETIRED_FIELDS[key] || key.includes("_")) continue;
|
|
1921
|
+
if (!known.has(key)) {
|
|
1922
|
+
warnings.push({
|
|
1923
|
+
field: key,
|
|
1924
|
+
problem: "not documented on this operation \u2014 it will be rejected if the route validates strictly"
|
|
1925
|
+
});
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
for (const field of operation.bodyFields) {
|
|
1929
|
+
const value = (input.body ?? {})[field.name];
|
|
1930
|
+
if (value === void 0) {
|
|
1931
|
+
if (field.required) errors.push({ field: field.name, problem: "required field is missing" });
|
|
1932
|
+
continue;
|
|
1933
|
+
}
|
|
1934
|
+
if (field.enum && field.enum.length > 0 && typeof value === "string" && !field.enum.includes(value)) {
|
|
1935
|
+
errors.push({
|
|
1936
|
+
field: field.name,
|
|
1937
|
+
problem: `value "${value}" is not allowed`,
|
|
1938
|
+
suggestion: `one of: ${field.enum.join(", ")}`
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
return {
|
|
1943
|
+
ok: errors.length === 0,
|
|
1944
|
+
matched: `${operation.method} ${operation.path}`,
|
|
1945
|
+
errors,
|
|
1946
|
+
warnings
|
|
1947
|
+
};
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
// src/docs.ts
|
|
1951
|
+
var DOCS_ORIGIN = "https://usethrottle.dev/docs";
|
|
1952
|
+
function excerptAround(text, needle, radius = 160) {
|
|
1953
|
+
const at = text.toLowerCase().indexOf(needle.toLowerCase());
|
|
1954
|
+
if (at < 0) return text.slice(0, radius * 2).trim();
|
|
1955
|
+
const start = Math.max(0, at - radius);
|
|
1956
|
+
const end = Math.min(text.length, at + needle.length + radius);
|
|
1957
|
+
return `${start > 0 ? "\u2026" : ""}${text.slice(start, end).trim()}${end < text.length ? "\u2026" : ""}`;
|
|
1958
|
+
}
|
|
1959
|
+
function searchDocs(index, query, limit = 5) {
|
|
1960
|
+
const phrase = query.trim().toLowerCase();
|
|
1961
|
+
if (!phrase) return [];
|
|
1962
|
+
const terms = phrase.split(/\s+/).filter((t) => t.length > 1);
|
|
1963
|
+
const scored = index.entries.map((entry) => {
|
|
1964
|
+
const title = entry.title.toLowerCase();
|
|
1965
|
+
const headings = entry.headings.join(" \0 ").toLowerCase();
|
|
1966
|
+
const body = entry.text.toLowerCase();
|
|
1967
|
+
let score = 0;
|
|
1968
|
+
if (title === phrase) score += 100;
|
|
1969
|
+
else if (title.startsWith(phrase)) score += 60;
|
|
1970
|
+
else if (title.includes(phrase)) score += 40;
|
|
1971
|
+
if (headings.includes(phrase)) score += 25;
|
|
1972
|
+
if (body.includes(phrase)) score += 15;
|
|
1973
|
+
for (const term of terms) {
|
|
1974
|
+
if (title.includes(term)) score += 8;
|
|
1975
|
+
if (headings.includes(term)) score += 4;
|
|
1976
|
+
if (body.includes(term)) score += 1;
|
|
1977
|
+
}
|
|
1978
|
+
return { entry, score };
|
|
1979
|
+
});
|
|
1980
|
+
return scored.filter((s) => s.score > 0).sort((a, b) => b.score - a.score || a.entry.route.localeCompare(b.entry.route)).slice(0, Math.max(1, limit)).map(({ entry, score }) => ({
|
|
1981
|
+
title: entry.title,
|
|
1982
|
+
url: `${DOCS_ORIGIN}${entry.route}`,
|
|
1983
|
+
score,
|
|
1984
|
+
excerpt: excerptAround(entry.text, phrase)
|
|
1985
|
+
}));
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
// src/handlers.ts
|
|
1989
|
+
function coveringAction(operation) {
|
|
1990
|
+
const target = normalizePath(operation.path);
|
|
1991
|
+
for (const action of ACTIONS) {
|
|
1992
|
+
const hit = action.requests.some(
|
|
1993
|
+
(r) => r.method === operation.method && normalizePath(r.path) === target
|
|
1994
|
+
);
|
|
1995
|
+
if (hit) return { tool: action.id, requiredScopes: action.scopes };
|
|
1996
|
+
}
|
|
1997
|
+
return {};
|
|
1998
|
+
}
|
|
1999
|
+
var page = (args) => ({ limit: args.limit, cursor: args.cursor });
|
|
2000
|
+
var HANDLERS = {
|
|
2001
|
+
// ---------------------------------------------------------------- identity
|
|
2002
|
+
whoami: async (ctx) => ({
|
|
2003
|
+
...ctx.identity,
|
|
2004
|
+
note: ctx.identity.environment.providerEnvironment === "production" ? "This credential is pinned to PRODUCTION. Reads return live data." : "This credential is pinned to a non-production environment. Nothing here is live data."
|
|
2005
|
+
}),
|
|
2006
|
+
// ------------------------------------------------------- docs and contract
|
|
2007
|
+
search_docs: async (ctx, args) => {
|
|
2008
|
+
const hits = searchDocs(ctx.docs, String(args.query ?? ""), Number(args.limit ?? 5));
|
|
2009
|
+
return hits.length > 0 ? { hits } : { hits: [], note: "No documentation matched. Try fewer or more general terms." };
|
|
2010
|
+
},
|
|
2011
|
+
describe_endpoint: async (ctx, args) => {
|
|
2012
|
+
const operations = findOperations(ctx.contract, {
|
|
2013
|
+
path: String(args.path ?? ""),
|
|
2014
|
+
method: args.method ? String(args.method) : void 0
|
|
2015
|
+
});
|
|
2016
|
+
if (operations.length === 0) {
|
|
2017
|
+
return {
|
|
2018
|
+
operations: [],
|
|
2019
|
+
note: 'No operation matched. Paths look like /api/v1/orders; try a shorter fragment such as "orders".'
|
|
2020
|
+
};
|
|
2021
|
+
}
|
|
2022
|
+
return {
|
|
2023
|
+
operations: operations.slice(0, 8).map((op) => ({ ...op, ...coveringAction(op) })),
|
|
2024
|
+
truncated: operations.length > 8 ? operations.length - 8 : void 0
|
|
2025
|
+
};
|
|
2026
|
+
},
|
|
2027
|
+
validate_payload: async (ctx, args) => validatePayload(ctx.contract, {
|
|
2028
|
+
method: String(args.method ?? "POST"),
|
|
2029
|
+
path: String(args.path ?? ""),
|
|
2030
|
+
body: args.body ?? {}
|
|
2031
|
+
}),
|
|
2032
|
+
// ------------------------------------------------------------- generic read
|
|
2033
|
+
api_get: async (ctx, args) => {
|
|
2034
|
+
const path = String(args.path ?? "");
|
|
2035
|
+
const resolved = new URL(path, "https://throttle.invalid").pathname;
|
|
2036
|
+
if (!path.startsWith("/api/v1/") || !resolved.startsWith("/api/v1/") || /(^|[\/\\])\.(\.)?([\/\\?#]|$)|%2e/i.test(path)) {
|
|
2037
|
+
throw new Error(
|
|
2038
|
+
`Refusing to call "${path}". api_get only reads paths beginning with /api/v1/ on the configured Throttle host.`
|
|
2039
|
+
);
|
|
2040
|
+
}
|
|
2041
|
+
return ctx.client.get(path, void 0, { applicationId: args.applicationId });
|
|
2042
|
+
},
|
|
2043
|
+
// ------------------------------------------------------------------ orders
|
|
2044
|
+
search_orders: async (ctx, args) => ctx.client.list(
|
|
2045
|
+
"/api/v1/orders",
|
|
2046
|
+
{
|
|
2047
|
+
q: args.q,
|
|
2048
|
+
status: args.status,
|
|
2049
|
+
paymentStatus: args.paymentStatus,
|
|
2050
|
+
createdAfter: args.createdAfter,
|
|
2051
|
+
createdBefore: args.createdBefore,
|
|
2052
|
+
...page(args)
|
|
2053
|
+
},
|
|
2054
|
+
{ applicationId: args.applicationId }
|
|
2055
|
+
),
|
|
2056
|
+
get_order: async (ctx, args) => {
|
|
2057
|
+
const id = String(args.id);
|
|
2058
|
+
const opts = { applicationId: args.applicationId };
|
|
2059
|
+
const order = await ctx.client.get(`/api/v1/orders/${id}`, void 0, opts);
|
|
2060
|
+
const [payments, returns, fulfillments] = await Promise.all([
|
|
2061
|
+
optional(() => ctx.client.list(`/api/v1/orders/${id}/payments`, void 0, opts)),
|
|
2062
|
+
optional(() => ctx.client.list(`/api/v1/orders/${id}/returns`, void 0, opts)),
|
|
2063
|
+
optional(() => ctx.client.list(`/api/v1/orders/${id}/fulfillments`, void 0, opts))
|
|
2064
|
+
]);
|
|
2065
|
+
return {
|
|
2066
|
+
order,
|
|
2067
|
+
payments: payments.ok ? payments.value.data : payments.unavailable,
|
|
2068
|
+
returns: returns.ok ? returns.value.data : returns.unavailable,
|
|
2069
|
+
fulfillments: fulfillments.ok ? fulfillments.value.data : fulfillments.unavailable
|
|
2070
|
+
};
|
|
2071
|
+
},
|
|
2072
|
+
// --------------------------------------------------------------- customers
|
|
2073
|
+
search_customers: async (ctx, args) => ctx.client.list(
|
|
2074
|
+
"/api/v1/customers",
|
|
2075
|
+
{
|
|
2076
|
+
q: args.q,
|
|
2077
|
+
createdAfter: args.createdAfter,
|
|
2078
|
+
createdBefore: args.createdBefore,
|
|
2079
|
+
...page(args)
|
|
2080
|
+
},
|
|
2081
|
+
{ applicationId: args.applicationId }
|
|
2082
|
+
),
|
|
2083
|
+
get_customer: async (ctx, args) => {
|
|
2084
|
+
const id = String(args.id);
|
|
2085
|
+
const opts = { applicationId: args.applicationId };
|
|
2086
|
+
const customer = await ctx.client.get(`/api/v1/customers/${id}`, void 0, opts);
|
|
2087
|
+
const [addresses, subscriptions] = await Promise.all([
|
|
2088
|
+
optional(() => ctx.client.list(`/api/v1/customers/${id}/addresses`, void 0, opts)),
|
|
2089
|
+
optional(() => ctx.client.list("/api/v1/subscriptions", { customerId: id }, opts))
|
|
2090
|
+
]);
|
|
2091
|
+
return {
|
|
2092
|
+
customer,
|
|
2093
|
+
addresses: addresses.ok ? addresses.value.data : addresses.unavailable,
|
|
2094
|
+
subscriptions: subscriptions.ok ? subscriptions.value.data : subscriptions.unavailable
|
|
2095
|
+
};
|
|
2096
|
+
},
|
|
2097
|
+
// ----------------------------------------------------------- subscriptions
|
|
2098
|
+
list_subscriptions: async (ctx, args) => ctx.client.list(
|
|
2099
|
+
"/api/v1/subscriptions",
|
|
2100
|
+
{
|
|
2101
|
+
customerId: args.customerId,
|
|
2102
|
+
status: args.status,
|
|
2103
|
+
createdAfter: args.createdAfter,
|
|
2104
|
+
createdBefore: args.createdBefore,
|
|
2105
|
+
...page(args)
|
|
2106
|
+
},
|
|
2107
|
+
{ applicationId: args.applicationId }
|
|
2108
|
+
),
|
|
2109
|
+
get_subscription: async (ctx, args) => ctx.client.get(`/api/v1/subscriptions/${String(args.id)}`, void 0, {
|
|
2110
|
+
applicationId: args.applicationId
|
|
2111
|
+
}),
|
|
2112
|
+
// ------------------------------------------------------------------ quotes
|
|
2113
|
+
search_quotes: async (ctx, args) => ctx.client.list(
|
|
2114
|
+
"/api/v1/quotes",
|
|
2115
|
+
{
|
|
2116
|
+
status: args.status,
|
|
2117
|
+
createdAfter: args.createdAfter,
|
|
2118
|
+
createdBefore: args.createdBefore,
|
|
2119
|
+
...page(args)
|
|
2120
|
+
},
|
|
2121
|
+
{ applicationId: args.applicationId }
|
|
2122
|
+
),
|
|
2123
|
+
get_quote: async (ctx, args) => ctx.client.get(`/api/v1/quotes/${String(args.id)}`, void 0, {
|
|
2124
|
+
applicationId: args.applicationId
|
|
2125
|
+
}),
|
|
2126
|
+
// ---------------------------------------------------------------- invoices
|
|
2127
|
+
list_invoices: async (ctx, args) => ctx.client.list(
|
|
2128
|
+
"/api/v1/invoices",
|
|
2129
|
+
{ status: args.status, ...page(args) },
|
|
2130
|
+
{ applicationId: args.applicationId }
|
|
2131
|
+
),
|
|
2132
|
+
receivables_aging: async (ctx, args) => ctx.client.get("/api/v1/invoices/aging", void 0, { applicationId: args.applicationId }),
|
|
2133
|
+
// --------------------------------------------------------------- discounts
|
|
2134
|
+
search_discounts: async (ctx, args) => ctx.client.list(
|
|
2135
|
+
"/api/v1/discounts",
|
|
2136
|
+
{
|
|
2137
|
+
q: args.q,
|
|
2138
|
+
code: args.code,
|
|
2139
|
+
type: args.type,
|
|
2140
|
+
isActive: args.isActive,
|
|
2141
|
+
createdAfter: args.createdAfter,
|
|
2142
|
+
createdBefore: args.createdBefore,
|
|
2143
|
+
...page(args)
|
|
2144
|
+
},
|
|
2145
|
+
{ applicationId: args.applicationId }
|
|
2146
|
+
),
|
|
2147
|
+
get_discount: async (ctx, args) => ctx.client.get(`/api/v1/discounts/${String(args.id)}`, void 0, {
|
|
2148
|
+
applicationId: args.applicationId
|
|
2149
|
+
}),
|
|
2150
|
+
// ---------------------------------------------------------------- payments
|
|
2151
|
+
search_payments: async (ctx, args) => ctx.client.list(
|
|
2152
|
+
"/api/v1/payments",
|
|
2153
|
+
{
|
|
2154
|
+
method: args.method,
|
|
2155
|
+
status: args.status,
|
|
2156
|
+
// The route only accepts these as snake_case query params -- confirmed
|
|
2157
|
+
// by reading its querystring schema directly, not assumed from the
|
|
2158
|
+
// platform's usual camelCase convention.
|
|
2159
|
+
order_id: args.orderId,
|
|
2160
|
+
aging: args.aging,
|
|
2161
|
+
due_from: args.dueFrom,
|
|
2162
|
+
due_to: args.dueTo,
|
|
2163
|
+
amount_min: args.amountMin,
|
|
2164
|
+
amount_max: args.amountMax,
|
|
2165
|
+
...page(args)
|
|
2166
|
+
},
|
|
2167
|
+
{ applicationId: args.applicationId }
|
|
2168
|
+
),
|
|
2169
|
+
get_payment: async (ctx, args) => {
|
|
2170
|
+
const id = String(args.id);
|
|
2171
|
+
const opts = { applicationId: args.applicationId };
|
|
2172
|
+
const payment = await ctx.client.get(`/api/v1/payments/${id}`, void 0, opts);
|
|
2173
|
+
const transactions = await optional(
|
|
2174
|
+
() => ctx.client.list(`/api/v1/payments/${id}/transactions`, void 0, opts)
|
|
2175
|
+
);
|
|
2176
|
+
return {
|
|
2177
|
+
payment,
|
|
2178
|
+
transactions: transactions.ok ? transactions.value.data : transactions.unavailable
|
|
2179
|
+
};
|
|
2180
|
+
},
|
|
2181
|
+
// ---------------------------------------------------------------- invoices
|
|
2182
|
+
get_invoice: async (ctx, args) => ctx.client.get(`/api/v1/invoices/${String(args.id)}`, void 0, {
|
|
2183
|
+
applicationId: args.applicationId
|
|
2184
|
+
}),
|
|
2185
|
+
// ------------------------------------------------------------------ carts
|
|
2186
|
+
list_abandoned_carts: async (ctx, args) => {
|
|
2187
|
+
const opts = { applicationId: args.applicationId };
|
|
2188
|
+
const [carts, summary] = await Promise.all([
|
|
2189
|
+
optional(() => ctx.client.list("/api/v1/abandoned-carts", { ...page(args) }, opts)),
|
|
2190
|
+
optional(
|
|
2191
|
+
() => ctx.client.get("/api/v1/abandoned-carts/summary", { sinceDays: args.sinceDays }, opts)
|
|
2192
|
+
)
|
|
2193
|
+
]);
|
|
2194
|
+
return {
|
|
2195
|
+
carts: carts.ok ? carts.value.data : carts.unavailable,
|
|
2196
|
+
summary: summary.ok ? summary.value : summary.unavailable
|
|
2197
|
+
};
|
|
2198
|
+
},
|
|
2199
|
+
// --------------------------------------------------------------- debugging
|
|
2200
|
+
search_events: async (ctx, args) => ctx.client.list(
|
|
2201
|
+
"/api/v1/events",
|
|
2202
|
+
{
|
|
2203
|
+
type: args.type,
|
|
2204
|
+
entityType: args.entityType,
|
|
2205
|
+
entityId: args.entityId,
|
|
2206
|
+
...page(args)
|
|
2207
|
+
},
|
|
2208
|
+
{ applicationId: args.applicationId }
|
|
2209
|
+
),
|
|
2210
|
+
list_webhook_deliveries: async (ctx, args) => ctx.client.list(
|
|
2211
|
+
"/api/v1/webhook-deliveries",
|
|
2212
|
+
{
|
|
2213
|
+
endpointId: args.endpointId,
|
|
2214
|
+
status: args.status,
|
|
2215
|
+
eventType: args.eventType,
|
|
2216
|
+
limit: args.limit
|
|
2217
|
+
},
|
|
2218
|
+
{ applicationId: args.applicationId }
|
|
2219
|
+
),
|
|
2220
|
+
get_webhook_delivery: async (ctx, args) => ctx.client.get(`/api/v1/webhook-deliveries/${String(args.id)}`, void 0, {
|
|
2221
|
+
applicationId: args.applicationId
|
|
2222
|
+
}),
|
|
2223
|
+
send_test_webhook: async (ctx, args) => ctx.client.post(`/api/v1/webhook-endpoints/${String(args.id)}/test`, {
|
|
2224
|
+
body: { eventType: args.eventType },
|
|
2225
|
+
idempotencyKey: `mcp-send-test-webhook-${String(args.id)}-${Date.now()}`
|
|
2226
|
+
}),
|
|
2227
|
+
replay_webhook_delivery: async (ctx, args) => ctx.client.post(`/api/v1/webhook-deliveries/${String(args.id)}/replay`, {
|
|
2228
|
+
idempotencyKey: `mcp-replay-webhook-delivery-${String(args.id)}-${Date.now()}`
|
|
2229
|
+
}),
|
|
2230
|
+
explain_checkout_failure: async (ctx, args) => {
|
|
2231
|
+
const id = String(args.id);
|
|
2232
|
+
const opts = { applicationId: args.applicationId };
|
|
2233
|
+
const session = await optional(
|
|
2234
|
+
() => ctx.client.get(`/api/v1/checkout-sessions/${id}`, void 0, opts)
|
|
2235
|
+
);
|
|
2236
|
+
if (!session.ok) {
|
|
2237
|
+
return {
|
|
2238
|
+
note: `No checkout session ${id} (${session.unavailable}). If this is a cart id, use search_events for its activity (or read /api/v1/carts/${id} with api_get, where that tool is available).`
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
const cartId = session.value?.cartId ?? void 0;
|
|
2242
|
+
const [cart, sessionEvents, cartEvents, deliveries] = await Promise.all([
|
|
2243
|
+
optional(() => ctx.client.get(`/api/v1/checkout-sessions/${id}/cart`, void 0, opts)),
|
|
2244
|
+
optional(() => ctx.client.list("/api/v1/events", { entityId: id, limit: 25 }, opts)),
|
|
2245
|
+
cartId ? optional(() => ctx.client.list("/api/v1/events", { entityId: cartId, limit: 25 }, opts)) : Promise.resolve({ ok: true, value: { data: [], pagination: null } }),
|
|
2246
|
+
optional(() => ctx.client.list("/api/v1/webhook-deliveries", { limit: 15 }, opts))
|
|
2247
|
+
]);
|
|
2248
|
+
return {
|
|
2249
|
+
session: session.value,
|
|
2250
|
+
cart: cart.ok ? cart.value : cart.unavailable,
|
|
2251
|
+
events: [
|
|
2252
|
+
...sessionEvents.ok ? sessionEvents.value.data : [],
|
|
2253
|
+
...cartEvents.ok ? cartEvents.value.data : []
|
|
2254
|
+
],
|
|
2255
|
+
eventsUnavailable: sessionEvents.ok ? void 0 : sessionEvents.unavailable,
|
|
2256
|
+
recentWebhookDeliveries: deliveries.ok ? deliveries.value.data : deliveries.unavailable,
|
|
2257
|
+
hint: "Compare the session state against the events: a session that never emitted checkout_started usually means the browser SDK failed before submitting, not a payment decline."
|
|
2258
|
+
};
|
|
2259
|
+
},
|
|
2260
|
+
// ------------------------------------------------------------ sandbox seed
|
|
2261
|
+
seed_test_data: async (ctx, args) => {
|
|
2262
|
+
if (ctx.identity.environment.providerEnvironment === "production") {
|
|
2263
|
+
throw new Error(
|
|
2264
|
+
"seed_test_data refuses to run against a production environment. Use a non-production API key."
|
|
2265
|
+
);
|
|
2266
|
+
}
|
|
2267
|
+
const stamp = Date.now();
|
|
2268
|
+
const customer = await ctx.client.post("/api/v1/customers", {
|
|
2269
|
+
body: {
|
|
2270
|
+
email: String(args.customerEmail ?? `mcp-seed-${stamp}@example.test`),
|
|
2271
|
+
firstName: "Seed",
|
|
2272
|
+
lastName: "Customer"
|
|
2273
|
+
},
|
|
2274
|
+
idempotencyKey: `mcp-seed-customer-${stamp}`
|
|
2275
|
+
});
|
|
2276
|
+
const cart = await ctx.client.post("/api/v1/carts", {
|
|
2277
|
+
// Unlike /api/v1/customers, cart creation requires applicationId
|
|
2278
|
+
// explicitly in the body (it's cross-checked against the caller's own
|
|
2279
|
+
// authenticated application, not inferred) -- omitting it is a real
|
|
2280
|
+
// 400 missing_application_id from the live API, not a hypothetical.
|
|
2281
|
+
body: { applicationId: ctx.identity.application?.id, customerId: customer?.id },
|
|
2282
|
+
idempotencyKey: `mcp-seed-cart-${stamp}`
|
|
2283
|
+
});
|
|
2284
|
+
const requested = Array.isArray(args.lineItems) && args.lineItems.length > 0 ? args.lineItems : [{ name: "Seed widget", unitPrice: 2500, quantity: 2 }];
|
|
2285
|
+
const items = [];
|
|
2286
|
+
for (const [index, item] of requested.entries()) {
|
|
2287
|
+
items.push(
|
|
2288
|
+
await ctx.client.post(`/api/v1/carts/${cart?.id}/items`, {
|
|
2289
|
+
body: item,
|
|
2290
|
+
idempotencyKey: `mcp-seed-item-${stamp}-${index}`
|
|
2291
|
+
})
|
|
2292
|
+
);
|
|
2293
|
+
}
|
|
2294
|
+
const order = await ctx.client.post(`/api/v1/carts/${cart?.id}/finalize`, {
|
|
2295
|
+
idempotencyKey: `mcp-seed-finalize-${stamp}`
|
|
2296
|
+
});
|
|
2297
|
+
return {
|
|
2298
|
+
environment: ctx.identity.environment.slug,
|
|
2299
|
+
customer,
|
|
2300
|
+
cart,
|
|
2301
|
+
lineItems: items,
|
|
2302
|
+
order,
|
|
2303
|
+
note: "Seeded a finalized DRAFT order. No payment was captured \u2014 that needs a browser-tokenised payment method, which a server-side key cannot produce."
|
|
2304
|
+
};
|
|
2305
|
+
},
|
|
2306
|
+
// ---------------------------------------------------------- inbound writes
|
|
2307
|
+
create_customer: async (ctx, args) => ctx.client.post("/api/v1/customers", {
|
|
2308
|
+
// `createCustomerBody` is `.strict()`, so only fields it declares may be
|
|
2309
|
+
// sent; `undefined` values drop out at JSON.stringify.
|
|
2310
|
+
body: {
|
|
2311
|
+
email: args.email,
|
|
2312
|
+
firstName: args.firstName,
|
|
2313
|
+
lastName: args.lastName,
|
|
2314
|
+
phone: args.phone,
|
|
2315
|
+
company: args.company,
|
|
2316
|
+
externalId: args.externalId,
|
|
2317
|
+
netN: args.netN,
|
|
2318
|
+
acceptsMarketing: args.acceptsMarketing
|
|
2319
|
+
},
|
|
2320
|
+
idempotencyKey: `mcp-create-customer-${String(args.email)}-${Date.now()}`
|
|
2321
|
+
}),
|
|
2322
|
+
update_customer: async (ctx, args) => ctx.client.patch(`/api/v1/customers/${String(args.id)}`, {
|
|
2323
|
+
// `id` is the path parameter, not a body field — `updateCustomerBody` is
|
|
2324
|
+
// `.strict()` and would reject it. A null `externalId` is meaningful
|
|
2325
|
+
// (it clears the value), so only `undefined` is dropped.
|
|
2326
|
+
body: {
|
|
2327
|
+
email: args.email,
|
|
2328
|
+
firstName: args.firstName,
|
|
2329
|
+
lastName: args.lastName,
|
|
2330
|
+
phone: args.phone,
|
|
2331
|
+
company: args.company,
|
|
2332
|
+
externalId: args.externalId,
|
|
2333
|
+
netN: args.netN,
|
|
2334
|
+
acceptsMarketing: args.acceptsMarketing
|
|
2335
|
+
},
|
|
2336
|
+
idempotencyKey: `mcp-update-customer-${String(args.id)}-${Date.now()}`
|
|
2337
|
+
}),
|
|
2338
|
+
create_checkout_link: async (ctx, args) => {
|
|
2339
|
+
const lineItems = Array.isArray(args.lineItems) ? args.lineItems : [];
|
|
2340
|
+
if (lineItems.length === 0) {
|
|
2341
|
+
throw new Error("create_checkout_link: lineItems must contain at least one item.");
|
|
2342
|
+
}
|
|
2343
|
+
const stamp = Date.now();
|
|
2344
|
+
const applicationId = ctx.identity.application?.id;
|
|
2345
|
+
const cart = await ctx.client.post("/api/v1/carts", {
|
|
2346
|
+
body: {
|
|
2347
|
+
applicationId,
|
|
2348
|
+
customerId: args.customerId,
|
|
2349
|
+
customerEmail: args.customerEmail,
|
|
2350
|
+
netN: args.netN
|
|
2351
|
+
},
|
|
2352
|
+
idempotencyKey: `mcp-checkout-link-cart-${stamp}`
|
|
2353
|
+
});
|
|
2354
|
+
for (const [index, item] of lineItems.entries()) {
|
|
2355
|
+
await ctx.client.post(`/api/v1/carts/${cart?.id}/items`, {
|
|
2356
|
+
body: item,
|
|
2357
|
+
idempotencyKey: `mcp-checkout-link-item-${stamp}-${index}`
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2360
|
+
const session = await ctx.client.post("/api/v1/checkout/sessions", {
|
|
2361
|
+
body: {
|
|
2362
|
+
applicationId,
|
|
2363
|
+
cartId: cart?.id,
|
|
2364
|
+
returnUrl: args.returnUrl,
|
|
2365
|
+
cancelUrl: args.cancelUrl,
|
|
2366
|
+
customerEmail: args.customerEmail,
|
|
2367
|
+
discountCode: args.discountCode
|
|
2368
|
+
},
|
|
2369
|
+
idempotencyKey: `mcp-checkout-link-session-${stamp}`
|
|
2370
|
+
});
|
|
2371
|
+
return { cartId: cart?.id, ...session };
|
|
2372
|
+
},
|
|
2373
|
+
// -------------------------------------------------------------- money/mail
|
|
2374
|
+
manage_subscription: async (ctx, args) => {
|
|
2375
|
+
const id = String(args.id);
|
|
2376
|
+
const action = String(args.action);
|
|
2377
|
+
if (action !== "pause" && action !== "resume") {
|
|
2378
|
+
throw new Error(`manage_subscription: action must be "pause" or "resume", got "${action}".`);
|
|
2379
|
+
}
|
|
2380
|
+
return ctx.client.post(`/api/v1/subscriptions/${id}/${action}`, {
|
|
2381
|
+
idempotencyKey: `mcp-manage-subscription-${id}-${action}-${Date.now()}`
|
|
2382
|
+
});
|
|
2383
|
+
},
|
|
2384
|
+
create_quote: async (ctx, args) => (
|
|
2385
|
+
// The real route's body shape differs from this tool's flatter,
|
|
2386
|
+
// model-facing input: line items are "items" (not "lineItems"), Net-N
|
|
2387
|
+
// terms are nested under paymentTerms.netN with an explicit mode (not a
|
|
2388
|
+
// flat "netN"), and the buyer-visible note field is "buyerNote" (not
|
|
2389
|
+
// "notes"). Confirmed against packages/platform-api/src/validation/quotes.ts's
|
|
2390
|
+
// actual zod schema after a live call 400'd with unrecognized_keys.
|
|
2391
|
+
ctx.client.post("/api/v1/quotes", {
|
|
2392
|
+
body: {
|
|
2393
|
+
customerId: args.customerId,
|
|
2394
|
+
items: args.items,
|
|
2395
|
+
expiresAt: args.expiresAt,
|
|
2396
|
+
paymentTerms: args.netN !== void 0 ? { mode: "net_terms", netN: args.netN } : void 0,
|
|
2397
|
+
buyerNote: args.notes
|
|
2398
|
+
},
|
|
2399
|
+
idempotencyKey: `mcp-create-quote-${String(args.customerId)}-${Date.now()}`
|
|
2400
|
+
})
|
|
2401
|
+
),
|
|
2402
|
+
get_sales_timeseries: async (ctx, args) => ctx.client.get(
|
|
2403
|
+
"/api/v1/analytics/orders-timeseries",
|
|
2404
|
+
{
|
|
2405
|
+
from: args.from,
|
|
2406
|
+
to: args.to,
|
|
2407
|
+
groupBy: args.groupBy,
|
|
2408
|
+
timezone: args.timezone,
|
|
2409
|
+
compareTo: args.compareTo
|
|
2410
|
+
},
|
|
2411
|
+
{ applicationId: args.applicationId }
|
|
2412
|
+
),
|
|
2413
|
+
get_business_summary: async (ctx, args) => ctx.client.get(
|
|
2414
|
+
"/api/v1/analytics/business-summary",
|
|
2415
|
+
{
|
|
2416
|
+
period: args.period,
|
|
2417
|
+
from: args.from,
|
|
2418
|
+
to: args.to,
|
|
2419
|
+
timezone: args.timezone
|
|
2420
|
+
},
|
|
2421
|
+
{ applicationId: args.applicationId }
|
|
2422
|
+
),
|
|
2423
|
+
get_attention_digest: async (ctx, args) => ctx.client.get("/api/v1/analytics/attention-digest", void 0, {
|
|
2424
|
+
applicationId: args.applicationId
|
|
2425
|
+
}),
|
|
2426
|
+
get_top_products: async (ctx, args) => ctx.client.get(
|
|
2427
|
+
"/api/v1/analytics/products",
|
|
2428
|
+
{
|
|
2429
|
+
from: args.from,
|
|
2430
|
+
to: args.to,
|
|
2431
|
+
timezone: args.timezone,
|
|
2432
|
+
by: args.by,
|
|
2433
|
+
limit: args.limit
|
|
2434
|
+
},
|
|
2435
|
+
{ applicationId: args.applicationId }
|
|
2436
|
+
),
|
|
2437
|
+
// `.get()`, not `.list()` — the response is a single object (`{ data: {
|
|
2438
|
+
// range, signups, ordersByCustomerType, topCustomers, totals } }`), and
|
|
2439
|
+
// `.list()` only unwraps arrays: it would silently return an empty list
|
|
2440
|
+
// instead of the real payload.
|
|
2441
|
+
get_customer_growth: async (ctx, args) => ctx.client.get(
|
|
2442
|
+
"/api/v1/analytics/customers",
|
|
2443
|
+
{
|
|
2444
|
+
from: args.from,
|
|
2445
|
+
to: args.to,
|
|
2446
|
+
groupBy: args.groupBy,
|
|
2447
|
+
timezone: args.timezone,
|
|
2448
|
+
topBy: args.topBy,
|
|
2449
|
+
topLimit: args.topLimit
|
|
2450
|
+
},
|
|
2451
|
+
{ applicationId: args.applicationId }
|
|
2452
|
+
),
|
|
2453
|
+
// `.get()`, not `.list()` — the response is a single object (`{ data: {
|
|
2454
|
+
// range, dimension, rows, totals, note } }`), not a paginated array.
|
|
2455
|
+
get_revenue_breakdown: async (ctx, args) => ctx.client.get(
|
|
2456
|
+
"/api/v1/analytics/revenue-breakdown",
|
|
2457
|
+
{
|
|
2458
|
+
dimension: args.dimension,
|
|
2459
|
+
from: args.from,
|
|
2460
|
+
to: args.to,
|
|
2461
|
+
timezone: args.timezone
|
|
2462
|
+
},
|
|
2463
|
+
{ applicationId: args.applicationId }
|
|
2464
|
+
),
|
|
2465
|
+
// `.get()`, not `.list()` — the response is a single object (`{ data: {
|
|
2466
|
+
// range, stages, conversionRate, dropOff, note } }`), not a paginated array.
|
|
2467
|
+
get_funnel_conversion: async (ctx, args) => ctx.client.get(
|
|
2468
|
+
"/api/v1/analytics/funnel",
|
|
2469
|
+
{
|
|
2470
|
+
from: args.from,
|
|
2471
|
+
to: args.to,
|
|
2472
|
+
timezone: args.timezone
|
|
2473
|
+
},
|
|
2474
|
+
{ applicationId: args.applicationId }
|
|
2475
|
+
),
|
|
2476
|
+
// `.get()`, not `.list()` — the response is a single object (`{ data: {
|
|
2477
|
+
// range, series, totals, note } }`), not a paginated array.
|
|
2478
|
+
get_subscription_movement: async (ctx, args) => ctx.client.get(
|
|
2479
|
+
"/api/v1/analytics/subscriptions",
|
|
2480
|
+
{
|
|
2481
|
+
from: args.from,
|
|
2482
|
+
to: args.to,
|
|
2483
|
+
timezone: args.timezone,
|
|
2484
|
+
groupBy: args.groupBy
|
|
2485
|
+
},
|
|
2486
|
+
{ applicationId: args.applicationId }
|
|
2487
|
+
),
|
|
2488
|
+
// `.get()`, not `.list()` — the response is a single object (`{ data: {
|
|
2489
|
+
// range, rows, totals, note } }`), not a paginated array.
|
|
2490
|
+
get_discount_performance: async (ctx, args) => ctx.client.get(
|
|
2491
|
+
"/api/v1/analytics/discounts",
|
|
2492
|
+
{
|
|
2493
|
+
from: args.from,
|
|
2494
|
+
to: args.to,
|
|
2495
|
+
timezone: args.timezone,
|
|
2496
|
+
limit: args.limit
|
|
2497
|
+
},
|
|
2498
|
+
{ applicationId: args.applicationId }
|
|
2499
|
+
),
|
|
2500
|
+
// ------------------------------------------------------------- extensions
|
|
2501
|
+
list_extension_installations: async (ctx, args) => ctx.client.list(
|
|
2502
|
+
"/api/v1/installations",
|
|
2503
|
+
{ status: args.status, ...page(args) },
|
|
2504
|
+
{ applicationId: args.applicationId }
|
|
2505
|
+
),
|
|
2506
|
+
// ------------------------------------------------------------- connectors
|
|
2507
|
+
get_connector_routing: async (ctx, args) => {
|
|
2508
|
+
const opts = { applicationId: args.applicationId };
|
|
2509
|
+
const [paymentRouting, routingConnectors, cardDecline, otherDecline] = await Promise.all([
|
|
2510
|
+
optional(() => ctx.client.get("/api/v1/payment-routing", void 0, opts)),
|
|
2511
|
+
optional(() => ctx.client.get("/api/v1/routing-connectors", void 0, opts)),
|
|
2512
|
+
optional(() => ctx.client.get("/api/v1/card-decline", void 0, opts)),
|
|
2513
|
+
optional(() => ctx.client.get("/api/v1/other-decline", void 0, opts))
|
|
2514
|
+
]);
|
|
2515
|
+
return {
|
|
2516
|
+
paymentRouting: paymentRouting.ok ? paymentRouting.value : paymentRouting.unavailable,
|
|
2517
|
+
routingConnectors: routingConnectors.ok ? routingConnectors.value : routingConnectors.unavailable,
|
|
2518
|
+
cardDecline: cardDecline.ok ? cardDecline.value : cardDecline.unavailable,
|
|
2519
|
+
otherDecline: otherDecline.ok ? otherDecline.value : otherDecline.unavailable
|
|
2520
|
+
};
|
|
2521
|
+
},
|
|
2522
|
+
get_integration_status: async (ctx, args) => {
|
|
2523
|
+
const opts = { applicationId: args.applicationId };
|
|
2524
|
+
const [connectors, endpoints, coverage] = await Promise.all([
|
|
2525
|
+
optional(() => ctx.client.list("/api/v1/connectors", void 0, opts)),
|
|
2526
|
+
optional(() => ctx.client.list("/api/v1/webhook-endpoints", void 0, opts)),
|
|
2527
|
+
optional(() => ctx.client.get("/api/v1/webhook-endpoints/coverage", void 0, opts))
|
|
2528
|
+
]);
|
|
2529
|
+
const overridden = Boolean(args.applicationId) && args.applicationId !== ctx.identity.application?.id;
|
|
2530
|
+
return {
|
|
2531
|
+
environment: ctx.identity.environment,
|
|
2532
|
+
workspace: ctx.identity.workspace,
|
|
2533
|
+
applicationId: args.applicationId ?? ctx.identity.application?.id ?? null,
|
|
2534
|
+
application: overridden ? void 0 : ctx.identity.application,
|
|
2535
|
+
connectors: connectors.ok ? connectors.value.data : connectors.unavailable,
|
|
2536
|
+
webhookEndpoints: endpoints.ok ? endpoints.value.data : endpoints.unavailable,
|
|
2537
|
+
unsubscribedEvents: coverage.ok ? coverage.value : coverage.unavailable
|
|
2538
|
+
};
|
|
2539
|
+
},
|
|
2540
|
+
// --------------------------------------------------------------- workspace
|
|
2541
|
+
// No applicationId forwarding here: /api/v1/merchants/me is workspace-only
|
|
2542
|
+
// (`WHERE workspace_id = ...`, never reads auth.applicationId) — an
|
|
2543
|
+
// applicationId field on this tool would be a silent no-op affordance.
|
|
2544
|
+
get_workspace_settings: async (ctx) => ctx.client.get("/api/v1/merchants/me"),
|
|
2545
|
+
// No applicationId forwarding here either: /api/v1/audit-log filters by
|
|
2546
|
+
// workspaceId (and optionally environmentId), never applicationId.
|
|
2547
|
+
get_audit_log: async (ctx, args) => ctx.client.list("/api/v1/audit-log", { limit: args.limit }),
|
|
2548
|
+
// --------------------------------------------------------- applications
|
|
2549
|
+
// `.get()`, not `.list()` — the legacy /v1/stores route returns a bare
|
|
2550
|
+
// array with no `meta.pagination`, and the brief calls for `.get()` here
|
|
2551
|
+
// specifically.
|
|
2552
|
+
list_applications: async (ctx) => ctx.client.get("/api/v1/stores")
|
|
2553
|
+
};
|
|
2554
|
+
|
|
2555
|
+
// src/input.ts
|
|
2556
|
+
import { z } from "zod";
|
|
2557
|
+
function fieldsToZodShape(fields) {
|
|
2558
|
+
const shape = {};
|
|
2559
|
+
for (const field of fields) {
|
|
2560
|
+
shape[field.name] = applyModifiers(field, baseType(field));
|
|
2561
|
+
}
|
|
2562
|
+
return shape;
|
|
2563
|
+
}
|
|
2564
|
+
function baseType(field) {
|
|
2565
|
+
if (field.enum && field.enum.length > 0) {
|
|
2566
|
+
return z.enum([...field.enum]);
|
|
2567
|
+
}
|
|
2568
|
+
switch (field.type) {
|
|
2569
|
+
case "string":
|
|
2570
|
+
return z.string();
|
|
2571
|
+
case "number":
|
|
2572
|
+
return z.number();
|
|
2573
|
+
case "boolean":
|
|
2574
|
+
return z.boolean();
|
|
2575
|
+
case "array":
|
|
2576
|
+
return z.array(z.unknown());
|
|
2577
|
+
case "object":
|
|
2578
|
+
return z.record(z.unknown());
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
function applyModifiers(field, type) {
|
|
2582
|
+
const described = type.describe(field.description);
|
|
2583
|
+
if (field.required) return described;
|
|
2584
|
+
return field.default === void 0 ? described.optional() : described.default(field.default);
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2587
|
+
// src/projection.ts
|
|
2588
|
+
var S = "scalar";
|
|
2589
|
+
var T = "text";
|
|
2590
|
+
var PASS = "pass";
|
|
2591
|
+
var section = (shape) => ({ __section: shape });
|
|
2592
|
+
var oneOf = (values) => ({ __oneOf: new Set(values) });
|
|
2593
|
+
function isPrimitive(value) {
|
|
2594
|
+
return value === null || ["string", "number", "boolean"].includes(typeof value);
|
|
2595
|
+
}
|
|
2596
|
+
var TOKEN = /^[^\s@]{0,200}$/;
|
|
2597
|
+
var OMITTED = { omitted: S, grantable: T, reason: T };
|
|
2598
|
+
var UNAVAILABLE = /^(not readable with this credential \(missing scope\)|not found|unavailable \([^\s@]{0,100}\))$/;
|
|
2599
|
+
function project(value, shape) {
|
|
2600
|
+
if (value === void 0) return void 0;
|
|
2601
|
+
if (shape === PASS) return value;
|
|
2602
|
+
if (shape === S) {
|
|
2603
|
+
if (!isPrimitive(value)) return void 0;
|
|
2604
|
+
return typeof value === "string" && !TOKEN.test(value) ? null : value;
|
|
2605
|
+
}
|
|
2606
|
+
if (shape === T) return isPrimitive(value) ? value : void 0;
|
|
2607
|
+
if ("__oneOf" in shape) {
|
|
2608
|
+
if (!isPrimitive(value)) return void 0;
|
|
2609
|
+
return typeof value === "string" && !shape.__oneOf.has(value) ? null : value;
|
|
2610
|
+
}
|
|
2611
|
+
if (Array.isArray(shape)) {
|
|
2612
|
+
return Array.isArray(value) ? value.map((item) => project(item, shape[0])) : void 0;
|
|
2613
|
+
}
|
|
2614
|
+
if ("__section" in shape) {
|
|
2615
|
+
if (typeof value === "string") return UNAVAILABLE.test(value) ? value : null;
|
|
2616
|
+
if (value && typeof value === "object" && value.omitted === true) {
|
|
2617
|
+
return project(value, OMITTED);
|
|
2618
|
+
}
|
|
2619
|
+
return project(value, shape.__section);
|
|
2620
|
+
}
|
|
2621
|
+
if (value === null) return null;
|
|
2622
|
+
if (typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
2623
|
+
const out = {};
|
|
2624
|
+
for (const [key, child] of Object.entries(shape)) {
|
|
2625
|
+
const projected = project(value[key], child);
|
|
2626
|
+
if (projected !== void 0) out[key] = projected;
|
|
2627
|
+
}
|
|
2628
|
+
return out;
|
|
2629
|
+
}
|
|
2630
|
+
var PAGINATION = { cursor: S, nextCursor: S, hasMore: S };
|
|
2631
|
+
var page2 = (row) => ({ data: [row], pagination: PAGINATION });
|
|
2632
|
+
var ADDRESS = { countryCode: S };
|
|
2633
|
+
var CUSTOMER_REF = { id: S };
|
|
2634
|
+
var APPLICATION = { id: S, name: T, slug: S };
|
|
2635
|
+
var LIFECYCLE_LABELS = ["Draft", "Pending", "Processing", "Partially fulfilled", "Fulfilled", "Cancelled", "Closed"];
|
|
2636
|
+
var DISPLAY_QUALIFIERS = [
|
|
2637
|
+
"Comped",
|
|
2638
|
+
"Awaiting payment",
|
|
2639
|
+
"Authorized",
|
|
2640
|
+
"Partially paid",
|
|
2641
|
+
"Partially refunded",
|
|
2642
|
+
"Refunded",
|
|
2643
|
+
"Payment failed",
|
|
2644
|
+
"Voided",
|
|
2645
|
+
"Payment processing",
|
|
2646
|
+
"Disputed",
|
|
2647
|
+
"Authorization expired",
|
|
2648
|
+
"Returned",
|
|
2649
|
+
"Partially returned",
|
|
2650
|
+
"Delivered",
|
|
2651
|
+
"In transit"
|
|
2652
|
+
];
|
|
2653
|
+
var ORDER_DISPLAY_STATUSES = new Set(
|
|
2654
|
+
LIFECYCLE_LABELS.flatMap((l) => [l, ...DISPLAY_QUALIFIERS.map((q) => `${l} \xB7 ${q}`)])
|
|
2655
|
+
);
|
|
2656
|
+
var DISPLAY_STATUS = oneOf(ORDER_DISPLAY_STATUSES);
|
|
2657
|
+
var RANGE = { from: S, to: S, timezone: S, groupBy: S };
|
|
2658
|
+
var LINE_ITEM = {
|
|
2659
|
+
id: S,
|
|
2660
|
+
type: S,
|
|
2661
|
+
quantity: S,
|
|
2662
|
+
unitPrice: S,
|
|
2663
|
+
subtotal: S,
|
|
2664
|
+
discountAmount: S,
|
|
2665
|
+
taxAmount: S,
|
|
2666
|
+
total: S,
|
|
2667
|
+
recurring: S
|
|
2668
|
+
};
|
|
2669
|
+
var ORDER = {
|
|
2670
|
+
id: S,
|
|
2671
|
+
orderNumber: S,
|
|
2672
|
+
status: S,
|
|
2673
|
+
displayStatus: DISPLAY_STATUS,
|
|
2674
|
+
paymentStatus: S,
|
|
2675
|
+
type: S,
|
|
2676
|
+
source: S,
|
|
2677
|
+
currency: S,
|
|
2678
|
+
subtotal: S,
|
|
2679
|
+
discountTotal: S,
|
|
2680
|
+
shippingTotal: S,
|
|
2681
|
+
taxTotal: S,
|
|
2682
|
+
total: S,
|
|
2683
|
+
capturedAmount: S,
|
|
2684
|
+
refundedAmount: S,
|
|
2685
|
+
compAmount: S,
|
|
2686
|
+
onHold: S,
|
|
2687
|
+
taxReverseCharge: S,
|
|
2688
|
+
customerId: S,
|
|
2689
|
+
customer: CUSTOMER_REF,
|
|
2690
|
+
subscriptionId: S,
|
|
2691
|
+
shippingAddress: ADDRESS,
|
|
2692
|
+
billingAddress: ADDRESS,
|
|
2693
|
+
fulfillmentSummary: { itemsFulfilled: S, itemsRemaining: S, itemsTotal: S },
|
|
2694
|
+
lineItems: [LINE_ITEM],
|
|
2695
|
+
createdAt: S,
|
|
2696
|
+
completedAt: S,
|
|
2697
|
+
cancelledAt: S,
|
|
2698
|
+
closedAt: S
|
|
2699
|
+
};
|
|
2700
|
+
var PAYMENT = {
|
|
2701
|
+
id: S,
|
|
2702
|
+
orderId: S,
|
|
2703
|
+
status: S,
|
|
2704
|
+
method: S,
|
|
2705
|
+
processor: S,
|
|
2706
|
+
amount: S,
|
|
2707
|
+
capturedAmount: S,
|
|
2708
|
+
currency: S,
|
|
2709
|
+
cardBrand: S,
|
|
2710
|
+
disputed: S,
|
|
2711
|
+
disputeOpenedAt: S,
|
|
2712
|
+
errorCode: S,
|
|
2713
|
+
netN: S,
|
|
2714
|
+
netNSource: S,
|
|
2715
|
+
authorizedAt: S,
|
|
2716
|
+
capturedAt: S,
|
|
2717
|
+
voidedAt: S,
|
|
2718
|
+
createdAt: S
|
|
2719
|
+
};
|
|
2720
|
+
var RETURN = {
|
|
2721
|
+
id: S,
|
|
2722
|
+
orderId: S,
|
|
2723
|
+
status: S,
|
|
2724
|
+
restock: S,
|
|
2725
|
+
refundAmount: S,
|
|
2726
|
+
refundPaymentId: S,
|
|
2727
|
+
createdAt: S,
|
|
2728
|
+
items: [{ lineItemId: S, quantity: S }]
|
|
2729
|
+
};
|
|
2730
|
+
var FULFILLMENT = {
|
|
2731
|
+
id: S,
|
|
2732
|
+
orderId: S,
|
|
2733
|
+
type: S,
|
|
2734
|
+
status: S,
|
|
2735
|
+
createdAt: S,
|
|
2736
|
+
lineItems: [{ lineItemId: S, quantity: S }],
|
|
2737
|
+
detail: { carrier: T, serviceLevel: T, trackingNumber: T, trackingUrl: T, shippedAt: S, estimatedDelivery: S, actualDelivery: S }
|
|
2738
|
+
};
|
|
2739
|
+
var CUSTOMER = { id: S, netN: S, acceptsMarketing: S, createdAt: S };
|
|
2740
|
+
var SUBSCRIPTION = {
|
|
2741
|
+
id: S,
|
|
2742
|
+
status: S,
|
|
2743
|
+
planName: T,
|
|
2744
|
+
planReference: T,
|
|
2745
|
+
amount: S,
|
|
2746
|
+
currency: S,
|
|
2747
|
+
interval: S,
|
|
2748
|
+
quantity: S,
|
|
2749
|
+
intervalUnit: S,
|
|
2750
|
+
intervalCount: S,
|
|
2751
|
+
totalPayments: S,
|
|
2752
|
+
paymentsMade: S,
|
|
2753
|
+
completedAt: S,
|
|
2754
|
+
customerId: S,
|
|
2755
|
+
customer: CUSTOMER_REF,
|
|
2756
|
+
currentPeriodStart: S,
|
|
2757
|
+
currentPeriodEnd: S,
|
|
2758
|
+
billingAnchorAt: S,
|
|
2759
|
+
cancelAtPeriodEnd: S,
|
|
2760
|
+
trialEnd: S,
|
|
2761
|
+
pausedAt: S,
|
|
2762
|
+
cancelledAt: S,
|
|
2763
|
+
lastPaymentAt: S,
|
|
2764
|
+
failureCount: S,
|
|
2765
|
+
pendingPlanName: T,
|
|
2766
|
+
pendingPlanReference: T,
|
|
2767
|
+
pendingAmount: S,
|
|
2768
|
+
pendingInterval: S,
|
|
2769
|
+
pendingQuantity: S,
|
|
2770
|
+
pendingIntervalUnit: S,
|
|
2771
|
+
pendingIntervalCount: S,
|
|
2772
|
+
createdAt: S
|
|
2773
|
+
};
|
|
2774
|
+
var QUOTE_SUMMARY = {
|
|
2775
|
+
id: S,
|
|
2776
|
+
quoteNumber: S,
|
|
2777
|
+
status: S,
|
|
2778
|
+
source: S,
|
|
2779
|
+
currency: S,
|
|
2780
|
+
total: S,
|
|
2781
|
+
customerId: S,
|
|
2782
|
+
orderId: S,
|
|
2783
|
+
expiresAt: S,
|
|
2784
|
+
acceptedAt: S,
|
|
2785
|
+
declinedAt: S,
|
|
2786
|
+
createdAt: S
|
|
2787
|
+
};
|
|
2788
|
+
var QUOTE = {
|
|
2789
|
+
...QUOTE_SUMMARY,
|
|
2790
|
+
revisions: [{
|
|
2791
|
+
id: S,
|
|
2792
|
+
revisionNumber: S,
|
|
2793
|
+
state: S,
|
|
2794
|
+
subtotal: S,
|
|
2795
|
+
discountTotal: S,
|
|
2796
|
+
shippingTotal: S,
|
|
2797
|
+
taxTotal: S,
|
|
2798
|
+
total: S,
|
|
2799
|
+
depositAmount: S,
|
|
2800
|
+
shippingMode: S,
|
|
2801
|
+
issuedAt: S,
|
|
2802
|
+
expiresAt: S,
|
|
2803
|
+
paymentTerms: { mode: S, netN: S, balanceNetN: S, deposit: { type: S, value: S } },
|
|
2804
|
+
items: [{
|
|
2805
|
+
type: S,
|
|
2806
|
+
quantity: S,
|
|
2807
|
+
unitPrice: S,
|
|
2808
|
+
subtotal: S,
|
|
2809
|
+
discountAmount: S,
|
|
2810
|
+
taxAmount: S,
|
|
2811
|
+
total: S,
|
|
2812
|
+
optional: S,
|
|
2813
|
+
optionalSelected: S
|
|
2814
|
+
}]
|
|
2815
|
+
}],
|
|
2816
|
+
// Who commented and when, never what they wrote.
|
|
2817
|
+
comments: [{ authorType: S, visibility: S, createdAt: S }],
|
|
2818
|
+
timeline: [{ type: S, actorType: S, createdAt: S }]
|
|
2819
|
+
};
|
|
2820
|
+
var INVOICE = {
|
|
2821
|
+
id: S,
|
|
2822
|
+
number: S,
|
|
2823
|
+
status: S,
|
|
2824
|
+
sourceType: S,
|
|
2825
|
+
sourceId: S,
|
|
2826
|
+
customerId: S,
|
|
2827
|
+
currency: S,
|
|
2828
|
+
subtotal: S,
|
|
2829
|
+
discountTotal: S,
|
|
2830
|
+
shippingTotal: S,
|
|
2831
|
+
taxTotal: S,
|
|
2832
|
+
total: S,
|
|
2833
|
+
amountRefunded: S,
|
|
2834
|
+
issuedAt: S,
|
|
2835
|
+
dueAt: S,
|
|
2836
|
+
periodStart: S,
|
|
2837
|
+
periodEnd: S,
|
|
2838
|
+
createdAt: S,
|
|
2839
|
+
billingSnapshot: {
|
|
2840
|
+
planName: T,
|
|
2841
|
+
period: { start: S, end: S },
|
|
2842
|
+
lineItems: [{ quantity: S, unitPrice: S, discountAmount: S, taxAmount: S, total: S }],
|
|
2843
|
+
totals: { currency: S, subtotal: S, discountTotal: S, shippingTotal: S, taxTotal: S, total: S },
|
|
2844
|
+
payment: { method: S, brand: S, status: S }
|
|
2845
|
+
}
|
|
2846
|
+
};
|
|
2847
|
+
var DISCOUNT = {
|
|
2848
|
+
id: S,
|
|
2849
|
+
code: T,
|
|
2850
|
+
name: T,
|
|
2851
|
+
type: S,
|
|
2852
|
+
value: S,
|
|
2853
|
+
isActive: S,
|
|
2854
|
+
startsAt: S,
|
|
2855
|
+
endsAt: S,
|
|
2856
|
+
usageCount: S,
|
|
2857
|
+
usageLimit: S,
|
|
2858
|
+
maxRedemptionsPerCustomer: S,
|
|
2859
|
+
createdAt: S
|
|
2860
|
+
};
|
|
2861
|
+
var EVENT = {
|
|
2862
|
+
id: S,
|
|
2863
|
+
type: S,
|
|
2864
|
+
entityType: S,
|
|
2865
|
+
entityId: S,
|
|
2866
|
+
createdAt: S,
|
|
2867
|
+
data: {
|
|
2868
|
+
status: S,
|
|
2869
|
+
previousStatus: S,
|
|
2870
|
+
action: S,
|
|
2871
|
+
amount: S,
|
|
2872
|
+
currency: S,
|
|
2873
|
+
attempt: S,
|
|
2874
|
+
orderId: S,
|
|
2875
|
+
paymentId: S,
|
|
2876
|
+
order: { id: S, orderNumber: S, status: S, paymentStatus: S, currency: S, total: S },
|
|
2877
|
+
payment: { id: S, orderId: S, status: S, method: S, amount: S, currency: S },
|
|
2878
|
+
subscription: { id: S, status: S, planName: T, amount: S, currency: S, interval: S },
|
|
2879
|
+
fulfillment: { id: S, orderId: S, type: S, status: S }
|
|
2880
|
+
}
|
|
2881
|
+
};
|
|
2882
|
+
var DELIVERY = {
|
|
2883
|
+
id: S,
|
|
2884
|
+
endpointId: S,
|
|
2885
|
+
eventId: S,
|
|
2886
|
+
eventType: S,
|
|
2887
|
+
status: S,
|
|
2888
|
+
attemptCount: S,
|
|
2889
|
+
lastStatus: S,
|
|
2890
|
+
deliveredAt: S,
|
|
2891
|
+
nextRetryAt: S,
|
|
2892
|
+
createdAt: S,
|
|
2893
|
+
replayOf: S
|
|
2894
|
+
};
|
|
2895
|
+
var MONEY_COUNT = { count: S, totalCents: S };
|
|
2896
|
+
var ORDER_PERIOD = { orderCount: S, grossCents: S, netCents: S, refundsCents: S, avgOrderCents: S };
|
|
2897
|
+
var OAUTH_PROJECTIONS = {
|
|
2898
|
+
whoami: {
|
|
2899
|
+
type: S,
|
|
2900
|
+
workspace: { name: T, slug: S },
|
|
2901
|
+
application: APPLICATION,
|
|
2902
|
+
environment: { slug: S, kind: S, providerEnvironment: S },
|
|
2903
|
+
note: T
|
|
2904
|
+
},
|
|
2905
|
+
search_docs: PASS,
|
|
2906
|
+
describe_endpoint: PASS,
|
|
2907
|
+
validate_payload: PASS,
|
|
2908
|
+
search_orders: page2(ORDER),
|
|
2909
|
+
get_order: {
|
|
2910
|
+
order: ORDER,
|
|
2911
|
+
payments: section([PAYMENT]),
|
|
2912
|
+
returns: section([RETURN]),
|
|
2913
|
+
fulfillments: section([FULFILLMENT])
|
|
2914
|
+
},
|
|
2915
|
+
search_customers: page2(CUSTOMER),
|
|
2916
|
+
get_customer: {
|
|
2917
|
+
customer: CUSTOMER,
|
|
2918
|
+
addresses: section([{ id: S, isDefault: S, ...ADDRESS }]),
|
|
2919
|
+
subscriptions: section([SUBSCRIPTION])
|
|
2920
|
+
},
|
|
2921
|
+
list_subscriptions: page2(SUBSCRIPTION),
|
|
2922
|
+
get_subscription: SUBSCRIPTION,
|
|
2923
|
+
search_quotes: page2(QUOTE_SUMMARY),
|
|
2924
|
+
get_quote: QUOTE,
|
|
2925
|
+
list_invoices: page2(INVOICE),
|
|
2926
|
+
get_invoice: INVOICE,
|
|
2927
|
+
receivables_aging: {
|
|
2928
|
+
buckets: [{ key: S, label: T, count: S, total_amount: S }],
|
|
2929
|
+
total_outstanding_amount: S,
|
|
2930
|
+
total_outstanding_count: S
|
|
2931
|
+
},
|
|
2932
|
+
search_discounts: page2(DISCOUNT),
|
|
2933
|
+
get_discount: DISCOUNT,
|
|
2934
|
+
search_payments: page2(PAYMENT),
|
|
2935
|
+
get_payment: {
|
|
2936
|
+
payment: PAYMENT,
|
|
2937
|
+
transactions: section([{ id: S, type: S, status: S, amount: S, currency: S, createdAt: S }])
|
|
2938
|
+
},
|
|
2939
|
+
list_abandoned_carts: {
|
|
2940
|
+
carts: section([{
|
|
2941
|
+
id: S,
|
|
2942
|
+
abandonedAt: S,
|
|
2943
|
+
currency: S,
|
|
2944
|
+
itemCount: S,
|
|
2945
|
+
recoveryStatus: S,
|
|
2946
|
+
total: S,
|
|
2947
|
+
customer: { id: S }
|
|
2948
|
+
}]),
|
|
2949
|
+
summary: section({ abandonedCount: S, abandonedValue: S, recoveryEmailsSent: S, sinceDays: S })
|
|
2950
|
+
},
|
|
2951
|
+
search_events: page2(EVENT),
|
|
2952
|
+
list_webhook_deliveries: page2(DELIVERY),
|
|
2953
|
+
get_webhook_delivery: DELIVERY,
|
|
2954
|
+
explain_checkout_failure: {
|
|
2955
|
+
note: T,
|
|
2956
|
+
hint: T,
|
|
2957
|
+
session: {
|
|
2958
|
+
id: S,
|
|
2959
|
+
status: S,
|
|
2960
|
+
cartId: S,
|
|
2961
|
+
customerId: S,
|
|
2962
|
+
expiresAt: S,
|
|
2963
|
+
completedAt: S,
|
|
2964
|
+
allowedMethods: [S],
|
|
2965
|
+
collect: { shippingAddress: S, billingAddress: S, vatNumber: S },
|
|
2966
|
+
shippingAddress: ADDRESS,
|
|
2967
|
+
billingAddress: ADDRESS,
|
|
2968
|
+
recurringTerms: {
|
|
2969
|
+
interval: S,
|
|
2970
|
+
intervalUnit: S,
|
|
2971
|
+
intervalCount: S,
|
|
2972
|
+
totalPayments: S,
|
|
2973
|
+
taxApplies: S,
|
|
2974
|
+
planChargedToday: S,
|
|
2975
|
+
planName: T,
|
|
2976
|
+
trialDays: S,
|
|
2977
|
+
currency: S,
|
|
2978
|
+
firstChargeAmountMinor: S
|
|
2979
|
+
}
|
|
2980
|
+
},
|
|
2981
|
+
cart: section({
|
|
2982
|
+
id: S,
|
|
2983
|
+
status: S,
|
|
2984
|
+
currency: S,
|
|
2985
|
+
subtotal: S,
|
|
2986
|
+
discountTotal: S,
|
|
2987
|
+
shippingTotal: S,
|
|
2988
|
+
taxTotal: S,
|
|
2989
|
+
total: S,
|
|
2990
|
+
itemCount: S,
|
|
2991
|
+
items: [LINE_ITEM],
|
|
2992
|
+
lineItems: [LINE_ITEM]
|
|
2993
|
+
}),
|
|
2994
|
+
events: [EVENT],
|
|
2995
|
+
eventsUnavailable: T,
|
|
2996
|
+
recentWebhookDeliveries: section([DELIVERY])
|
|
2997
|
+
},
|
|
2998
|
+
list_extension_installations: page2({
|
|
2999
|
+
id: S,
|
|
3000
|
+
extensionId: S,
|
|
3001
|
+
extensionName: T,
|
|
3002
|
+
extensionSlug: S,
|
|
3003
|
+
versionId: S,
|
|
3004
|
+
status: S,
|
|
3005
|
+
environmentSlug: S,
|
|
3006
|
+
installedAt: S,
|
|
3007
|
+
uninstalledAt: S
|
|
3008
|
+
}),
|
|
3009
|
+
get_connector_routing: {
|
|
3010
|
+
paymentRouting: section({
|
|
3011
|
+
defaultCascade: [S],
|
|
3012
|
+
rules: [{ cascade: [S], conditions: [{ type: S, op: S, currency: S, min: S, max: S, values: [S] }] }]
|
|
3013
|
+
}),
|
|
3014
|
+
cardDecline: section({ rules: [{ errorCode: S, conditions: [{ type: S, op: S, values: [S] }] }] }),
|
|
3015
|
+
otherDecline: section({ rules: [{ errorCode: S, conditions: [{ type: S, op: S, values: [S] }] }] }),
|
|
3016
|
+
routingConnectors: section([{ id: S, displayName: T, method: S }])
|
|
3017
|
+
},
|
|
3018
|
+
get_integration_status: {
|
|
3019
|
+
environment: { slug: S, kind: S, providerEnvironment: S },
|
|
3020
|
+
workspace: { name: T, slug: S },
|
|
3021
|
+
applicationId: S,
|
|
3022
|
+
application: APPLICATION,
|
|
3023
|
+
connectors: section([{
|
|
3024
|
+
id: S,
|
|
3025
|
+
displayName: T,
|
|
3026
|
+
method: S,
|
|
3027
|
+
type: S,
|
|
3028
|
+
status: S,
|
|
3029
|
+
active: S,
|
|
3030
|
+
position: S,
|
|
3031
|
+
acceptedCountries: [S],
|
|
3032
|
+
acceptedCurrencies: [S],
|
|
3033
|
+
threeDSecureEnabled: S,
|
|
3034
|
+
createdAt: S
|
|
3035
|
+
}]),
|
|
3036
|
+
webhookEndpoints: section([{ id: S, isActive: S, enabledEvents: [S], createdAt: S }]),
|
|
3037
|
+
unsubscribedEvents: section({ windowDays: S, unsubscribed: [{ type: S, count: S, lastEmittedAt: S }] })
|
|
3038
|
+
},
|
|
3039
|
+
get_workspace_settings: { name: T, slug: S, brandColor: S, logoUrl: T, onboardingCompletedAt: S },
|
|
3040
|
+
// What happened and to which record; not which team member did it.
|
|
3041
|
+
get_audit_log: page2({ id: S, action: S, resourceType: S, resourceId: S, createdAt: S }),
|
|
3042
|
+
list_applications: [{ id: S, name: T, slug: S, currency: S, isActive: S }],
|
|
3043
|
+
// Analytics: computed aggregates, listed field by field all the same.
|
|
3044
|
+
get_business_summary: {
|
|
3045
|
+
period: S,
|
|
3046
|
+
range: RANGE,
|
|
3047
|
+
orders: section({ current: ORDER_PERIOD, previous: ORDER_PERIOD, deltaPct: S }),
|
|
3048
|
+
subscriptions: section({
|
|
3049
|
+
mrr: { currentCents: S, periodStartCents: S, deltaPct: S },
|
|
3050
|
+
newSubscriptions: S,
|
|
3051
|
+
cancelledSubscriptions: S,
|
|
3052
|
+
churnRate: S,
|
|
3053
|
+
note: T
|
|
3054
|
+
}),
|
|
3055
|
+
receivables: section({ outstandingCents: S, outstandingCount: S }),
|
|
3056
|
+
quotes: section({ sent: MONEY_COUNT, accepted: MONEY_COUNT, declined: MONEY_COUNT, expired: MONEY_COUNT })
|
|
3057
|
+
},
|
|
3058
|
+
get_attention_digest: {
|
|
3059
|
+
disputes: section({ open: S, totalCents: S }),
|
|
3060
|
+
subscriptionsInDunning: section(S),
|
|
3061
|
+
overdueInvoices: section(MONEY_COUNT),
|
|
3062
|
+
unhealthyWebhooks: section([{ endpointId: S, failureRate: S, attempts7d: S }])
|
|
3063
|
+
},
|
|
3064
|
+
get_sales_timeseries: {
|
|
3065
|
+
application: APPLICATION,
|
|
3066
|
+
range: RANGE,
|
|
3067
|
+
currency: S,
|
|
3068
|
+
days: S,
|
|
3069
|
+
note: T,
|
|
3070
|
+
series: [{ date: S, grossCents: S, orders: S }],
|
|
3071
|
+
totalGrossCents: S,
|
|
3072
|
+
totalOrders: S
|
|
3073
|
+
},
|
|
3074
|
+
// get_top_products has no entry, so it is not offered over OAuth: it ranks
|
|
3075
|
+
// products by line-item reference id or name, which a buyer can type.
|
|
3076
|
+
get_customer_growth: {
|
|
3077
|
+
application: APPLICATION,
|
|
3078
|
+
range: RANGE,
|
|
3079
|
+
note: T,
|
|
3080
|
+
topBy: S,
|
|
3081
|
+
signups: { total: S, series: [{ date: S, signups: S }] },
|
|
3082
|
+
ordersByCustomerType: { newCustomerOrders: S, returningCustomerOrders: S },
|
|
3083
|
+
// The ranking, by id: a top customer's name and email stay behind.
|
|
3084
|
+
topCustomers: [{ customerId: S, orderCount: S, revenueCents: S }],
|
|
3085
|
+
totals: { customerCount: S, orderCount: S, revenueCents: S }
|
|
3086
|
+
},
|
|
3087
|
+
get_revenue_breakdown: {
|
|
3088
|
+
application: APPLICATION,
|
|
3089
|
+
range: RANGE,
|
|
3090
|
+
dimension: S,
|
|
3091
|
+
note: T,
|
|
3092
|
+
rows: [{ key: S, orderCount: S, grossCents: S }],
|
|
3093
|
+
totals: { orderCount: S, grossCents: S }
|
|
3094
|
+
},
|
|
3095
|
+
get_funnel_conversion: {
|
|
3096
|
+
application: APPLICATION,
|
|
3097
|
+
range: RANGE,
|
|
3098
|
+
note: T,
|
|
3099
|
+
conversionRate: S,
|
|
3100
|
+
stages: [{ name: S, count: S }],
|
|
3101
|
+
dropOff: [{ from: S, to: S, ratePct: S }]
|
|
3102
|
+
},
|
|
3103
|
+
get_subscription_movement: {
|
|
3104
|
+
application: APPLICATION,
|
|
3105
|
+
range: RANGE,
|
|
3106
|
+
note: T,
|
|
3107
|
+
series: [{ date: S, newSubscriptions: S, churnedSubscriptions: S, mrrDeltaCents: S }],
|
|
3108
|
+
totals: { newSubscriptions: S, churnedSubscriptions: S, netMrrDeltaCents: S }
|
|
3109
|
+
},
|
|
3110
|
+
get_discount_performance: {
|
|
3111
|
+
application: APPLICATION,
|
|
3112
|
+
range: RANGE,
|
|
3113
|
+
note: T,
|
|
3114
|
+
rows: [{ discountId: S, code: T, redemptions: S, discountedRevenueCents: S, discountGivenCents: S }],
|
|
3115
|
+
totals: { redemptions: S, discountedRevenueCents: S, discountGivenCents: S }
|
|
3116
|
+
}
|
|
3117
|
+
};
|
|
3118
|
+
|
|
3119
|
+
// src/server.ts
|
|
3120
|
+
var VERSION = true ? "0.2.1" : "0.0.0-dev";
|
|
3121
|
+
function registerableActions(policy) {
|
|
3122
|
+
const isProduction = policy.identity.environment.providerEnvironment === "production";
|
|
3123
|
+
return actionsForChannel("mcp").filter((action) => {
|
|
3124
|
+
if (!HANDLERS[action.id]) return false;
|
|
3125
|
+
if (action.credentialScoped && policy.allowCredentialScoped === false) return false;
|
|
3126
|
+
if (!canRunAction(policy.identity.scopes, action)) return false;
|
|
3127
|
+
if (action.kind === "read") return true;
|
|
3128
|
+
if (action.sandboxOnly) return !isProduction && (policy.allowSandboxWrites ?? true);
|
|
3129
|
+
if (!policy.allowWrites) return false;
|
|
3130
|
+
return !isProduction || policy.allowLiveWrites;
|
|
3131
|
+
});
|
|
3132
|
+
}
|
|
3133
|
+
function buildInstructions(identity, actions, policy) {
|
|
3134
|
+
const isProduction = identity.environment.providerEnvironment === "production";
|
|
3135
|
+
const where = [
|
|
3136
|
+
identity.workspace?.name ?? identity.workspace?.slug ?? "unknown workspace",
|
|
3137
|
+
identity.application?.name ?? identity.application?.slug ?? null
|
|
3138
|
+
].filter(Boolean).join(" / ");
|
|
3139
|
+
const liveWrites = actions.filter((a) => a.kind === "write" && !a.sandboxOnly);
|
|
3140
|
+
const sandboxWrites = actions.filter((a) => a.kind === "write" && a.sandboxOnly);
|
|
3141
|
+
const lines = [
|
|
3142
|
+
`Throttle MCP ${VERSION}. Connected to ${where}, environment "${identity.environment.slug}" (${isProduction ? "PRODUCTION \u2014 live data" : "non-production \u2014 not live data"}).`,
|
|
3143
|
+
"",
|
|
3144
|
+
"Conventions:",
|
|
3145
|
+
"- The workspace and environment are fixed for this session and cannot be switched from inside a tool call. Call whoami if you need to state where you are.",
|
|
3146
|
+
'- The application can vary per call: pass "applicationId" on a read or analytics tool to reach a different application in this workspace, and call list_applications to see which ones this connection can reach. Omitting applicationId uses the application this connection was authorized for.',
|
|
3147
|
+
"- Every analytics result covers exactly ONE application and names it in `application`. Say which application a figure describes. If the user asks about their business as a whole and this connection reaches more than one application, do not answer from the default alone \u2014 call list_applications, then query each and add them up, or ask which application they mean.",
|
|
3148
|
+
'- List tools return { data, pagination }. When pagination.hasMore is true, pass pagination.cursor back as "cursor" rather than raising "limit".',
|
|
3149
|
+
"- Amounts are integer minor units (2500 = $25.00).",
|
|
3150
|
+
"- Throttle rejects snake_case on public request bodies. Before writing integration code, confirm shapes with describe_endpoint and check bodies with validate_payload instead of guessing field names.",
|
|
3151
|
+
"- API errors come back as text with a stable code. On insufficient_scopes, tell the user which scope to add \u2014 do not retry.",
|
|
3152
|
+
"- Analytics results may mark a section `omitted`. That means UNKNOWN, never zero. When `grantable` is false the data cannot be read over this connection at all \u2014 say so rather than reporting an absence."
|
|
3153
|
+
];
|
|
3154
|
+
if (liveWrites.length === 0) {
|
|
3155
|
+
lines.push(
|
|
3156
|
+
`- This session is READ-ONLY for real data${policy.allowWrites ? " (no write tools are available to this credential)" : " \u2014 writes were not enabled"}. Say so plainly if asked to change something.`
|
|
3157
|
+
);
|
|
3158
|
+
if (sandboxWrites.length > 0) {
|
|
3159
|
+
lines.push(
|
|
3160
|
+
`- ${sandboxWrites.map((a) => a.id).join(", ")} may create data, but only in this non-production environment.`
|
|
3161
|
+
);
|
|
3162
|
+
}
|
|
3163
|
+
} else {
|
|
3164
|
+
lines.push(
|
|
3165
|
+
`- Write tools are enabled (${liveWrites.map((a) => a.id).join(", ")}). They are irreversible and some are buyer-visible. Confirm with the user before calling one.`
|
|
3166
|
+
);
|
|
3167
|
+
}
|
|
3168
|
+
return lines.join("\n");
|
|
3169
|
+
}
|
|
3170
|
+
function declareSecuritySchemes(server, actions) {
|
|
3171
|
+
const inner = server.server;
|
|
3172
|
+
const handlers = inner._requestHandlers;
|
|
3173
|
+
const original = handlers?.get("tools/list");
|
|
3174
|
+
if (!original) return;
|
|
3175
|
+
const schemes = new Map(
|
|
3176
|
+
actions.map((a) => [
|
|
3177
|
+
a.id,
|
|
3178
|
+
[{
|
|
3179
|
+
type: "oauth2",
|
|
3180
|
+
scopes: [.../* @__PURE__ */ new Set([...a.scopes, ...a.sectionScopes ?? []])].filter((scope) => validateScopesForOAuth([scope]).ok)
|
|
3181
|
+
}]
|
|
3182
|
+
])
|
|
3183
|
+
);
|
|
3184
|
+
inner.setRequestHandler(ListToolsRequestSchema, async (request, extra) => {
|
|
3185
|
+
const result = await original(request, extra);
|
|
3186
|
+
return {
|
|
3187
|
+
...result,
|
|
3188
|
+
tools: result.tools.map((tool) => ({ ...tool, securitySchemes: schemes.get(tool.name) ?? [{ type: "oauth2", scopes: [] }] }))
|
|
3189
|
+
};
|
|
3190
|
+
});
|
|
3191
|
+
}
|
|
3192
|
+
function createServer(options) {
|
|
3193
|
+
const redactPii = options.identity.type === "oauth_token" && !hasScope(options.identity.scopes, "customer_pii:read");
|
|
3194
|
+
const actions = registerableActions(options).filter((a) => !redactPii || OAUTH_PROJECTIONS[a.id] !== void 0);
|
|
3195
|
+
const server = new McpServer(
|
|
3196
|
+
{ name: "throttle", version: VERSION },
|
|
3197
|
+
{ instructions: buildInstructions(options.identity, actions, options) }
|
|
3198
|
+
);
|
|
3199
|
+
const ctx = {
|
|
3200
|
+
client: options.client,
|
|
3201
|
+
identity: options.identity,
|
|
3202
|
+
contract: options.contract,
|
|
3203
|
+
docs: options.docs
|
|
3204
|
+
};
|
|
3205
|
+
for (const action of actions) {
|
|
3206
|
+
const handler = HANDLERS[action.id];
|
|
3207
|
+
server.registerTool(
|
|
3208
|
+
action.id,
|
|
3209
|
+
{
|
|
3210
|
+
title: action.title,
|
|
3211
|
+
description: describeForModel(action),
|
|
3212
|
+
inputSchema: fieldsToZodShape(action.input),
|
|
3213
|
+
// Every hint is an explicit boolean: directory reviews (OpenAI's in
|
|
3214
|
+
// particular) read a missing value as "unknown", not as false.
|
|
3215
|
+
annotations: {
|
|
3216
|
+
title: action.title,
|
|
3217
|
+
readOnlyHint: action.kind === "read",
|
|
3218
|
+
destructiveHint: action.kind === "write" && Boolean(action.destructive),
|
|
3219
|
+
idempotentHint: Boolean(action.idempotent),
|
|
3220
|
+
// Every tool is bounded to the connected workspace; none reaches the
|
|
3221
|
+
// public internet or an open-ended set of external entities.
|
|
3222
|
+
openWorldHint: false
|
|
3223
|
+
}
|
|
3224
|
+
},
|
|
3225
|
+
async (args) => {
|
|
3226
|
+
try {
|
|
3227
|
+
if (redactPii && action.id === "search_customers" && typeof args?.q === "string" && args.q.trim() !== "") {
|
|
3228
|
+
return {
|
|
3229
|
+
content: [{ type: "text", text: "Customer text search is not available over this connection, because names, emails, phone numbers and external ids are withheld. List customers by creation date (createdAfter/createdBefore), or open one by its Throttle id from an order, quote or subscription." }],
|
|
3230
|
+
isError: true
|
|
3231
|
+
};
|
|
3232
|
+
}
|
|
3233
|
+
const result = await handler(ctx, args ?? {});
|
|
3234
|
+
const shown = redactPii ? redactShopperPii(project(result, OAUTH_PROJECTIONS[action.id])) : result;
|
|
3235
|
+
return { content: [{ type: "text", text: formatResult(shown) }] };
|
|
3236
|
+
} catch (error) {
|
|
3237
|
+
return {
|
|
3238
|
+
content: [{ type: "text", text: formatError(error) }],
|
|
3239
|
+
isError: true,
|
|
3240
|
+
...options.authChallenge && isCredentialRejection(error) ? {
|
|
3241
|
+
_meta: {
|
|
3242
|
+
"mcp/www_authenticate": [
|
|
3243
|
+
`${options.authChallenge}, error="invalid_token", error_description="The connected credential was rejected. Sign in again to continue."`
|
|
3244
|
+
]
|
|
3245
|
+
}
|
|
3246
|
+
} : {}
|
|
3247
|
+
};
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
);
|
|
3251
|
+
}
|
|
3252
|
+
if (options.authChallenge) declareSecuritySchemes(server, actions);
|
|
3253
|
+
return server;
|
|
3254
|
+
}
|
|
3255
|
+
function isCredentialRejection(error) {
|
|
3256
|
+
return error?.statusCode === 401;
|
|
3257
|
+
}
|
|
3258
|
+
function describeForModel(action) {
|
|
3259
|
+
const parts = [action.description];
|
|
3260
|
+
if (action.guardrails && action.guardrails.length > 0) {
|
|
3261
|
+
parts.push(`Constraints: ${action.guardrails.join(" ")}`);
|
|
3262
|
+
}
|
|
3263
|
+
return parts.join(" ");
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
// src/indexes.ts
|
|
3267
|
+
import { readFileSync } from "fs";
|
|
3268
|
+
function loadIndex(file, empty, label) {
|
|
3269
|
+
try {
|
|
3270
|
+
return JSON.parse(readFileSync(new URL(`./${file}`, import.meta.url), "utf8"));
|
|
3271
|
+
} catch {
|
|
3272
|
+
process.stderr.write(
|
|
3273
|
+
`throttle-mcp: ${label} index missing (${file}); that tool will return no results. Run "pnpm --filter @usethrottle/mcp build:indexes".
|
|
3274
|
+
`
|
|
3275
|
+
);
|
|
3276
|
+
return empty;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
function loadDocsIndex() {
|
|
3280
|
+
return loadIndex("docs-index.json", { generatedAt: "", entries: [] }, "docs");
|
|
3281
|
+
}
|
|
3282
|
+
function loadContractIndex() {
|
|
3283
|
+
return loadIndex("contract-index.json", { generatedAt: "", operations: [] }, "contract");
|
|
3284
|
+
}
|
|
3285
|
+
export {
|
|
3286
|
+
ThrottleClient,
|
|
3287
|
+
VERSION,
|
|
3288
|
+
buildInstructions,
|
|
3289
|
+
createServer,
|
|
3290
|
+
loadContractIndex,
|
|
3291
|
+
loadDocsIndex,
|
|
3292
|
+
registerableActions
|
|
3293
|
+
};
|
|
3294
|
+
//# sourceMappingURL=lib.js.map
|