@zackbart/connecta 0.12.2 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +324 -0
  2. package/README.md +4 -1
  3. package/dist/catalog-service.d.ts +41 -0
  4. package/dist/catalog-service.d.ts.map +1 -1
  5. package/dist/catalog-service.js +127 -11
  6. package/dist/catalog-service.js.map +1 -1
  7. package/dist/connectors/api.d.ts +5 -4
  8. package/dist/connectors/api.d.ts.map +1 -1
  9. package/dist/connectors/api.js +5 -1
  10. package/dist/connectors/api.js.map +1 -1
  11. package/dist/connectors/remote-mcp.d.ts +5 -4
  12. package/dist/connectors/remote-mcp.d.ts.map +1 -1
  13. package/dist/connectors/remote-mcp.js.map +1 -1
  14. package/dist/execute.d.ts.map +1 -1
  15. package/dist/execute.js +12 -10
  16. package/dist/execute.js.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/meta-tools.d.ts.map +1 -1
  21. package/dist/meta-tools.js +5 -4
  22. package/dist/meta-tools.js.map +1 -1
  23. package/dist/providers/cloudflare.d.ts +53 -0
  24. package/dist/providers/cloudflare.d.ts.map +1 -0
  25. package/dist/providers/cloudflare.js +1385 -0
  26. package/dist/providers/cloudflare.js.map +1 -0
  27. package/dist/providers/linear.d.ts +44 -0
  28. package/dist/providers/linear.d.ts.map +1 -0
  29. package/dist/providers/linear.js +243 -0
  30. package/dist/providers/linear.js.map +1 -0
  31. package/dist/providers/mixpanel.d.ts +21 -0
  32. package/dist/providers/mixpanel.d.ts.map +1 -0
  33. package/dist/providers/mixpanel.js +191 -0
  34. package/dist/providers/mixpanel.js.map +1 -0
  35. package/dist/providers/notion.d.ts +39 -0
  36. package/dist/providers/notion.d.ts.map +1 -0
  37. package/dist/providers/notion.js +1625 -0
  38. package/dist/providers/notion.js.map +1 -0
  39. package/dist/providers/stripe.d.ts +37 -0
  40. package/dist/providers/stripe.d.ts.map +1 -0
  41. package/dist/providers/stripe.js +232 -0
  42. package/dist/providers/stripe.js.map +1 -0
  43. package/dist/skills.d.ts +7 -9
  44. package/dist/skills.d.ts.map +1 -1
  45. package/dist/skills.js +58 -24
  46. package/dist/skills.js.map +1 -1
  47. package/dist/types.d.ts +26 -6
  48. package/dist/types.d.ts.map +1 -1
  49. package/dist/version.d.ts +1 -1
  50. package/dist/version.js +1 -1
  51. package/documentation/cloudflare.md +268 -0
  52. package/documentation/code-mode.md +6 -6
  53. package/documentation/connectors.md +122 -4
  54. package/documentation/linear.md +144 -0
  55. package/documentation/meta-tools.md +91 -8
  56. package/documentation/mixpanel.md +77 -0
  57. package/documentation/notion.md +233 -0
  58. package/documentation/stripe.md +202 -0
  59. package/ethos.md +8 -3
  60. package/package.json +21 -1
  61. package/src/catalog-service.ts +174 -10
  62. package/src/connectors/api.ts +10 -4
  63. package/src/connectors/remote-mcp.ts +5 -3
  64. package/src/execute.ts +18 -10
  65. package/src/index.ts +1 -0
  66. package/src/meta-tools.ts +10 -4
  67. package/src/providers/cloudflare.ts +1696 -0
  68. package/src/providers/linear.ts +301 -0
  69. package/src/providers/mixpanel.ts +228 -0
  70. package/src/providers/notion.ts +1879 -0
  71. package/src/providers/stripe.ts +306 -0
  72. package/src/skills.ts +64 -23
  73. package/src/types.ts +27 -6
  74. package/src/version.ts +1 -1
  75. 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/skills.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { Connector } from "./types.js";
2
2
 
3
3
  export const CONNECTA_INSTRUCTIONS =
4
- 'Connecta exposes seven meta-tools. execute_code is primary: use connecta.search, describe, call, and batch for discovery, multiple or dependent calls, loops, joins, and result reduction. connecta.ui(html) is a guest function inside execute_code, never a connector address or search_tools result; pass one HTML string for display-only, or bind named read-only refresh/drill-down calls in its optional reads argument, and return the same initial summary data the HTML renders. For one read at an unknown address, search_tools with 2–4 distinctive action/object terms and includeSchemas="compact", then one call_tool — a lone cold call is cheaper direct than a program. Use call_destructive_tool individually for unannotated, write-capable, or destructive tools; authorize_connector follows auth_required; get_result follows truncation. If this routing is unfamiliar, fetch skills({ name: "usage" }).';
4
+ 'Connecta exposes seven meta-tools. For one read at an unknown address, search_tools with 2–4 distinctive action/object terms and includeSchemas="compact", then one call_tool — a lone cold call is cheaper direct than a program. For read-only reduction, multiple or dependent calls, loops, joins, or branches, do not call top-level search_tools: make one execute_code call whose program searches, selects, calls, and reduces; never return discovery for another call. connecta.ui(html) is a guest function inside execute_code, never a connector address or search_tools result; pass one HTML string for display-only, or bind named read-only refresh/drill-down calls in its optional reads argument, and return the same initial summary data the HTML renders. Unannotated, write-capable, or destructive tools stay top level: search_tools, then call_destructive_tool; authorize_connector follows auth_required; get_result follows truncation. If this routing is unfamiliar, fetch skills({ name: "usage" }).';
5
5
 
6
- export const USAGE_SKILL = `# Connecta usage
6
+ const USAGE_SKILL_BASE = `# Connecta usage
7
7
 
8
8
  ## The surface
9
9
 
@@ -23,7 +23,7 @@ Use exact addresses from discovery; never invent one. Search 2–4 distinctive a
23
23
 
24
24
  One async arrow function. The only capabilities are one global per connector (\`<connectorId>.<toolName>(args)\`), the \`connecta\` functions, and \`console.log\`.
25
25
 
26
- - \`connecta.search({})\` browses every catalog; \`safety: "readOnly"\` narrows to calls a program can execute, \`connector: "<id>"\` to one. This filters results, not authority; matches carry \`address\` and annotations.
26
+ - \`connecta.search({})\` loads all catalogs; pass \`connector: "<id>"\` when obvious to load one. \`safety: "readOnly"\` keeps executable calls. Neither grants authority. Matches carry \`address\` and annotations.
27
27
  - Exact schemas: \`connecta.describe({ address: "connector.tool" })\` for one, \`{ addresses: [...] }\` for many; \`format: "json"\` only for exact constraints.
28
28
  - Two to ten independent calls: \`connecta.batch([...])\`. Each outcome is \`{ address, ok: true, data }\` or \`{ address, ok: false, error, errorDetails: { code, retryable } }\` — how a program tells a policy refusal from a transient failure.
29
29
  - Search inside the run, not before it; return only the reduction the answer needs, never raw payloads.
@@ -35,18 +35,16 @@ One async arrow function. The only capabilities are one global per connector (\`
35
35
 
36
36
  `;
37
37
 
38
- /**
39
- * Appended to USAGE_SKILL only when the deployment actually has at least one
40
- * connector guide. A deployment with none — every deployment that has not
41
- * adopted the feature — keeps the base guide byte-for-byte, rather than paying
42
- * context for an instruction to fetch guides that do not exist.
43
- */
44
- export const CONNECTOR_GUIDES_SECTION = `
38
+ /** Deployment-scoped guide routing appended to the shared usage guide. */
39
+ const CONNECTOR_GUIDES_SECTION = `
45
40
  ## Per-connector guides
46
41
 
47
- Some connectors here ship their own usage guide preferred tools, address quirks, pagination conventions, rate-limit etiquette, query patterns. \`skills({})\` lists each one as \`connector:<connectorId>\`; fetch it with \`skills({ name: "connector:<connectorId>" })\`. \`search_tools\`, \`connecta.search\`, and \`connecta.describe\` set \`guide\` on matches whose connector has one. Read a connector's guide before working with it for the first time in a task.
42
+ When a connector here ships a deployment-scoped usage guide, \`skills({})\` and discovery return the exact \`guide\` name plus a bounded \`guideSummary\` saying what it covers. Fetch only a listed or carried name with \`skills({ name: <guide> })\`; never infer one from a connector id. \`guideRequired: true\` is a hard stop: fetch before calling. \`guideRequiredReasons\` says why — \`connector_required\` and \`approval_required\` stand however you expand the schema; \`schema_truncated\` clears once describe returns the exact one. Otherwise fetch when the summary names a connector-specific sequence, unit, pagination rule, alias, or generic API convention relevant to the task. A read-only call whose compact schema is complete and unambiguous may proceed without fetching an otherwise irrelevant guide. Connector guides do not replace the shared Connecta usage guide and never apply to another deployment implicitly.
48
43
  `;
49
44
 
45
+ /** Shared Connecta routing guidance, byte-identical across deployments. */
46
+ export const USAGE_SKILL = USAGE_SKILL_BASE + CONNECTOR_GUIDES_SECTION;
47
+
50
48
  /** The always-loaded MCP `instructions` string. */
51
49
  export function instructionsFor(): string {
52
50
  return CONNECTA_INSTRUCTIONS;
@@ -59,10 +57,14 @@ export function hasConnectorGuides(connectors: readonly Connector[]): boolean {
59
57
  );
60
58
  }
61
59
 
62
- /** The built-in usage guide, plus the guides section when there is one to point at. */
63
- function usageSkill(connectors: readonly Connector[]): string {
64
- if (!hasConnectorGuides(connectors)) return USAGE_SKILL;
65
- return USAGE_SKILL + CONNECTOR_GUIDES_SECTION;
60
+ /**
61
+ * The built-in usage guide is byte-identical across deployments, so an agent
62
+ * that has read it once in a task never needs an equivalent deployment-local
63
+ * copy. Guide-free deployments still pay no fixed tool-description cost: the
64
+ * conditional notes in meta-tools.ts remain absent.
65
+ */
66
+ function usageSkill(_connectors: readonly Connector[]): string {
67
+ return USAGE_SKILL;
66
68
  }
67
69
 
68
70
  const AVAILABLE_SKILLS = [
@@ -91,7 +93,8 @@ export function connectorSkillName(connectorId: string): string {
91
93
  /** The connector's guide, or undefined when it declares none (or a blank one). */
92
94
  export function connectorGuide(connector: Connector): string | undefined {
93
95
  const guide = connector.usageGuide;
94
- return guide && guide.trim() !== "" ? guide : undefined;
96
+ const content = typeof guide === "string" ? guide : guide?.content;
97
+ return content && content.trim() !== "" ? content : undefined;
95
98
  }
96
99
 
97
100
  const SUMMARY_LENGTH = 120;
@@ -125,8 +128,17 @@ function withoutFrontmatter(lines: string[]): string[] {
125
128
  * the connector's own description when the guide opens with nothing but
126
129
  * markup.
127
130
  */
131
+ function boundedSummary(summary: string): string | undefined {
132
+ const line = summary.replace(/\s+/g, " ").trim();
133
+ if (line === "") return undefined;
134
+ return line.length <= SUMMARY_LENGTH
135
+ ? line
136
+ : `${line.slice(0, SUMMARY_LENGTH - 1).trimEnd()}…`;
137
+ }
138
+
128
139
  function summarizeGuide(connector: Connector, guide: string): string {
129
140
  let inFence = false;
141
+ let headingFallback: string | undefined;
130
142
  for (const raw of withoutFrontmatter(guide.split("\n"))) {
131
143
  if (FENCE_RE.test(raw)) {
132
144
  inFence = !inFence;
@@ -134,6 +146,7 @@ function summarizeGuide(connector: Connector, guide: string): string {
134
146
  }
135
147
  if (inFence) continue;
136
148
  if (raw.trim() === "" || NOT_SUMMARY_RE.test(raw)) continue;
149
+ const heading = /^\s*#{1,6}/.test(raw);
137
150
  const line = raw
138
151
  // `\s*` (not `\s+`) so a bare `#` strips to nothing and is skipped, and
139
152
  // an unspaced `#Heading` is still read as a heading.
@@ -142,11 +155,37 @@ function summarizeGuide(connector: Connector, guide: string): string {
142
155
  .replace(/\s+/g, " ")
143
156
  .trim();
144
157
  if (line === "") continue;
145
- return line.length <= SUMMARY_LENGTH
146
- ? line
147
- : `${line.slice(0, SUMMARY_LENGTH - 1).trimEnd()}…`;
158
+ if (heading) {
159
+ headingFallback ??= boundedSummary(line);
160
+ continue;
161
+ }
162
+ return boundedSummary(line) ?? line;
148
163
  }
149
- return connector.description ?? `Usage guide for "${connector.id}".`;
164
+ if (headingFallback) return headingFallback;
165
+ const fallback = connector.description ?? `Usage guide for "${connector.id}".`;
166
+ return boundedSummary(fallback) ?? `Usage guide for "${connector.id}".`;
167
+ }
168
+
169
+ /** Bounded, decision-useful discovery summary for a connector guide. */
170
+ export function connectorGuideSummary(
171
+ connector: Connector,
172
+ ): string | undefined {
173
+ const guide = connectorGuide(connector);
174
+ if (!guide) return undefined;
175
+ const configured =
176
+ typeof connector.usageGuide === "object"
177
+ ? boundedSummary(connector.usageGuide.summary ?? "")
178
+ : undefined;
179
+ return configured ?? summarizeGuide(connector, guide);
180
+ }
181
+
182
+ /** Whether correct use always depends on conventions outside the tool schema. */
183
+ export function connectorGuideRequired(connector: Connector): boolean {
184
+ return (
185
+ connectorGuide(connector) !== undefined &&
186
+ typeof connector.usageGuide === "object" &&
187
+ connector.usageGuide.required === true
188
+ );
150
189
  }
151
190
 
152
191
  export interface SkillListing {
@@ -165,11 +204,13 @@ export function listSkills(connectors: readonly Connector[]): SkillListing[] {
165
204
  description: skill.description,
166
205
  }));
167
206
  for (const connector of connectors) {
168
- const guide = connectorGuide(connector);
169
- if (!guide) continue;
207
+ // Undefined here means "no guide" and nothing else: a connector that has
208
+ // one always summarizes to a non-empty line, configured or derived.
209
+ const summary = connectorGuideSummary(connector);
210
+ if (!summary) continue;
170
211
  listing.push({
171
212
  name: connectorSkillName(connector.id),
172
- description: summarizeGuide(connector, guide),
213
+ description: summary,
173
214
  });
174
215
  }
175
216
  return listing;
package/src/types.ts CHANGED
@@ -212,13 +212,17 @@ export interface Connector {
212
212
  */
213
213
  callAdmission?: ConnectorCallAdmissionPolicy;
214
214
  /**
215
- * Optional agent-facing usage guide (markdown) for this connector preferred
216
- * tools, address quirks, pagination conventions, rate-limit etiquette, good
217
- * query patterns. Listed by the `skills` meta-tool as `connector:<id>` and
218
- * returned verbatim by `skills({ name: "connector:<id>" })`. Keep it concise
219
- * and imperative; it is read by agents, not operators.
215
+ * Optional agent-facing usage guide for this connector. A string preserves
216
+ * the original markdown-only contract. The structured form can add a short
217
+ * discovery summary and require review when even a complete compact schema
218
+ * cannot describe correct use (for example a generic API wrapper or a
219
+ * cross-operation sequencing rule).
220
+ *
221
+ * Listed by `skills` as `connector:<id>` and returned verbatim by
222
+ * `skills({ name: "connector:<id>" })`. The guide remains deployment-owned
223
+ * configuration; no runtime registration or shared mutable copy exists.
220
224
  */
221
- usageGuide?: string;
225
+ usageGuide?: string | ConnectorUsageGuide;
222
226
  /** Optional operator-managed credential slot rendered on /credentials. */
223
227
  credential?: ConnectorCredentialConfig;
224
228
  /** Optional server-side check used by /credentials' Test action. */
@@ -309,6 +313,23 @@ export interface Connector {
309
313
  ): Promise<Response | null>;
310
314
  }
311
315
 
316
+ export interface ConnectorUsageGuide {
317
+ /** Markdown returned verbatim by `skills({ name: "connector:<id>" })`. */
318
+ content: string;
319
+ /**
320
+ * Bounded discovery hint describing the conventions the guide covers. When
321
+ * omitted, Connecta derives a summary from the guide's first meaningful line.
322
+ */
323
+ summary?: string;
324
+ /**
325
+ * Require review before every operation on this connector. Reserve this for
326
+ * cases whose correct arguments or sequence cannot be expressed by the
327
+ * downstream tool schema; mutations and truncated schemas are required
328
+ * automatically and do not need this flag.
329
+ */
330
+ required?: boolean;
331
+ }
332
+
312
333
  /** Result of one sandboxed code execution. */
313
334
  export interface ExecuteResult {
314
335
  result: unknown;
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.12.2";
7
+ export const CONNECTA_VERSION = "0.14.0";
@@ -12,7 +12,7 @@
12
12
  "typecheck": "tsc --noEmit"
13
13
  },
14
14
  "dependencies": {
15
- "@zackbart/connecta": "0.12.2",
15
+ "@zackbart/connecta": "0.14.0",
16
16
  "quickjs-emscripten": "0.32.0"
17
17
  },
18
18
  "devDependencies": {