@kubb/plugin-mcp 5.0.0-beta.84 → 5.0.0-beta.86
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 +35 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -16
- package/dist/index.js +35 -75
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -24,12 +24,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
//#endregion
|
|
27
|
-
let node_path = require("node:path");
|
|
28
|
-
node_path = __toESM(node_path, 1);
|
|
29
27
|
let kubb_kit = require("kubb/kit");
|
|
30
28
|
let kubb_jsx = require("kubb/jsx");
|
|
31
29
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
32
30
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
31
|
+
let node_path = require("node:path");
|
|
32
|
+
node_path = __toESM(node_path, 1);
|
|
33
33
|
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
34
34
|
//#region ../../internals/utils/src/casing.ts
|
|
35
35
|
/**
|
|
@@ -58,31 +58,6 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
58
58
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
59
59
|
}
|
|
60
60
|
//#endregion
|
|
61
|
-
//#region ../../internals/utils/src/fs.ts
|
|
62
|
-
/**
|
|
63
|
-
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
64
|
-
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
65
|
-
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
66
|
-
*
|
|
67
|
-
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
68
|
-
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
69
|
-
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
70
|
-
* absolute path, letting generated files escape the configured output directory.
|
|
71
|
-
*
|
|
72
|
-
* @example Nested path from a dotted name
|
|
73
|
-
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
74
|
-
*
|
|
75
|
-
* @example PascalCase the final segment
|
|
76
|
-
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
77
|
-
*
|
|
78
|
-
* @example Suffix applied to the final segment only
|
|
79
|
-
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
80
|
-
*/
|
|
81
|
-
function toFilePath(name, caseLast = camelCase) {
|
|
82
|
-
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
83
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
84
|
-
}
|
|
85
|
-
//#endregion
|
|
86
61
|
//#region ../../internals/utils/src/reserved.ts
|
|
87
62
|
/**
|
|
88
63
|
* JavaScript and Java reserved words.
|
|
@@ -338,13 +313,13 @@ function dedupeByCasedName(params) {
|
|
|
338
313
|
//#region ../../internals/shared/src/operation.ts
|
|
339
314
|
/**
|
|
340
315
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
341
|
-
* `resolver.
|
|
316
|
+
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
342
317
|
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
343
318
|
* that was repeated at dozens of call sites across the client and query plugins.
|
|
344
319
|
*
|
|
345
320
|
* @example
|
|
346
321
|
* ```ts
|
|
347
|
-
* resolver.
|
|
322
|
+
* resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
|
|
348
323
|
* ```
|
|
349
324
|
*/
|
|
350
325
|
function operationFileEntry(node, name, extname = ".ts") {
|
|
@@ -427,7 +402,7 @@ function getRequestGroupOptionality(node) {
|
|
|
427
402
|
}
|
|
428
403
|
/**
|
|
429
404
|
* Builds the grouped `{ path, query, body, headers }` parameter for a generated client
|
|
430
|
-
* function, typed from the operation's `
|
|
405
|
+
* function, typed from the operation's `Options` (minus `url`). Only the groups the
|
|
431
406
|
* operation actually has are destructured. The trailing `config` parameter carries the
|
|
432
407
|
* runtime `RequestConfig` overrides plus `client`.
|
|
433
408
|
*/
|
|
@@ -441,7 +416,7 @@ function buildRequestParamsSignature(node, resolver, options = {}) {
|
|
|
441
416
|
"headers"
|
|
442
417
|
].filter((key) => groups[key]);
|
|
443
418
|
return {
|
|
444
|
-
signature: [names.length > 0 ? `{ ${names.join(", ")} }: ${resolver.
|
|
419
|
+
signature: [names.length > 0 ? `{ ${names.join(", ")} }: ${resolver.response.options(node)}${isOptional ? " = {}" : ""}` : null, isConfigurable ? `config: ${buildRequestConfigType(node)} = {}` : null].filter(Boolean).join(", "),
|
|
445
420
|
groups
|
|
446
421
|
};
|
|
447
422
|
}
|
|
@@ -770,15 +745,15 @@ function resolveClientOperation(options) {
|
|
|
770
745
|
const { clientPlugin, driver, node, root, output } = options;
|
|
771
746
|
if (!clientPlugin) return null;
|
|
772
747
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
773
|
-
if (!resolver) return null;
|
|
774
748
|
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
775
|
-
const file = resolver.
|
|
749
|
+
const file = resolver.file({
|
|
750
|
+
...operationFileEntry(node, node.operationId),
|
|
776
751
|
root,
|
|
777
752
|
output: plugin?.options?.output ?? output,
|
|
778
753
|
group: plugin?.options?.group ?? void 0
|
|
779
754
|
});
|
|
780
755
|
return {
|
|
781
|
-
name: resolver.
|
|
756
|
+
name: resolver.name(node.operationId),
|
|
782
757
|
path: file.path,
|
|
783
758
|
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
784
759
|
};
|
|
@@ -809,25 +784,23 @@ const mcpGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
809
784
|
output
|
|
810
785
|
});
|
|
811
786
|
if (!contractOp) return null;
|
|
812
|
-
const
|
|
787
|
+
const optionsName = tsResolver.response.options(node);
|
|
813
788
|
const meta = {
|
|
814
|
-
name: resolver.
|
|
815
|
-
file: resolver.
|
|
789
|
+
name: resolver.handler.name(node),
|
|
790
|
+
file: resolver.file({
|
|
816
791
|
name: node.operationId,
|
|
817
792
|
extname: ".ts",
|
|
818
793
|
tag: node.tags[0] ?? "default",
|
|
819
|
-
path: node.path
|
|
820
|
-
}, {
|
|
794
|
+
path: node.path,
|
|
821
795
|
root,
|
|
822
796
|
output,
|
|
823
797
|
group: group ?? void 0
|
|
824
798
|
}),
|
|
825
|
-
fileTs: tsResolver.
|
|
799
|
+
fileTs: tsResolver.file({
|
|
826
800
|
name: node.operationId,
|
|
827
801
|
extname: ".ts",
|
|
828
802
|
tag: node.tags[0] ?? "default",
|
|
829
|
-
path: node.path
|
|
830
|
-
}, {
|
|
803
|
+
path: node.path,
|
|
831
804
|
root,
|
|
832
805
|
output: pluginTs.options?.output ?? output,
|
|
833
806
|
group: pluginTs.options?.group ?? void 0
|
|
@@ -838,8 +811,8 @@ const mcpGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
838
811
|
path: meta.file.path,
|
|
839
812
|
meta: meta.file.meta,
|
|
840
813
|
children: [
|
|
841
|
-
meta.fileTs &&
|
|
842
|
-
name: [
|
|
814
|
+
meta.fileTs && optionsName && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
815
|
+
name: [optionsName],
|
|
843
816
|
root: meta.file.path,
|
|
844
817
|
path: meta.fileTs.path,
|
|
845
818
|
isTypeOnly: true
|
|
@@ -904,32 +877,30 @@ const serverGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
904
877
|
};
|
|
905
878
|
const operationsMapped = nodes.filter(kubb_kit.ast.isHttpOperationNode).map((node) => {
|
|
906
879
|
const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node);
|
|
907
|
-
const mcpFile = resolver.
|
|
880
|
+
const mcpFile = resolver.file({
|
|
908
881
|
name: node.operationId,
|
|
909
882
|
extname: ".ts",
|
|
910
883
|
tag: node.tags[0] ?? "default",
|
|
911
|
-
path: node.path
|
|
912
|
-
}, {
|
|
884
|
+
path: node.path,
|
|
913
885
|
root,
|
|
914
886
|
output,
|
|
915
887
|
group: group ?? void 0
|
|
916
888
|
});
|
|
917
|
-
const zodFile = zodResolver.
|
|
889
|
+
const zodFile = zodResolver.file({
|
|
918
890
|
name: node.operationId,
|
|
919
891
|
extname: ".ts",
|
|
920
892
|
tag: node.tags[0] ?? "default",
|
|
921
|
-
path: node.path
|
|
922
|
-
}, {
|
|
893
|
+
path: node.path,
|
|
923
894
|
root,
|
|
924
895
|
output: pluginZod.options?.output ?? output,
|
|
925
896
|
group: pluginZod.options?.group ?? void 0
|
|
926
897
|
});
|
|
927
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? zodResolver.
|
|
898
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? zodResolver.response.body(node) : null;
|
|
928
899
|
const successStatus = findSuccessStatusCode(node.responses);
|
|
929
|
-
const responseName = successStatus ? zodResolver.
|
|
900
|
+
const responseName = successStatus ? zodResolver.response.status(node, successStatus) : null;
|
|
930
901
|
const resolveParams = (params) => params.map((p) => ({
|
|
931
902
|
name: p.name,
|
|
932
|
-
schemaName: zodResolver.
|
|
903
|
+
schemaName: zodResolver.param.name(node, p)
|
|
933
904
|
}));
|
|
934
905
|
return {
|
|
935
906
|
tool: {
|
|
@@ -938,7 +909,7 @@ const serverGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
938
909
|
description: node.description || `Make a ${node.method.toUpperCase()} request to ${node.path}`
|
|
939
910
|
},
|
|
940
911
|
mcp: {
|
|
941
|
-
name: resolver.
|
|
912
|
+
name: resolver.handler.name(node),
|
|
942
913
|
file: mcpFile
|
|
943
914
|
},
|
|
944
915
|
zod: {
|
|
@@ -975,7 +946,7 @@ const serverGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
975
946
|
baseName: serverFile.baseName,
|
|
976
947
|
path: serverFile.path,
|
|
977
948
|
meta: serverFile.meta,
|
|
978
|
-
banner: resolver.
|
|
949
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
979
950
|
output,
|
|
980
951
|
config,
|
|
981
952
|
file: {
|
|
@@ -983,7 +954,7 @@ const serverGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
983
954
|
baseName: serverFile.baseName
|
|
984
955
|
}
|
|
985
956
|
}),
|
|
986
|
-
footer: resolver.
|
|
957
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
987
958
|
output,
|
|
988
959
|
config,
|
|
989
960
|
file: {
|
|
@@ -1044,26 +1015,18 @@ const serverGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1044
1015
|
* ```ts
|
|
1045
1016
|
* import { resolverMcp } from '@kubb/plugin-mcp'
|
|
1046
1017
|
*
|
|
1047
|
-
* resolverMcp.
|
|
1018
|
+
* resolverMcp.name('addPet') // 'addPetHandler'
|
|
1048
1019
|
* ```
|
|
1049
1020
|
*/
|
|
1050
|
-
const resolverMcp = (0, kubb_kit.
|
|
1051
|
-
name: "default",
|
|
1021
|
+
const resolverMcp = (0, kubb_kit.createResolver)({
|
|
1052
1022
|
pluginName: "plugin-mcp",
|
|
1053
|
-
|
|
1054
|
-
if (type === "file") return toFilePath(name);
|
|
1023
|
+
name(name) {
|
|
1055
1024
|
return camelCase(name, { suffix: "handler" });
|
|
1056
1025
|
},
|
|
1057
|
-
|
|
1058
|
-
return this.
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
return this.default(name, type);
|
|
1062
|
-
},
|
|
1063
|
-
resolveHandlerName(node) {
|
|
1064
|
-
return this.resolveName(node.operationId);
|
|
1065
|
-
}
|
|
1066
|
-
}));
|
|
1026
|
+
handler: { name(node) {
|
|
1027
|
+
return this.name(node.operationId);
|
|
1028
|
+
} }
|
|
1029
|
+
});
|
|
1067
1030
|
//#endregion
|
|
1068
1031
|
//#region src/plugin.ts
|
|
1069
1032
|
/**
|
|
@@ -1109,10 +1072,7 @@ const pluginMcp = (0, kubb_kit.definePlugin)((options) => {
|
|
|
1109
1072
|
options,
|
|
1110
1073
|
dependencies: [_kubb_plugin_ts.pluginTsName, _kubb_plugin_zod.pluginZodName],
|
|
1111
1074
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1112
|
-
const resolver = userResolver ?
|
|
1113
|
-
...resolverMcp,
|
|
1114
|
-
...userResolver
|
|
1115
|
-
} : resolverMcp;
|
|
1075
|
+
const resolver = userResolver ? kubb_kit.Resolver.merge(resolverMcp, userResolver) : resolverMcp;
|
|
1116
1076
|
const resolvedClient = resolveClient({
|
|
1117
1077
|
client,
|
|
1118
1078
|
pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
|