@cyanheads/mcp-ts-core 0.13.13 → 0.13.14
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/AGENTS.md +4 -4
- package/CLAUDE.md +4 -4
- package/README.md +1 -1
- package/changelog/0.13.x/0.13.14.md +68 -0
- package/dist/core/app.d.ts +4 -3
- package/dist/core/app.d.ts.map +1 -1
- package/dist/core/app.js.map +1 -1
- package/dist/mcp-server/prompts/prompt-registration.d.ts.map +1 -1
- package/dist/mcp-server/prompts/prompt-registration.js +12 -5
- package/dist/mcp-server/prompts/prompt-registration.js.map +1 -1
- package/dist/mcp-server/prompts/utils/promptDefinition.d.ts +4 -1
- package/dist/mcp-server/prompts/utils/promptDefinition.d.ts.map +1 -1
- package/dist/mcp-server/prompts/utils/promptDefinition.js.map +1 -1
- package/dist/mcp-server/tools/utils/inputPrevalidation.d.ts +309 -26
- package/dist/mcp-server/tools/utils/inputPrevalidation.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/inputPrevalidation.js +870 -106
- package/dist/mcp-server/tools/utils/inputPrevalidation.js.map +1 -1
- package/dist/mcp-server/tools/utils/schemaShape.d.ts +127 -5
- package/dist/mcp-server/tools/utils/schemaShape.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/schemaShape.js +432 -4
- package/dist/mcp-server/tools/utils/schemaShape.js.map +1 -1
- package/dist/mcp-server/tools/utils/toolDefinition.d.ts +7 -3
- package/dist/mcp-server/tools/utils/toolDefinition.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/toolDefinition.js.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +47 -23
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js +777 -236
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
- package/dist/utils/telemetry/attributes.d.ts +3 -2
- package/dist/utils/telemetry/attributes.d.ts.map +1 -1
- package/dist/utils/telemetry/attributes.js +3 -2
- package/dist/utils/telemetry/attributes.js.map +1 -1
- package/framework-skills/add-tool/SKILL.md +15 -7
- package/framework-skills/api-errors/SKILL.md +8 -8
- package/framework-skills/api-telemetry/SKILL.md +4 -4
- package/framework-skills/api-testing/SKILL.md +2 -2
- package/framework-skills/design-mcp-server/SKILL.md +3 -2
- package/framework-skills/field-test/SKILL.md +3 -2
- package/package.json +3 -3
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Runtime shape checks for the Zod roots a tool definition may
|
|
3
|
-
* declare
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* declare, and the walk from a root down an argument path to the object that
|
|
4
|
+
* path sits in, the field it names, or the value that field received. Zod 4
|
|
5
|
+
* tags every schema with `_zod.def.type`, and a discriminated union tags as
|
|
6
|
+
* `'union'` like any other — the discriminator on its `def` is what separates
|
|
7
|
+
* the two. Kept in one place so the definition builder, the server manifest,
|
|
8
|
+
* the linter, the argument-rejection hint, and the argument repair agree on
|
|
9
|
+
* what a union root is and which schema and value a path names.
|
|
10
|
+
*
|
|
11
|
+
* An argument path names the value a schema received, which is not always one
|
|
12
|
+
* the caller sent: below a `z.preprocess()` or a `.transform().pipe()`, Zod's
|
|
13
|
+
* issue paths run through the transform's output (`items.0` for a lone object
|
|
14
|
+
* the transform wrapped in a list). The walk re-applies such a transform
|
|
15
|
+
* in-process and continues in the pipe's output schema, so every reader of a
|
|
16
|
+
* path reads the value Zod reported on (#599).
|
|
7
17
|
* @module src/mcp-server/tools/utils/schemaShape
|
|
8
18
|
*/
|
|
9
19
|
/** Reads `_zod.def` from any value; `undefined` when it is not a Zod 4 schema. */
|
|
@@ -42,4 +52,422 @@ export function inputVariants(schema) {
|
|
|
42
52
|
}
|
|
43
53
|
return isZodObjectSchema(schema) ? [schema] : [];
|
|
44
54
|
}
|
|
55
|
+
/** The caller's value one step down, or `undefined` when nothing owns one there. */
|
|
56
|
+
export function stepInto(value, step) {
|
|
57
|
+
return value !== null && typeof value === 'object' && Object.hasOwn(value, step)
|
|
58
|
+
? value[step]
|
|
59
|
+
: undefined;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The `z.object()` an argument path sits in, found by walking the path down
|
|
63
|
+
* from `schema` beside the caller's own `value` — or `undefined` when the path
|
|
64
|
+
* does not land on exactly one object (#566).
|
|
65
|
+
*
|
|
66
|
+
* Wrappers (`optional`, `nullable`, `default`, …), `pipe`, and `z.lazy()` are
|
|
67
|
+
* looked through. A pipe whose input side transforms — `z.preprocess()`, or
|
|
68
|
+
* `.transform()` followed by `.pipe()` — is walked through its output schema,
|
|
69
|
+
* beside what the transform makes of the value (#599). A numeric step enters
|
|
70
|
+
* an array element or tuple item; a string step, a property, a record value,
|
|
71
|
+
* or the value of a key an author's `.catchall()` types.
|
|
72
|
+
* A discriminated union follows the variant the argument's own discriminator
|
|
73
|
+
* selects, as Zod did. A plain union follows the one option under which the
|
|
74
|
+
* rest of the path still lands on an object, an option whose single-valued
|
|
75
|
+
* literal field refuses the argument's value there left out unless every
|
|
76
|
+
* object option does ({@link unionCandidates}). Anything else, an
|
|
77
|
+
* intersection or a union two options satisfy (one declaring the key, another
|
|
78
|
+
* declaring or catching it), resolves to nothing.
|
|
79
|
+
*/
|
|
80
|
+
export function objectSchemaAt(schema, path, value, transforms = new Map()) {
|
|
81
|
+
return walkTo(schema, path, 0, value, transforms, (node) => isZodObjectSchema(node) ? node : undefined);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Whether any schema an argument path can land on routes its value through a
|
|
85
|
+
* transform ({@link routesThroughPipe}). Descends as {@link objectSchemaAt}
|
|
86
|
+
* does, and a key no `z.object()` declares lands on the author's `.catchall()`
|
|
87
|
+
* schema when one types it, so a pipe there counts as a declared field's
|
|
88
|
+
* would; under `.strict()` or `.passthrough()` it lands on nothing. Where the
|
|
89
|
+
* path resolves under several options of a plain union (one option declaring
|
|
90
|
+
* the key and another declaring or catching it) or under both sides of an
|
|
91
|
+
* intersection, every one is asked — and where a plain union's literal tags
|
|
92
|
+
* refuse every object option, every option ({@link unionCandidates}). The
|
|
93
|
+
* walk cannot tell which of them the parse read the value with, so a second
|
|
94
|
+
* reading of the path never hides a transform.
|
|
95
|
+
*/
|
|
96
|
+
export function routesThroughPipeAt(schema, path, value, transforms = new Map()) {
|
|
97
|
+
const piped = (node) => routesThroughPipe(node) || undefined;
|
|
98
|
+
return walkTo(schema, path, 0, value, transforms, piped, 'any') === true;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The value an argument path names, walked down from `schema` beside the
|
|
102
|
+
* caller's `value` (#599). Descends as {@link objectSchemaAt} does — through a
|
|
103
|
+
* transforming pipe's output with the transform re-applied, an author catchall's
|
|
104
|
+
* value included — and where the schema no longer says what the path names (a
|
|
105
|
+
* key no object declares or types, an intersection, a union no single option
|
|
106
|
+
* resolves), it reads on in the value alone, as Zod's own issue paths do.
|
|
107
|
+
*
|
|
108
|
+
* A transform whose input side rejects the value is walked through that input
|
|
109
|
+
* side instead: the issue below it is the input side's own, about the value as
|
|
110
|
+
* sent. One that throws when re-applied leaves the path unknown. A pipe the
|
|
111
|
+
* path ends on is not run when the value is absent there — the caller left it
|
|
112
|
+
* out, whatever the transform would have made of that.
|
|
113
|
+
*/
|
|
114
|
+
export function argumentAt(schema, path, value, transforms = new Map()) {
|
|
115
|
+
// Only a walk trying one union option comes back unresolved; this one reads on in the value.
|
|
116
|
+
const walks = new Map();
|
|
117
|
+
const at = walkArgument(schema, path, 0, value, undefined, false, transforms, walks);
|
|
118
|
+
const sent = at.transformed || at.sites.length === 0
|
|
119
|
+
? at.value
|
|
120
|
+
: path.reduce((current, step) => stepInto(current, step), value);
|
|
121
|
+
return { ...at, sent };
|
|
122
|
+
}
|
|
123
|
+
/** The sites of a {@link SiteList}, outermost first. */
|
|
124
|
+
function siteArray(list) {
|
|
125
|
+
const sites = [];
|
|
126
|
+
for (let entry = list; entry; entry = entry.outer)
|
|
127
|
+
sites.push(entry.site);
|
|
128
|
+
return sites.reverse();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* {@link argumentAt} from step `start` of `path`, below the transforms
|
|
132
|
+
* `sites` names. `strict` is set while trying one option of a union: the walk
|
|
133
|
+
* then comes back `undefined` wherever {@link walkTo} would — a step the
|
|
134
|
+
* schema does not declare, a union no single option resolves, a transform that
|
|
135
|
+
* throws above the path's end — and at a step taken from a value that is no
|
|
136
|
+
* object or array, which that option cannot have parsed below, instead of
|
|
137
|
+
* reading on in the value alone. A string beside a list option and an option
|
|
138
|
+
* that splits it then resolves to the option that split it.
|
|
139
|
+
*
|
|
140
|
+
* At a union, each option is walked to the end of the path once, and the one
|
|
141
|
+
* that resolves is the result. Picking the option with a walk to the end and
|
|
142
|
+
* then walking the rest again would cost the square of the depth on a
|
|
143
|
+
* recursive schema with a union at every level, and `walks` keeps what each
|
|
144
|
+
* union resolved, so options that walk on into the same union below read it
|
|
145
|
+
* once ({@link walkedAt}).
|
|
146
|
+
*/
|
|
147
|
+
function walkArgument(schema, path, start, value, sites, strict, transforms, walks) {
|
|
148
|
+
let node = schema;
|
|
149
|
+
let current = value;
|
|
150
|
+
let passed = sites;
|
|
151
|
+
for (let index = start;; index++) {
|
|
152
|
+
const atPath = current;
|
|
153
|
+
let transformed = false;
|
|
154
|
+
for (let def = zodDef(node); def; def = zodDef(node)) {
|
|
155
|
+
if (def.type === 'lazy') {
|
|
156
|
+
node = lazyInner(node);
|
|
157
|
+
}
|
|
158
|
+
else if (def.type === 'pipe') {
|
|
159
|
+
if (!transformsIn(def.in) || (index === path.length && current === undefined)) {
|
|
160
|
+
node = def.in;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const applied = transformedBy(def.in, current, transforms);
|
|
164
|
+
if (applied.kind === 'threw') {
|
|
165
|
+
if (strict && index < path.length)
|
|
166
|
+
return undefined;
|
|
167
|
+
return {
|
|
168
|
+
known: false,
|
|
169
|
+
received: undefined,
|
|
170
|
+
sites: siteArray(passed),
|
|
171
|
+
transformed: false,
|
|
172
|
+
value: undefined,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
if (applied.kind === 'rejected') {
|
|
176
|
+
node = def.in;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (index < path.length) {
|
|
180
|
+
const site = { depth: index, output: applied.output, transform: def.in };
|
|
181
|
+
passed = { outer: passed, site };
|
|
182
|
+
}
|
|
183
|
+
transformed = true;
|
|
184
|
+
current = applied.output;
|
|
185
|
+
node = def.out;
|
|
186
|
+
}
|
|
187
|
+
else if (def.innerType !== undefined) {
|
|
188
|
+
node = def.innerType;
|
|
189
|
+
}
|
|
190
|
+
else if (def.type === 'union' && index < path.length) {
|
|
191
|
+
const through = unionThrough(def, path, index, current, passed, transforms, walks);
|
|
192
|
+
if (through !== undefined || strict)
|
|
193
|
+
return through;
|
|
194
|
+
node = undefined;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (index === path.length) {
|
|
201
|
+
return {
|
|
202
|
+
known: true,
|
|
203
|
+
received: current,
|
|
204
|
+
sites: siteArray(passed),
|
|
205
|
+
transformed,
|
|
206
|
+
value: atPath,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const step = path[index];
|
|
210
|
+
node = childAt(zodDef(node), step);
|
|
211
|
+
if (strict && (zodDef(node) === undefined || current === null || typeof current !== 'object')) {
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
current = stepInto(current, step);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Whether a field routes its value through a transform before the type the
|
|
219
|
+
* field reports — a `.transform()`, `.pipe()`, or `z.preprocess()` on the field
|
|
220
|
+
* itself, behind any wrapper or `z.lazy()`, or on one option of a union. Such a
|
|
221
|
+
* field's rejection can describe the transform's output rather than the value
|
|
222
|
+
* the caller sent. A pipe inside an array element or an object property is the
|
|
223
|
+
* element's or property's own, not the field's.
|
|
224
|
+
*/
|
|
225
|
+
export function routesThroughPipe(schema) {
|
|
226
|
+
const seen = new Set();
|
|
227
|
+
const piped = (node) => {
|
|
228
|
+
const def = zodDef(node);
|
|
229
|
+
if (!def || seen.has(node))
|
|
230
|
+
return false;
|
|
231
|
+
seen.add(node);
|
|
232
|
+
if (def.type === 'pipe')
|
|
233
|
+
return true;
|
|
234
|
+
if (def.type === 'lazy')
|
|
235
|
+
return piped(lazyInner(node));
|
|
236
|
+
if (def.innerType !== undefined)
|
|
237
|
+
return piped(def.innerType);
|
|
238
|
+
return def.type === 'union' && (def.options ?? []).some(piped);
|
|
239
|
+
};
|
|
240
|
+
return piped(schema);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* A `z.lazy()` schema's inner type. Zod resolves the getter once and caches
|
|
244
|
+
* the result, so a walk reads the same schema the parse validated with instead
|
|
245
|
+
* of building a new one per step, which on a recursive schema would cost a
|
|
246
|
+
* schema per level per path.
|
|
247
|
+
*/
|
|
248
|
+
function lazyInner(schema) {
|
|
249
|
+
return schema._zod.innerType;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* The walk behind {@link objectSchemaAt} and {@link routesThroughPipeAt}: from
|
|
253
|
+
* `schema`, beside the caller's `value`, down `path` from `index`. `found`
|
|
254
|
+
* decides the node the path ends at — it is offered each node there, outermost
|
|
255
|
+
* first, and the walk looks through a wrapper, a `pipe`, or a `z.lazy()` only
|
|
256
|
+
* while `found` declines. Indexing the path rather than slicing it keeps a walk
|
|
257
|
+
* linear in its depth.
|
|
258
|
+
*
|
|
259
|
+
* `readings` decides a path several schemas resolve. Under `'one'` a plain
|
|
260
|
+
* union resolves only when one of its {@link unionCandidates} does, and an
|
|
261
|
+
* intersection never does. Under `'any'` the first candidate or side `found`
|
|
262
|
+
* accepts is returned. Either way each union and intersection is walked once
|
|
263
|
+
* per step and value, through `walks` ({@link walkedAt}).
|
|
264
|
+
*/
|
|
265
|
+
function walkTo(schema, path, index, value, transforms, found, readings = 'one', walks = new Map()) {
|
|
266
|
+
const def = zodDef(schema);
|
|
267
|
+
if (!def)
|
|
268
|
+
return undefined;
|
|
269
|
+
if (index === path.length) {
|
|
270
|
+
const node = found(schema);
|
|
271
|
+
if (node !== undefined)
|
|
272
|
+
return node;
|
|
273
|
+
}
|
|
274
|
+
const on = (next, nextIndex, nextValue) => walkTo(next, path, nextIndex, nextValue, transforms, found, readings, walks);
|
|
275
|
+
if (def.type === 'lazy')
|
|
276
|
+
return on(lazyInner(schema), index, value);
|
|
277
|
+
if (def.type === 'pipe') {
|
|
278
|
+
if (!transformsIn(def.in))
|
|
279
|
+
return on(def.in, index, value);
|
|
280
|
+
const applied = transformedBy(def.in, value, transforms);
|
|
281
|
+
if (applied.kind === 'threw')
|
|
282
|
+
return undefined;
|
|
283
|
+
return applied.kind === 'output'
|
|
284
|
+
? on(def.out, index, applied.output)
|
|
285
|
+
: on(def.in, index, value);
|
|
286
|
+
}
|
|
287
|
+
if (def.innerType !== undefined)
|
|
288
|
+
return on(def.innerType, index, value);
|
|
289
|
+
if (def.type === 'union' || (def.type === 'intersection' && readings === 'any')) {
|
|
290
|
+
const walked = walkedAt(walks, [def, index]);
|
|
291
|
+
if (walked.has(value))
|
|
292
|
+
return walked.get(value);
|
|
293
|
+
let result;
|
|
294
|
+
if (def.type === 'union') {
|
|
295
|
+
const resolved = [];
|
|
296
|
+
for (const option of unionCandidates(def, value)) {
|
|
297
|
+
const node = on(option, index, value);
|
|
298
|
+
if (node !== undefined)
|
|
299
|
+
resolved.push(node);
|
|
300
|
+
}
|
|
301
|
+
result =
|
|
302
|
+
resolved.length === 1 || (readings === 'any' && resolved.length > 0)
|
|
303
|
+
? resolved[0]
|
|
304
|
+
: undefined;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
result = on(def.left, index, value) ?? on(def.right, index, value);
|
|
308
|
+
}
|
|
309
|
+
walked.set(value, result);
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
if (index === path.length)
|
|
313
|
+
return undefined;
|
|
314
|
+
const step = path[index];
|
|
315
|
+
return on(childAt(def, step), index + 1, stepInto(value, step));
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* The schema one path step enters from a container, or `undefined` when it
|
|
319
|
+
* declares none there. A key an object leaves undeclared enters its author's
|
|
320
|
+
* `.catchall()`, the schema Zod parses that key's value with.
|
|
321
|
+
*/
|
|
322
|
+
function childAt(def, step) {
|
|
323
|
+
switch (def?.type) {
|
|
324
|
+
case 'object':
|
|
325
|
+
if (typeof step !== 'string')
|
|
326
|
+
return undefined;
|
|
327
|
+
return def.shape && Object.hasOwn(def.shape, step) ? def.shape[step] : typedCatchall(def);
|
|
328
|
+
case 'record':
|
|
329
|
+
return def.valueType;
|
|
330
|
+
case 'array':
|
|
331
|
+
return typeof step === 'number' ? def.element : undefined;
|
|
332
|
+
case 'tuple':
|
|
333
|
+
return typeof step === 'number' ? (def.items?.[step] ?? def.rest) : undefined;
|
|
334
|
+
default:
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* An object's catchall when it types its undeclared keys' values. `.strict()`
|
|
340
|
+
* records a `never` catchall, whose keys fail as one `unrecognized_keys` issue
|
|
341
|
+
* on the object itself, and `.passthrough()` an `unknown` one, which no value
|
|
342
|
+
* fails — no issue sits below either, so neither is walked, and a plain
|
|
343
|
+
* union's option open in either way never competes with one declaring the
|
|
344
|
+
* key. A typed catchall does compete: a path one option declares and another
|
|
345
|
+
* catches resolves under both.
|
|
346
|
+
*/
|
|
347
|
+
function typedCatchall(def) {
|
|
348
|
+
const type = zodDef(def.catchall)?.type;
|
|
349
|
+
return type === undefined || type === 'never' || type === 'unknown' || type === 'any'
|
|
350
|
+
? undefined
|
|
351
|
+
: def.catchall;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* The options of a union a walk may follow for `value`: the variant a
|
|
355
|
+
* discriminated union's own discriminator selects, as Zod did, or every option
|
|
356
|
+
* of a plain union but one whose single-valued literal field — a tag like
|
|
357
|
+
* `kind: z.literal('a')` — refuses the value there. Zod reports such an option
|
|
358
|
+
* as that literal's failure alone, which the rejection drops (#417), so the
|
|
359
|
+
* walk does not follow it either (#570).
|
|
360
|
+
*
|
|
361
|
+
* When the tags leave no object option, every option is followed. The branch
|
|
362
|
+
* a rejection kept can refuse its own tag too — `"c"` where no branch takes
|
|
363
|
+
* it, `"1"` for `z.literal(1)`, a one-value enum left out — and a walk that
|
|
364
|
+
* found no branch would read its values off the arguments alone: a value a
|
|
365
|
+
* `z.preprocess()` there wrapped in a list would read as absent, a `null`
|
|
366
|
+
* there would never read as an optional key, and the string-repair gate would
|
|
367
|
+
* miss a field that routes through a transform.
|
|
368
|
+
*/
|
|
369
|
+
function unionCandidates(def, value) {
|
|
370
|
+
const options = def.options ?? [];
|
|
371
|
+
const { discriminator } = def;
|
|
372
|
+
if (typeof discriminator !== 'string') {
|
|
373
|
+
const tagged = options.filter((option) => !refusesTag(option, value));
|
|
374
|
+
return tagged.some(isZodObjectSchema) ? tagged : options;
|
|
375
|
+
}
|
|
376
|
+
const tag = stepInto(value, discriminator);
|
|
377
|
+
const selected = options.find((option) => {
|
|
378
|
+
const field = isZodObjectSchema(option) ? option.shape[discriminator] : undefined;
|
|
379
|
+
return field?.safeParse(tag).success === true;
|
|
380
|
+
});
|
|
381
|
+
return selected === undefined ? [] : [selected];
|
|
382
|
+
}
|
|
383
|
+
/** Whether an object option has a single-valued literal field that refuses `value`'s own field. */
|
|
384
|
+
function refusesTag(option, value) {
|
|
385
|
+
const shape = isZodObjectSchema(option) ? zodDef(option)?.shape : undefined;
|
|
386
|
+
if (!shape)
|
|
387
|
+
return false;
|
|
388
|
+
return Object.entries(shape).some(([key, field]) => {
|
|
389
|
+
const def = zodDef(field);
|
|
390
|
+
const singleValued = def?.type === 'literal'
|
|
391
|
+
? def.values?.length === 1
|
|
392
|
+
: def?.type === 'enum' && Object.keys(def.entries ?? {}).length === 1;
|
|
393
|
+
return singleValued && !field.safeParse(stepInto(value, key)).success;
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* What {@link argumentAt} reads at the end of the path through the one union
|
|
398
|
+
* candidate the rest of the path resolves under, or `undefined` when none or
|
|
399
|
+
* several do.
|
|
400
|
+
*/
|
|
401
|
+
function unionThrough(def, path, index, value, sites, transforms, walks) {
|
|
402
|
+
const walked = walkedAt(walks, [def, index, sites]);
|
|
403
|
+
if (walked.has(value))
|
|
404
|
+
return walked.get(value);
|
|
405
|
+
let only;
|
|
406
|
+
for (const option of unionCandidates(def, value)) {
|
|
407
|
+
const at = walkArgument(option, path, index, value, sites, true, transforms, walks);
|
|
408
|
+
if (at === undefined)
|
|
409
|
+
continue;
|
|
410
|
+
if (only !== undefined) {
|
|
411
|
+
only = undefined;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
only = at;
|
|
415
|
+
}
|
|
416
|
+
walked.set(value, only);
|
|
417
|
+
return only;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* The map of `walks` that holds, by value, what the walk resolved at `keys`
|
|
421
|
+
* (#648) — created on first use. Looked up before a node is walked and
|
|
422
|
+
* written after, so a walk keeps the depth of call stack it had without it.
|
|
423
|
+
*/
|
|
424
|
+
function walkedAt(walks, keys) {
|
|
425
|
+
let level = walks;
|
|
426
|
+
for (const key of keys) {
|
|
427
|
+
let next = level.get(key);
|
|
428
|
+
if (next === undefined) {
|
|
429
|
+
next = new Map();
|
|
430
|
+
level.set(key, next);
|
|
431
|
+
}
|
|
432
|
+
level = next;
|
|
433
|
+
}
|
|
434
|
+
return level;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Whether a pipe's input side transforms the value its output schema
|
|
438
|
+
* receives: `z.preprocess()`'s input side is the transform itself, and
|
|
439
|
+
* `.transform(f).pipe(B)`'s is a pipe ending in one. Any other pipe — `.pipe()`
|
|
440
|
+
* after a plain schema, or a bare `.transform()`, whose input side is the
|
|
441
|
+
* schema it transforms — is walked through its input side, whose issues name
|
|
442
|
+
* the value as sent.
|
|
443
|
+
*/
|
|
444
|
+
function transformsIn(schema) {
|
|
445
|
+
const def = zodDef(schema);
|
|
446
|
+
return def?.type === 'transform' || (def?.type === 'pipe' && transformsIn(def.out));
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* A pipe's input side re-applied to `value`, once per value per
|
|
450
|
+
* {@link TransformCache}. The author's transform may throw — on a value only
|
|
451
|
+
* the walk feeds it, or on a second run — and that is recorded rather than
|
|
452
|
+
* thrown, so reading a rejection's paths never turns it into a crash.
|
|
453
|
+
*/
|
|
454
|
+
function transformedBy(input, value, transforms) {
|
|
455
|
+
let byValue = transforms.get(input);
|
|
456
|
+
if (byValue === undefined) {
|
|
457
|
+
byValue = new Map();
|
|
458
|
+
transforms.set(input, byValue);
|
|
459
|
+
}
|
|
460
|
+
let applied = byValue.get(value);
|
|
461
|
+
if (applied === undefined) {
|
|
462
|
+
try {
|
|
463
|
+
const parsed = input.safeParse(value);
|
|
464
|
+
applied = parsed.success ? { kind: 'output', output: parsed.data } : { kind: 'rejected' };
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
applied = { kind: 'threw' };
|
|
468
|
+
}
|
|
469
|
+
byValue.set(value, applied);
|
|
470
|
+
}
|
|
471
|
+
return applied;
|
|
472
|
+
}
|
|
45
473
|
//# sourceMappingURL=schemaShape.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaShape.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/schemaShape.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAwBH,kFAAkF;AAClF,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KA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
236
236
|
* Aliases are not advertised — `inputSchema` is byte-identical with or
|
|
237
237
|
* without them, so the canonical key keeps its place in `required` and the
|
|
238
238
|
* model is still told to use it. A rewrite applies only when the target key
|
|
239
|
-
* is absent; with both present the call
|
|
240
|
-
*
|
|
241
|
-
*
|
|
239
|
+
* is absent; with both present the call is rejected, and its hint names the
|
|
240
|
+
* alias beside its target (`drug_name is an alias of drug; send one of them,
|
|
241
|
+
* not both.`) rather than calling it an unknown key. The exception is an
|
|
242
|
+
* `_`-prefixed alias the drop discards as a client-added key: the target's
|
|
243
|
+
* value then validates. Case-style variants of a declared key (`max_results`
|
|
244
|
+
* for `maxResults`) are rewritten without any declaration — see
|
|
245
|
+
* `createApp({ input: { caseStyleAliases } })`.
|
|
242
246
|
*
|
|
243
247
|
* Root level only, matching `.strict()` itself. `lint:mcp` rejects an alias
|
|
244
248
|
* that shadows a declared key, names a target that does not exist, or is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolDefinition.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAEtF,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAK9D,OAAO,EAAE,KAAK,gBAAgB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,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,CAAC,EACtB,SAAS,aAAa,EAAE,GAAG,SAAS,EACpC,WAAW,GAAG,SAAS,CACxB,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,IAAI,CAClB,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,SAAS,CAAC,WAAW,CAAC,EACtC,KAAK,CAAC,OAAO,SAAS,SAAS,aAAa,EAAE,GAAG,SAAS,GAAG,SAAS,EACtE,KAAK,CAAC,OAAO,SAAS,WAAW,GAAG,SAAS,GAAG,SAAS,EAEzD,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,GACvE,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAOnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolDefinition.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAgE,CAAC,EAAE,MAAM,KAAK,CAAC;AAItF,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAwB,MAAM,qBAAqB,CAAC;AAElF,OAAO,EAAyB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"toolDefinition.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAgE,CAAC,EAAE,MAAM,KAAK,CAAC;AAItF,OAAO,EAAE,wBAAwB,EAAE,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AQ;YACR,KAAK,EAAE,CAAC,CAAC,kBAAkB,CACzB,KAAK,CAAC,GAAG,CAAC,aAAa,EACvB,UAAmB,CACC;SACvB,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACjE,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC5B,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAY,EAAE,CAAC;AACvD,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module src/mcp-server/tools/utils/toolHandlerFactory
|
|
5
5
|
*/
|
|
6
6
|
import type { CallToolResult, ContentBlock, InputRequiredResult, ServerContext } from '@modelcontextprotocol/server';
|
|
7
|
-
import { type
|
|
7
|
+
import { type ZodObject, type ZodRawShape, z } from 'zod';
|
|
8
8
|
import type { Context } from '../../../core/context.js';
|
|
9
9
|
import { type HandlerServices } from '../../handlerContext.js';
|
|
10
10
|
import { type ClientCapabilityView } from '../../inputRequired.js';
|
|
@@ -53,17 +53,6 @@ export declare function renderToolContent(def: AnyToolDefinition, validatedOutpu
|
|
|
53
53
|
* path's `structuredContent` surface.
|
|
54
54
|
*/
|
|
55
55
|
export declare function buildToolErrorResult(code: JsonRpcErrorCode, message: string, data: Record<string, unknown> | undefined): CallToolResult;
|
|
56
|
-
/**
|
|
57
|
-
* Renders an argument-validation failure the way the MCP SDK renders its own,
|
|
58
|
-
* so the readable diagnostic — the offending key or field, and why it failed —
|
|
59
|
-
* is unchanged for clients that read `content[]` text. The framework owns this
|
|
60
|
-
* rejection (see `deferInputValidation`) purely so it can also carry
|
|
61
|
-
* `structuredContent.error`.
|
|
62
|
-
*
|
|
63
|
-
* `args` are the caller's raw arguments, read only through
|
|
64
|
-
* {@link readArgumentAt}; see {@link renderIssueMessage} for what that decides.
|
|
65
|
-
*/
|
|
66
|
-
export declare function formatInputValidationMessage(toolName: string, error: ZodError, args: unknown): string;
|
|
67
56
|
/** What {@link parseToolArguments} needs beyond the definition and the arguments. */
|
|
68
57
|
export interface ParseToolArgumentsOptions {
|
|
69
58
|
/** Request context the pre-validation step's debug logs correlate to. */
|
|
@@ -80,25 +69,60 @@ export interface ParseToolArgumentsOptions {
|
|
|
80
69
|
* synthesizes (#445). {@link buildToolErrorResult} mirrors that hint into
|
|
81
70
|
* `content[]`, so it reaches format()-only clients with no extra work.
|
|
82
71
|
*
|
|
72
|
+
* The rejection is bounded whatever the caller sends (#648), here at the
|
|
73
|
+
* throw, so every path through this function carries the bound: the message
|
|
74
|
+
* and the hint render the first 10 issue lines, each cut to 1,024 characters,
|
|
75
|
+
* and `data.issues` and `data.input` are {@link boundedProjection}s — the
|
|
76
|
+
* first 10 entries of every array and own keys of every object, the first
|
|
77
|
+
* 1,024 characters of every string and key, and {@link REJECTION_LEVELS} levels
|
|
78
|
+
* of nesting below each issue, the uncut count or length beside each cut — with
|
|
79
|
+
* `data.issues` keeping at most {@link REJECTION_ISSUES} issues in all through
|
|
80
|
+
* every union's branches. `data.issuesCount`, how many issues Zod raised at
|
|
81
|
+
* the top level, sits beside `data.issues` whenever it keeps fewer of them —
|
|
82
|
+
* past the first 10, or sooner when that budget runs out — as `errorsCount`
|
|
83
|
+
* sits beside a cut branch list. A rejection within those caps carries Zod's
|
|
84
|
+
* list and the report exactly. Its cost grows
|
|
85
|
+
* with the distinct issues Zod raised, not with how many branches list one:
|
|
86
|
+
* every reader of the issues walks a shared one once or stops at a bound.
|
|
87
|
+
*
|
|
83
88
|
* An ordered pre-validation step wraps the parse. Before it,
|
|
84
89
|
* {@link prevalidateToolArguments} drops client-added keys (#453) and rewrites
|
|
85
90
|
* key aliases (#452); after a failure — and only then —
|
|
86
|
-
* {@link repairRepresentations} undoes a stringified array or object
|
|
87
|
-
* integer sent for a string,
|
|
88
|
-
*
|
|
91
|
+
* {@link repairRepresentations} undoes a stringified array or object, an
|
|
92
|
+
* integer sent for a string, a string sent for a number or boolean, or a lone
|
|
93
|
+
* string sent for an array, and deletes `null` sent for an optional field, at
|
|
94
|
+
* the paths {@link renderedIssues} names — inside a union field's one surviving
|
|
95
|
+
* branch (#570), at a discriminator or literal tag no variant accepts (#714),
|
|
96
|
+
* and inside a `z.preprocess()` output (#599) included — and the
|
|
97
|
+
* arguments are parsed once more (#234, #479, #487, #707, #602, #616), the
|
|
98
|
+
* repair kept only if the author's own schema now accepts it. The repair
|
|
99
|
+
* 0.13.13 made, of Zod's own issues in the arguments as sent
|
|
100
|
+
* ({@link repairAsSent}), is parsed before it, so every call that repair
|
|
101
|
+
* validated keeps its value. Every path the
|
|
102
|
+
* repair, the message, and the hint read is walked through the input schema,
|
|
103
|
+
* a transform on the way re-applied once per value for the whole call.
|
|
89
104
|
* When that attempt still fails and its drop discarded a key,
|
|
90
105
|
* {@link prevalidateAliasFirst} reruns the stages alias-first and the same
|
|
91
106
|
* parse-then-repair runs on the result, kept only if it validates (#563).
|
|
92
107
|
* {@link recordPrevalidation} then counts and logs the attempt the handler
|
|
93
108
|
* receives, so a call the first attempt validates is untouched by the retry.
|
|
94
|
-
* When nothing validates, the
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
109
|
+
* When nothing validates, the last attempt's rejection is thrown — the
|
|
110
|
+
* retry's when it ran, since there every key the drop discarded reached its
|
|
111
|
+
* target and the issues name what is wrong with the value it carried. It is a
|
|
112
|
+
* parse of that attempt's arguments with only the repairs that held applied
|
|
113
|
+
* (#706, {@link repairAttempt}), rendered from those same arguments: a value
|
|
114
|
+
* the schema accepted once repaired is not reported — one that held only
|
|
115
|
+
* written in place below a transform that reorders or rewrites it excepted —
|
|
116
|
+
* and one whose repair the schema refused is reported as sent, so a call no
|
|
117
|
+
* repair helped gets exactly
|
|
118
|
+
* the rejection it gets under `input: { coerce: false }` — as does one the
|
|
119
|
+
* held repairs alone would validate (only a union or a cross-field refinement
|
|
120
|
+
* allows that), held values included. It carries the rewrites and
|
|
121
|
+
* underscore-rule drops that attempt made as `data.input`, and as sentences
|
|
122
|
+
* closing the hint (#468); a call with neither gains no `data.input`, and
|
|
123
|
+
* nothing in it says a repair held. An alias that attempt
|
|
124
|
+
* declined because its target was already present is named in the hint as an
|
|
125
|
+
* alias of that target (#639), never as an unknown or a dropped key.
|
|
102
126
|
*
|
|
103
127
|
* The single argument-rejection path. {@link createToolHandler} and the
|
|
104
128
|
* `runToolContract` test helper both route through it, so a test written to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolHandlerFactory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACd,MAAM,8BAA8B,CAAC;AAEtC,OAAO,
|
|
1
|
+
{"version":3,"file":"toolHandlerFactory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACd,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAiB,KAAK,SAAS,EAAE,KAAK,WAAW,EAAgB,CAAC,EAAE,MAAM,KAAK,CAAC;AAGvF,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,mBAAmB,CAAC;AAElE,OAAO,EAEL,KAAK,eAAe,EAGrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAEL,KAAK,oBAAoB,EAG1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGrE,OAAO,EAIL,gBAAgB,EAEjB,MAAM,0BAA0B,CAAC;AAalC,OAAO,EACL,KA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