@kubb/plugin-mcp 5.0.0-alpha.34 → 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 +62 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -11
- package/dist/index.js +60 -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 +5 -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");
|
|
@@ -332,7 +332,7 @@ function McpHandler({ name, node, resolver, baseURL, dataReturnType, paramsCasin
|
|
|
332
332
|
const urlPath = new URLPath(node.path);
|
|
333
333
|
const contentType = node.requestBody?.contentType;
|
|
334
334
|
const isFormData = contentType === "multipart/form-data";
|
|
335
|
-
const casedParams =
|
|
335
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
336
336
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
337
337
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
338
338
|
const originalPathParams = node.parameters.filter((p) => p.in === "path");
|
|
@@ -346,7 +346,7 @@ function McpHandler({ name, node, resolver, baseURL, dataReturnType, paramsCasin
|
|
|
346
346
|
`ResponseErrorConfig<${errorResponses.length > 0 ? errorResponses.join(" | ") : "Error"}>`,
|
|
347
347
|
requestName || "unknown"
|
|
348
348
|
].filter(Boolean);
|
|
349
|
-
const paramsNode =
|
|
349
|
+
const paramsNode = _kubb_core.ast.createOperationParams(node, {
|
|
350
350
|
paramsType: "object",
|
|
351
351
|
pathParamsType: "inline",
|
|
352
352
|
resolver,
|
|
@@ -440,7 +440,7 @@ function Server({ name, serverName, serverVersion, paramsCasing, operations }) {
|
|
|
440
440
|
`
|
|
441
441
|
}),
|
|
442
442
|
operations.map(({ tool, mcp, zod, node }) => {
|
|
443
|
-
const pathParams =
|
|
443
|
+
const pathParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing).filter((p) => p.in === "path");
|
|
444
444
|
const pathEntries = [];
|
|
445
445
|
const otherEntries = [];
|
|
446
446
|
for (const p of pathParams) {
|
|
@@ -464,7 +464,7 @@ function Server({ name, serverName, serverVersion, paramsCasing, operations }) {
|
|
|
464
464
|
});
|
|
465
465
|
otherEntries.sort((a, b) => a.key.localeCompare(b.key));
|
|
466
466
|
const entries = [...pathEntries, ...otherEntries];
|
|
467
|
-
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({
|
|
468
468
|
name: e.key,
|
|
469
469
|
optional: false
|
|
470
470
|
})) })] }) : void 0;
|
|
@@ -512,12 +512,13 @@ server.registerTool(${JSON.stringify(tool.name)}, {
|
|
|
512
512
|
//#region src/generators/mcpGenerator.tsx
|
|
513
513
|
const mcpGenerator = (0, _kubb_core.defineGenerator)({
|
|
514
514
|
name: "mcp",
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
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;
|
|
518
519
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
519
520
|
if (!pluginTs?.resolver) return null;
|
|
520
|
-
const casedParams =
|
|
521
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
521
522
|
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
522
523
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
523
524
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
@@ -638,9 +639,10 @@ const mcpGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
638
639
|
*/
|
|
639
640
|
const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
640
641
|
name: "operations",
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
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;
|
|
644
646
|
const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
|
|
645
647
|
if (!pluginZod?.resolver) return;
|
|
646
648
|
const name = "server";
|
|
@@ -655,7 +657,7 @@ const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
655
657
|
meta: { pluginName: plugin.name }
|
|
656
658
|
};
|
|
657
659
|
const operationsMapped = nodes.map((node) => {
|
|
658
|
-
const casedParams =
|
|
660
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
659
661
|
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
660
662
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
661
663
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
@@ -792,9 +794,10 @@ const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
792
794
|
*/
|
|
793
795
|
const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
794
796
|
name: "operations",
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
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;
|
|
798
801
|
const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
|
|
799
802
|
if (!pluginZod?.resolver) return;
|
|
800
803
|
const name = "server";
|
|
@@ -809,7 +812,7 @@ const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
809
812
|
meta: { pluginName: plugin.name }
|
|
810
813
|
};
|
|
811
814
|
const operationsMapped = nodes.map((node) => {
|
|
812
|
-
const casedParams =
|
|
815
|
+
const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
813
816
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
814
817
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
815
818
|
const mcpFile = resolver.resolveFile({
|
|
@@ -930,9 +933,6 @@ const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
930
933
|
}
|
|
931
934
|
});
|
|
932
935
|
//#endregion
|
|
933
|
-
//#region package.json
|
|
934
|
-
var version = "5.0.0-alpha.34";
|
|
935
|
-
//#endregion
|
|
936
936
|
//#region src/resolvers/resolverMcp.ts
|
|
937
937
|
/**
|
|
938
938
|
* Resolver for `@kubb/plugin-mcp` that provides the default naming
|
|
@@ -958,65 +958,38 @@ const resolverMcp = (0, _kubb_core.defineResolver)(() => ({
|
|
|
958
958
|
}
|
|
959
959
|
}));
|
|
960
960
|
//#endregion
|
|
961
|
-
//#region src/presets.ts
|
|
962
|
-
/**
|
|
963
|
-
* Built-in preset registry for `@kubb/plugin-mcp`.
|
|
964
|
-
*
|
|
965
|
-
* - `default` — v5 naming with individual zod schemas and per-status responses.
|
|
966
|
-
* - `kubbV4` — legacy naming with grouped zod schemas and combined responses.
|
|
967
|
-
*/
|
|
968
|
-
const presets = (0, _kubb_core.definePresets)({
|
|
969
|
-
default: {
|
|
970
|
-
name: "default",
|
|
971
|
-
resolver: resolverMcp,
|
|
972
|
-
generators: [mcpGenerator, serverGenerator]
|
|
973
|
-
},
|
|
974
|
-
kubbV4: {
|
|
975
|
-
name: "kubbV4",
|
|
976
|
-
resolver: resolverMcp,
|
|
977
|
-
generators: [mcpGenerator, serverGeneratorLegacy]
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
//#endregion
|
|
981
961
|
//#region src/plugin.ts
|
|
982
962
|
const pluginMcpName = "plugin-mcp";
|
|
983
|
-
const pluginMcp = (0, _kubb_core.
|
|
963
|
+
const pluginMcp = (0, _kubb_core.definePlugin)((options) => {
|
|
984
964
|
const { output = {
|
|
985
965
|
path: "mcp",
|
|
986
966
|
barrelType: "named"
|
|
987
|
-
}, 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;
|
|
988
969
|
const clientName = client?.client ?? "axios";
|
|
989
970
|
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
|
|
990
|
-
const
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
997
|
-
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;
|
|
998
978
|
return {
|
|
999
979
|
name: pluginMcpName,
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
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({
|
|
1009
988
|
output,
|
|
1010
989
|
exclude,
|
|
1011
990
|
include,
|
|
1012
991
|
override,
|
|
1013
|
-
group:
|
|
1014
|
-
...group,
|
|
1015
|
-
name: group.name ? group.name : (ctx) => {
|
|
1016
|
-
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
1017
|
-
return `${camelCase(ctx.group)}Requests`;
|
|
1018
|
-
}
|
|
1019
|
-
} : void 0,
|
|
992
|
+
group: groupConfig,
|
|
1020
993
|
paramsCasing,
|
|
1021
994
|
client: {
|
|
1022
995
|
client: clientName,
|
|
@@ -1027,51 +1000,36 @@ const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1027
1000
|
baseURL: client?.baseURL,
|
|
1028
1001
|
paramsCasing: client?.paramsCasing
|
|
1029
1002
|
},
|
|
1030
|
-
resolver
|
|
1031
|
-
};
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
async operations(nodes, options) {
|
|
1041
|
-
return mergedGenerator.operations?.call(this, nodes, options);
|
|
1042
|
-
},
|
|
1043
|
-
async buildStart() {
|
|
1044
|
-
const { adapter, driver } = this;
|
|
1045
|
-
const root = this.root;
|
|
1046
|
-
const baseURL = adapter?.inputNode?.meta?.baseURL;
|
|
1047
|
-
if (baseURL) this.plugin.options.client.baseURL = this.plugin.options.client.baseURL || baseURL;
|
|
1048
|
-
const hasClientPlugin = !!driver.getPlugin(_kubb_plugin_client.pluginClientName);
|
|
1049
|
-
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({
|
|
1050
1013
|
baseName: "fetch.ts",
|
|
1051
|
-
path: node_path.default.resolve(root, ".kubb/fetch.ts"),
|
|
1052
|
-
sources: [
|
|
1014
|
+
path: node_path$1.default.resolve(root, ".kubb/fetch.ts"),
|
|
1015
|
+
sources: [_kubb_core.ast.createSource({
|
|
1053
1016
|
name: "fetch",
|
|
1054
|
-
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)],
|
|
1055
1018
|
isExportable: true,
|
|
1056
1019
|
isIndexable: true
|
|
1057
|
-
})]
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
}));
|
|
1061
|
-
if (!hasClientPlugin) await this.addFile((0, _kubb_ast.createFile)({
|
|
1020
|
+
})]
|
|
1021
|
+
});
|
|
1022
|
+
if (!hasClientPlugin) ctx.injectFile({
|
|
1062
1023
|
baseName: "config.ts",
|
|
1063
|
-
path: node_path.default.resolve(root, ".kubb/config.ts"),
|
|
1064
|
-
sources: [
|
|
1024
|
+
path: node_path$1.default.resolve(root, ".kubb/config.ts"),
|
|
1025
|
+
sources: [_kubb_core.ast.createSource({
|
|
1065
1026
|
name: "config",
|
|
1066
|
-
nodes: [
|
|
1027
|
+
nodes: [_kubb_core.ast.createText(_kubb_plugin_client_templates_config_source.source)],
|
|
1067
1028
|
isExportable: false,
|
|
1068
1029
|
isIndexable: false
|
|
1069
|
-
})]
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
}));
|
|
1073
|
-
await this.openInStudio({ ast: true });
|
|
1074
|
-
}
|
|
1030
|
+
})]
|
|
1031
|
+
});
|
|
1032
|
+
} }
|
|
1075
1033
|
};
|
|
1076
1034
|
});
|
|
1077
1035
|
//#endregion
|