@kubb/plugin-mcp 5.0.0-alpha.3 → 5.0.0-alpha.30

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,1042 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_Server = require("./Server-DV9zFrUP.cjs");
3
- const require_generators = require("./generators-DQalD1bu.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
+ operation(node, options) {
507
+ const { resolver, driver, root } = this;
508
+ const { output, client, paramsCasing, group } = options;
509
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
510
+ if (!pluginTs?.resolver) return null;
511
+ const casedParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
512
+ const pathParams = casedParams.filter((p) => p.in === "path");
513
+ const queryParams = casedParams.filter((p) => p.in === "query");
514
+ const headerParams = casedParams.filter((p) => p.in === "header");
515
+ const importedTypeNames = [
516
+ ...pathParams.map((p) => pluginTs.resolver.resolvePathParamsName(node, p)),
517
+ ...queryParams.map((p) => pluginTs.resolver.resolveQueryParamsName(node, p)),
518
+ ...headerParams.map((p) => pluginTs.resolver.resolveHeaderParamsName(node, p)),
519
+ node.requestBody?.schema ? pluginTs.resolver.resolveDataName(node) : void 0,
520
+ pluginTs.resolver.resolveResponseName(node),
521
+ ...node.responses.filter((r) => Number(r.statusCode) >= 400).map((r) => pluginTs.resolver.resolveResponseStatusName(node, r.statusCode))
522
+ ].filter(Boolean);
523
+ const meta = {
524
+ name: resolver.resolveName(node.operationId),
525
+ file: resolver.resolveFile({
526
+ name: node.operationId,
527
+ extname: ".ts",
528
+ tag: node.tags[0] ?? "default",
529
+ path: node.path
530
+ }, {
531
+ root,
532
+ output,
533
+ group
534
+ }),
535
+ fileTs: pluginTs.resolver.resolveFile({
536
+ name: node.operationId,
537
+ extname: ".ts",
538
+ tag: node.tags[0] ?? "default",
539
+ path: node.path
540
+ }, {
541
+ root,
542
+ output: pluginTs.options?.output ?? output,
543
+ group: pluginTs.options?.group
544
+ })
545
+ };
546
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
547
+ baseName: meta.file.baseName,
548
+ path: meta.file.path,
549
+ meta: meta.file.meta,
550
+ children: [
551
+ meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
552
+ name: Array.from(new Set(importedTypeNames)).sort(),
553
+ root: meta.file.path,
554
+ path: meta.fileTs.path,
555
+ isTypeOnly: true
556
+ }),
557
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
558
+ name: ["CallToolResult"],
559
+ path: "@modelcontextprotocol/sdk/types",
560
+ isTypeOnly: true
561
+ }),
562
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
563
+ name: ["buildFormData"],
564
+ root: meta.file.path,
565
+ path: node_path.default.resolve(root, ".kubb/config.ts")
566
+ }),
567
+ client.importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
568
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
569
+ name: [
570
+ "Client",
571
+ "RequestConfig",
572
+ "ResponseErrorConfig"
573
+ ],
574
+ path: client.importPath,
575
+ isTypeOnly: true
576
+ }),
577
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
578
+ name: "fetch",
579
+ path: client.importPath
580
+ }),
581
+ client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
582
+ name: ["ResponseConfig"],
583
+ path: client.importPath,
584
+ isTypeOnly: true
585
+ })
586
+ ] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
587
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
588
+ name: [
589
+ "Client",
590
+ "RequestConfig",
591
+ "ResponseErrorConfig"
592
+ ],
593
+ root: meta.file.path,
594
+ path: node_path.default.resolve(root, ".kubb/fetch.ts"),
595
+ isTypeOnly: true
596
+ }),
597
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
598
+ name: ["fetch"],
599
+ root: meta.file.path,
600
+ path: node_path.default.resolve(root, ".kubb/fetch.ts")
601
+ }),
602
+ client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
603
+ name: ["ResponseConfig"],
604
+ root: meta.file.path,
605
+ path: node_path.default.resolve(root, ".kubb/fetch.ts"),
606
+ isTypeOnly: true
607
+ })
608
+ ] }),
609
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(McpHandler, {
610
+ name: meta.name,
611
+ node,
612
+ resolver: pluginTs.resolver,
613
+ baseURL: client.baseURL,
614
+ dataReturnType: client.dataReturnType || "data",
615
+ paramsCasing
616
+ })
617
+ ]
618
+ });
619
+ }
620
+ });
621
+ //#endregion
622
+ //#region src/generators/serverGenerator.tsx
623
+ /**
624
+ * Default server generator for `compatibilityPreset: 'default'` (v5).
625
+ *
626
+ * Uses individual zod schemas for each param (e.g. `createPetsPathUuidSchema`, `createPetsQueryOffsetSchema`)
627
+ * and `resolveResponseStatusName` for per-status response schemas.
628
+ * Query and header params are composed into `z.object({ ... })` from individual schemas.
629
+ */
630
+ const serverGenerator = (0, _kubb_core.defineGenerator)({
631
+ name: "operations",
632
+ operations(nodes, options) {
633
+ const { adapter, config, resolver, plugin, driver, root } = this;
634
+ const { output, paramsCasing, group } = options;
635
+ const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
636
+ if (!pluginZod?.resolver) return;
637
+ const name = "server";
638
+ const serverFile = {
639
+ baseName: "server.ts",
640
+ path: node_path.default.resolve(root, output.path, "server.ts"),
641
+ meta: { pluginName: plugin.name }
642
+ };
643
+ const jsonFile = {
644
+ baseName: ".mcp.json",
645
+ path: node_path.default.resolve(root, output.path, ".mcp.json"),
646
+ meta: { pluginName: plugin.name }
647
+ };
648
+ const operationsMapped = nodes.map((node) => {
649
+ const casedParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
650
+ const pathParams = casedParams.filter((p) => p.in === "path");
651
+ const queryParams = casedParams.filter((p) => p.in === "query");
652
+ const headerParams = casedParams.filter((p) => p.in === "header");
653
+ const mcpFile = resolver.resolveFile({
654
+ name: node.operationId,
655
+ extname: ".ts",
656
+ tag: node.tags[0] ?? "default",
657
+ path: node.path
658
+ }, {
659
+ root,
660
+ output,
661
+ group
662
+ });
663
+ const zodFile = pluginZod.resolver.resolveFile({
664
+ name: node.operationId,
665
+ extname: ".ts",
666
+ tag: node.tags[0] ?? "default",
667
+ path: node.path
668
+ }, {
669
+ root,
670
+ output: pluginZod.options?.output ?? output,
671
+ group: pluginZod.options?.group
672
+ });
673
+ const requestName = node.requestBody?.schema ? pluginZod.resolver.resolveDataName(node) : void 0;
674
+ const successStatus = findSuccessStatusCode(node.responses);
675
+ const responseName = successStatus ? pluginZod.resolver.resolveResponseStatusName(node, successStatus) : void 0;
676
+ const resolveParams = (params) => params.map((p) => ({
677
+ name: p.name,
678
+ schemaName: pluginZod.resolver.resolveParamName(node, p)
679
+ }));
680
+ return {
681
+ tool: {
682
+ name: node.operationId,
683
+ title: node.summary || void 0,
684
+ description: node.description || `Make a ${node.method.toUpperCase()} request to ${node.path}`
685
+ },
686
+ mcp: {
687
+ name: resolver.resolveName(node.operationId),
688
+ file: mcpFile
689
+ },
690
+ zod: {
691
+ pathParams: resolveParams(pathParams),
692
+ queryParams: queryParams.length ? resolveParams(queryParams) : void 0,
693
+ headerParams: headerParams.length ? resolveParams(headerParams) : void 0,
694
+ requestName,
695
+ responseName,
696
+ file: zodFile
697
+ },
698
+ node
699
+ };
700
+ });
701
+ const imports = operationsMapped.flatMap(({ mcp, zod }) => {
702
+ const zodNames = [
703
+ ...zod.pathParams.map((p) => p.schemaName),
704
+ ...(zod.queryParams ?? []).map((p) => p.schemaName),
705
+ ...(zod.headerParams ?? []).map((p) => p.schemaName),
706
+ zod.requestName,
707
+ zod.responseName
708
+ ].filter(Boolean);
709
+ const uniqueNames = [...new Set(zodNames)].sort();
710
+ return [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
711
+ name: [mcp.name],
712
+ root: serverFile.path,
713
+ path: mcp.file.path
714
+ }, mcp.name), uniqueNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
715
+ name: uniqueNames,
716
+ root: serverFile.path,
717
+ path: zod.file.path
718
+ }, `zod-${mcp.name}`)].filter(Boolean);
719
+ });
720
+ 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, {
721
+ baseName: serverFile.baseName,
722
+ path: serverFile.path,
723
+ meta: serverFile.meta,
724
+ banner: resolver.resolveBanner(adapter.rootNode, {
725
+ output,
726
+ config
727
+ }),
728
+ footer: resolver.resolveFooter(adapter.rootNode, {
729
+ output,
730
+ config
731
+ }),
732
+ children: [
733
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
734
+ name: ["McpServer"],
735
+ path: "@modelcontextprotocol/sdk/server/mcp"
736
+ }),
737
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
738
+ name: ["z"],
739
+ path: "zod"
740
+ }),
741
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
742
+ name: ["StdioServerTransport"],
743
+ path: "@modelcontextprotocol/sdk/server/stdio"
744
+ }),
745
+ imports,
746
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Server, {
747
+ name,
748
+ serverName: adapter.rootNode?.meta?.title ?? "server",
749
+ serverVersion: adapter.rootNode?.meta?.version ?? "0.0.0",
750
+ paramsCasing,
751
+ operations: operationsMapped
752
+ })
753
+ ]
754
+ }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File, {
755
+ baseName: jsonFile.baseName,
756
+ path: jsonFile.path,
757
+ meta: jsonFile.meta,
758
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
759
+ name,
760
+ children: `
761
+ {
762
+ "mcpServers": {
763
+ "${adapter.rootNode?.meta?.title || "server"}": {
764
+ "type": "stdio",
765
+ "command": "npx",
766
+ "args": ["tsx", "${node_path.default.relative(node_path.default.dirname(jsonFile.path), serverFile.path)}"]
767
+ }
768
+ }
769
+ }
770
+ `
771
+ })
772
+ })] });
773
+ }
774
+ });
775
+ //#endregion
776
+ //#region src/generators/serverGeneratorLegacy.tsx
777
+ /**
778
+ * Legacy server generator for `compatibilityPreset: 'kubbV4'`.
779
+ *
780
+ * Uses grouped zod schemas for query/header params (e.g. `createPetsQueryParamsSchema`)
781
+ * and `resolveResponseName` for the combined response schema.
782
+ * Path params are always rendered inline (no named imports).
783
+ */
784
+ const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
785
+ name: "operations",
786
+ operations(nodes, options) {
787
+ const { adapter, config, resolver, plugin, driver, root } = this;
788
+ const { output, paramsCasing, group } = options;
789
+ const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
790
+ if (!pluginZod?.resolver) return;
791
+ const name = "server";
792
+ const serverFile = {
793
+ baseName: "server.ts",
794
+ path: node_path.default.resolve(root, output.path, "server.ts"),
795
+ meta: { pluginName: plugin.name }
796
+ };
797
+ const jsonFile = {
798
+ baseName: ".mcp.json",
799
+ path: node_path.default.resolve(root, output.path, ".mcp.json"),
800
+ meta: { pluginName: plugin.name }
801
+ };
802
+ const operationsMapped = nodes.map((node) => {
803
+ const casedParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
804
+ const queryParams = casedParams.filter((p) => p.in === "query");
805
+ const headerParams = casedParams.filter((p) => p.in === "header");
806
+ const mcpFile = resolver.resolveFile({
807
+ name: node.operationId,
808
+ extname: ".ts",
809
+ tag: node.tags[0] ?? "default",
810
+ path: node.path
811
+ }, {
812
+ root,
813
+ output,
814
+ group
815
+ });
816
+ const zodFile = pluginZod?.resolver.resolveFile({
817
+ name: node.operationId,
818
+ extname: ".ts",
819
+ tag: node.tags[0] ?? "default",
820
+ path: node.path
821
+ }, {
822
+ root,
823
+ output: pluginZod?.options?.output ?? output,
824
+ group: pluginZod?.options?.group
825
+ });
826
+ const requestName = node.requestBody?.schema ? pluginZod?.resolver.resolveDataName(node) : void 0;
827
+ const responseName = pluginZod?.resolver.resolveResponseName(node);
828
+ const zodQueryParams = queryParams.length ? pluginZod?.resolver.resolveQueryParamsName(node, queryParams[0]) : void 0;
829
+ const zodHeaderParams = headerParams.length ? pluginZod?.resolver.resolveHeaderParamsName(node, headerParams[0]) : void 0;
830
+ return {
831
+ tool: {
832
+ name: node.operationId,
833
+ title: node.summary || void 0,
834
+ description: node.description || `Make a ${node.method.toUpperCase()} request to ${node.path}`
835
+ },
836
+ mcp: {
837
+ name: resolver.resolveName(node.operationId),
838
+ file: mcpFile
839
+ },
840
+ zod: {
841
+ pathParams: [],
842
+ queryParams: zodQueryParams,
843
+ headerParams: zodHeaderParams,
844
+ requestName,
845
+ responseName,
846
+ file: zodFile
847
+ },
848
+ node
849
+ };
850
+ });
851
+ const imports = operationsMapped.flatMap(({ mcp, zod }) => {
852
+ const zodNames = [
853
+ zod.queryParams,
854
+ zod.headerParams,
855
+ zod.requestName,
856
+ zod.responseName
857
+ ].filter(Boolean);
858
+ return [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
859
+ name: [mcp.name],
860
+ root: serverFile.path,
861
+ path: mcp.file.path
862
+ }, mcp.name), zod.file && zodNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
863
+ name: zodNames.sort(),
864
+ root: serverFile.path,
865
+ path: zod.file.path
866
+ }, `zod-${mcp.name}`)].filter(Boolean);
867
+ });
868
+ 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, {
869
+ baseName: serverFile.baseName,
870
+ path: serverFile.path,
871
+ meta: serverFile.meta,
872
+ banner: resolver.resolveBanner(adapter.rootNode, {
873
+ output,
874
+ config
875
+ }),
876
+ footer: resolver.resolveFooter(adapter.rootNode, {
877
+ output,
878
+ config
879
+ }),
880
+ children: [
881
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
882
+ name: ["McpServer"],
883
+ path: "@modelcontextprotocol/sdk/server/mcp"
884
+ }),
885
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
886
+ name: ["z"],
887
+ path: "zod"
888
+ }),
889
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
890
+ name: ["StdioServerTransport"],
891
+ path: "@modelcontextprotocol/sdk/server/stdio"
892
+ }),
893
+ imports,
894
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Server, {
895
+ name,
896
+ serverName: adapter.rootNode?.meta?.title ?? "server",
897
+ serverVersion: adapter.document?.openapi ?? adapter.rootNode?.meta?.version ?? "0.0.0",
898
+ paramsCasing,
899
+ operations: operationsMapped
900
+ })
901
+ ]
902
+ }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File, {
903
+ baseName: jsonFile.baseName,
904
+ path: jsonFile.path,
905
+ meta: jsonFile.meta,
906
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
907
+ name,
908
+ children: `
909
+ {
910
+ "mcpServers": {
911
+ "${adapter.rootNode?.meta?.title || "server"}": {
912
+ "type": "stdio",
913
+ "command": "npx",
914
+ "args": ["tsx", "${node_path.default.relative(node_path.default.dirname(jsonFile.path), serverFile.path)}"]
915
+ }
916
+ }
917
+ }
918
+ `
919
+ })
920
+ })] });
921
+ }
922
+ });
923
+ //#endregion
924
+ //#region package.json
925
+ var version = "5.0.0-alpha.30";
926
+ //#endregion
927
+ //#region src/resolvers/resolverMcp.ts
928
+ /**
929
+ * Resolver for `@kubb/plugin-mcp` that provides the default naming
930
+ * and path-resolution helpers used by the plugin.
931
+ *
932
+ * @example
933
+ * ```ts
934
+ * import { resolverMcp } from '@kubb/plugin-mcp'
935
+ *
936
+ * resolverMcp.default('addPet', 'function') // -> 'addPetHandler'
937
+ * resolverMcp.resolveName('show pet by id') // -> 'showPetByIdHandler'
938
+ * ```
939
+ */
940
+ const resolverMcp = (0, _kubb_core.defineResolver)(() => ({
941
+ name: "default",
942
+ pluginName: "plugin-mcp",
943
+ default(name, type) {
944
+ if (type === "file") return camelCase(name, { isFile: true });
945
+ return camelCase(name, { suffix: "handler" });
946
+ },
947
+ resolveName(name) {
948
+ return this.default(name, "function");
949
+ }
950
+ }));
951
+ //#endregion
952
+ //#region src/presets.ts
953
+ /**
954
+ * Built-in preset registry for `@kubb/plugin-mcp`.
955
+ *
956
+ * - `default` — v5 naming with individual zod schemas and per-status responses.
957
+ * - `kubbV4` — legacy naming with grouped zod schemas and combined responses.
958
+ */
959
+ const presets = (0, _kubb_core.definePresets)({
960
+ default: {
961
+ name: "default",
962
+ resolver: resolverMcp,
963
+ generators: [mcpGenerator, serverGenerator]
964
+ },
965
+ kubbV4: {
966
+ name: "kubbV4",
967
+ resolver: resolverMcp,
968
+ generators: [mcpGenerator, serverGeneratorLegacy]
969
+ }
970
+ });
971
+ //#endregion
14
972
  //#region src/plugin.ts
15
973
  const pluginMcpName = "plugin-mcp";
16
- const pluginMcp = (0, _kubb_core.definePlugin)((options) => {
974
+ const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
17
975
  const { output = {
18
976
  path: "mcp",
19
977
  barrelType: "named"
20
- }, group, exclude = [], include, override = [], transformers = {}, generators = [require_generators.mcpGenerator, require_generators.serverGenerator].filter(Boolean), contentType, paramsCasing, client } = options;
978
+ }, group, exclude = [], include, override = [], paramsCasing, client, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
21
979
  const clientName = client?.client ?? "axios";
22
980
  const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
981
+ const preset = (0, _kubb_core.getPreset)({
982
+ preset: compatibilityPreset,
983
+ presets,
984
+ resolver: userResolver,
985
+ transformer: userTransformer,
986
+ generators: userGenerators
987
+ });
988
+ const mergedGenerator = (0, _kubb_core.mergeGenerators)(preset.generators ?? []);
23
989
  return {
24
990
  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
- }
991
+ version,
992
+ get resolver() {
993
+ return preset.resolver;
38
994
  },
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);
995
+ get transformer() {
996
+ return preset.transformer;
60
997
  },
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;
998
+ get options() {
999
+ return {
1000
+ output,
1001
+ exclude,
1002
+ include,
1003
+ override,
1004
+ group: group ? {
1005
+ ...group,
1006
+ name: group.name ? group.name : (ctx) => {
1007
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1008
+ return `${camelCase(ctx.group)}Requests`;
1009
+ }
1010
+ } : void 0,
1011
+ paramsCasing,
1012
+ client: {
1013
+ client: clientName,
1014
+ clientType: client?.clientType ?? "function",
1015
+ importPath: clientImportPath,
1016
+ dataReturnType: client?.dataReturnType ?? "data",
1017
+ bundle: client?.bundle,
1018
+ baseURL: client?.baseURL,
1019
+ paramsCasing: client?.paramsCasing
1020
+ },
1021
+ resolver: preset.resolver
1022
+ };
1023
+ },
1024
+ pre: [_kubb_plugin_ts.pluginTsName, _kubb_plugin_zod.pluginZodName].filter(Boolean),
1025
+ async schema(node, options) {
1026
+ return mergedGenerator.schema?.call(this, node, options);
1027
+ },
1028
+ async operation(node, options) {
1029
+ return mergedGenerator.operation?.call(this, node, options);
1030
+ },
1031
+ async operations(nodes, options) {
1032
+ return mergedGenerator.operations?.call(this, nodes, options);
65
1033
  },
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.pluginManager.getPluginByName(_kubb_plugin_client.pluginClientName);
1034
+ async buildStart() {
1035
+ const { adapter, driver } = this;
1036
+ const root = this.root;
1037
+ const baseURL = adapter?.rootNode?.meta?.baseURL;
1038
+ if (baseURL) this.plugin.options.client.baseURL = this.plugin.options.client.baseURL || baseURL;
1039
+ const hasClientPlugin = !!driver.getPlugin(_kubb_plugin_client.pluginClientName);
73
1040
  if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.addFile({
74
1041
  baseName: "fetch.ts",
75
1042
  path: node_path.default.resolve(root, ".kubb/fetch.ts"),
@@ -94,31 +1061,18 @@ const pluginMcp = (0, _kubb_core.definePlugin)((options) => {
94
1061
  imports: [],
95
1062
  exports: []
96
1063
  });
97
- const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
98
- fabric: this.fabric,
99
- oas,
100
- pluginManager: this.pluginManager,
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 }
115
- });
116
- await this.upsertFile(...barrelFiles);
1064
+ await this.openInStudio({ ast: true });
117
1065
  }
118
1066
  };
119
1067
  });
120
1068
  //#endregion
1069
+ exports.McpHandler = McpHandler;
1070
+ exports.Server = Server;
1071
+ exports.mcpGenerator = mcpGenerator;
121
1072
  exports.pluginMcp = pluginMcp;
122
1073
  exports.pluginMcpName = pluginMcpName;
1074
+ exports.resolverMcp = resolverMcp;
1075
+ exports.serverGenerator = serverGenerator;
1076
+ exports.serverGeneratorLegacy = serverGeneratorLegacy;
123
1077
 
124
1078
  //# sourceMappingURL=index.cjs.map