@kubb/plugin-mcp 5.1.0 → 5.1.2
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/README.md +2 -2
- package/dist/index.cjs +116 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +118 -63
- package/dist/index.js.map +1 -1
- package/docs/guides/server.md +95 -0
- package/docs/options.md +79 -0
- package/docs/overview.md +44 -0
- package/kubb-extension.json +10 -3
- package/package.json +7 -7
- package/OVERVIEW.md +0 -15
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import { Resolver, Url, addGenerator, ast, createResolver,
|
|
3
|
-
import path from "node:path";
|
|
2
|
+
import { Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
3
|
+
import path, { posix } from "node:path";
|
|
4
4
|
import { Const, File, Function, jsxRenderer } from "kubb/jsx";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
6
6
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
@@ -235,6 +235,27 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
235
235
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
236
236
|
}
|
|
237
237
|
//#endregion
|
|
238
|
+
//#region ../../internals/utils/src/fs.ts
|
|
239
|
+
function toSlash(p) {
|
|
240
|
+
if (p.startsWith("\\\\?\\")) return p;
|
|
241
|
+
return p.replaceAll("\\", "/");
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Returns the relative path from `rootDir` to `filePath`, always using forward slashes
|
|
245
|
+
* and prefixed with `./` when not already traversing upward.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'
|
|
250
|
+
* getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
function getRelativePath(rootDir, filePath) {
|
|
254
|
+
if (!rootDir || !filePath) throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
255
|
+
const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath));
|
|
256
|
+
return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
238
259
|
//#region ../../internals/shared/src/group.ts
|
|
239
260
|
/**
|
|
240
261
|
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
@@ -692,11 +713,21 @@ const serverGenerator = defineGenerator({
|
|
|
692
713
|
path: path.resolve(root, output.path, "server.ts"),
|
|
693
714
|
meta: { pluginName: plugin.name }
|
|
694
715
|
};
|
|
716
|
+
const startFile = {
|
|
717
|
+
baseName: "start.ts",
|
|
718
|
+
path: path.resolve(root, output.path, "start.ts"),
|
|
719
|
+
meta: { pluginName: plugin.name }
|
|
720
|
+
};
|
|
695
721
|
const jsonFile = {
|
|
696
722
|
baseName: ".mcp.json",
|
|
697
723
|
path: path.resolve(root, output.path, ".mcp.json"),
|
|
698
724
|
meta: { pluginName: plugin.name }
|
|
699
725
|
};
|
|
726
|
+
const mcpConfig = { mcpServers: { [ctx.meta.title || "server"]: {
|
|
727
|
+
type: "stdio",
|
|
728
|
+
command: "npx",
|
|
729
|
+
args: ["tsx", getRelativePath(path.resolve(config.root), startFile.path)]
|
|
730
|
+
} } };
|
|
700
731
|
const operationsMapped = nodes.filter(ast.isHttpOperationNode).map((node) => {
|
|
701
732
|
const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node);
|
|
702
733
|
const mcpFile = resolver.file({
|
|
@@ -764,76 +795,98 @@ const serverGenerator = defineGenerator({
|
|
|
764
795
|
path: zod.file.path
|
|
765
796
|
}, `zod-${mcp.name}`)].filter(Boolean);
|
|
766
797
|
});
|
|
767
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
footer: resolver.default.footer(ctx.meta, {
|
|
780
|
-
output,
|
|
781
|
-
config,
|
|
782
|
-
file: {
|
|
783
|
-
path: serverFile.path,
|
|
784
|
-
baseName: serverFile.baseName
|
|
785
|
-
}
|
|
786
|
-
}),
|
|
787
|
-
children: [
|
|
788
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
789
|
-
name: ["McpServer"],
|
|
790
|
-
path: "@modelcontextprotocol/server"
|
|
798
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
799
|
+
/* @__PURE__ */ jsxs(File, {
|
|
800
|
+
baseName: serverFile.baseName,
|
|
801
|
+
path: serverFile.path,
|
|
802
|
+
meta: serverFile.meta,
|
|
803
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
804
|
+
output,
|
|
805
|
+
config,
|
|
806
|
+
file: {
|
|
807
|
+
path: serverFile.path,
|
|
808
|
+
baseName: serverFile.baseName
|
|
809
|
+
}
|
|
791
810
|
}),
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
811
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
812
|
+
output,
|
|
813
|
+
config,
|
|
814
|
+
file: {
|
|
815
|
+
path: serverFile.path,
|
|
816
|
+
baseName: serverFile.baseName
|
|
817
|
+
}
|
|
795
818
|
}),
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
819
|
+
children: [
|
|
820
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
821
|
+
name: ["McpServer"],
|
|
822
|
+
path: "@modelcontextprotocol/server"
|
|
823
|
+
}),
|
|
824
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
825
|
+
name: ["serveStdio"],
|
|
826
|
+
path: "@modelcontextprotocol/server/stdio"
|
|
827
|
+
}),
|
|
828
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
829
|
+
name: ["z"],
|
|
830
|
+
path: "zod"
|
|
831
|
+
}),
|
|
832
|
+
imports,
|
|
833
|
+
/* @__PURE__ */ jsx(Server, {
|
|
834
|
+
serverName: ctx.meta.title ?? "server",
|
|
835
|
+
serverVersion: ctx.meta.version ?? "0.0.0",
|
|
836
|
+
operations: operationsMapped
|
|
837
|
+
})
|
|
838
|
+
]
|
|
839
|
+
}),
|
|
840
|
+
/* @__PURE__ */ jsxs(File, {
|
|
841
|
+
baseName: startFile.baseName,
|
|
842
|
+
path: startFile.path,
|
|
843
|
+
meta: startFile.meta,
|
|
844
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
845
|
+
output,
|
|
846
|
+
config,
|
|
847
|
+
file: {
|
|
848
|
+
path: startFile.path,
|
|
849
|
+
baseName: startFile.baseName
|
|
850
|
+
}
|
|
799
851
|
}),
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
852
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
853
|
+
output,
|
|
854
|
+
config,
|
|
855
|
+
file: {
|
|
856
|
+
path: startFile.path,
|
|
857
|
+
baseName: startFile.baseName
|
|
858
|
+
}
|
|
859
|
+
}),
|
|
860
|
+
children: [/* @__PURE__ */ jsx(File.Import, {
|
|
861
|
+
name: ["startServer"],
|
|
862
|
+
root: startFile.path,
|
|
863
|
+
path: serverFile.path
|
|
864
|
+
}), /* @__PURE__ */ jsx(File.Source, {
|
|
865
|
+
name: "start",
|
|
866
|
+
children: "void startServer()"
|
|
867
|
+
})]
|
|
868
|
+
}),
|
|
869
|
+
/* @__PURE__ */ jsx(File, {
|
|
870
|
+
baseName: jsonFile.baseName,
|
|
871
|
+
path: jsonFile.path,
|
|
872
|
+
meta: jsonFile.meta,
|
|
873
|
+
children: /* @__PURE__ */ jsx(File.Source, {
|
|
874
|
+
name,
|
|
875
|
+
children: `${JSON.stringify(mcpConfig, null, 2)}\n`
|
|
805
876
|
})
|
|
806
|
-
]
|
|
807
|
-
}), /* @__PURE__ */ jsx(File, {
|
|
808
|
-
baseName: jsonFile.baseName,
|
|
809
|
-
path: jsonFile.path,
|
|
810
|
-
meta: jsonFile.meta,
|
|
811
|
-
children: /* @__PURE__ */ jsx(File.Source, {
|
|
812
|
-
name,
|
|
813
|
-
children: `
|
|
814
|
-
{
|
|
815
|
-
"mcpServers": {
|
|
816
|
-
"${ctx.meta.title || "server"}": {
|
|
817
|
-
"type": "stdio",
|
|
818
|
-
"command": "npx",
|
|
819
|
-
"args": ["tsx", "${path.relative(path.dirname(jsonFile.path), serverFile.path)}"]
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
`
|
|
824
877
|
})
|
|
825
|
-
|
|
878
|
+
] });
|
|
826
879
|
}
|
|
827
880
|
});
|
|
828
881
|
//#endregion
|
|
829
882
|
//#region kubb-extension.json
|
|
830
883
|
var compatibility = {
|
|
831
|
-
"kubb": ">=5.8.
|
|
884
|
+
"kubb": ">=5.8.3",
|
|
832
885
|
"node": ">=22"
|
|
833
886
|
};
|
|
834
887
|
//#endregion
|
|
835
888
|
//#region package.json
|
|
836
|
-
var version = "5.1.
|
|
889
|
+
var version = "5.1.2";
|
|
837
890
|
//#endregion
|
|
838
891
|
//#region src/resolvers/resolverMcp.ts
|
|
839
892
|
/**
|
|
@@ -869,12 +922,15 @@ const pluginMcpName = "plugin-mcp";
|
|
|
869
922
|
* operation becomes a typed MCP tool that AI assistants (Claude Desktop, Claude
|
|
870
923
|
* Code, MCP-compatible clients) can call directly. Each handler calls a contract
|
|
871
924
|
* client `<op>` from a registered `@kubb/plugin-axios` or `@kubb/plugin-fetch`.
|
|
925
|
+
* Next to the handlers it writes `server.ts`, a `start.ts` entry that serves the
|
|
926
|
+
* tools over stdio, and a `.mcp.json` that runs `start.ts` with `tsx`.
|
|
872
927
|
*
|
|
873
928
|
* @example
|
|
874
929
|
* ```ts
|
|
875
930
|
* import { defineConfig } from 'kubb/config'
|
|
876
931
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
877
932
|
* import { pluginZod } from '@kubb/plugin-zod'
|
|
933
|
+
* import { pluginFetch } from '@kubb/plugin-fetch'
|
|
878
934
|
* import { pluginMcp } from '@kubb/plugin-mcp'
|
|
879
935
|
*
|
|
880
936
|
* export default defineConfig({
|
|
@@ -883,15 +939,14 @@ const pluginMcpName = "plugin-mcp";
|
|
|
883
939
|
* plugins: [
|
|
884
940
|
* pluginTs(),
|
|
885
941
|
* pluginZod(),
|
|
886
|
-
*
|
|
887
|
-
*
|
|
888
|
-
* baseURL: 'https://petstore.swagger.io/v2',
|
|
889
|
-
* }),
|
|
942
|
+
* pluginFetch({ baseURL: 'https://petstore.swagger.io/v2' }),
|
|
943
|
+
* pluginMcp({ output: { path: 'mcp' } }),
|
|
890
944
|
* ],
|
|
891
945
|
* })
|
|
892
946
|
* ```
|
|
893
947
|
*/
|
|
894
|
-
const pluginMcp =
|
|
948
|
+
const pluginMcp = defineExtension({
|
|
949
|
+
kind: "plugin",
|
|
895
950
|
meta: {
|
|
896
951
|
name: pluginMcpName,
|
|
897
952
|
version,
|