@setluca/mcp 0.2.1 → 0.3.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 (69) hide show
  1. package/CHANGELOG.md +331 -0
  2. package/LICENSE +21 -0
  3. package/README.md +19 -288
  4. package/dist/annotations.js +33 -18
  5. package/dist/client-address.js +64 -0
  6. package/dist/completions.js +24 -27
  7. package/dist/config.js +89 -38
  8. package/dist/errors.js +94 -13
  9. package/dist/fields.js +68 -0
  10. package/dist/fixed-window.js +46 -0
  11. package/dist/generated/openapi-inputs.js +216 -5820
  12. package/dist/generated/openapi-outputs.js +19014 -14001
  13. package/dist/generated/route-catalog.js +80 -0
  14. package/dist/http.js +107 -44
  15. package/dist/index.js +4 -1
  16. package/dist/oauth-challenge.js +74 -0
  17. package/dist/oauth-resolver.js +58 -61
  18. package/dist/observability.js +30 -15
  19. package/dist/openapi-schema.js +175 -0
  20. package/dist/operations/catalog.js +17 -0
  21. package/dist/operations/groups/analytics.js +20 -10
  22. package/dist/operations/groups/bookings.js +43 -15
  23. package/dist/operations/groups/broadcasts.js +29 -58
  24. package/dist/operations/groups/cadences.js +3 -1
  25. package/dist/operations/groups/callEvents.js +19 -72
  26. package/dist/operations/groups/campaigns.js +28 -32
  27. package/dist/operations/groups/channels.js +23 -0
  28. package/dist/operations/groups/conversations.js +14 -25
  29. package/dist/operations/groups/insights.js +4 -0
  30. package/dist/operations/groups/integrations.js +15 -17
  31. package/dist/operations/groups/knowledge.js +5 -1
  32. package/dist/operations/groups/leads.js +22 -23
  33. package/dist/operations/groups/learning.js +13 -1
  34. package/dist/operations/groups/memory.js +4 -6
  35. package/dist/operations/groups/reports.js +1 -1
  36. package/dist/operations/groups/reviewQueue.js +17 -14
  37. package/dist/operations/groups/safety.js +1 -1
  38. package/dist/operations/groups/voice.js +0 -1
  39. package/dist/operations/groups/webhooks.js +15 -3
  40. package/dist/operations/manifest.js +7 -6
  41. package/dist/operations/registry.js +102 -108
  42. package/dist/operations.js +4 -3
  43. package/dist/optional-field.js +15 -3
  44. package/dist/page-contract.js +74 -0
  45. package/dist/pagination.js +147 -67
  46. package/dist/prompts.js +122 -97
  47. package/dist/rate-limit.js +40 -0
  48. package/dist/remote.js +145 -65
  49. package/dist/resilience.js +107 -52
  50. package/dist/resolvers.js +125 -0
  51. package/dist/scopes.js +70 -17
  52. package/dist/serialization.js +32 -22
  53. package/dist/server.js +148 -132
  54. package/dist/standard-schema.js +215 -0
  55. package/dist/task-tools/analytics.js +145 -86
  56. package/dist/task-tools/bookings.js +168 -81
  57. package/dist/task-tools/cadences.js +30 -45
  58. package/dist/task-tools/calls.js +131 -124
  59. package/dist/task-tools/inbox.js +37 -47
  60. package/dist/task-tools/leads.js +49 -77
  61. package/dist/task-tools/runtime.js +75 -15
  62. package/dist/token-verification.js +47 -0
  63. package/dist/tool-cache.js +3 -2
  64. package/dist/tool.js +151 -96
  65. package/dist/version.js +1 -1
  66. package/package.json +37 -16
  67. package/dist/openapi-zod.js +0 -335
  68. package/dist/page-shape.js +0 -62
  69. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,335 +0,0 @@
1
- import * as z from "zod/v4";
2
- function isNullable(schema) {
3
- return (schema.nullable === true ||
4
- (Array.isArray(schema.type) && schema.type.includes("null")));
5
- }
6
- function nonNullTypes(schema) {
7
- if (Array.isArray(schema.type)) {
8
- return schema.type.filter((type) => type !== "null");
9
- }
10
- // Forcing this guard true yields `[undefined]`, which `baseSchema` reads
11
- // exactly as it reads the empty list: the first element is undefined either
12
- // way, so the same Zod schema comes out.
13
- // Stryker disable next-line ConditionalExpression: `[undefined]` and `[]` are indistinguishable in `baseSchema`
14
- if (schema.type) {
15
- return [schema.type];
16
- }
17
- return [];
18
- }
19
- function withDescription(schema, description) {
20
- return description ? schema.describe(description) : schema;
21
- }
22
- const JsonLiteralSchema = z.union([
23
- z.string(),
24
- z.number(),
25
- z.boolean(),
26
- z.null(),
27
- ]);
28
- function enumSchema(values) {
29
- const strings = z.array(z.string()).safeParse(values);
30
- if (strings.success) {
31
- // An empty enum lands here too, since the empty list is a list of strings.
32
- // It admits nothing, which is also the only thing `z.enum` cannot express.
33
- const [first, ...rest] = strings.data;
34
- return first === undefined ? z.never() : z.enum([first, ...rest]);
35
- }
36
- const literals = z.array(JsonLiteralSchema).safeParse(values);
37
- if (!literals.success) {
38
- return z.never();
39
- }
40
- const [firstValue, secondValue, ...restValues] = literals.data;
41
- // The empty list already went down the string branch, so this one is not
42
- // empty. The guard exists to satisfy the compiler's view of destructuring.
43
- // Stryker disable next-line ConditionalExpression,BlockStatement: unreachable, an empty enum is a list of strings
44
- if (firstValue === undefined) {
45
- return z.never();
46
- }
47
- const first = z.literal(firstValue);
48
- if (secondValue === undefined) {
49
- return first;
50
- }
51
- const second = z.literal(secondValue);
52
- const rest = restValues.map((value) => z.literal(value));
53
- return z.union([first, second, ...rest]);
54
- }
55
- /**
56
- * Zod 4 moved the string formats to top-level constructors: the `.uuid()` /
57
- * `.url()` / `.datetime()` methods on a ZodString are deprecated. They all
58
- * still subclass ZodString, so the length and pattern refinements below chain
59
- * onto whichever base a format picks.
60
- */
61
- function formatBase(format) {
62
- if (format === "uuid") {
63
- return z.uuid();
64
- }
65
- if (format === "uri") {
66
- return z.url();
67
- }
68
- if (format === "date-time") {
69
- return z.iso.datetime({ offset: true });
70
- }
71
- return z.string();
72
- }
73
- function stringSchema(schema) {
74
- let result = formatBase(schema.format);
75
- if (schema.minLength !== undefined) {
76
- result = result.min(schema.minLength);
77
- }
78
- if (schema.maxLength !== undefined) {
79
- result = result.max(schema.maxLength);
80
- }
81
- // Forcing this guard true is an equivalent mutation rather than an untested
82
- // branch: with no pattern the body builds `new RegExp(undefined)`, which is
83
- // the empty pattern `/(?:)/` and matches every string, so the constraint it
84
- // adds rejects nothing. Forcing it false is a real change and is covered.
85
- // Stryker disable next-line ConditionalExpression: an absent pattern compiles to /(?:)/, which constrains nothing
86
- if (schema.pattern) {
87
- // fallow-ignore-next-line security-sink -- patterns come from Luca's checked-in generated OpenAPI document at startup, never from MCP tool arguments or request data
88
- result = result.regex(new RegExp(schema.pattern));
89
- }
90
- return result;
91
- }
92
- function numberSchema(schema, integer) {
93
- let result = integer ? z.number().int() : z.number();
94
- if (schema.minimum !== undefined) {
95
- result =
96
- schema.exclusiveMinimum === true
97
- ? result.gt(schema.minimum)
98
- : result.min(schema.minimum);
99
- }
100
- if (schema.maximum !== undefined) {
101
- result =
102
- schema.exclusiveMaximum === true
103
- ? result.lt(schema.maximum)
104
- : result.max(schema.maximum);
105
- }
106
- return result;
107
- }
108
- function arraySchema(schema) {
109
- let result = z.array(schema.items ? schemaToZod(schema.items) : z.unknown());
110
- if (schema.minItems !== undefined) {
111
- result = result.min(schema.minItems);
112
- }
113
- if (schema.maxItems !== undefined) {
114
- result = result.max(schema.maxItems);
115
- }
116
- return result;
117
- }
118
- function scalarSchema(schema, type) {
119
- if (type === "string") {
120
- return stringSchema(schema);
121
- }
122
- if (type === "integer" || type === "number") {
123
- return numberSchema(schema, type === "integer");
124
- }
125
- return scalarSchemaWithoutConstraints(schema, type);
126
- }
127
- function scalarSchemaWithoutConstraints(schema, type) {
128
- switch (type) {
129
- case "boolean":
130
- return z.boolean();
131
- case "array":
132
- return arraySchema(schema);
133
- case "object":
134
- return objectSchema(schema);
135
- default:
136
- return z.unknown();
137
- }
138
- }
139
- function objectSchema(schema) {
140
- const properties = schema.properties ?? {};
141
- const required = new Set(schema.required ?? []);
142
- const fields = {};
143
- for (const [key, property] of Object.entries(properties)) {
144
- const propertySchema = schemaToZod(property);
145
- fields[key] = required.has(key)
146
- ? propertySchema
147
- : propertySchema.optional();
148
- }
149
- const result = z.object(fields);
150
- if (schema.additionalProperties === true) {
151
- return result.catchall(z.unknown());
152
- }
153
- // Absent, `false`, and the malformed scalars a generated document can carry
154
- // all close the object. Only a nested schema opens it, and every extra key
155
- // then has to match that schema.
156
- const extra = schema.additionalProperties;
157
- if (typeof extra !== "object") {
158
- return result;
159
- }
160
- return result.catchall(schemaToZod(extra));
161
- }
162
- function schemaToZod(schema) {
163
- const literal = literalOrEnumSchema(schema);
164
- if (literal) {
165
- return literal;
166
- }
167
- const composite = compositeSchema(schema);
168
- if (composite) {
169
- return composite;
170
- }
171
- return describedBaseSchema(schema);
172
- }
173
- function literalOrEnumSchema(schema) {
174
- if (schema.const !== undefined) {
175
- const literal = JsonLiteralSchema.safeParse(schema.const);
176
- return literal.success ? z.literal(literal.data) : z.never();
177
- }
178
- if (schema.enum) {
179
- return withDescription(enumSchema(schema.enum), schema.description);
180
- }
181
- return;
182
- }
183
- function compositeSchema(schema) {
184
- const variants = schema.anyOf ?? schema.oneOf;
185
- if (variants?.length) {
186
- return variantSchema(schema, variants);
187
- }
188
- const allOf = schema.allOf;
189
- if (allOf?.length) {
190
- return withDescription(schemaToZod(mergeAllOf(allOf)), schema.description);
191
- }
192
- return;
193
- }
194
- function variantSchema(schema, variants) {
195
- const [first, second, ...rest] = variants.map(schemaToZod);
196
- // `compositeSchema` only calls here for a non-empty variant list, so there is
197
- // always a first. The guard exists to satisfy the compiler's view of
198
- // destructuring.
199
- // Stryker disable next-line ConditionalExpression,BlockStatement: unreachable, the variant list is non-empty by construction
200
- if (first === undefined) {
201
- return z.never();
202
- }
203
- // A single variant is the variant itself. Wrapping one schema in a union
204
- // would change nothing except what a client reads in the JSON Schema.
205
- const union = second === undefined ? first : z.union([first, second, ...rest]);
206
- return withDescription(isNullable(schema) ? union.nullable() : union, schema.description);
207
- }
208
- function describedBaseSchema(schema) {
209
- const base = baseSchema(schema);
210
- return withDescription(isNullable(schema) ? base.nullable() : base, schema.description);
211
- }
212
- function mergeAllOf(allOf) {
213
- const merged = {};
214
- const properties = {};
215
- const required = [];
216
- for (const item of allOf) {
217
- Object.assign(merged, item);
218
- Object.assign(properties, item.properties);
219
- required.push(...(item.required ?? []));
220
- }
221
- return {
222
- ...merged,
223
- ...(Object.keys(properties).length > 0 ? { properties } : undefined),
224
- // Equivalent under this module's public contract: an empty `required: []`
225
- // and an absent `required` produce the identical Zod object schema, because
226
- // `objectSchema` derives its required-set from `schema.required ?? []`, so
227
- // both yield an all-optional object. The guard only avoids emitting a noise key.
228
- // Stryker disable next-line ConditionalExpression,EqualityOperator: empty and absent `required` are indistinguishable downstream
229
- ...(required.length > 0 ? { required } : undefined),
230
- };
231
- }
232
- function baseSchema(schema) {
233
- const types = nonNullTypes(schema);
234
- const [first, second, ...rest] = types;
235
- if (first === undefined) {
236
- return schema.properties ? objectSchema(schema) : z.unknown();
237
- }
238
- if (second === undefined) {
239
- return scalarSchema(schema, first);
240
- }
241
- return z.union([
242
- scalarSchema(schema, first),
243
- scalarSchema(schema, second),
244
- ...rest.map((type) => scalarSchema(schema, type)),
245
- ]);
246
- }
247
- function relaxJsonSchema(schema) {
248
- const relaxed = {};
249
- // Forcing this guard true assigns `relaxed.type = undefined` when there is no
250
- // type, which is indistinguishable downstream from omitting the key: both
251
- // `nonNullTypes` and the object-routing in `baseSchema` treat an undefined
252
- // `type` and an absent `type` identically, producing the same Zod schema.
253
- // Stryker disable next-line ConditionalExpression: an undefined `type` and an absent one yield the identical relaxed schema
254
- if (schema.type !== undefined) {
255
- relaxed.type = schema.type;
256
- }
257
- if (isNullable(schema)) {
258
- relaxed.nullable = true;
259
- }
260
- if (schema.properties) {
261
- const properties = {};
262
- for (const [key, value] of Object.entries(schema.properties)) {
263
- properties[key] = relaxJsonSchema(value);
264
- }
265
- relaxed.properties = properties;
266
- relaxed.required = [];
267
- relaxed.additionalProperties = true;
268
- // Defensive belt-and-suspenders: with `properties` present, `baseSchema`
269
- // routes an absent type and an explicit `"object"` type to the same
270
- // `objectSchema` call, so setting the type here never changes the produced
271
- // Zod schema. Verified equivalent through both public entry points.
272
- // Stryker disable next-line ConditionalExpression,BlockStatement: object routing is identical with or without an explicit type when properties exist
273
- if (relaxed.type === undefined) {
274
- // Stryker disable next-line StringLiteral: type value is inert here, properties already force objectSchema downstream
275
- relaxed.type = "object";
276
- }
277
- }
278
- if (schema.anyOf) {
279
- relaxed.anyOf = schema.anyOf.map(relaxJsonSchema);
280
- }
281
- if (schema.oneOf) {
282
- relaxed.oneOf = schema.oneOf.map(relaxJsonSchema);
283
- }
284
- if (schema.allOf) {
285
- relaxed.allOf = schema.allOf.map(relaxJsonSchema);
286
- }
287
- // Array items and scalar formats/patterns/ranges/enums are intentionally
288
- // dropped. See the doc comment.
289
- return relaxed;
290
- }
291
- const untrustedProvenanceSchema = z
292
- .object({ untrusted: z.literal(true), note: z.string() })
293
- .loose();
294
- /**
295
- * The `structuredContent` fields for a tool: `{ result }`, plus an optional
296
- * `provenance` marker for operations that carry lead-authored text. `result` is
297
- * the operation's success-response body, deep-relaxed (see
298
- * {@link relaxJsonSchema}) so real results validate while malformed ones fail
299
- * loud.
300
- */
301
- export function openApiToolOutputFields(input) {
302
- const resultSchema = input.body
303
- ? schemaToZod(relaxJsonSchema(input.body))
304
- : z.unknown();
305
- return input.untrustedContent
306
- ? {
307
- result: resultSchema,
308
- provenance: untrustedProvenanceSchema.optional(),
309
- }
310
- : { result: resultSchema };
311
- }
312
- export function openApiToolInputFields(input) {
313
- const fields = new Map(Object.entries(input.workspaceInput));
314
- if (input.idempotencyRequired) {
315
- for (const [key, schema] of Object.entries(input.idempotencyInput)) {
316
- fields.set(key, schema);
317
- }
318
- }
319
- const pathSchema = input.spec?.path
320
- ? schemaToZod(input.spec.path)
321
- : undefined;
322
- if (pathSchema instanceof z.ZodObject) {
323
- // oxlint-disable-next-line typescript/dot-notation -- Zod owns this public property name; bracket access avoids classifying the library member as a local shape symbol.
324
- for (const [key, schema] of Object.entries(pathSchema["shape"])) {
325
- fields.set(key, schema);
326
- }
327
- }
328
- if (input.spec?.query) {
329
- fields.set("query", schemaToZod(input.spec.query).optional());
330
- }
331
- if (input.spec?.body) {
332
- fields.set("body", schemaToZod(input.spec.body));
333
- }
334
- return Object.fromEntries(fields);
335
- }
@@ -1,62 +0,0 @@
1
- import { OPENAPI_INPUTS } from "./generated/openapi-inputs.js";
2
- import { OPENAPI_OUTPUTS } from "./generated/openapi-outputs.js";
3
- const INPUTS_BY_ROUTE = new Map(Object.entries(OPENAPI_INPUTS));
4
- const OUTPUTS_BY_ROUTE = new Map(Object.entries(OPENAPI_OUTPUTS));
5
- /**
6
- * Every name a page cursor goes by in the manifest: `cursor` almost everywhere,
7
- * and `before` on the conversation-messages route. This is an allowlist of two
8
- * names, not inference. A schema cannot say which of a route's string query
9
- * fields is a cursor without a naming convention, and there are two.
10
- */
11
- const CURSOR_QUERY_PARAMS = ["cursor", "before"];
12
- /**
13
- * The query field a route takes its page cursor in, absent when it takes none.
14
- *
15
- * Takes the query schema rather than the route so the shape rules can be tested
16
- * against a schema directly. The generated manifest carries only the schemas
17
- * the API actually serves, and a rule this small should be provable against the
18
- * ones it does not.
19
- */
20
- export function cursorQueryParamOf(query) {
21
- return CURSOR_QUERY_PARAMS.find((name) => query?.properties?.[name] !== undefined);
22
- }
23
- /**
24
- * The array field a page carries its records in, absent when the body hands
25
- * back no cursor or declares no array. The items array is the first
26
- * array-valued property the body declares, which is deterministic rather than a
27
- * guess among equals: key order here is OpenAPI declaration order.
28
- */
29
- export function itemsKeyOf(body) {
30
- if (body?.type !== "object" || body.properties?.nextCursor === undefined) {
31
- return;
32
- }
33
- return Object.entries(body.properties).find(([key, schema]) => key !== "nextCursor" && schema?.type === "array")?.[0];
34
- }
35
- /**
36
- * The page shape of a route, absent when the route does not paginate.
37
- *
38
- * Walking a list needs both halves: a body that hands back a cursor and an
39
- * array to merge, and a query field to send the cursor in. Guessing from the
40
- * operation id used to answer this, and was wrong fourteen times: twelve routes
41
- * that answer with a plain array and no cursor, and two that paginate under an
42
- * id that does not end in `.list`.
43
- */
44
- export function pageShapeFor(method, path) {
45
- const route = `${method} ${path}`;
46
- return pageShapeOf(INPUTS_BY_ROUTE.get(route)?.query, OUTPUTS_BY_ROUTE.get(route));
47
- }
48
- /**
49
- * The page shape a request and response schema pair describes, absent when
50
- * either half is missing. Split from {@link pageShapeFor} so both halves can be
51
- * withheld independently: the manifest happens to carry no route that takes a
52
- * cursor and answers without one, and that asymmetry is a fact about today's
53
- * API rather than a rule this function may assume.
54
- */
55
- export function pageShapeOf(query, body) {
56
- const cursorQueryParam = cursorQueryParamOf(query);
57
- const itemsKey = itemsKeyOf(body);
58
- if (cursorQueryParam === undefined || itemsKey === undefined) {
59
- return;
60
- }
61
- return { cursorQueryParam, itemsKey };
62
- }