@kubb/plugin-mcp 5.0.0-alpha.29 → 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 +75 -101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.js +77 -103
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/generators/mcpGenerator.tsx +15 -24
- package/src/generators/serverGenerator.tsx +16 -24
- package/src/generators/serverGeneratorLegacy.tsx +16 -22
- package/src/plugin.ts +25 -45
- package/src/types.ts +11 -0
package/dist/index.cjs
CHANGED
|
@@ -503,42 +503,40 @@ server.registerTool(${JSON.stringify(tool.name)}, {
|
|
|
503
503
|
//#region src/generators/mcpGenerator.tsx
|
|
504
504
|
const mcpGenerator = (0, _kubb_core.defineGenerator)({
|
|
505
505
|
name: "mcp",
|
|
506
|
-
|
|
507
|
-
|
|
506
|
+
operation(node, options) {
|
|
507
|
+
const { resolver, driver, root } = this;
|
|
508
508
|
const { output, client, paramsCasing, group } = options;
|
|
509
|
-
const root = node_path.default.resolve(config.root, config.output.path);
|
|
510
509
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
511
510
|
if (!pluginTs?.resolver) return null;
|
|
512
|
-
const
|
|
513
|
-
const casedParams = (0, _kubb_ast.caseParams)(transformedNode.parameters, paramsCasing);
|
|
511
|
+
const casedParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
|
|
514
512
|
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
515
513
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
516
514
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
517
515
|
const importedTypeNames = [
|
|
518
|
-
...pathParams.map((p) => pluginTs.resolver.resolvePathParamsName(
|
|
519
|
-
...queryParams.map((p) => pluginTs.resolver.resolveQueryParamsName(
|
|
520
|
-
...headerParams.map((p) => pluginTs.resolver.resolveHeaderParamsName(
|
|
521
|
-
|
|
522
|
-
pluginTs.resolver.resolveResponseName(
|
|
523
|
-
...
|
|
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))
|
|
524
522
|
].filter(Boolean);
|
|
525
523
|
const meta = {
|
|
526
|
-
name: resolver.resolveName(
|
|
524
|
+
name: resolver.resolveName(node.operationId),
|
|
527
525
|
file: resolver.resolveFile({
|
|
528
|
-
name:
|
|
526
|
+
name: node.operationId,
|
|
529
527
|
extname: ".ts",
|
|
530
|
-
tag:
|
|
531
|
-
path:
|
|
528
|
+
tag: node.tags[0] ?? "default",
|
|
529
|
+
path: node.path
|
|
532
530
|
}, {
|
|
533
531
|
root,
|
|
534
532
|
output,
|
|
535
533
|
group
|
|
536
534
|
}),
|
|
537
535
|
fileTs: pluginTs.resolver.resolveFile({
|
|
538
|
-
name:
|
|
536
|
+
name: node.operationId,
|
|
539
537
|
extname: ".ts",
|
|
540
|
-
tag:
|
|
541
|
-
path:
|
|
538
|
+
tag: node.tags[0] ?? "default",
|
|
539
|
+
path: node.path
|
|
542
540
|
}, {
|
|
543
541
|
root,
|
|
544
542
|
output: pluginTs.options?.output ?? output,
|
|
@@ -610,7 +608,7 @@ const mcpGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
610
608
|
] }),
|
|
611
609
|
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(McpHandler, {
|
|
612
610
|
name: meta.name,
|
|
613
|
-
node
|
|
611
|
+
node,
|
|
614
612
|
resolver: pluginTs.resolver,
|
|
615
613
|
baseURL: client.baseURL,
|
|
616
614
|
dataReturnType: client.dataReturnType || "data",
|
|
@@ -631,10 +629,9 @@ const mcpGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
631
629
|
*/
|
|
632
630
|
const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
633
631
|
name: "operations",
|
|
634
|
-
|
|
635
|
-
|
|
632
|
+
operations(nodes, options) {
|
|
633
|
+
const { adapter, config, resolver, plugin, driver, root } = this;
|
|
636
634
|
const { output, paramsCasing, group } = options;
|
|
637
|
-
const root = node_path.default.resolve(config.root, config.output.path);
|
|
638
635
|
const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
|
|
639
636
|
if (!pluginZod?.resolver) return;
|
|
640
637
|
const name = "server";
|
|
@@ -649,46 +646,45 @@ const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
649
646
|
meta: { pluginName: plugin.name }
|
|
650
647
|
};
|
|
651
648
|
const operationsMapped = nodes.map((node) => {
|
|
652
|
-
const
|
|
653
|
-
const casedParams = (0, _kubb_ast.caseParams)(transformedNode.parameters, paramsCasing);
|
|
649
|
+
const casedParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
|
|
654
650
|
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
655
651
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
656
652
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
657
653
|
const mcpFile = resolver.resolveFile({
|
|
658
|
-
name:
|
|
654
|
+
name: node.operationId,
|
|
659
655
|
extname: ".ts",
|
|
660
|
-
tag:
|
|
661
|
-
path:
|
|
656
|
+
tag: node.tags[0] ?? "default",
|
|
657
|
+
path: node.path
|
|
662
658
|
}, {
|
|
663
659
|
root,
|
|
664
660
|
output,
|
|
665
661
|
group
|
|
666
662
|
});
|
|
667
663
|
const zodFile = pluginZod.resolver.resolveFile({
|
|
668
|
-
name:
|
|
664
|
+
name: node.operationId,
|
|
669
665
|
extname: ".ts",
|
|
670
|
-
tag:
|
|
671
|
-
path:
|
|
666
|
+
tag: node.tags[0] ?? "default",
|
|
667
|
+
path: node.path
|
|
672
668
|
}, {
|
|
673
669
|
root,
|
|
674
670
|
output: pluginZod.options?.output ?? output,
|
|
675
671
|
group: pluginZod.options?.group
|
|
676
672
|
});
|
|
677
|
-
const requestName =
|
|
678
|
-
const successStatus = findSuccessStatusCode(
|
|
679
|
-
const responseName = successStatus ? pluginZod.resolver.resolveResponseStatusName(
|
|
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;
|
|
680
676
|
const resolveParams = (params) => params.map((p) => ({
|
|
681
677
|
name: p.name,
|
|
682
|
-
schemaName: pluginZod.resolver.resolveParamName(
|
|
678
|
+
schemaName: pluginZod.resolver.resolveParamName(node, p)
|
|
683
679
|
}));
|
|
684
680
|
return {
|
|
685
681
|
tool: {
|
|
686
|
-
name:
|
|
687
|
-
title:
|
|
688
|
-
description:
|
|
682
|
+
name: node.operationId,
|
|
683
|
+
title: node.summary || void 0,
|
|
684
|
+
description: node.description || `Make a ${node.method.toUpperCase()} request to ${node.path}`
|
|
689
685
|
},
|
|
690
686
|
mcp: {
|
|
691
|
-
name: resolver.resolveName(
|
|
687
|
+
name: resolver.resolveName(node.operationId),
|
|
692
688
|
file: mcpFile
|
|
693
689
|
},
|
|
694
690
|
zod: {
|
|
@@ -699,7 +695,7 @@ const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
699
695
|
responseName,
|
|
700
696
|
file: zodFile
|
|
701
697
|
},
|
|
702
|
-
node
|
|
698
|
+
node
|
|
703
699
|
};
|
|
704
700
|
});
|
|
705
701
|
const imports = operationsMapped.flatMap(({ mcp, zod }) => {
|
|
@@ -787,10 +783,9 @@ const serverGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
787
783
|
*/
|
|
788
784
|
const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
789
785
|
name: "operations",
|
|
790
|
-
|
|
791
|
-
|
|
786
|
+
operations(nodes, options) {
|
|
787
|
+
const { adapter, config, resolver, plugin, driver, root } = this;
|
|
792
788
|
const { output, paramsCasing, group } = options;
|
|
793
|
-
const root = node_path.default.resolve(config.root, config.output.path);
|
|
794
789
|
const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
|
|
795
790
|
if (!pluginZod?.resolver) return;
|
|
796
791
|
const name = "server";
|
|
@@ -805,42 +800,41 @@ const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
805
800
|
meta: { pluginName: plugin.name }
|
|
806
801
|
};
|
|
807
802
|
const operationsMapped = nodes.map((node) => {
|
|
808
|
-
const
|
|
809
|
-
const casedParams = (0, _kubb_ast.caseParams)(transformedNode.parameters, paramsCasing);
|
|
803
|
+
const casedParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
|
|
810
804
|
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
811
805
|
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
812
806
|
const mcpFile = resolver.resolveFile({
|
|
813
|
-
name:
|
|
807
|
+
name: node.operationId,
|
|
814
808
|
extname: ".ts",
|
|
815
|
-
tag:
|
|
816
|
-
path:
|
|
809
|
+
tag: node.tags[0] ?? "default",
|
|
810
|
+
path: node.path
|
|
817
811
|
}, {
|
|
818
812
|
root,
|
|
819
813
|
output,
|
|
820
814
|
group
|
|
821
815
|
});
|
|
822
816
|
const zodFile = pluginZod?.resolver.resolveFile({
|
|
823
|
-
name:
|
|
817
|
+
name: node.operationId,
|
|
824
818
|
extname: ".ts",
|
|
825
|
-
tag:
|
|
826
|
-
path:
|
|
819
|
+
tag: node.tags[0] ?? "default",
|
|
820
|
+
path: node.path
|
|
827
821
|
}, {
|
|
828
822
|
root,
|
|
829
823
|
output: pluginZod?.options?.output ?? output,
|
|
830
824
|
group: pluginZod?.options?.group
|
|
831
825
|
});
|
|
832
|
-
const requestName =
|
|
833
|
-
const responseName = pluginZod?.resolver.resolveResponseName(
|
|
834
|
-
const zodQueryParams = queryParams.length ? pluginZod?.resolver.resolveQueryParamsName(
|
|
835
|
-
const zodHeaderParams = headerParams.length ? pluginZod?.resolver.resolveHeaderParamsName(
|
|
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;
|
|
836
830
|
return {
|
|
837
831
|
tool: {
|
|
838
|
-
name:
|
|
839
|
-
title:
|
|
840
|
-
description:
|
|
832
|
+
name: node.operationId,
|
|
833
|
+
title: node.summary || void 0,
|
|
834
|
+
description: node.description || `Make a ${node.method.toUpperCase()} request to ${node.path}`
|
|
841
835
|
},
|
|
842
836
|
mcp: {
|
|
843
|
-
name: resolver.resolveName(
|
|
837
|
+
name: resolver.resolveName(node.operationId),
|
|
844
838
|
file: mcpFile
|
|
845
839
|
},
|
|
846
840
|
zod: {
|
|
@@ -851,7 +845,7 @@ const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
851
845
|
responseName,
|
|
852
846
|
file: zodFile
|
|
853
847
|
},
|
|
854
|
-
node
|
|
848
|
+
node
|
|
855
849
|
};
|
|
856
850
|
});
|
|
857
851
|
const imports = operationsMapped.flatMap(({ mcp, zod }) => {
|
|
@@ -927,6 +921,9 @@ const serverGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
927
921
|
}
|
|
928
922
|
});
|
|
929
923
|
//#endregion
|
|
924
|
+
//#region package.json
|
|
925
|
+
var version = "5.0.0-alpha.30";
|
|
926
|
+
//#endregion
|
|
930
927
|
//#region src/resolvers/resolverMcp.ts
|
|
931
928
|
/**
|
|
932
929
|
* Resolver for `@kubb/plugin-mcp` that provides the default naming
|
|
@@ -988,8 +985,10 @@ const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
|
|
|
988
985
|
transformer: userTransformer,
|
|
989
986
|
generators: userGenerators
|
|
990
987
|
});
|
|
988
|
+
const mergedGenerator = (0, _kubb_core.mergeGenerators)(preset.generators ?? []);
|
|
991
989
|
return {
|
|
992
990
|
name: pluginMcpName,
|
|
991
|
+
version,
|
|
993
992
|
get resolver() {
|
|
994
993
|
return preset.resolver;
|
|
995
994
|
},
|
|
@@ -999,6 +998,9 @@ const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
|
|
|
999
998
|
get options() {
|
|
1000
999
|
return {
|
|
1001
1000
|
output,
|
|
1001
|
+
exclude,
|
|
1002
|
+
include,
|
|
1003
|
+
override,
|
|
1002
1004
|
group: group ? {
|
|
1003
1005
|
...group,
|
|
1004
1006
|
name: group.name ? group.name : (ctx) => {
|
|
@@ -1020,12 +1022,19 @@ const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1020
1022
|
};
|
|
1021
1023
|
},
|
|
1022
1024
|
pre: [_kubb_plugin_ts.pluginTsName, _kubb_plugin_zod.pluginZodName].filter(Boolean),
|
|
1023
|
-
async
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
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);
|
|
1033
|
+
},
|
|
1034
|
+
async buildStart() {
|
|
1035
|
+
const { adapter, driver } = this;
|
|
1036
|
+
const root = this.root;
|
|
1037
|
+
const baseURL = adapter?.rootNode?.meta?.baseURL;
|
|
1029
1038
|
if (baseURL) this.plugin.options.client.baseURL = this.plugin.options.client.baseURL || baseURL;
|
|
1030
1039
|
const hasClientPlugin = !!driver.getPlugin(_kubb_plugin_client.pluginClientName);
|
|
1031
1040
|
if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.addFile({
|
|
@@ -1052,42 +1061,7 @@ const pluginMcp = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1052
1061
|
imports: [],
|
|
1053
1062
|
exports: []
|
|
1054
1063
|
});
|
|
1055
|
-
|
|
1056
|
-
const generatorContext = {
|
|
1057
|
-
generators: preset.generators,
|
|
1058
|
-
plugin,
|
|
1059
|
-
resolver,
|
|
1060
|
-
exclude,
|
|
1061
|
-
include,
|
|
1062
|
-
override,
|
|
1063
|
-
fabric,
|
|
1064
|
-
adapter,
|
|
1065
|
-
config,
|
|
1066
|
-
driver
|
|
1067
|
-
};
|
|
1068
|
-
await (0, _kubb_ast.walk)(rootNode, {
|
|
1069
|
-
depth: "shallow",
|
|
1070
|
-
async schema(schemaNode) {
|
|
1071
|
-
await (0, _kubb_core.runGeneratorSchema)(schemaNode, generatorContext);
|
|
1072
|
-
},
|
|
1073
|
-
async operation(operationNode) {
|
|
1074
|
-
if (resolver.resolveOptions(operationNode, {
|
|
1075
|
-
options: plugin.options,
|
|
1076
|
-
exclude,
|
|
1077
|
-
include,
|
|
1078
|
-
override
|
|
1079
|
-
}) !== null) collectedOperations.push(operationNode);
|
|
1080
|
-
await (0, _kubb_core.runGeneratorOperation)(operationNode, generatorContext);
|
|
1081
|
-
}
|
|
1082
|
-
});
|
|
1083
|
-
await (0, _kubb_core.runGeneratorOperations)(collectedOperations, generatorContext);
|
|
1084
|
-
const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
1085
|
-
type: output.barrelType ?? "named",
|
|
1086
|
-
root,
|
|
1087
|
-
output,
|
|
1088
|
-
meta: { pluginName: this.plugin.name }
|
|
1089
|
-
});
|
|
1090
|
-
await this.upsertFile(...barrelFiles);
|
|
1064
|
+
await this.openInStudio({ ast: true });
|
|
1091
1065
|
}
|
|
1092
1066
|
};
|
|
1093
1067
|
});
|