@kubb/plugin-mcp 5.5.0-canary.20261111T122007 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +128 -135
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +136 -143
- package/dist/index.js.map +1 -1
- package/docs/guides/server.md +1 -1
- package/docs/options.md +1 -1
- package/docs/overview.md +2 -1
- package/kubb-extension.json +8 -21
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -54,9 +54,9 @@ type Props = {
|
|
|
54
54
|
zod: {
|
|
55
55
|
pathParams: Array<ZodParam>;
|
|
56
56
|
/**
|
|
57
|
-
* Query params — individual schemas to compose into `z.object({ ... })
|
|
57
|
+
* Query params — individual schemas to compose into `z.object({ ... })`, or the name of the grouped query schema.
|
|
58
58
|
*/
|
|
59
|
-
queryParams?: Array<ZodParam> | null;
|
|
59
|
+
queryParams?: Array<ZodParam> | string | null;
|
|
60
60
|
/**
|
|
61
61
|
* Header params — individual schemas to compose into `z.object({ ... })`.
|
|
62
62
|
*/
|
|
@@ -86,8 +86,8 @@ type ResolvedContractClient = {
|
|
|
86
86
|
pluginName: string;
|
|
87
87
|
};
|
|
88
88
|
/**
|
|
89
|
-
* The
|
|
90
|
-
*
|
|
89
|
+
* The per-operation type names a generated client references: the grouped input, the per-status
|
|
90
|
+
* responses record its `RequestResult` is keyed on, and the headers each response declares.
|
|
91
91
|
*/
|
|
92
92
|
type OperationTypeNames = {
|
|
93
93
|
response: {
|
|
@@ -99,6 +99,10 @@ type OperationTypeNames = {
|
|
|
99
99
|
* Resolves the name of the operation's per-status responses record type.
|
|
100
100
|
*/
|
|
101
101
|
responses(node: ast.OperationNode): string;
|
|
102
|
+
/**
|
|
103
|
+
* Resolves the name of the type of the headers one response declares. Left out, results keep untyped headers.
|
|
104
|
+
*/
|
|
105
|
+
headers?(node: ast.OperationNode, statusCode: ast.StatusCode): string;
|
|
102
106
|
};
|
|
103
107
|
};
|
|
104
108
|
/**
|
|
@@ -269,5 +273,4 @@ export declare const pluginMcp: import("@kubb/kit").PluginFactory<PluginMcp>;
|
|
|
269
273
|
* ```
|
|
270
274
|
*/
|
|
271
275
|
export declare const resolverMcp: ResolverMcp;
|
|
272
|
-
export { type PluginMcp, type ResolverMcp, pluginMcp as default };
|
|
273
|
-
//# sourceMappingURL=index.d.ts.map
|
|
276
|
+
export { type PluginMcp, type ResolverMcp, pluginMcp as default };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,41 @@
|
|
|
1
|
-
import { Diagnostics, Resolver, addGenerator, ast,
|
|
1
|
+
import { Diagnostics, Resolver, addGenerator, ast, casing, createResolver, defineExtension, defineGenerator, setMacros, setResolver, text, useConfig } from "@kubb/kit";
|
|
2
2
|
import path, { posix } from "node:path";
|
|
3
3
|
import { Const, File, Function, jsxRenderer } from "@kubb/renderer-jsx";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
5
5
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
6
|
-
import { pluginZodName } from "@kubb/plugin-zod";
|
|
6
|
+
import { pluginZodName as pluginZodName$1 } from "@kubb/plugin-zod";
|
|
7
|
+
// ../../internals/utils/src/fs.ts
|
|
8
|
+
function toSlash(p) {
|
|
9
|
+
if (p.startsWith("\\\\?\\")) return p;
|
|
10
|
+
return p.replaceAll("\\", "/");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Returns the relative path from `rootDir` to `filePath`, always using forward slashes
|
|
14
|
+
* and prefixed with `./` when not already traversing upward.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'
|
|
19
|
+
* getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function getRelativePath(rootDir, filePath) {
|
|
23
|
+
const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath));
|
|
24
|
+
return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
|
|
25
|
+
}
|
|
26
|
+
// ../../internals/utils/src/strings.ts
|
|
27
|
+
/**
|
|
28
|
+
* Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
|
|
29
|
+
* Editors render `\@` as `@` in hovers.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* jsDocEscape('intro\n@example value') // 'intro\n\\@example value'
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function jsDocEscape(input) {
|
|
37
|
+
return `${input}`.replace(/^(\s*)@/gm, "$1\\@");
|
|
38
|
+
}
|
|
7
39
|
// ../../internals/shared/src/operation.ts
|
|
8
40
|
/**
|
|
9
41
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
@@ -73,7 +105,7 @@ function resolveOperationFile(options) {
|
|
|
73
105
|
* The operation's method and path as plain text, such as `` `GET /pet/{petId}` ``. A path is not a valid `{@link}` target.
|
|
74
106
|
*/
|
|
75
107
|
function getOperationRequestLine(node) {
|
|
76
|
-
return ast.
|
|
108
|
+
return ast.http.isOperation(node) && node.path ? `\`${node.method.toUpperCase()} ${node.path}\`` : null;
|
|
77
109
|
}
|
|
78
110
|
/**
|
|
79
111
|
* Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
|
|
@@ -97,7 +129,48 @@ function getContentTypeInfo(node) {
|
|
|
97
129
|
* whether several are present, so the client can let a caller pick which one to accept.
|
|
98
130
|
*/
|
|
99
131
|
function getResponseContentTypeInfo(node) {
|
|
100
|
-
return buildContentTypeInfo(
|
|
132
|
+
return buildContentTypeInfo(ast.http.responses.findPrimary(node)?.content?.map((e) => e.contentType) ?? []);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* How an operation streams its primary success response item by item, when that response declares one content type:
|
|
136
|
+
* - `'event'` for `text/event-stream` whose `itemSchema` types the whole event with its own `event` and `data`
|
|
137
|
+
* - `'data'` for `text/event-stream` typed by its payload only
|
|
138
|
+
* - `'line'` for JSON Lines, one parsed JSON value per line
|
|
139
|
+
*
|
|
140
|
+
* Returns `null` for any other response, and for a response that also declares another content type, which stays a normal
|
|
141
|
+
* call with its query hooks.
|
|
142
|
+
*/
|
|
143
|
+
function getEventStream(node) {
|
|
144
|
+
const content = ast.http.responses.findPrimary(node)?.content ?? [];
|
|
145
|
+
if (content.length !== 1) return null;
|
|
146
|
+
const entry = content[0];
|
|
147
|
+
const framing = getStreamFraming(entry);
|
|
148
|
+
if (framing === "events") return entry.stream?.shape ?? "data";
|
|
149
|
+
return framing === "lines" ? "line" : null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* How a content entry is framed as a stream: `'events'` for Server-Sent Events, `'lines'` for JSON Lines.
|
|
153
|
+
*/
|
|
154
|
+
function getStreamFraming(entry) {
|
|
155
|
+
if (ast.mediaType.getBase(entry) === "text/event-stream") return "events";
|
|
156
|
+
return entry.stream && ast.mediaType.isStream(entry) ? "lines" : void 0;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Whether an operation streams its primary success response, as Server-Sent Events or JSON Lines. The client generator uses
|
|
160
|
+
* this to return a typed stream of items instead of a one-shot `RequestResult`.
|
|
161
|
+
*/
|
|
162
|
+
function isEventStream(node) {
|
|
163
|
+
return getEventStream(node) !== null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Whether a success response offers a stream media type next to other content types. The client returns that variant's
|
|
167
|
+
* body as a `ReadableStream`, so the stream runtime is registered and a hook's data type includes the stream.
|
|
168
|
+
*/
|
|
169
|
+
function hasStreamVariant(node) {
|
|
170
|
+
return ast.http.responses.filterSuccess(node).some((response) => {
|
|
171
|
+
const variants = (response.content ?? []).filter((entry) => entry.schema);
|
|
172
|
+
return variants.length > 1 && variants.some((entry) => ast.mediaType.isStream(entry));
|
|
173
|
+
});
|
|
101
174
|
}
|
|
102
175
|
/**
|
|
103
176
|
* Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
|
|
@@ -140,11 +213,11 @@ const requestGroupOrder = [
|
|
|
140
213
|
* Which of the grouped request options an operation carries.
|
|
141
214
|
*/
|
|
142
215
|
function getRequestGroups(node) {
|
|
143
|
-
const { path, query, header, cookie } =
|
|
216
|
+
const { path, query, header, cookie } = ast.http.groupParameters(node);
|
|
144
217
|
return {
|
|
145
218
|
path: path.length > 0,
|
|
146
219
|
query: query.length > 0,
|
|
147
|
-
body: Boolean(
|
|
220
|
+
body: Boolean(ast.http.requestBody.getSchema(node)),
|
|
148
221
|
headers: header.length > 0,
|
|
149
222
|
cookies: cookie.length > 0
|
|
150
223
|
};
|
|
@@ -156,7 +229,7 @@ function getRequestGroups(node) {
|
|
|
156
229
|
*/
|
|
157
230
|
function getRequestGroupOptionality(node) {
|
|
158
231
|
const groups = getRequestGroups(node);
|
|
159
|
-
const { path, query, header } =
|
|
232
|
+
const { path, query, header } = ast.http.groupParameters(node);
|
|
160
233
|
const hasRequiredPath = path.some((param) => param.required);
|
|
161
234
|
const hasRequiredQuery = query.some((param) => param.required);
|
|
162
235
|
const hasRequiredHeader = header.some((param) => param.required);
|
|
@@ -191,55 +264,12 @@ function buildOperationComments(node, options = {}) {
|
|
|
191
264
|
getOperationRequestLine(node),
|
|
192
265
|
node.description && `@description ${node.description}`,
|
|
193
266
|
node.summary && `@summary ${node.summary}`,
|
|
194
|
-
node.deprecated && "@deprecated"
|
|
267
|
+
node.deprecated && "@deprecated",
|
|
268
|
+
node.externalDocs && `@see ${jsDocEscape([node.externalDocs.url, node.externalDocs.description].filter(Boolean).join(" "))}`
|
|
195
269
|
].filter((comment) => Boolean(comment));
|
|
196
270
|
if (!splitLines) return filteredComments;
|
|
197
271
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
198
272
|
}
|
|
199
|
-
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
200
|
-
/**
|
|
201
|
-
* An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
|
|
202
|
-
* per property, typed and serialized like any other.
|
|
203
|
-
* Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
|
|
204
|
-
*/
|
|
205
|
-
function spreadQuerystring(param) {
|
|
206
|
-
const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
|
|
207
|
-
const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
|
|
208
|
-
if (schema?.type !== "object" || !formEncoded) return [param];
|
|
209
|
-
return schema.properties.map((property) => ast.factory.createParameter({
|
|
210
|
-
name: property.name,
|
|
211
|
-
in: "query",
|
|
212
|
-
schema: property.schema,
|
|
213
|
-
required: param.required && property.required
|
|
214
|
-
}));
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
218
|
-
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
219
|
-
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
220
|
-
* same parameters once per plugin.
|
|
221
|
-
*/
|
|
222
|
-
function getOperationParameters(node) {
|
|
223
|
-
const cached = operationParameterGroupsByNode.get(node);
|
|
224
|
-
if (cached) return cached;
|
|
225
|
-
const dedupe = (params) => {
|
|
226
|
-
const seen = /* @__PURE__ */ new Set();
|
|
227
|
-
return params.filter((param) => {
|
|
228
|
-
if (seen.has(param.name)) return false;
|
|
229
|
-
seen.add(param.name);
|
|
230
|
-
return true;
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
|
|
234
|
-
const groups = {
|
|
235
|
-
path: group("path"),
|
|
236
|
-
query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
|
|
237
|
-
header: group("header"),
|
|
238
|
-
cookie: group("cookie")
|
|
239
|
-
};
|
|
240
|
-
operationParameterGroupsByNode.set(node, groups);
|
|
241
|
-
return groups;
|
|
242
|
-
}
|
|
243
273
|
/**
|
|
244
274
|
* Whether the operation declares more than one request media type with a schema, so a caller must pick one on `contentType`.
|
|
245
275
|
*/
|
|
@@ -252,42 +282,6 @@ function hasRequestContentTypeChoice(node) {
|
|
|
252
282
|
function castToClientOptions(callArg, clientName, returnType = "full") {
|
|
253
283
|
return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
|
|
254
284
|
}
|
|
255
|
-
function getStatusCodeNumber(statusCode) {
|
|
256
|
-
const code = Number(statusCode);
|
|
257
|
-
return Number.isNaN(code) ? null : code;
|
|
258
|
-
}
|
|
259
|
-
function isSuccessStatusCode(statusCode) {
|
|
260
|
-
const code = getStatusCodeNumber(statusCode);
|
|
261
|
-
return code !== null && code >= 200 && code < 300;
|
|
262
|
-
}
|
|
263
|
-
function getSuccessResponses(responses) {
|
|
264
|
-
return responses.filter((response) => isSuccessStatusCode(response.statusCode));
|
|
265
|
-
}
|
|
266
|
-
function getOperationSuccessResponses(node) {
|
|
267
|
-
return getSuccessResponses(node.responses);
|
|
268
|
-
}
|
|
269
|
-
function getPrimarySuccessResponse(node) {
|
|
270
|
-
return getOperationSuccessResponses(node)[0] ?? null;
|
|
271
|
-
}
|
|
272
|
-
// ../../internals/utils/src/fs.ts
|
|
273
|
-
function toSlash(p) {
|
|
274
|
-
if (p.startsWith("\\\\?\\")) return p;
|
|
275
|
-
return p.replaceAll("\\", "/");
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Returns the relative path from `rootDir` to `filePath`, always using forward slashes
|
|
279
|
-
* and prefixed with `./` when not already traversing upward.
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* ```ts
|
|
283
|
-
* getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'
|
|
284
|
-
* getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
function getRelativePath(rootDir, filePath) {
|
|
288
|
-
const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath));
|
|
289
|
-
return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
|
|
290
|
-
}
|
|
291
285
|
// ../../internals/shared/src/resolver.ts
|
|
292
286
|
/**
|
|
293
287
|
* Builds the allocation key for a declaration an operation owns. `scope` names which declaration
|
|
@@ -309,36 +303,6 @@ function operationKey(node, ...scope) {
|
|
|
309
303
|
...scope.map(String)
|
|
310
304
|
];
|
|
311
305
|
}
|
|
312
|
-
// ../../internals/shared/src/group.ts
|
|
313
|
-
/**
|
|
314
|
-
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
315
|
-
* shared default naming so every plugin groups output consistently:
|
|
316
|
-
*
|
|
317
|
-
* - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
|
|
318
|
-
* - other groups use the camelCased group (`pet store` → `petStore`).
|
|
319
|
-
*
|
|
320
|
-
* A user-provided `group.name` always wins over the default namer, so callers stay in
|
|
321
|
-
* control of their output folders. Returns `null` when grouping is disabled, matching the
|
|
322
|
-
* per-plugin convention.
|
|
323
|
-
*
|
|
324
|
-
* @param group - The user-supplied group option, or `undefined` to disable grouping.
|
|
325
|
-
*
|
|
326
|
-
* @example
|
|
327
|
-
* ```ts
|
|
328
|
-
* createGroupConfig(group) // shared across every plugin
|
|
329
|
-
* ```
|
|
330
|
-
*/
|
|
331
|
-
function createGroupConfig(group) {
|
|
332
|
-
if (!group) return null;
|
|
333
|
-
const defaultName = (ctx) => {
|
|
334
|
-
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
335
|
-
return camelCase(ctx.group);
|
|
336
|
-
};
|
|
337
|
-
return {
|
|
338
|
-
...group,
|
|
339
|
-
name: group.name ? group.name : defaultName
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
306
|
// src/components/McpHandler.tsx
|
|
343
307
|
function McpHandler({ name, clientName, node, resolver, returnType = "full" }) {
|
|
344
308
|
const { signature, names: callArgs } = buildRequestParamsSignature(node, resolver, { isConfigurable: false });
|
|
@@ -392,7 +356,7 @@ function Server({ serverName, serverVersion, operations }) {
|
|
|
392
356
|
});
|
|
393
357
|
if (zod.queryParams) entries.push({
|
|
394
358
|
key: "query",
|
|
395
|
-
value: zodObject(zod.queryParams)
|
|
359
|
+
value: typeof zod.queryParams === "string" ? zod.queryParams : zodObject(zod.queryParams)
|
|
396
360
|
});
|
|
397
361
|
if (zod.headerParams) entries.push({
|
|
398
362
|
key: "headers",
|
|
@@ -407,12 +371,12 @@ function Server({ serverName, serverVersion, operations }) {
|
|
|
407
371
|
value: zod.requestName
|
|
408
372
|
});
|
|
409
373
|
const destructured = `{ ${entries.map((e) => e.key).join(", ")} }`;
|
|
410
|
-
const inputSchema = entries.length ? `z.object({ ${entries.map((e) => `${e.key}: ${e.value}`).join(", ")} })` : null;
|
|
374
|
+
const inputSchema = entries.length ? `toolSchema(z.object({ ${entries.map((e) => `${e.key}: ${e.value}`).join(", ")} }))` : null;
|
|
411
375
|
const outputSchema = zod.responseName;
|
|
412
376
|
const config = [
|
|
413
377
|
tool.title ? `title: ${JSON.stringify(tool.title)}` : null,
|
|
414
378
|
`description: ${JSON.stringify(tool.description)}`,
|
|
415
|
-
outputSchema ? `outputSchema: z.object({ data: ${outputSchema} })` : null
|
|
379
|
+
outputSchema ? `outputSchema: toolSchema(z.object({ data: ${outputSchema} }))` : null
|
|
416
380
|
].filter(Boolean).join(",\n ");
|
|
417
381
|
if (inputSchema) return `
|
|
418
382
|
server.registerTool(${JSON.stringify(tool.name)}, {
|
|
@@ -431,6 +395,31 @@ server.registerTool(${JSON.stringify(tool.name)}, {
|
|
|
431
395
|
`;
|
|
432
396
|
}).filter(Boolean).join("");
|
|
433
397
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
398
|
+
/* @__PURE__ */ jsx(File.Source, {
|
|
399
|
+
name: "toolSchema",
|
|
400
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
401
|
+
name: "toolSchema",
|
|
402
|
+
generics: "T extends z.ZodType",
|
|
403
|
+
params: "schema: T",
|
|
404
|
+
JSDoc: { comments: ["Converts with `unrepresentable: \"any\"`, because a `bigint` or `Blob` in one tool schema fails every `tools/list` request.", "A `bigint` is listed as an `int64` integer and a `Blob` as an unconstrained value."] },
|
|
405
|
+
children: `const standard = schema['~standard']
|
|
406
|
+
const convert = (io: 'input' | 'output') => (options: Parameters<typeof standard.jsonSchema.input>[0]) =>
|
|
407
|
+
standard.jsonSchema[io]({
|
|
408
|
+
...options,
|
|
409
|
+
libraryOptions: {
|
|
410
|
+
unrepresentable: 'any',
|
|
411
|
+
override: ({ zodSchema, jsonSchema }: { zodSchema: z.core.$ZodType; jsonSchema: Record<string, unknown> }) => {
|
|
412
|
+
if (zodSchema._zod.def.type === 'bigint') {
|
|
413
|
+
jsonSchema.type = 'integer'
|
|
414
|
+
jsonSchema.format = 'int64'
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
return { '~standard': { ...standard, jsonSchema: { input: convert('input'), output: convert('output') } } }`
|
|
421
|
+
})
|
|
422
|
+
}),
|
|
434
423
|
/* @__PURE__ */ jsx(File.Source, {
|
|
435
424
|
name: "getServer",
|
|
436
425
|
isExportable: true,
|
|
@@ -439,8 +428,8 @@ server.registerTool(${JSON.stringify(tool.name)}, {
|
|
|
439
428
|
name: "getServer",
|
|
440
429
|
export: true,
|
|
441
430
|
children: `const server = new McpServer({
|
|
442
|
-
name:
|
|
443
|
-
version:
|
|
431
|
+
name: ${text.quote(serverName)},
|
|
432
|
+
version: ${text.quote(serverVersion)},
|
|
444
433
|
})
|
|
445
434
|
${registrations}
|
|
446
435
|
return server`
|
|
@@ -640,12 +629,13 @@ function resolveClientOperation(options) {
|
|
|
640
629
|
operationFile: file.path
|
|
641
630
|
}),
|
|
642
631
|
clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
|
|
643
|
-
returnType: operationOptions.returnType ?? "full"
|
|
632
|
+
returnType: operationOptions.returnType ?? "full",
|
|
633
|
+
typedHeaders: importPath === void 0
|
|
644
634
|
};
|
|
645
635
|
});
|
|
646
636
|
}
|
|
647
637
|
// ../../internals/client/src/resolveOperationTypes.ts
|
|
648
|
-
const pluginZodName
|
|
638
|
+
const pluginZodName = "plugin-zod";
|
|
649
639
|
/**
|
|
650
640
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
651
641
|
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
@@ -668,6 +658,7 @@ function toZodTypeResolver(resolver) {
|
|
|
668
658
|
status: (node, statusCode) => type(resolver.response.status(node, statusCode)),
|
|
669
659
|
response: (node) => type(resolver.response.response(node)),
|
|
670
660
|
responses: (node) => type(resolver.response.responses(node)),
|
|
661
|
+
headers: (node, statusCode) => type(resolver.response.headers(node, statusCode)),
|
|
671
662
|
options: (node) => resolver.response.options(node)
|
|
672
663
|
}
|
|
673
664
|
};
|
|
@@ -688,7 +679,7 @@ function toZodTypeResolver(resolver) {
|
|
|
688
679
|
function resolveOperationTypes(driver, pluginName) {
|
|
689
680
|
return driver.memo(`operationTypes:${pluginName}`, () => {
|
|
690
681
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
691
|
-
const pluginZod = driver.getPlugin(pluginZodName
|
|
682
|
+
const pluginZod = driver.getPlugin(pluginZodName);
|
|
692
683
|
if (pluginTs && pluginZod?.options?.inferred !== "codec") {
|
|
693
684
|
const resolver = driver.getResolver(pluginTsName);
|
|
694
685
|
return {
|
|
@@ -706,7 +697,7 @@ function resolveOperationTypes(driver, pluginName) {
|
|
|
706
697
|
location: { kind: "config" },
|
|
707
698
|
plugin: pluginName
|
|
708
699
|
});
|
|
709
|
-
const resolver = toZodTypeResolver(driver.getResolver(pluginZodName
|
|
700
|
+
const resolver = toZodTypeResolver(driver.getResolver(pluginZodName));
|
|
710
701
|
return {
|
|
711
702
|
response: resolver.response,
|
|
712
703
|
resolver,
|
|
@@ -726,7 +717,8 @@ const mcpGenerator = defineGenerator({
|
|
|
726
717
|
name: "mcp",
|
|
727
718
|
renderer: jsxRenderer,
|
|
728
719
|
operation(node, ctx) {
|
|
729
|
-
if (!ast.
|
|
720
|
+
if (!ast.http.isOperation(node)) return null;
|
|
721
|
+
if (isEventStream(node) || hasStreamVariant(node)) return null;
|
|
730
722
|
const { resolver, driver, root, config } = ctx;
|
|
731
723
|
const { output, client, group } = ctx.options;
|
|
732
724
|
const types = resolveOperationTypes(driver, resolver.pluginName);
|
|
@@ -820,8 +812,8 @@ const serverGenerator = defineGenerator({
|
|
|
820
812
|
operations(nodes, ctx) {
|
|
821
813
|
const { config, resolver, plugin, driver, root } = ctx;
|
|
822
814
|
const { output, group } = ctx.options;
|
|
823
|
-
const pluginZod = ctx.requirePlugin(pluginZodName);
|
|
824
|
-
const zodResolver = driver.getResolver(pluginZodName);
|
|
815
|
+
const pluginZod = ctx.requirePlugin(pluginZodName$1);
|
|
816
|
+
const zodResolver = driver.getResolver(pluginZodName$1);
|
|
825
817
|
const fileAt = (baseName) => ({
|
|
826
818
|
baseName,
|
|
827
819
|
path: path.resolve(root, output.path, baseName),
|
|
@@ -835,8 +827,8 @@ const serverGenerator = defineGenerator({
|
|
|
835
827
|
command: "npx",
|
|
836
828
|
args: ["tsx", getRelativePath(path.resolve(config.root), startFile.path)]
|
|
837
829
|
} } };
|
|
838
|
-
const operationsMapped = nodes.filter(ast.
|
|
839
|
-
const { path: pathParams, query: queryParams, header: headerParams, cookie: cookieParams } =
|
|
830
|
+
const operationsMapped = nodes.filter(ast.http.isOperation).filter((node) => !isEventStream(node) && !hasStreamVariant(node)).map((node) => {
|
|
831
|
+
const { path: pathParams, query: queryParams, header: headerParams, cookie: cookieParams } = ast.http.groupParameters(node);
|
|
840
832
|
const mcpFile = resolver.file({
|
|
841
833
|
...operationFileEntry(node, node.operationId),
|
|
842
834
|
root,
|
|
@@ -851,13 +843,14 @@ const serverGenerator = defineGenerator({
|
|
|
851
843
|
output: pluginZod.options?.output ?? output,
|
|
852
844
|
group: pluginZod.options?.group ?? void 0
|
|
853
845
|
});
|
|
854
|
-
const requestName =
|
|
855
|
-
const successStatus =
|
|
846
|
+
const requestName = ast.http.requestBody.getSchema(node) ? zodResolver.response.body(node) : null;
|
|
847
|
+
const successStatus = ast.http.responses.findPrimary(node)?.statusCode;
|
|
856
848
|
const responseName = successStatus ? zodResolver.response.status(node, successStatus) : null;
|
|
857
849
|
const resolveParams = (params) => params.map((p) => ({
|
|
858
850
|
name: p.name,
|
|
859
851
|
schemaName: zodResolver.param.name(node, p)
|
|
860
852
|
}));
|
|
853
|
+
const resolveOptional = (params) => params.length ? resolveParams(params) : null;
|
|
861
854
|
return {
|
|
862
855
|
tool: {
|
|
863
856
|
name: node.operationId,
|
|
@@ -870,9 +863,9 @@ const serverGenerator = defineGenerator({
|
|
|
870
863
|
},
|
|
871
864
|
zod: {
|
|
872
865
|
pathParams: resolveParams(pathParams),
|
|
873
|
-
queryParams:
|
|
874
|
-
headerParams:
|
|
875
|
-
cookieParams:
|
|
866
|
+
queryParams: resolveOptional(queryParams),
|
|
867
|
+
headerParams: resolveOptional(headerParams),
|
|
868
|
+
cookieParams: resolveOptional(cookieParams),
|
|
876
869
|
requestName,
|
|
877
870
|
responseName,
|
|
878
871
|
file: zodFile
|
|
@@ -882,7 +875,7 @@ const serverGenerator = defineGenerator({
|
|
|
882
875
|
const imports = operationsMapped.flatMap(({ mcp, zod }) => {
|
|
883
876
|
const zodNames = [
|
|
884
877
|
...zod.pathParams.map((p) => p.schemaName),
|
|
885
|
-
...(zod.queryParams ?? []).map((p) => p.schemaName),
|
|
878
|
+
...typeof zod.queryParams === "string" ? [zod.queryParams] : (zod.queryParams ?? []).map((p) => p.schemaName),
|
|
886
879
|
...(zod.headerParams ?? []).map((p) => p.schemaName),
|
|
887
880
|
...(zod.cookieParams ?? []).map((p) => p.schemaName),
|
|
888
881
|
zod.requestName,
|
|
@@ -984,11 +977,11 @@ const serverGenerator = defineGenerator({
|
|
|
984
977
|
});
|
|
985
978
|
// kubb-extension.json
|
|
986
979
|
var compatibility = {
|
|
987
|
-
"kubb": ">=5.
|
|
980
|
+
"kubb": ">=5.18.4",
|
|
988
981
|
"node": ">=22.22"
|
|
989
982
|
};
|
|
990
983
|
// package.json
|
|
991
|
-
var version = "5.5.
|
|
984
|
+
var version = "5.5.1";
|
|
992
985
|
// src/resolvers/resolverMcp.ts
|
|
993
986
|
/**
|
|
994
987
|
* Default resolver used by `@kubb/plugin-mcp`. Decides the names and file
|
|
@@ -1005,7 +998,7 @@ var version = "5.5.0-canary.20261111T122007";
|
|
|
1005
998
|
const resolverMcp = createResolver({
|
|
1006
999
|
pluginName: "plugin-mcp",
|
|
1007
1000
|
name(name) {
|
|
1008
|
-
return this.memo(`name:${name}`, () =>
|
|
1001
|
+
return this.memo(`name:${name}`, () => casing.camel(name, { suffix: "handler" }));
|
|
1009
1002
|
},
|
|
1010
1003
|
handler: { name(node) {
|
|
1011
1004
|
const name = this.name(node.operationId);
|
|
@@ -1058,7 +1051,7 @@ const pluginMcp = defineExtension({
|
|
|
1058
1051
|
},
|
|
1059
1052
|
dependencies: {
|
|
1060
1053
|
[pluginTsName]: { optional: true },
|
|
1061
|
-
[pluginZodName]: {}
|
|
1054
|
+
[pluginZodName$1]: {}
|
|
1062
1055
|
},
|
|
1063
1056
|
setup(options) {
|
|
1064
1057
|
const { output = {
|
|
@@ -1074,7 +1067,7 @@ const pluginMcp = defineExtension({
|
|
|
1074
1067
|
exclude,
|
|
1075
1068
|
include,
|
|
1076
1069
|
override,
|
|
1077
|
-
group:
|
|
1070
|
+
group: group ?? null,
|
|
1078
1071
|
client: resolveContractClient({
|
|
1079
1072
|
plugin: pluginMcpName,
|
|
1080
1073
|
client,
|