@kubb/plugin-mcp 5.3.2 → 5.3.3
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 +67 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -16
- package/dist/index.d.ts +0 -16
- package/dist/index.js +66 -37
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
|
|
5
|
+
// \0rolldown/runtime.js
|
|
6
6
|
var __create = Object.create;
|
|
7
7
|
var __defProp = Object.defineProperty;
|
|
8
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
value: mod,
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
|
-
//#endregion
|
|
27
26
|
let kubb_kit = require("kubb/kit");
|
|
28
27
|
let node_path = require("node:path");
|
|
29
28
|
node_path = __toESM(node_path, 1);
|
|
@@ -31,7 +30,7 @@ let kubb_jsx = require("kubb/jsx");
|
|
|
31
30
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
32
31
|
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
33
32
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
34
|
-
|
|
33
|
+
// ../../internals/shared/src/operation.ts
|
|
35
34
|
/**
|
|
36
35
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
37
36
|
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
@@ -153,8 +152,9 @@ function buildRequestParamsSignature(node, resolver, options = {}) {
|
|
|
153
152
|
"body",
|
|
154
153
|
"headers"
|
|
155
154
|
].filter((key) => groups[key]);
|
|
155
|
+
const optionsType = hasRequestContentTypeChoice(node) ? `Pick<${resolver.response.options(node)}, ${names.map((name) => `'${name}'`).join(" | ")}>` : resolver.response.options(node);
|
|
156
156
|
return {
|
|
157
|
-
signature: [names.length > 0 ? `{ ${names.join(", ")} }: ${
|
|
157
|
+
signature: [names.length > 0 ? `{ ${names.join(", ")} }: ${optionsType}${isOptional ? " = {}" : ""}` : null, isConfigurable ? `config: ${buildRequestConfigType(node)} = {}` : null].filter(Boolean).join(", "),
|
|
158
158
|
groups
|
|
159
159
|
};
|
|
160
160
|
}
|
|
@@ -202,6 +202,22 @@ function getOperationParameters(node) {
|
|
|
202
202
|
operationParameterGroupsByNode.set(node, groups);
|
|
203
203
|
return groups;
|
|
204
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Builds the combined `{ body, path, query, headers }` options object schema for an operation,
|
|
207
|
+
* referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s
|
|
208
|
+
* `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same
|
|
209
|
+
* shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod
|
|
210
|
+
* printer to emit `z.object(…)` rather than a record.
|
|
211
|
+
*/
|
|
212
|
+
function hasRequestContentTypeChoice(node) {
|
|
213
|
+
return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
|
|
217
|
+
*/
|
|
218
|
+
function castToClientOptions(callArg, clientName, returnType = "full") {
|
|
219
|
+
return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
|
|
220
|
+
}
|
|
205
221
|
function getStatusCodeNumber(statusCode) {
|
|
206
222
|
const code = Number(statusCode);
|
|
207
223
|
return Number.isNaN(code) ? null : code;
|
|
@@ -219,8 +235,7 @@ function getOperationSuccessResponses(node) {
|
|
|
219
235
|
function getPrimarySuccessResponse(node) {
|
|
220
236
|
return getOperationSuccessResponses(node)[0] ?? null;
|
|
221
237
|
}
|
|
222
|
-
|
|
223
|
-
//#region ../../internals/utils/src/casing.ts
|
|
238
|
+
// ../../internals/utils/src/casing.ts
|
|
224
239
|
/**
|
|
225
240
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
226
241
|
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
@@ -257,8 +272,7 @@ function toCamelOrPascal(text, pascal) {
|
|
|
257
272
|
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
258
273
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
259
274
|
}
|
|
260
|
-
|
|
261
|
-
//#region ../../internals/utils/src/fs.ts
|
|
275
|
+
// ../../internals/utils/src/fs.ts
|
|
262
276
|
function toSlash(p) {
|
|
263
277
|
if (p.startsWith("\\\\?\\")) return p;
|
|
264
278
|
return p.replaceAll("\\", "/");
|
|
@@ -277,8 +291,26 @@ function getRelativePath(rootDir, filePath) {
|
|
|
277
291
|
const relativePath = node_path.posix.relative(toSlash(rootDir), toSlash(filePath));
|
|
278
292
|
return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
|
|
279
293
|
}
|
|
280
|
-
|
|
281
|
-
|
|
294
|
+
// ../../internals/shared/src/resolver.ts
|
|
295
|
+
/**
|
|
296
|
+
* Builds the allocation key for a declaration an operation owns. `scope` names which declaration
|
|
297
|
+
* it is, so two of them never share an allocation even when a custom resolver gives both the same
|
|
298
|
+
* name. Leave `scope` empty for the operation's own declaration.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
function operationKey(node, ...scope) {
|
|
306
|
+
return [
|
|
307
|
+
"operation",
|
|
308
|
+
node.method,
|
|
309
|
+
node.path,
|
|
310
|
+
...scope.map(String)
|
|
311
|
+
];
|
|
312
|
+
}
|
|
313
|
+
// ../../internals/shared/src/group.ts
|
|
282
314
|
/**
|
|
283
315
|
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
284
316
|
* shared default naming so every plugin groups output consistently:
|
|
@@ -308,8 +340,7 @@ function createGroupConfig(group) {
|
|
|
308
340
|
name: group.name ? group.name : defaultName
|
|
309
341
|
};
|
|
310
342
|
}
|
|
311
|
-
|
|
312
|
-
//#region src/components/McpHandler.tsx
|
|
343
|
+
// src/components/McpHandler.tsx
|
|
313
344
|
const requestGroupOrder = [
|
|
314
345
|
"path",
|
|
315
346
|
"query",
|
|
@@ -324,6 +355,7 @@ function McpHandler({ name, clientName, node, resolver, returnType = "full" }) {
|
|
|
324
355
|
"signal: ctx.mcpReq.signal",
|
|
325
356
|
"throwOnError: true"
|
|
326
357
|
].join(", ")} }`;
|
|
358
|
+
const callArg = hasRequestContentTypeChoice(node) ? castToClientOptions(callConfig, clientName, returnType) : callConfig;
|
|
327
359
|
const body = returnType === "data" ? "res" : "res.data";
|
|
328
360
|
const callToolResult = `return {
|
|
329
361
|
content: [
|
|
@@ -346,15 +378,14 @@ function McpHandler({ name, clientName, node, resolver, returnType = "full" }) {
|
|
|
346
378
|
JSDoc: { comments: buildOperationComments(node) },
|
|
347
379
|
returnType: "CallToolResult",
|
|
348
380
|
children: [
|
|
349
|
-
`const res = await ${clientName}(${
|
|
381
|
+
`const res = await ${clientName}(${callArg})`,
|
|
350
382
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)("br", {}),
|
|
351
383
|
callToolResult
|
|
352
384
|
]
|
|
353
385
|
})
|
|
354
386
|
});
|
|
355
387
|
}
|
|
356
|
-
|
|
357
|
-
//#region src/components/Server.tsx
|
|
388
|
+
// src/components/Server.tsx
|
|
358
389
|
/**
|
|
359
390
|
* Composes individual param schemas into `z.object({ ... })`.
|
|
360
391
|
*/
|
|
@@ -443,8 +474,7 @@ return server`
|
|
|
443
474
|
})
|
|
444
475
|
] });
|
|
445
476
|
}
|
|
446
|
-
|
|
447
|
-
//#region ../../internals/client/src/resolveOperationTypes.ts
|
|
477
|
+
// ../../internals/client/src/resolveOperationTypes.ts
|
|
448
478
|
/**
|
|
449
479
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
450
480
|
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
@@ -510,8 +540,7 @@ function resolveOperationTypes(driver, pluginName) {
|
|
|
510
540
|
group: pluginZod.options.group ?? void 0
|
|
511
541
|
};
|
|
512
542
|
}
|
|
513
|
-
|
|
514
|
-
//#region ../../internals/client/src/resolveClient.ts
|
|
543
|
+
// ../../internals/client/src/resolveClient.ts
|
|
515
544
|
/**
|
|
516
545
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
517
546
|
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
@@ -621,8 +650,7 @@ function resolveContractClient(options) {
|
|
|
621
650
|
}
|
|
622
651
|
return resolved;
|
|
623
652
|
}
|
|
624
|
-
|
|
625
|
-
//#region ../../internals/client/src/resolveClientOperation.ts
|
|
653
|
+
// ../../internals/client/src/resolveClientOperation.ts
|
|
626
654
|
function isRelativeImport(importPath) {
|
|
627
655
|
return importPath.startsWith(".");
|
|
628
656
|
}
|
|
@@ -669,8 +697,12 @@ function resolveClientOperation(options) {
|
|
|
669
697
|
group: operationOptions.group ?? void 0
|
|
670
698
|
});
|
|
671
699
|
const { importPath } = operationOptions;
|
|
700
|
+
const name = resolver.name(node.operationId);
|
|
672
701
|
return {
|
|
673
|
-
name: resolver.
|
|
702
|
+
name: resolver.resolveName({
|
|
703
|
+
key: operationKey(node),
|
|
704
|
+
name
|
|
705
|
+
}),
|
|
674
706
|
path: file.path,
|
|
675
707
|
clientPath: importPath === void 0 ? node_path.default.resolve(root, ".kubb/client.ts") : resolveImportPath({
|
|
676
708
|
importPath,
|
|
@@ -681,8 +713,7 @@ function resolveClientOperation(options) {
|
|
|
681
713
|
};
|
|
682
714
|
});
|
|
683
715
|
}
|
|
684
|
-
|
|
685
|
-
//#region src/generators/mcpGenerator.tsx
|
|
716
|
+
// src/generators/mcpGenerator.tsx
|
|
686
717
|
/**
|
|
687
718
|
* Built-in operation generator for `@kubb/plugin-mcp`. Emits one MCP tool
|
|
688
719
|
* handler per OpenAPI operation. The handler takes the grouped `{ path, query,
|
|
@@ -773,8 +804,7 @@ const mcpGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
773
804
|
});
|
|
774
805
|
}
|
|
775
806
|
});
|
|
776
|
-
|
|
777
|
-
//#region src/generators/serverGenerator.tsx
|
|
807
|
+
// src/generators/serverGenerator.tsx
|
|
778
808
|
/**
|
|
779
809
|
* Default v5 server generator for `@kubb/plugin-mcp`.
|
|
780
810
|
*
|
|
@@ -947,17 +977,14 @@ const serverGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
947
977
|
] });
|
|
948
978
|
}
|
|
949
979
|
});
|
|
950
|
-
|
|
951
|
-
//#region kubb-extension.json
|
|
980
|
+
// kubb-extension.json
|
|
952
981
|
var compatibility = {
|
|
953
|
-
"kubb": ">=5.
|
|
982
|
+
"kubb": ">=5.14.6",
|
|
954
983
|
"node": ">=22.22"
|
|
955
984
|
};
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
//#endregion
|
|
960
|
-
//#region src/resolvers/resolverMcp.ts
|
|
985
|
+
// package.json
|
|
986
|
+
var version = "5.3.3";
|
|
987
|
+
// src/resolvers/resolverMcp.ts
|
|
961
988
|
/**
|
|
962
989
|
* Default resolver used by `@kubb/plugin-mcp`. Decides the names and file
|
|
963
990
|
* paths for every generated MCP tool handler. Function names get a `Handler`
|
|
@@ -976,11 +1003,14 @@ const resolverMcp = (0, kubb_kit.createResolver)({
|
|
|
976
1003
|
return camelCase(name, { suffix: "handler" });
|
|
977
1004
|
},
|
|
978
1005
|
handler: { name(node) {
|
|
979
|
-
|
|
1006
|
+
const name = this.name(node.operationId);
|
|
1007
|
+
return this.resolveName({
|
|
1008
|
+
key: operationKey(node, "handler", "name"),
|
|
1009
|
+
name
|
|
1010
|
+
});
|
|
980
1011
|
} }
|
|
981
1012
|
});
|
|
982
|
-
|
|
983
|
-
//#region src/plugin.ts
|
|
1013
|
+
// src/plugin.ts
|
|
984
1014
|
/**
|
|
985
1015
|
* Canonical plugin name for `@kubb/plugin-mcp`. Used for driver lookups and
|
|
986
1016
|
* cross-plugin dependency references.
|
|
@@ -1049,7 +1079,6 @@ const pluginMcp = (0, kubb_kit.defineExtension)({
|
|
|
1049
1079
|
};
|
|
1050
1080
|
}
|
|
1051
1081
|
});
|
|
1052
|
-
//#endregion
|
|
1053
1082
|
exports.McpHandler = McpHandler;
|
|
1054
1083
|
exports.Server = Server;
|
|
1055
1084
|
exports.default = pluginMcp;
|