@zackbart/connecta 0.13.0 → 0.14.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +225 -0
  2. package/dist/catalog-service.d.ts.map +1 -1
  3. package/dist/catalog-service.js +33 -6
  4. package/dist/catalog-service.js.map +1 -1
  5. package/dist/connectors/api.d.ts.map +1 -1
  6. package/dist/connectors/api.js +5 -1
  7. package/dist/connectors/api.js.map +1 -1
  8. package/dist/execute.js +1 -1
  9. package/dist/execute.js.map +1 -1
  10. package/dist/providers/cloudflare.d.ts +54 -0
  11. package/dist/providers/cloudflare.d.ts.map +1 -0
  12. package/dist/providers/cloudflare.js +3210 -0
  13. package/dist/providers/cloudflare.js.map +1 -0
  14. package/dist/providers/linear.d.ts +44 -0
  15. package/dist/providers/linear.d.ts.map +1 -0
  16. package/dist/providers/linear.js +243 -0
  17. package/dist/providers/linear.js.map +1 -0
  18. package/dist/providers/mixpanel.d.ts.map +1 -1
  19. package/dist/providers/mixpanel.js +15 -7
  20. package/dist/providers/mixpanel.js.map +1 -1
  21. package/dist/providers/notion.d.ts +39 -0
  22. package/dist/providers/notion.d.ts.map +1 -0
  23. package/dist/providers/notion.js +1625 -0
  24. package/dist/providers/notion.js.map +1 -0
  25. package/dist/providers/stripe.d.ts +37 -0
  26. package/dist/providers/stripe.d.ts.map +1 -0
  27. package/dist/providers/stripe.js +232 -0
  28. package/dist/providers/stripe.js.map +1 -0
  29. package/dist/version.d.ts +1 -1
  30. package/dist/version.js +1 -1
  31. package/documentation/cloudflare.md +313 -0
  32. package/documentation/connectors.md +13 -7
  33. package/documentation/linear.md +144 -0
  34. package/documentation/meta-tools.md +12 -1
  35. package/documentation/mixpanel.md +12 -7
  36. package/documentation/notion.md +233 -0
  37. package/documentation/stripe.md +202 -0
  38. package/ethos.md +1 -0
  39. package/package.json +17 -1
  40. package/src/catalog-service.ts +35 -6
  41. package/src/connectors/api.ts +5 -1
  42. package/src/execute.ts +1 -1
  43. package/src/providers/cloudflare.ts +3803 -0
  44. package/src/providers/linear.ts +301 -0
  45. package/src/providers/mixpanel.ts +15 -7
  46. package/src/providers/notion.ts +1879 -0
  47. package/src/providers/stripe.ts +306 -0
  48. package/src/version.ts +1 -1
  49. package/templates/node/package.json +1 -1
@@ -0,0 +1,306 @@
1
+ import {
2
+ remoteMcp,
3
+ type RemoteMcpAuth,
4
+ } from "../connectors/remote-mcp.js";
5
+ import type {
6
+ Connector,
7
+ ConnectorCallAdmissionPolicy,
8
+ ToolDef,
9
+ } from "../types.js";
10
+
11
+ /**
12
+ * Which Stripe environment this instance speaks to. Required, and deliberately
13
+ * undefaulted: there is no safe guess between an account that moves real money
14
+ * and one that does not.
15
+ */
16
+ export type StripeMode = "production" | "sandbox";
17
+
18
+ /** Stripe publishes one hosted MCP endpoint; the credential selects the mode. */
19
+ export const STRIPE_MCP_ENDPOINT = "https://mcp.stripe.com/";
20
+
21
+ export interface StripeOptions {
22
+ /**
23
+ * Which Stripe environment this connector reaches. Shapes the title,
24
+ * description, guide, and admission budget, and is checked against a
25
+ * recognizable key prefix in `auth` headers.
26
+ */
27
+ mode: StripeMode;
28
+ /** Human-readable display name; defaults to "Stripe (<mode>)". */
29
+ title?: string;
30
+ /** Which business this account bills for, and what it may be asked. */
31
+ purpose: string;
32
+ /** OAuth by default; static headers support restricted API keys. */
33
+ auth?: RemoteMcpAuth;
34
+ /**
35
+ * Connect platform only: act as this connected account (`acct_...`) by
36
+ * sending Stripe's `Stripe-Account` header. Stripe does not support OAuth on
37
+ * connected-account calls, so this requires `headers` auth.
38
+ */
39
+ connectedAccount?: string;
40
+ /** Account-specific conventions appended to the maintained provider guide. */
41
+ instructions?: string;
42
+ /** Connector-specific inline result limit; omit to inherit the deployment. */
43
+ maxResultBytes?: number;
44
+ }
45
+
46
+ /**
47
+ * Stripe documents no MCP-specific rate limit, so this transcribes the account
48
+ * limit the MCP server spends: 100 requests per second in live mode, 25 in a
49
+ * sandbox (https://docs.stripe.com/rate-limits). The concurrency bound is
50
+ * connecta's own conservative choice — Stripe documents that per-account and
51
+ * per-endpoint concurrency limits exist and surface as `429` with a
52
+ * `Stripe-Rate-Limited-Reason` of `global-concurrency` or
53
+ * `endpoint-concurrency`, but publishes no number. Declaring `maxConcurrency`
54
+ * is also what earns the right to the queue settings beside it.
55
+ */
56
+ const STRIPE_ADMISSION: Readonly<
57
+ Record<StripeMode, ConnectorCallAdmissionPolicy>
58
+ > = {
59
+ production: {
60
+ rules: [
61
+ {
62
+ maxConcurrency: 8,
63
+ queueTimeoutMs: 5_000,
64
+ retryAfterMs: 1_000,
65
+ budget: { kind: "rolling-window", maxCalls: 100, windowMs: 1_000 },
66
+ },
67
+ ],
68
+ },
69
+ sandbox: {
70
+ rules: [
71
+ {
72
+ maxConcurrency: 4,
73
+ queueTimeoutMs: 5_000,
74
+ retryAfterMs: 1_000,
75
+ budget: { kind: "rolling-window", maxCalls: 25, windowMs: 1_000 },
76
+ },
77
+ ],
78
+ },
79
+ };
80
+
81
+ /**
82
+ * Tools whose official contract is observational rather than mutating.
83
+ *
84
+ * `stripe_api_read` is on this list because Stripe documents it as the `GET`
85
+ * half of the generic pair — the tool itself is the read boundary, not the
86
+ * endpoint an agent names inside it.
87
+ */
88
+ const READ_ONLY_TOOLS = new Set([
89
+ "stripe_api_search",
90
+ "stripe_api_details",
91
+ "stripe_api_read",
92
+ "get_stripe_account_info",
93
+ "get_balance_summary",
94
+ "search_stripe_documentation",
95
+ "stripe_implementation_planner",
96
+ ]);
97
+
98
+ /**
99
+ * The maintained write catalog. `"destructive"` tools modify or remove state
100
+ * that already exists; `"additive"` ones only bring something new into being.
101
+ * Both leave the read-only path — the distinction only decides whether the
102
+ * connection asserts `destructiveHint`, which shapes the host's approval copy.
103
+ *
104
+ * `create_refund` is filed destructive despite its name: it reverses a
105
+ * settled charge and moves money back out, which is a mutation of something
106
+ * that already exists, not a fresh object appearing beside it.
107
+ */
108
+ const WRITE_TOOLS: ReadonlyMap<string, "additive" | "destructive"> = new Map([
109
+ ["stripe_api_write", "destructive"],
110
+ ["create_refund", "destructive"],
111
+ ["stripe_report", "additive"],
112
+ ["send_stripe_mcp_feedback", "additive"],
113
+ ]);
114
+
115
+ /**
116
+ * Fill in what the downstream leaves unsaid; never argue with what it says.
117
+ *
118
+ * Silence is what a vetted classification is for, and an explicit downstream
119
+ * annotation wins in both directions. `destructiveHint: true` or
120
+ * `readOnlyHint: false` on an allowlisted read name is the downstream telling
121
+ * us this release's allowlist is stale; `readOnlyHint: true` on a name no
122
+ * release has classified says the same thing from the other side. The single
123
+ * place a vetted verdict still overrides the downstream is a name this release
124
+ * reviewed and filed destructive: there connecta knows what the tool does, and
125
+ * a claim to the contrary is a downstream bug rather than news
126
+ * ([#310](https://github.com/zackbart/connecta/issues/310)).
127
+ */
128
+ function vettedSafety(definition: ToolDef): ToolDef {
129
+ const downstream = definition.annotations ?? {};
130
+ if (READ_ONLY_TOOLS.has(definition.name)) {
131
+ if (
132
+ downstream.destructiveHint === true ||
133
+ downstream.readOnlyHint === false
134
+ ) {
135
+ return definition;
136
+ }
137
+ return {
138
+ ...definition,
139
+ annotations: {
140
+ ...downstream,
141
+ readOnlyHint: true,
142
+ destructiveHint: downstream.destructiveHint ?? false,
143
+ },
144
+ };
145
+ }
146
+ if (WRITE_TOOLS.get(definition.name) === "destructive") {
147
+ return {
148
+ ...definition,
149
+ annotations: {
150
+ ...downstream,
151
+ readOnlyHint: false,
152
+ destructiveHint: true,
153
+ },
154
+ };
155
+ }
156
+ // Maintained additive writes and tools this release has never seen land here
157
+ // alike. Fill-in only: a silent tool is not read-only, so drift still fails
158
+ // closed onto `call_destructive_tool`, and neither population gets a
159
+ // `destructiveHint` it has not earned. A tool that arrives explicitly
160
+ // read-only keeps that annotation — on a name no release has reviewed, the
161
+ // downstream's own word is the only evidence there is, and rewriting it
162
+ // would be an overrule rather than a fill-in.
163
+ return {
164
+ ...definition,
165
+ annotations: {
166
+ ...downstream,
167
+ readOnlyHint: downstream.readOnlyHint ?? false,
168
+ },
169
+ };
170
+ }
171
+
172
+ /** Stripe key prefixes carry their own mode; only a clear reading counts. */
173
+ const LIVE_KEY = /\b(?:sk|rk|pk)_live_/;
174
+ const TEST_KEY = /\b(?:sk|rk|pk)_test_/;
175
+
176
+ /**
177
+ * Refuse a deployment whose declared mode and supplied key disagree.
178
+ *
179
+ * This is the one half of production/sandbox routing connecta can actually
180
+ * enforce. Nothing here reads or reports key material: an unrecognizable
181
+ * credential (OAuth, or a key shape this release does not know) is left alone
182
+ * rather than guessed at, and a mismatch names only the two modes.
183
+ */
184
+ function assertModeMatchesKey(
185
+ id: string,
186
+ mode: StripeMode,
187
+ auth: RemoteMcpAuth,
188
+ ): void {
189
+ if (auth.type !== "headers") return;
190
+ for (const value of Object.values(auth.headers)) {
191
+ const keyMode = LIVE_KEY.test(value)
192
+ ? "production"
193
+ : TEST_KEY.test(value)
194
+ ? "sandbox"
195
+ : undefined;
196
+ if (keyMode !== undefined && keyMode !== mode) {
197
+ throw new Error(
198
+ `stripe("${id}") declares mode "${mode}" but its auth headers carry a ` +
199
+ `${keyMode === "production" ? "live" : "test"}-mode Stripe key.`,
200
+ );
201
+ }
202
+ }
203
+ }
204
+
205
+ function resolveAuth(id: string, options: StripeOptions): RemoteMcpAuth {
206
+ const auth = options.auth ?? { type: "oauth" };
207
+ const connectedAccount = options.connectedAccount?.trim();
208
+ if (connectedAccount === undefined || connectedAccount === "") return auth;
209
+ if (!connectedAccount.startsWith("acct_")) {
210
+ throw new Error(
211
+ `stripe("${id}") connectedAccount must be a Stripe account id ("acct_...").`,
212
+ );
213
+ }
214
+ if (auth.type !== "headers") {
215
+ throw new Error(
216
+ `stripe("${id}") cannot reach a connected account over OAuth; Stripe ` +
217
+ `requires a restricted API key for Stripe-Account calls.`,
218
+ );
219
+ }
220
+ return {
221
+ type: "headers",
222
+ headers: { ...auth.headers, "Stripe-Account": connectedAccount },
223
+ };
224
+ }
225
+
226
+ const MODE_COPY: Readonly<
227
+ Record<StripeMode, { title: string; blurb: string; warning: string }>
228
+ > = {
229
+ production: {
230
+ title: "Stripe (production)",
231
+ blurb: "production — live money and real customers",
232
+ warning:
233
+ "This is a PRODUCTION account. Every write moves real money against real customers, and a refund cannot be undone. If a request could plausibly be a rehearsal, route it to a sandbox connector instead.",
234
+ },
235
+ sandbox: {
236
+ title: "Stripe (sandbox)",
237
+ blurb: "sandbox — test data, no real money",
238
+ warning:
239
+ "This is a SANDBOX account. Nothing here is real money and none of these objects exist in production, so never answer a question about live revenue, payouts, or a named customer from this connector.",
240
+ },
241
+ };
242
+
243
+ function usageGuide(
244
+ mode: StripeMode,
245
+ purpose: string,
246
+ instructions: string | undefined,
247
+ ): string {
248
+ const copy = MODE_COPY[mode];
249
+ const accountInstructions = instructions?.trim();
250
+ const rate = mode === "production" ? "100" : "25";
251
+ return `# Stripe usage
252
+
253
+ Mode: ${mode}. Account purpose: ${purpose}
254
+
255
+ ${copy.warning}
256
+
257
+ - Four generic tools reach any Stripe API method. Find the method with \`stripe_api_search\`, read its parameters with \`stripe_api_details\`, then call \`stripe_api_read\` (GET) or \`stripe_api_write\` (POST/PATCH/PUT/DELETE). Never guess a path or a parameter name — \`stripe_api_details\` is cheaper than a rejected write.
258
+ - Prefer a dedicated tool when one covers the task: \`get_stripe_account_info\` for which account this is, \`get_balance_summary\` for balances, \`create_refund\` for refunds, \`stripe_report\` for reports. One call instead of three, and a refund named \`create_refund\` reads far more clearly in the approval a human sees than the same refund buried in \`stripe_api_write\` arguments.
259
+ - \`stripe_api_write\` carries the blast radius of the entire write API — every POST, PATCH, PUT, and DELETE, from a customer edit to a subscription cancellation. State the method and path explicitly; expect approval on every call.
260
+ - Lists are cursor-paginated: \`limit\` defaults to 10 and caps at 100, \`starting_after\` and \`ending_before\` take an object id and are mutually exclusive, and \`has_more\` says whether to continue. Page inside \`execute_code\` and reduce before returning.
261
+ - Amounts are integers in the currency's minor unit: \`1099\` is 10.99 USD, and zero-decimal currencies like JPY take \`10\` for 10 JPY. Never send a decimal.
262
+ - Send an \`Idempotency-Key\` on every write you might retry, if the tool accepts it, and reuse the same key for the retry. A retry with a fresh key is a second charge, not a second attempt.
263
+ - Stripe answers a rate limit with \`429\` and a \`Stripe-Rate-Limited-Reason\` header; back off on that rather than retrying immediately. This account's documented ceiling is ${rate} requests per second, and any single endpoint is capped at 25 per second regardless of mode, so paging one list is the real constraint.
264
+ - Use \`search_stripe_documentation\` when the shape of an object or a flow is unclear; it is a read and costs nothing but a call.
265
+ - Treat every create, update, delete, refund, and report run as a write. Connecta routes the maintained write catalog through \`call_destructive_tool\`; newly added tools also fail closed until classified.
266
+ ${
267
+ accountInstructions
268
+ ? `\n## Account instructions\n\n${accountInstructions}\n`
269
+ : ""
270
+ }`;
271
+ }
272
+
273
+ /** A maintained Stripe hosted-MCP connection. */
274
+ export function stripe(id: string, options: StripeOptions): Connector {
275
+ const purpose = options.purpose.trim();
276
+ if (!purpose) {
277
+ throw new Error("stripe() requires a non-empty account purpose.");
278
+ }
279
+ const mode = options.mode;
280
+ if (mode !== "production" && mode !== "sandbox") {
281
+ throw new Error(
282
+ `stripe("${id}") requires mode "production" or "sandbox".`,
283
+ );
284
+ }
285
+ const auth = resolveAuth(id, options);
286
+ assertModeMatchesKey(id, mode, auth);
287
+ const copy = MODE_COPY[mode];
288
+ const connector = remoteMcp(id, {
289
+ url: STRIPE_MCP_ENDPOINT,
290
+ title: options.title ?? copy.title,
291
+ description: `Stripe payments (${copy.blurb}) — ${purpose}`,
292
+ auth,
293
+ requireHttps: true,
294
+ callAdmission: STRIPE_ADMISSION[mode],
295
+ usageGuide: usageGuide(mode, purpose, options.instructions),
296
+ ...(options.maxResultBytes !== undefined
297
+ ? { maxResultBytes: options.maxResultBytes }
298
+ : {}),
299
+ });
300
+ return {
301
+ ...connector,
302
+ async listTools(ctx) {
303
+ return (await connector.listTools(ctx)).map(vettedSafety);
304
+ },
305
+ };
306
+ }
package/src/version.ts CHANGED
@@ -4,4 +4,4 @@
4
4
  * a bump that forgets this file fails the build rather than shipping a stale
5
5
  * version to `/health` and to downstream MCP handshakes.
6
6
  */
7
- export const CONNECTA_VERSION = "0.13.0";
7
+ export const CONNECTA_VERSION = "0.14.1";
@@ -12,7 +12,7 @@
12
12
  "typecheck": "tsc --noEmit"
13
13
  },
14
14
  "dependencies": {
15
- "@zackbart/connecta": "0.13.0",
15
+ "@zackbart/connecta": "0.14.1",
16
16
  "quickjs-emscripten": "0.32.0"
17
17
  },
18
18
  "devDependencies": {