@kubb/plugin-mcp 5.0.0-alpha.27 → 5.0.0-alpha.28

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 CHANGED
@@ -1,75 +1,1033 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_Server = require("./Server-EjbvNRYy.cjs");
3
- const require_generators = require("./generators-CzP7VKQw.cjs");
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
4
24
  let node_path = require("node:path");
5
- node_path = require_Server.__toESM(node_path);
25
+ node_path = __toESM(node_path);
26
+ let _kubb_ast = require("@kubb/ast");
27
+ let _kubb_plugin_ts = require("@kubb/plugin-ts");
28
+ let _kubb_react_fabric = require("@kubb/react-fabric");
29
+ let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
6
30
  let _kubb_core = require("@kubb/core");
31
+ let _kubb_plugin_zod = require("@kubb/plugin-zod");
7
32
  let _kubb_plugin_client = require("@kubb/plugin-client");
8
33
  let _kubb_plugin_client_templates_clients_axios_source = require("@kubb/plugin-client/templates/clients/axios.source");
9
34
  let _kubb_plugin_client_templates_clients_fetch_source = require("@kubb/plugin-client/templates/clients/fetch.source");
10
35
  let _kubb_plugin_client_templates_config_source = require("@kubb/plugin-client/templates/config.source");
11
- let _kubb_plugin_oas = require("@kubb/plugin-oas");
12
- let _kubb_plugin_ts = require("@kubb/plugin-ts");
13
- let _kubb_plugin_zod = require("@kubb/plugin-zod");
36
+ //#region ../../internals/utils/src/casing.ts
37
+ /**
38
+ * Shared implementation for camelCase and PascalCase conversion.
39
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
40
+ * and capitalizes each word according to `pascal`.
41
+ *
42
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
43
+ */
44
+ function toCamelOrPascal(text, pascal) {
45
+ return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
46
+ if (word.length > 1 && word === word.toUpperCase()) return word;
47
+ if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
48
+ return word.charAt(0).toUpperCase() + word.slice(1);
49
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
50
+ }
51
+ /**
52
+ * Splits `text` on `.` and applies `transformPart` to each segment.
53
+ * The last segment receives `isLast = true`, all earlier segments receive `false`.
54
+ * Segments are joined with `/` to form a file path.
55
+ *
56
+ * Only splits on dots followed by a letter so that version numbers
57
+ * embedded in operationIds (e.g. `v2025.0`) are kept intact.
58
+ */
59
+ function applyToFileParts(text, transformPart) {
60
+ const parts = text.split(/\.(?=[a-zA-Z])/);
61
+ return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
62
+ }
63
+ /**
64
+ * Converts `text` to camelCase.
65
+ * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
66
+ *
67
+ * @example
68
+ * camelCase('hello-world') // 'helloWorld'
69
+ * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
70
+ */
71
+ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
72
+ if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
73
+ prefix,
74
+ suffix
75
+ } : {}));
76
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
77
+ }
78
+ //#endregion
79
+ //#region ../../internals/utils/src/reserved.ts
80
+ /**
81
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * isValidVarName('status') // true
86
+ * isValidVarName('class') // false (reserved word)
87
+ * isValidVarName('42foo') // false (starts with digit)
88
+ * ```
89
+ */
90
+ function isValidVarName(name) {
91
+ try {
92
+ new Function(`var ${name}`);
93
+ } catch {
94
+ return false;
95
+ }
96
+ return true;
97
+ }
98
+ //#endregion
99
+ //#region ../../internals/utils/src/urlPath.ts
100
+ /**
101
+ * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
102
+ *
103
+ * @example
104
+ * const p = new URLPath('/pet/{petId}')
105
+ * p.URL // '/pet/:petId'
106
+ * p.template // '`/pet/${petId}`'
107
+ */
108
+ var URLPath = class {
109
+ /**
110
+ * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
111
+ */
112
+ path;
113
+ #options;
114
+ constructor(path, options = {}) {
115
+ this.path = path;
116
+ this.#options = options;
117
+ }
118
+ /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * new URLPath('/pet/{petId}').URL // '/pet/:petId'
123
+ * ```
124
+ */
125
+ get URL() {
126
+ return this.toURLPath();
127
+ }
128
+ /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
133
+ * new URLPath('/pet/{petId}').isURL // false
134
+ * ```
135
+ */
136
+ get isURL() {
137
+ try {
138
+ return !!new URL(this.path).href;
139
+ } catch {
140
+ return false;
141
+ }
142
+ }
143
+ /**
144
+ * Converts the OpenAPI path to a TypeScript template literal string.
145
+ *
146
+ * @example
147
+ * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
148
+ * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
149
+ */
150
+ get template() {
151
+ return this.toTemplateString();
152
+ }
153
+ /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * new URLPath('/pet/{petId}').object
158
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
159
+ * ```
160
+ */
161
+ get object() {
162
+ return this.toObject();
163
+ }
164
+ /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * new URLPath('/pet/{petId}').params // { petId: 'petId' }
169
+ * new URLPath('/pet').params // undefined
170
+ * ```
171
+ */
172
+ get params() {
173
+ return this.getParams();
174
+ }
175
+ #transformParam(raw) {
176
+ const param = isValidVarName(raw) ? raw : camelCase(raw);
177
+ return this.#options.casing === "camelcase" ? camelCase(param) : param;
178
+ }
179
+ /**
180
+ * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
181
+ */
182
+ #eachParam(fn) {
183
+ for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
184
+ const raw = match[1];
185
+ fn(raw, this.#transformParam(raw));
186
+ }
187
+ }
188
+ toObject({ type = "path", replacer, stringify } = {}) {
189
+ const object = {
190
+ url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
191
+ params: this.getParams()
192
+ };
193
+ if (stringify) {
194
+ if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
195
+ if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
196
+ return `{ url: '${object.url}' }`;
197
+ }
198
+ return object;
199
+ }
200
+ /**
201
+ * Converts the OpenAPI path to a TypeScript template literal string.
202
+ * An optional `replacer` can transform each extracted parameter name before interpolation.
203
+ *
204
+ * @example
205
+ * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
206
+ */
207
+ toTemplateString({ prefix = "", replacer } = {}) {
208
+ return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
209
+ if (i % 2 === 0) return part;
210
+ const param = this.#transformParam(part);
211
+ return `\${${replacer ? replacer(param) : param}}`;
212
+ }).join("")}\``;
213
+ }
214
+ /**
215
+ * Extracts all `{param}` segments from the path and returns them as a key-value map.
216
+ * An optional `replacer` transforms each parameter name in both key and value positions.
217
+ * Returns `undefined` when no path parameters are found.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * new URLPath('/pet/{petId}/tag/{tagId}').getParams()
222
+ * // { petId: 'petId', tagId: 'tagId' }
223
+ * ```
224
+ */
225
+ getParams(replacer) {
226
+ const params = {};
227
+ this.#eachParam((_raw, param) => {
228
+ const key = replacer ? replacer(param) : param;
229
+ params[key] = key;
230
+ });
231
+ return Object.keys(params).length > 0 ? params : void 0;
232
+ }
233
+ /** Converts the OpenAPI path to Express-style colon syntax.
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
238
+ * ```
239
+ */
240
+ toURLPath() {
241
+ return this.path.replace(/\{([^}]+)\}/g, ":$1");
242
+ }
243
+ };
244
+ //#endregion
245
+ //#region src/utils.ts
246
+ /**
247
+ * Find the first 2xx response status code from an operation's responses.
248
+ */
249
+ function findSuccessStatusCode(responses) {
250
+ for (const res of responses) {
251
+ const code = Number(res.statusCode);
252
+ if (code >= 200 && code < 300) return res.statusCode;
253
+ }
254
+ }
255
+ /**
256
+ * Render a group param value — either a group schema name directly (kubbV4),
257
+ * or compose individual schemas into `z.object({ ... })` (v5).
258
+ */
259
+ function zodGroupExpr(entry) {
260
+ if (typeof entry === "string") return entry;
261
+ return `z.object({ ${entry.map((p) => `${JSON.stringify(p.name)}: ${p.schemaName}`).join(", ")} })`;
262
+ }
263
+ /**
264
+ * Build JSDoc comment lines from an OperationNode.
265
+ */
266
+ function getComments(node) {
267
+ return [
268
+ node.description && `@description ${node.description}`,
269
+ node.summary && `@summary ${node.summary}`,
270
+ node.deprecated && "@deprecated",
271
+ `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`
272
+ ].filter((x) => Boolean(x));
273
+ }
274
+ /**
275
+ * Build a mapping of original param names → camelCase names.
276
+ * Returns `undefined` when no names actually change (no remapping needed).
277
+ */
278
+ function getParamsMapping(params) {
279
+ if (!params.length) return;
280
+ const mapping = {};
281
+ let hasDifference = false;
282
+ for (const p of params) {
283
+ const camelName = camelCase(p.name);
284
+ mapping[p.name] = camelName;
285
+ if (p.name !== camelName) hasDifference = true;
286
+ }
287
+ return hasDifference ? mapping : void 0;
288
+ }
289
+ /**
290
+ * Convert a SchemaNode type to an inline Zod expression string.
291
+ * Used as fallback when no named zod schema is available for a path parameter.
292
+ */
293
+ function zodExprFromSchemaNode(schema) {
294
+ let expr;
295
+ switch (schema.type) {
296
+ case "integer":
297
+ expr = "z.coerce.number()";
298
+ break;
299
+ case "number":
300
+ expr = "z.number()";
301
+ break;
302
+ case "boolean":
303
+ expr = "z.boolean()";
304
+ break;
305
+ case "array":
306
+ expr = "z.array(z.unknown())";
307
+ break;
308
+ default: expr = "z.string()";
309
+ }
310
+ if (schema.nullable) expr = `${expr}.nullable()`;
311
+ return expr;
312
+ }
313
+ //#endregion
314
+ //#region src/components/McpHandler.tsx
315
+ /**
316
+ * Generate a remapping statement: `const mappedX = x ? { "orig": x.camel, ... } : undefined`
317
+ */
318
+ function buildRemappingCode(mapping, varName, sourceName) {
319
+ return `const ${varName} = ${sourceName} ? { ${Object.entries(mapping).map(([orig, camel]) => `"${orig}": ${sourceName}.${camel}`).join(", ")} } : undefined`;
320
+ }
321
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
322
+ function McpHandler({ name, node, resolver, baseURL, dataReturnType, paramsCasing }) {
323
+ const urlPath = new URLPath(node.path);
324
+ const contentType = node.requestBody?.contentType;
325
+ const isFormData = contentType === "multipart/form-data";
326
+ const casedParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
327
+ const queryParams = casedParams.filter((p) => p.in === "query");
328
+ const headerParams = casedParams.filter((p) => p.in === "header");
329
+ const originalPathParams = node.parameters.filter((p) => p.in === "path");
330
+ const originalQueryParams = node.parameters.filter((p) => p.in === "query");
331
+ const originalHeaderParams = node.parameters.filter((p) => p.in === "header");
332
+ const requestName = node.requestBody?.schema ? resolver.resolveDataName(node) : void 0;
333
+ const responseName = resolver.resolveResponseName(node);
334
+ const errorResponses = node.responses.filter((r) => Number(r.statusCode) >= 400).map((r) => resolver.resolveResponseStatusName(node, r.statusCode));
335
+ const generics = [
336
+ responseName,
337
+ `ResponseErrorConfig<${errorResponses.length > 0 ? errorResponses.join(" | ") : "Error"}>`,
338
+ requestName || "unknown"
339
+ ].filter(Boolean);
340
+ const paramsNode = (0, _kubb_ast.createOperationParams)(node, {
341
+ paramsType: "object",
342
+ pathParamsType: "inline",
343
+ resolver,
344
+ paramsCasing
345
+ });
346
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
347
+ const pathParamsMapping = paramsCasing ? getParamsMapping(originalPathParams) : void 0;
348
+ const queryParamsMapping = paramsCasing ? getParamsMapping(originalQueryParams) : void 0;
349
+ const headerParamsMapping = paramsCasing ? getParamsMapping(originalHeaderParams) : void 0;
350
+ const contentTypeHeader = contentType && contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0;
351
+ const headers = [headerParams.length ? headerParamsMapping ? "...mappedHeaders" : "...headers" : void 0, contentTypeHeader].filter(Boolean);
352
+ const fetchConfig = [];
353
+ fetchConfig.push(`method: ${JSON.stringify(node.method.toUpperCase())}`);
354
+ fetchConfig.push(`url: ${urlPath.template}`);
355
+ if (baseURL) fetchConfig.push(`baseURL: \`${baseURL}\``);
356
+ if (queryParams.length) fetchConfig.push(queryParamsMapping ? "params: mappedParams" : "params");
357
+ if (requestName) fetchConfig.push(`data: ${isFormData ? "formData as FormData" : "requestData"}`);
358
+ if (headers.length) fetchConfig.push(`headers: { ${headers.join(", ")} }`);
359
+ const callToolResult = dataReturnType === "data" ? `return {
360
+ content: [
361
+ {
362
+ type: 'text',
363
+ text: JSON.stringify(res.data)
364
+ }
365
+ ],
366
+ structuredContent: { data: res.data }
367
+ }` : `return {
368
+ content: [
369
+ {
370
+ type: 'text',
371
+ text: JSON.stringify(res)
372
+ }
373
+ ],
374
+ structuredContent: { data: res.data }
375
+ }`;
376
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
377
+ name,
378
+ isExportable: true,
379
+ isIndexable: true,
380
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
381
+ name,
382
+ async: true,
383
+ export: true,
384
+ params: paramsSignature,
385
+ JSDoc: { comments: getComments(node) },
386
+ returnType: "Promise<CallToolResult>",
387
+ children: [
388
+ "",
389
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
390
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
391
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => originalName !== camelCaseName && isValidVarName(originalName)).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
392
+ pathParamsMapping && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})] }),
393
+ queryParamsMapping && queryParams.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
394
+ buildRemappingCode(queryParamsMapping, "mappedParams", "params"),
395
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
396
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
397
+ ] }),
398
+ headerParamsMapping && headerParams.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
399
+ buildRemappingCode(headerParamsMapping, "mappedHeaders", "headers"),
400
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
401
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
402
+ ] }),
403
+ requestName && "const requestData = data",
404
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
405
+ isFormData && requestName && "const formData = buildFormData(requestData)",
406
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
407
+ `const res = await fetch<${generics.join(", ")}>({ ${fetchConfig.join(", ")} })`,
408
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
409
+ callToolResult
410
+ ]
411
+ })
412
+ });
413
+ }
414
+ //#endregion
415
+ //#region src/components/Server.tsx
416
+ const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
417
+ function Server({ name, serverName, serverVersion, paramsCasing, operations }) {
418
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File.Source, {
419
+ name,
420
+ isExportable: true,
421
+ isIndexable: true,
422
+ children: [
423
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
424
+ name: "server",
425
+ export: true,
426
+ children: `
427
+ new McpServer({
428
+ name: '${serverName}',
429
+ version: '${serverVersion}',
430
+ })
431
+ `
432
+ }),
433
+ operations.map(({ tool, mcp, zod, node }) => {
434
+ const pathParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing).filter((p) => p.in === "path");
435
+ const pathEntries = [];
436
+ const otherEntries = [];
437
+ for (const p of pathParams) {
438
+ const zodParam = zod.pathParams.find((zp) => zp.name === p.name);
439
+ pathEntries.push({
440
+ key: p.name,
441
+ value: zodParam ? zodParam.schemaName : zodExprFromSchemaNode(p.schema)
442
+ });
443
+ }
444
+ if (zod.requestName) otherEntries.push({
445
+ key: "data",
446
+ value: zod.requestName
447
+ });
448
+ if (zod.queryParams) otherEntries.push({
449
+ key: "params",
450
+ value: zodGroupExpr(zod.queryParams)
451
+ });
452
+ if (zod.headerParams) otherEntries.push({
453
+ key: "headers",
454
+ value: zodGroupExpr(zod.headerParams)
455
+ });
456
+ otherEntries.sort((a, b) => a.key.localeCompare(b.key));
457
+ const entries = [...pathEntries, ...otherEntries];
458
+ const paramsNode = entries.length ? (0, _kubb_ast.createFunctionParameters)({ params: [(0, _kubb_ast.createParameterGroup)({ properties: entries.map((e) => (0, _kubb_ast.createFunctionParameter)({
459
+ name: e.key,
460
+ optional: false
461
+ })) })] }) : void 0;
462
+ const destructured = paramsNode ? keysPrinter.print(paramsNode) ?? "" : "";
463
+ const inputSchema = entries.length ? `{ ${entries.map((e) => `${e.key}: ${e.value}`).join(", ")} }` : void 0;
464
+ const outputSchema = zod.responseName;
465
+ const config = [
466
+ tool.title ? `title: ${JSON.stringify(tool.title)}` : null,
467
+ `description: ${JSON.stringify(tool.description)}`,
468
+ outputSchema ? `outputSchema: { data: ${outputSchema} }` : null
469
+ ].filter(Boolean).join(",\n ");
470
+ if (inputSchema) return `
471
+ server.registerTool(${JSON.stringify(tool.name)}, {
472
+ ${config},
473
+ inputSchema: ${inputSchema},
474
+ }, async (${destructured}) => {
475
+ return ${mcp.name}(${destructured})
476
+ })
477
+ `;
478
+ return `
479
+ server.registerTool(${JSON.stringify(tool.name)}, {
480
+ ${config},
481
+ }, async () => {
482
+ return ${mcp.name}()
483
+ })
484
+ `;
485
+ }).filter(Boolean),
486
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
487
+ name: "startServer",
488
+ async: true,
489
+ export: true,
490
+ children: `try {
491
+ const transport = new StdioServerTransport()
492
+ await server.connect(transport)
493
+
494
+ } catch (error) {
495
+ console.error('Failed to start server:', error)
496
+ process.exit(1)
497
+ }`
498
+ })
499
+ ]
500
+ });
501
+ }
502
+ //#endregion
503
+ //#region src/generators/mcpGenerator.tsx
504
+ const mcpGenerator = (0, _kubb_core.defineGenerator)({
505
+ name: "mcp",
506
+ type: "react",
507
+ Operation({ node, options, config, driver, resolver, plugin }) {
508
+ const { output, client, paramsCasing, group } = options;
509
+ const root = node_path.default.resolve(config.root, config.output.path);
510
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
511
+ if (!pluginTs?.resolver) return null;
512
+ const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
513
+ const casedParams = (0, _kubb_ast.caseParams)(transformedNode.parameters, paramsCasing);
514
+ const pathParams = casedParams.filter((p) => p.in === "path");
515
+ const queryParams = casedParams.filter((p) => p.in === "query");
516
+ const headerParams = casedParams.filter((p) => p.in === "header");
517
+ const importedTypeNames = [
518
+ ...pathParams.map((p) => pluginTs.resolver.resolvePathParamsName(transformedNode, p)),
519
+ ...queryParams.map((p) => pluginTs.resolver.resolveQueryParamsName(transformedNode, p)),
520
+ ...headerParams.map((p) => pluginTs.resolver.resolveHeaderParamsName(transformedNode, p)),
521
+ transformedNode.requestBody?.schema ? pluginTs.resolver.resolveDataName(transformedNode) : void 0,
522
+ pluginTs.resolver.resolveResponseName(transformedNode),
523
+ ...transformedNode.responses.filter((r) => Number(r.statusCode) >= 400).map((r) => pluginTs.resolver.resolveResponseStatusName(transformedNode, r.statusCode))
524
+ ].filter(Boolean);
525
+ const meta = {
526
+ name: resolver.resolveName(transformedNode.operationId),
527
+ file: resolver.resolveFile({
528
+ name: transformedNode.operationId,
529
+ extname: ".ts",
530
+ tag: transformedNode.tags[0] ?? "default",
531
+ path: transformedNode.path
532
+ }, {
533
+ root,
534
+ output,
535
+ group
536
+ }),
537
+ fileTs: pluginTs.resolver.resolveFile({
538
+ name: transformedNode.operationId,
539
+ extname: ".ts",
540
+ tag: transformedNode.tags[0] ?? "default",
541
+ path: transformedNode.path
542
+ }, {
543
+ root,
544
+ output: pluginTs.options?.output ?? output,
545
+ group: pluginTs.options?.group
546
+ })
547
+ };
548
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
549
+ baseName: meta.file.baseName,
550
+ path: meta.file.path,
551
+ meta: meta.file.meta,
552
+ children: [
553
+ meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
554
+ name: Array.from(new Set(importedTypeNames)).sort(),
555
+ root: meta.file.path,
556
+ path: meta.fileTs.path,
557
+ isTypeOnly: true
558
+ }),
559
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
560
+ name: ["CallToolResult"],
561
+ path: "@modelcontextprotocol/sdk/types",
562
+ isTypeOnly: true
563
+ }),
564
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
565
+ name: ["buildFormData"],
566
+ root: meta.file.path,
567
+ path: node_path.default.resolve(root, ".kubb/config.ts")
568
+ }),
569
+ client.importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
570
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
571
+ name: [
572
+ "Client",
573
+ "RequestConfig",
574
+ "ResponseErrorConfig"
575
+ ],
576
+ path: client.importPath,
577
+ isTypeOnly: true
578
+ }),
579
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
580
+ name: "fetch",
581
+ path: client.importPath
582
+ }),
583
+ client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
584
+ name: ["ResponseConfig"],
585
+ path: client.importPath,
586
+ isTypeOnly: true
587
+ })
588
+ ] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
589
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
590
+ name: [
591
+ "Client",
592
+ "RequestConfig",
593
+ "ResponseErrorConfig"
594
+ ],
595
+ root: meta.file.path,
596
+ path: node_path.default.resolve(root, ".kubb/fetch.ts"),
597
+ isTypeOnly: true
598
+ }),
599
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
600
+ name: ["fetch"],
601
+ root: meta.file.path,
602
+ path: node_path.default.resolve(root, ".kubb/fetch.ts")
603
+ }),
604
+ client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
605
+ name: ["ResponseConfig"],
606
+ root: meta.file.path,
607
+ path: node_path.default.resolve(root, ".kubb/fetch.ts"),
608
+ isTypeOnly: true
609
+ })
610
+ ] }),
611
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(McpHandler, {
612
+ name: meta.name,
613
+ node: transformedNode,
614
+ resolver: pluginTs.resolver,
615
+ baseURL: client.baseURL,
616
+ dataReturnType: client.dataReturnType || "data",
617
+ paramsCasing
618
+ })
619
+ ]
620
+ });
621
+ }
622
+ });
623
+ //#endregion
624
+ //#region src/generators/serverGenerator.tsx
625
+ /**
626
+ * Default server generator for `compatibilityPreset: 'default'` (v5).
627
+ *
628
+ * Uses individual zod schemas for each param (e.g. `createPetsPathUuidSchema`, `createPetsQueryOffsetSchema`)
629
+ * and `resolveResponseStatusName` for per-status response schemas.
630
+ * Query and header params are composed into `z.object({ ... })` from individual schemas.
631
+ */
632
+ const serverGenerator = (0, _kubb_core.defineGenerator)({
633
+ name: "operations",
634
+ type: "react",
635
+ Operations({ nodes, adapter, options, config, driver, resolver, plugin }) {
636
+ const { output, paramsCasing, group } = options;
637
+ const root = node_path.default.resolve(config.root, config.output.path);
638
+ const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
639
+ if (!pluginZod?.resolver) return;
640
+ const name = "server";
641
+ const serverFile = {
642
+ baseName: "server.ts",
643
+ path: node_path.default.resolve(root, output.path, "server.ts"),
644
+ meta: { pluginName: plugin.name }
645
+ };
646
+ const jsonFile = {
647
+ baseName: ".mcp.json",
648
+ path: node_path.default.resolve(root, output.path, ".mcp.json"),
649
+ meta: { pluginName: plugin.name }
650
+ };
651
+ const operationsMapped = nodes.map((node) => {
652
+ const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
653
+ const casedParams = (0, _kubb_ast.caseParams)(transformedNode.parameters, paramsCasing);
654
+ const pathParams = casedParams.filter((p) => p.in === "path");
655
+ const queryParams = casedParams.filter((p) => p.in === "query");
656
+ const headerParams = casedParams.filter((p) => p.in === "header");
657
+ const mcpFile = resolver.resolveFile({
658
+ name: transformedNode.operationId,
659
+ extname: ".ts",
660
+ tag: transformedNode.tags[0] ?? "default",
661
+ path: transformedNode.path
662
+ }, {
663
+ root,
664
+ output,
665
+ group
666
+ });
667
+ const zodFile = pluginZod.resolver.resolveFile({
668
+ name: transformedNode.operationId,
669
+ extname: ".ts",
670
+ tag: transformedNode.tags[0] ?? "default",
671
+ path: transformedNode.path
672
+ }, {
673
+ root,
674
+ output: pluginZod.options?.output ?? output,
675
+ group: pluginZod.options?.group
676
+ });
677
+ const requestName = transformedNode.requestBody?.schema ? pluginZod.resolver.resolveDataName(transformedNode) : void 0;
678
+ const successStatus = findSuccessStatusCode(transformedNode.responses);
679
+ const responseName = successStatus ? pluginZod.resolver.resolveResponseStatusName(transformedNode, successStatus) : void 0;
680
+ const resolveParams = (params) => params.map((p) => ({
681
+ name: p.name,
682
+ schemaName: pluginZod.resolver.resolveParamName(transformedNode, p)
683
+ }));
684
+ return {
685
+ tool: {
686
+ name: transformedNode.operationId,
687
+ title: transformedNode.summary || void 0,
688
+ description: transformedNode.description || `Make a ${transformedNode.method.toUpperCase()} request to ${transformedNode.path}`
689
+ },
690
+ mcp: {
691
+ name: resolver.resolveName(transformedNode.operationId),
692
+ file: mcpFile
693
+ },
694
+ zod: {
695
+ pathParams: resolveParams(pathParams),
696
+ queryParams: queryParams.length ? resolveParams(queryParams) : void 0,
697
+ headerParams: headerParams.length ? resolveParams(headerParams) : void 0,
698
+ requestName,
699
+ responseName,
700
+ file: zodFile
701
+ },
702
+ node: transformedNode
703
+ };
704
+ });
705
+ const imports = operationsMapped.flatMap(({ mcp, zod }) => {
706
+ const zodNames = [
707
+ ...zod.pathParams.map((p) => p.schemaName),
708
+ ...(zod.queryParams ?? []).map((p) => p.schemaName),
709
+ ...(zod.headerParams ?? []).map((p) => p.schemaName),
710
+ zod.requestName,
711
+ zod.responseName
712
+ ].filter(Boolean);
713
+ const uniqueNames = [...new Set(zodNames)].sort();
714
+ return [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
715
+ name: [mcp.name],
716
+ root: serverFile.path,
717
+ path: mcp.file.path
718
+ }, mcp.name), uniqueNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
719
+ name: uniqueNames,
720
+ root: serverFile.path,
721
+ path: zod.file.path
722
+ }, `zod-${mcp.name}`)].filter(Boolean);
723
+ });
724
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
725
+ baseName: serverFile.baseName,
726
+ path: serverFile.path,
727
+ meta: serverFile.meta,
728
+ banner: resolver.resolveBanner(adapter.rootNode, {
729
+ output,
730
+ config
731
+ }),
732
+ footer: resolver.resolveFooter(adapter.rootNode, {
733
+ output,
734
+ config
735
+ }),
736
+ children: [
737
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
738
+ name: ["McpServer"],
739
+ path: "@modelcontextprotocol/sdk/server/mcp"
740
+ }),
741
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
742
+ name: ["z"],
743
+ path: "zod"
744
+ }),
745
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
746
+ name: ["StdioServerTransport"],
747
+ path: "@modelcontextprotocol/sdk/server/stdio"
748
+ }),
749
+ imports,
750
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Server, {
751
+ name,
752
+ serverName: adapter.rootNode?.meta?.title ?? "server",
753
+ serverVersion: adapter.rootNode?.meta?.version ?? "0.0.0",
754
+ paramsCasing,
755
+ operations: operationsMapped
756
+ })
757
+ ]
758
+ }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File, {
759
+ baseName: jsonFile.baseName,
760
+ path: jsonFile.path,
761
+ meta: jsonFile.meta,
762
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
763
+ name,
764
+ children: `
765
+ {
766
+ "mcpServers": {
767
+ "${adapter.rootNode?.meta?.title || "server"}": {
768
+ "type": "stdio",
769
+ "command": "npx",
770
+ "args": ["tsx", "${node_path.default.relative(node_path.default.dirname(jsonFile.path), serverFile.path)}"]
771
+ }
772
+ }
773
+ }
774
+ `
775
+ })
776
+ })] });
777
+ }
778
+ });
779
+ //#endregion
780
+ //#region src/generators/serverGeneratorLegacy.tsx
781
+ /**
782
+ * Legacy server generator for `compatibilityPreset: 'kubbV4'`.
783
+ *
784
+ * Uses grouped zod schemas for query/header params (e.g. `createPetsQueryParamsSchema`)
785
+ * and `resolveResponseName` for the combined response schema.
786
+ * Path params are always rendered inline (no named imports).
787
+ */
788
+ const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
789
+ name: "operations",
790
+ type: "react",
791
+ Operations({ nodes, adapter, options, config, driver, resolver, plugin }) {
792
+ const { output, paramsCasing, group } = options;
793
+ const root = node_path.default.resolve(config.root, config.output.path);
794
+ const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
795
+ if (!pluginZod?.resolver) return;
796
+ const name = "server";
797
+ const serverFile = {
798
+ baseName: "server.ts",
799
+ path: node_path.default.resolve(root, output.path, "server.ts"),
800
+ meta: { pluginName: plugin.name }
801
+ };
802
+ const jsonFile = {
803
+ baseName: ".mcp.json",
804
+ path: node_path.default.resolve(root, output.path, ".mcp.json"),
805
+ meta: { pluginName: plugin.name }
806
+ };
807
+ const operationsMapped = nodes.map((node) => {
808
+ const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
809
+ const casedParams = (0, _kubb_ast.caseParams)(transformedNode.parameters, paramsCasing);
810
+ const queryParams = casedParams.filter((p) => p.in === "query");
811
+ const headerParams = casedParams.filter((p) => p.in === "header");
812
+ const mcpFile = resolver.resolveFile({
813
+ name: transformedNode.operationId,
814
+ extname: ".ts",
815
+ tag: transformedNode.tags[0] ?? "default",
816
+ path: transformedNode.path
817
+ }, {
818
+ root,
819
+ output,
820
+ group
821
+ });
822
+ const zodFile = pluginZod?.resolver.resolveFile({
823
+ name: transformedNode.operationId,
824
+ extname: ".ts",
825
+ tag: transformedNode.tags[0] ?? "default",
826
+ path: transformedNode.path
827
+ }, {
828
+ root,
829
+ output: pluginZod?.options?.output ?? output,
830
+ group: pluginZod?.options?.group
831
+ });
832
+ const requestName = transformedNode.requestBody?.schema ? pluginZod?.resolver.resolveDataName(transformedNode) : void 0;
833
+ const responseName = pluginZod?.resolver.resolveResponseName(transformedNode);
834
+ const zodQueryParams = queryParams.length ? pluginZod?.resolver.resolveQueryParamsName(transformedNode, queryParams[0]) : void 0;
835
+ const zodHeaderParams = headerParams.length ? pluginZod?.resolver.resolveHeaderParamsName(transformedNode, headerParams[0]) : void 0;
836
+ return {
837
+ tool: {
838
+ name: transformedNode.operationId,
839
+ title: transformedNode.summary || void 0,
840
+ description: transformedNode.description || `Make a ${transformedNode.method.toUpperCase()} request to ${transformedNode.path}`
841
+ },
842
+ mcp: {
843
+ name: resolver.resolveName(transformedNode.operationId),
844
+ file: mcpFile
845
+ },
846
+ zod: {
847
+ pathParams: [],
848
+ queryParams: zodQueryParams,
849
+ headerParams: zodHeaderParams,
850
+ requestName,
851
+ responseName,
852
+ file: zodFile
853
+ },
854
+ node: transformedNode
855
+ };
856
+ });
857
+ const imports = operationsMapped.flatMap(({ mcp, zod }) => {
858
+ const zodNames = [
859
+ zod.queryParams,
860
+ zod.headerParams,
861
+ zod.requestName,
862
+ zod.responseName
863
+ ].filter(Boolean);
864
+ return [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
865
+ name: [mcp.name],
866
+ root: serverFile.path,
867
+ path: mcp.file.path
868
+ }, mcp.name), zod.file && zodNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
869
+ name: zodNames.sort(),
870
+ root: serverFile.path,
871
+ path: zod.file.path
872
+ }, `zod-${mcp.name}`)].filter(Boolean);
873
+ });
874
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
875
+ baseName: serverFile.baseName,
876
+ path: serverFile.path,
877
+ meta: serverFile.meta,
878
+ banner: resolver.resolveBanner(adapter.rootNode, {
879
+ output,
880
+ config
881
+ }),
882
+ footer: resolver.resolveFooter(adapter.rootNode, {
883
+ output,
884
+ config
885
+ }),
886
+ children: [
887
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
888
+ name: ["McpServer"],
889
+ path: "@modelcontextprotocol/sdk/server/mcp"
890
+ }),
891
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
892
+ name: ["z"],
893
+ path: "zod"
894
+ }),
895
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
896
+ name: ["StdioServerTransport"],
897
+ path: "@modelcontextprotocol/sdk/server/stdio"
898
+ }),
899
+ imports,
900
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Server, {
901
+ name,
902
+ serverName: adapter.rootNode?.meta?.title ?? "server",
903
+ serverVersion: adapter.document?.openapi ?? adapter.rootNode?.meta?.version ?? "0.0.0",
904
+ paramsCasing,
905
+ operations: operationsMapped
906
+ })
907
+ ]
908
+ }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File, {
909
+ baseName: jsonFile.baseName,
910
+ path: jsonFile.path,
911
+ meta: jsonFile.meta,
912
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
913
+ name,
914
+ children: `
915
+ {
916
+ "mcpServers": {
917
+ "${adapter.rootNode?.meta?.title || "server"}": {
918
+ "type": "stdio",
919
+ "command": "npx",
920
+ "args": ["tsx", "${node_path.default.relative(node_path.default.dirname(jsonFile.path), serverFile.path)}"]
921
+ }
922
+ }
923
+ }
924
+ `
925
+ })
926
+ })] });
927
+ }
928
+ });
929
+ //#endregion
930
+ //#region src/resolvers/resolverMcp.ts
931
+ /**
932
+ * Resolver for `@kubb/plugin-mcp` that provides the default naming
933
+ * and path-resolution helpers used by the plugin.
934
+ *
935
+ * @example
936
+ * ```ts
937
+ * import { resolverMcp } from '@kubb/plugin-mcp'
938
+ *
939
+ * resolverMcp.default('addPet', 'function') // -> 'addPetHandler'
940
+ * resolverMcp.resolveName('show pet by id') // -> 'showPetByIdHandler'
941
+ * ```
942
+ */
943
+ const resolverMcp = (0, _kubb_core.defineResolver)(() => ({
944
+ name: "default",
945
+ pluginName: "plugin-mcp",
946
+ default(name, type) {
947
+ if (type === "file") return camelCase(name, { isFile: true });
948
+ return camelCase(name, { suffix: "handler" });
949
+ },
950
+ resolveName(name) {
951
+ return this.default(name, "function");
952
+ }
953
+ }));
954
+ //#endregion
955
+ //#region src/presets.ts
956
+ /**
957
+ * Built-in preset registry for `@kubb/plugin-mcp`.
958
+ *
959
+ * - `default` — v5 naming with individual zod schemas and per-status responses.
960
+ * - `kubbV4` — legacy naming with grouped zod schemas and combined responses.
961
+ */
962
+ const presets = (0, _kubb_core.definePresets)({
963
+ default: {
964
+ name: "default",
965
+ resolver: resolverMcp,
966
+ generators: [mcpGenerator, serverGenerator]
967
+ },
968
+ kubbV4: {
969
+ name: "kubbV4",
970
+ resolver: resolverMcp,
971
+ generators: [mcpGenerator, serverGeneratorLegacy]
972
+ }
973
+ });
974
+ //#endregion
14
975
  //#region src/plugin.ts
15
976
  const pluginMcpName = "plugin-mcp";
16
977
  const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
17
978
  const { output = {
18
979
  path: "mcp",
19
980
  barrelType: "named"
20
- }, group, exclude = [], include, override = [], transformers = {}, generators = [require_generators.mcpGenerator, require_generators.serverGenerator].filter(Boolean), contentType, paramsCasing, client } = options;
981
+ }, group, exclude = [], include, override = [], paramsCasing, client, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
21
982
  const clientName = client?.client ?? "axios";
22
983
  const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
984
+ const preset = (0, _kubb_core.getPreset)({
985
+ preset: compatibilityPreset,
986
+ presets,
987
+ resolver: userResolver,
988
+ transformer: userTransformer,
989
+ generators: userGenerators
990
+ });
23
991
  return {
24
992
  name: pluginMcpName,
25
- options: {
26
- output,
27
- group,
28
- paramsCasing,
29
- client: {
30
- client: clientName,
31
- clientType: client?.clientType ?? "function",
32
- importPath: clientImportPath,
33
- dataReturnType: client?.dataReturnType ?? "data",
34
- bundle: client?.bundle,
35
- baseURL: client?.baseURL,
36
- paramsCasing: client?.paramsCasing
37
- }
993
+ get resolver() {
994
+ return preset.resolver;
38
995
  },
39
- pre: [
40
- _kubb_plugin_oas.pluginOasName,
41
- _kubb_plugin_ts.pluginTsName,
42
- _kubb_plugin_zod.pluginZodName
43
- ].filter(Boolean),
44
- resolvePath(baseName, pathMode, options) {
45
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
46
- if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
47
- /**
48
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
49
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
50
- */
51
- return node_path.default.resolve(root, output.path);
52
- if (group && (options?.group?.path || options?.group?.tag)) {
53
- const groupName = group?.name ? group.name : (ctx) => {
54
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
55
- return `${require_Server.camelCase(ctx.group)}Requests`;
56
- };
57
- return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
58
- }
59
- return node_path.default.resolve(root, output.path, baseName);
996
+ get transformer() {
997
+ return preset.transformer;
60
998
  },
61
- resolveName(name, type) {
62
- const resolvedName = require_Server.camelCase(name, { isFile: type === "file" });
63
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
64
- return resolvedName;
999
+ get options() {
1000
+ return {
1001
+ output,
1002
+ group: group ? {
1003
+ ...group,
1004
+ name: group.name ? group.name : (ctx) => {
1005
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1006
+ return `${camelCase(ctx.group)}Requests`;
1007
+ }
1008
+ } : void 0,
1009
+ paramsCasing,
1010
+ client: {
1011
+ client: clientName,
1012
+ clientType: client?.clientType ?? "function",
1013
+ importPath: clientImportPath,
1014
+ dataReturnType: client?.dataReturnType ?? "data",
1015
+ bundle: client?.bundle,
1016
+ baseURL: client?.baseURL,
1017
+ paramsCasing: client?.paramsCasing
1018
+ },
1019
+ resolver: preset.resolver
1020
+ };
65
1021
  },
1022
+ pre: [_kubb_plugin_ts.pluginTsName, _kubb_plugin_zod.pluginZodName].filter(Boolean),
66
1023
  async install() {
67
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
68
- const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
69
- const oas = await this.getOas();
70
- const baseURL = await this.getBaseURL();
71
- if (baseURL) this.plugin.options.client.baseURL = baseURL;
72
- const hasClientPlugin = !!this.getPlugin(_kubb_plugin_client.pluginClientName);
1024
+ const { config, fabric, plugin, adapter, rootNode, driver } = this;
1025
+ const root = node_path.default.resolve(config.root, config.output.path);
1026
+ const resolver = preset.resolver;
1027
+ if (!adapter) throw new Error("Plugin cannot work without adapter being set");
1028
+ const baseURL = adapter.rootNode?.meta?.baseURL;
1029
+ if (baseURL) this.plugin.options.client.baseURL = this.plugin.options.client.baseURL || baseURL;
1030
+ const hasClientPlugin = !!driver.getPlugin(_kubb_plugin_client.pluginClientName);
73
1031
  if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.addFile({
74
1032
  baseName: "fetch.ts",
75
1033
  path: node_path.default.resolve(root, ".kubb/fetch.ts"),
@@ -94,19 +1052,35 @@ const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
94
1052
  imports: [],
95
1053
  exports: []
96
1054
  });
97
- const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
98
- fabric: this.fabric,
99
- oas,
100
- driver: this.driver,
101
- events: this.events,
102
- plugin: this.plugin,
103
- contentType,
1055
+ const collectedOperations = [];
1056
+ const generatorContext = {
1057
+ generators: preset.generators,
1058
+ plugin,
1059
+ resolver,
104
1060
  exclude,
105
1061
  include,
106
1062
  override,
107
- mode
108
- }).build(...generators);
109
- await this.upsertFile(...files);
1063
+ fabric,
1064
+ adapter,
1065
+ config,
1066
+ driver
1067
+ };
1068
+ await (0, _kubb_ast.walk)(rootNode, {
1069
+ depth: "shallow",
1070
+ async schema(schemaNode) {
1071
+ await (0, _kubb_core.runGeneratorSchema)(schemaNode, generatorContext);
1072
+ },
1073
+ async operation(operationNode) {
1074
+ if (resolver.resolveOptions(operationNode, {
1075
+ options: plugin.options,
1076
+ exclude,
1077
+ include,
1078
+ override
1079
+ }) !== null) collectedOperations.push(operationNode);
1080
+ await (0, _kubb_core.runGeneratorOperation)(operationNode, generatorContext);
1081
+ }
1082
+ });
1083
+ await (0, _kubb_core.runGeneratorOperations)(collectedOperations, generatorContext);
110
1084
  const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
111
1085
  type: output.barrelType ?? "named",
112
1086
  root,
@@ -118,7 +1092,13 @@ const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
118
1092
  };
119
1093
  });
120
1094
  //#endregion
1095
+ exports.McpHandler = McpHandler;
1096
+ exports.Server = Server;
1097
+ exports.mcpGenerator = mcpGenerator;
121
1098
  exports.pluginMcp = pluginMcp;
122
1099
  exports.pluginMcpName = pluginMcpName;
1100
+ exports.resolverMcp = resolverMcp;
1101
+ exports.serverGenerator = serverGenerator;
1102
+ exports.serverGeneratorLegacy = serverGeneratorLegacy;
123
1103
 
124
1104
  //# sourceMappingURL=index.cjs.map