@kubb/plugin-mcp 5.0.0-alpha.9 → 5.0.0-beta.15

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