@kubb/plugin-mcp 5.0.0-alpha.33 → 5.0.0-alpha.35
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 +71 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -11
- package/dist/index.js +69 -103
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
- package/src/components/McpHandler.tsx +4 -5
- package/src/components/Server.tsx +7 -8
- package/src/generators/mcpGenerator.tsx +8 -7
- package/src/generators/serverGenerator.tsx +8 -7
- package/src/generators/serverGeneratorLegacy.tsx +8 -7
- package/src/plugin.ts +70 -95
- package/src/types.ts +2 -2
- package/src/utils.ts +21 -5
- package/src/presets.ts +0 -25
package/dist/index.cjs
CHANGED
|
@@ -22,12 +22,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
24
|
let node_path = require("node:path");
|
|
25
|
+
let node_path$1 = __toESM(node_path, 1);
|
|
25
26
|
node_path = __toESM(node_path);
|
|
26
|
-
let
|
|
27
|
+
let _kubb_core = require("@kubb/core");
|
|
27
28
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
28
29
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
29
30
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
30
|
-
let _kubb_core = require("@kubb/core");
|
|
31
31
|
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
32
32
|
let _kubb_plugin_client = require("@kubb/plugin-client");
|
|
33
33
|
let _kubb_plugin_client_templates_clients_axios_source = require("@kubb/plugin-client/templates/clients/axios.source");
|
|
@@ -293,6 +293,15 @@ function getParamsMapping(params) {
|
|
|
293
293
|
function zodExprFromSchemaNode(schema) {
|
|
294
294
|
let expr;
|
|
295
295
|
switch (schema.type) {
|
|
296
|
+
case "enum": {
|
|
297
|
+
const rawValues = schema.namedEnumValues?.length ? schema.namedEnumValues.map((v) => v.value) : (schema.enumValues ?? []).filter((v) => v !== null);
|
|
298
|
+
if (rawValues.length > 0 && rawValues.every((v) => typeof v === "string")) expr = `z.enum([${rawValues.map((v) => JSON.stringify(v)).join(", ")}])`;
|
|
299
|
+
else if (rawValues.length > 0) {
|
|
300
|
+
const literals = rawValues.map((v) => `z.literal(${JSON.stringify(v)})`);
|
|
301
|
+
expr = literals.length === 1 ? literals[0] : `z.union([${literals.join(", ")}])`;
|
|
302
|
+
} else expr = "z.string()";
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
296
305
|
case "integer":
|
|
297
306
|
expr = "z.coerce.number()";
|
|
298
307
|
break;
|
|
@@ -323,7 +332,7 @@ function McpHandler({ name, node, resolver, baseURL, dataReturnType, paramsCasin
|
|
|
323
332
|
const urlPath = new URLPath(node.path);
|
|
324
333
|
const contentType = node.requestBody?.contentType;
|
|
325
334
|
const isFormData = contentType === "multipart/form-data";
|
|
326
|
-
const casedParams =
|
|
335
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
327
336
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
328
337
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
329
338
|
const originalPathParams = node.parameters.filter((p) => p.in === "path");
|
|
@@ -337,7 +346,7 @@ function McpHandler({ name, node, resolver, baseURL, dataReturnType, paramsCasin
|
|
|
337
346
|
`ResponseErrorConfig<${errorResponses.length > 0 ? errorResponses.join(" | ") : "Error"}>`,
|
|
338
347
|
requestName || "unknown"
|
|
339
348
|
].filter(Boolean);
|
|
340
|
-
const paramsNode =
|
|
349
|
+
const paramsNode = _kubb_core.ast.createOperationParams(node, {
|
|
341
350
|
paramsType: "object",
|
|
342
351
|
pathParamsType: "inline",
|
|
343
352
|
resolver,
|
|
@@ -431,7 +440,7 @@ function Server({ name, serverName, serverVersion, paramsCasing, operations }) {
|
|
|
431
440
|
`
|
|
432
441
|
}),
|
|
433
442
|
operations.map(({ tool, mcp, zod, node }) => {
|
|
434
|
-
const pathParams =
|
|
443
|
+
const pathParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing).filter((p) => p.in === "path");
|
|
435
444
|
const pathEntries = [];
|
|
436
445
|
const otherEntries = [];
|
|
437
446
|
for (const p of pathParams) {
|
|
@@ -455,7 +464,7 @@ function Server({ name, serverName, serverVersion, paramsCasing, operations }) {
|
|
|
455
464
|
});
|
|
456
465
|
otherEntries.sort((a, b) => a.key.localeCompare(b.key));
|
|
457
466
|
const entries = [...pathEntries, ...otherEntries];
|
|
458
|
-
const paramsNode = entries.length ?
|
|
467
|
+
const paramsNode = entries.length ? _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createParameterGroup({ properties: entries.map((e) => _kubb_core.ast.createFunctionParameter({
|
|
459
468
|
name: e.key,
|
|
460
469
|
optional: false
|
|
461
470
|
})) })] }) : void 0;
|
|
@@ -503,12 +512,13 @@ server.registerTool(${JSON.stringify(tool.name)}, {
|
|
|
503
512
|
//#region src/generators/mcpGenerator.tsx
|
|
504
513
|
const mcpGenerator = (0, _kubb_core.defineGenerator)({
|
|
505
514
|
name: "mcp",
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
const {
|
|
515
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
516
|
+
operation(node, ctx) {
|
|
517
|
+
const { resolver, driver, root } = ctx;
|
|
518
|
+
const { output, client, paramsCasing, group } = ctx.options;
|
|
509
519
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
510
520
|
if (!pluginTs?.resolver) return null;
|
|
511
|
-
const casedParams =
|
|
521
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
512
522
|
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
513
523
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
514
524
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
@@ -629,9 +639,10 @@ const mcpGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
629
639
|
*/
|
|
630
640
|
const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
631
641
|
name: "operations",
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
const {
|
|
642
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
643
|
+
operations(nodes, ctx) {
|
|
644
|
+
const { adapter, config, resolver, plugin, driver, root } = ctx;
|
|
645
|
+
const { output, paramsCasing, group } = ctx.options;
|
|
635
646
|
const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
|
|
636
647
|
if (!pluginZod?.resolver) return;
|
|
637
648
|
const name = "server";
|
|
@@ -646,7 +657,7 @@ const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
646
657
|
meta: { pluginName: plugin.name }
|
|
647
658
|
};
|
|
648
659
|
const operationsMapped = nodes.map((node) => {
|
|
649
|
-
const casedParams =
|
|
660
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
650
661
|
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
651
662
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
652
663
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
@@ -783,9 +794,10 @@ const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
783
794
|
*/
|
|
784
795
|
const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
785
796
|
name: "operations",
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
const {
|
|
797
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
798
|
+
operations(nodes, ctx) {
|
|
799
|
+
const { adapter, config, resolver, plugin, driver, root } = ctx;
|
|
800
|
+
const { output, paramsCasing, group } = ctx.options;
|
|
789
801
|
const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
|
|
790
802
|
if (!pluginZod?.resolver) return;
|
|
791
803
|
const name = "server";
|
|
@@ -800,7 +812,7 @@ const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
800
812
|
meta: { pluginName: plugin.name }
|
|
801
813
|
};
|
|
802
814
|
const operationsMapped = nodes.map((node) => {
|
|
803
|
-
const casedParams =
|
|
815
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
804
816
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
805
817
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
806
818
|
const mcpFile = resolver.resolveFile({
|
|
@@ -921,9 +933,6 @@ const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
921
933
|
}
|
|
922
934
|
});
|
|
923
935
|
//#endregion
|
|
924
|
-
//#region package.json
|
|
925
|
-
var version = "5.0.0-alpha.33";
|
|
926
|
-
//#endregion
|
|
927
936
|
//#region src/resolvers/resolverMcp.ts
|
|
928
937
|
/**
|
|
929
938
|
* Resolver for `@kubb/plugin-mcp` that provides the default naming
|
|
@@ -949,65 +958,38 @@ const resolverMcp = (0, _kubb_core.defineResolver)(() => ({
|
|
|
949
958
|
}
|
|
950
959
|
}));
|
|
951
960
|
//#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
|
|
972
961
|
//#region src/plugin.ts
|
|
973
962
|
const pluginMcpName = "plugin-mcp";
|
|
974
|
-
const pluginMcp = (0, _kubb_core.
|
|
963
|
+
const pluginMcp = (0, _kubb_core.definePlugin)((options) => {
|
|
975
964
|
const { output = {
|
|
976
965
|
path: "mcp",
|
|
977
966
|
barrelType: "named"
|
|
978
|
-
}, group, exclude = [], include, override = [], paramsCasing, client,
|
|
967
|
+
}, group, exclude = [], include, override = [], paramsCasing, client, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [], compatibilityPreset = "default" } = options;
|
|
968
|
+
const defaultServerGenerator = compatibilityPreset === "kubbV4" ? serverGeneratorLegacy : serverGenerator;
|
|
979
969
|
const clientName = client?.client ?? "axios";
|
|
980
970
|
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
|
|
981
|
-
const
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
}
|
|
988
|
-
const mergedGenerator = (0, _kubb_core.mergeGenerators)(preset.generators ?? []);
|
|
971
|
+
const groupConfig = group ? {
|
|
972
|
+
...group,
|
|
973
|
+
name: group.name ? group.name : (ctx) => {
|
|
974
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
975
|
+
return `${camelCase(ctx.group)}Requests`;
|
|
976
|
+
}
|
|
977
|
+
} : void 0;
|
|
989
978
|
return {
|
|
990
979
|
name: pluginMcpName,
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
return {
|
|
980
|
+
options,
|
|
981
|
+
dependencies: [_kubb_plugin_ts.pluginTsName, _kubb_plugin_zod.pluginZodName],
|
|
982
|
+
hooks: { "kubb:plugin:setup"(ctx) {
|
|
983
|
+
const resolver = userResolver ? {
|
|
984
|
+
...resolverMcp,
|
|
985
|
+
...userResolver
|
|
986
|
+
} : resolverMcp;
|
|
987
|
+
ctx.setOptions({
|
|
1000
988
|
output,
|
|
1001
989
|
exclude,
|
|
1002
990
|
include,
|
|
1003
991
|
override,
|
|
1004
|
-
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,
|
|
992
|
+
group: groupConfig,
|
|
1011
993
|
paramsCasing,
|
|
1012
994
|
client: {
|
|
1013
995
|
client: clientName,
|
|
@@ -1018,51 +1000,36 @@ const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1018
1000
|
baseURL: client?.baseURL,
|
|
1019
1001
|
paramsCasing: client?.paramsCasing
|
|
1020
1002
|
},
|
|
1021
|
-
resolver
|
|
1022
|
-
};
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
async operations(nodes, options) {
|
|
1032
|
-
return mergedGenerator.operations?.call(this, nodes, options);
|
|
1033
|
-
},
|
|
1034
|
-
async buildStart() {
|
|
1035
|
-
const { adapter, driver } = this;
|
|
1036
|
-
const root = this.root;
|
|
1037
|
-
const baseURL = adapter?.inputNode?.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);
|
|
1040
|
-
if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.addFile((0, _kubb_ast.createFile)({
|
|
1003
|
+
resolver
|
|
1004
|
+
});
|
|
1005
|
+
ctx.setResolver(resolver);
|
|
1006
|
+
if (userTransformer) ctx.setTransformer(userTransformer);
|
|
1007
|
+
ctx.addGenerator(mcpGenerator);
|
|
1008
|
+
ctx.addGenerator(defaultServerGenerator);
|
|
1009
|
+
for (const gen of userGenerators) ctx.addGenerator(gen);
|
|
1010
|
+
const root = node_path$1.default.resolve(ctx.config.root, ctx.config.output.path);
|
|
1011
|
+
const hasClientPlugin = ctx.config.plugins?.some((p) => p.name === _kubb_plugin_client.pluginClientName);
|
|
1012
|
+
if (client?.bundle && !hasClientPlugin && !clientImportPath) ctx.injectFile({
|
|
1041
1013
|
baseName: "fetch.ts",
|
|
1042
|
-
path: node_path.default.resolve(root, ".kubb/fetch.ts"),
|
|
1043
|
-
sources: [
|
|
1014
|
+
path: node_path$1.default.resolve(root, ".kubb/fetch.ts"),
|
|
1015
|
+
sources: [_kubb_core.ast.createSource({
|
|
1044
1016
|
name: "fetch",
|
|
1045
|
-
nodes: [
|
|
1017
|
+
nodes: [_kubb_core.ast.createText(clientName === "fetch" ? _kubb_plugin_client_templates_clients_fetch_source.source : _kubb_plugin_client_templates_clients_axios_source.source)],
|
|
1046
1018
|
isExportable: true,
|
|
1047
1019
|
isIndexable: true
|
|
1048
|
-
})]
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
}));
|
|
1052
|
-
if (!hasClientPlugin) await this.addFile((0, _kubb_ast.createFile)({
|
|
1020
|
+
})]
|
|
1021
|
+
});
|
|
1022
|
+
if (!hasClientPlugin) ctx.injectFile({
|
|
1053
1023
|
baseName: "config.ts",
|
|
1054
|
-
path: node_path.default.resolve(root, ".kubb/config.ts"),
|
|
1055
|
-
sources: [
|
|
1024
|
+
path: node_path$1.default.resolve(root, ".kubb/config.ts"),
|
|
1025
|
+
sources: [_kubb_core.ast.createSource({
|
|
1056
1026
|
name: "config",
|
|
1057
|
-
nodes: [
|
|
1027
|
+
nodes: [_kubb_core.ast.createText(_kubb_plugin_client_templates_config_source.source)],
|
|
1058
1028
|
isExportable: false,
|
|
1059
1029
|
isIndexable: false
|
|
1060
|
-
})]
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
}));
|
|
1064
|
-
await this.openInStudio({ ast: true });
|
|
1065
|
-
}
|
|
1030
|
+
})]
|
|
1031
|
+
});
|
|
1032
|
+
} }
|
|
1066
1033
|
};
|
|
1067
1034
|
});
|
|
1068
1035
|
//#endregion
|