@kubb/plugin-mcp 0.0.0-canary-20250414193247

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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/chunk-5AJXTSAA.cjs +179 -0
  4. package/dist/chunk-5AJXTSAA.cjs.map +1 -0
  5. package/dist/chunk-RN55DM2O.cjs +97 -0
  6. package/dist/chunk-RN55DM2O.cjs.map +1 -0
  7. package/dist/chunk-VPK2OEBV.js +95 -0
  8. package/dist/chunk-VPK2OEBV.js.map +1 -0
  9. package/dist/chunk-WEY2R35B.js +176 -0
  10. package/dist/chunk-WEY2R35B.js.map +1 -0
  11. package/dist/components.cjs +12 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +27 -0
  14. package/dist/components.d.ts +27 -0
  15. package/dist/components.js +3 -0
  16. package/dist/components.js.map +1 -0
  17. package/dist/generators.cjs +17 -0
  18. package/dist/generators.cjs.map +1 -0
  19. package/dist/generators.d.cts +11 -0
  20. package/dist/generators.d.ts +11 -0
  21. package/dist/generators.js +4 -0
  22. package/dist/generators.js.map +1 -0
  23. package/dist/index.cjs +108 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +10 -0
  26. package/dist/index.d.ts +10 -0
  27. package/dist/index.js +101 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-B4DlUSkU.d.cts +54 -0
  30. package/dist/types-B4DlUSkU.d.ts +54 -0
  31. package/package.json +117 -0
  32. package/src/components/Server.tsx +141 -0
  33. package/src/components/index.ts +1 -0
  34. package/src/generators/__snapshots__/.mcp.json +9 -0
  35. package/src/generators/__snapshots__/createPet.ts +19 -0
  36. package/src/generators/__snapshots__/deletePet.ts +18 -0
  37. package/src/generators/__snapshots__/getPets.ts +19 -0
  38. package/src/generators/__snapshots__/server.ts +37 -0
  39. package/src/generators/__snapshots__/showPetById.ts +25 -0
  40. package/src/generators/index.ts +2 -0
  41. package/src/generators/mcpGenerator.tsx +89 -0
  42. package/src/generators/serverGenerator.tsx +93 -0
  43. package/src/index.ts +2 -0
  44. package/src/plugin.ts +120 -0
  45. package/src/types.ts +54 -0
@@ -0,0 +1,176 @@
1
+ import { Server } from './chunk-VPK2OEBV.js';
2
+ import { createReactGenerator } from '@kubb/plugin-oas';
3
+ import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks';
4
+ import { getFooter, getBanner } from '@kubb/plugin-oas/utils';
5
+ import { pluginTsName } from '@kubb/plugin-ts';
6
+ import { useApp, File } from '@kubb/react';
7
+ import { Client } from '@kubb/plugin-client/components';
8
+ import { jsxs, jsx, Fragment } from '@kubb/react/jsx-runtime';
9
+ import { pluginZodName } from '@kubb/plugin-zod';
10
+
11
+ var mcpGenerator = createReactGenerator({
12
+ name: "mcp",
13
+ Operation({ operation }) {
14
+ const {
15
+ plugin: { options }
16
+ } = useApp();
17
+ const oas = useOas();
18
+ const { getSchemas, getName, getFile } = useOperationManager();
19
+ const mcp = {
20
+ name: getName(operation, { type: "function", suffix: "handler" }),
21
+ file: getFile(operation)
22
+ };
23
+ const type = {
24
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
25
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
26
+ };
27
+ return /* @__PURE__ */ jsxs(
28
+ File,
29
+ {
30
+ baseName: mcp.file.baseName,
31
+ path: mcp.file.path,
32
+ meta: mcp.file.meta,
33
+ banner: getBanner({ oas, output: options.output }),
34
+ footer: getFooter({ oas, output: options.output }),
35
+ children: [
36
+ /* @__PURE__ */ jsx(File.Import, { name: ["CallToolResult"], path: "@modelcontextprotocol/sdk/types", isTypeOnly: true }),
37
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
38
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig", "ResponseErrorConfig"], path: options.client.importPath, isTypeOnly: true }),
39
+ /* @__PURE__ */ jsx(
40
+ File.Import,
41
+ {
42
+ name: [
43
+ type.schemas.request?.name,
44
+ type.schemas.response.name,
45
+ type.schemas.pathParams?.name,
46
+ type.schemas.queryParams?.name,
47
+ type.schemas.headerParams?.name,
48
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
49
+ ].filter(Boolean),
50
+ root: mcp.file.path,
51
+ path: type.file.path,
52
+ isTypeOnly: true
53
+ }
54
+ ),
55
+ /* @__PURE__ */ jsxs(
56
+ Client,
57
+ {
58
+ name: mcp.name,
59
+ isConfigurable: false,
60
+ returnType: "Promise<CallToolResult>",
61
+ baseURL: options.client.baseURL,
62
+ operation,
63
+ typeSchemas: type.schemas,
64
+ zodSchemas: void 0,
65
+ dataReturnType: options.client.dataReturnType,
66
+ paramsType: "object",
67
+ paramsCasing: "camelcase",
68
+ pathParamsType: "object",
69
+ parser: "client",
70
+ children: [
71
+ options.client.dataReturnType === "data" && `return {
72
+ content: [
73
+ {
74
+ type: 'text',
75
+ text: JSON.stringify(res.data)
76
+ }
77
+ ]
78
+ }`,
79
+ options.client.dataReturnType === "full" && `return {
80
+ content: [
81
+ {
82
+ type: 'text',
83
+ text: JSON.stringify(res)
84
+ }
85
+ ]
86
+ }`
87
+ ]
88
+ }
89
+ )
90
+ ]
91
+ }
92
+ );
93
+ }
94
+ });
95
+ var serverGenerator = createReactGenerator({
96
+ name: "operations",
97
+ Operations({ operations, options }) {
98
+ const { pluginManager, plugin } = useApp();
99
+ const oas = useOas();
100
+ const { getFile, getName, getSchemas } = useOperationManager();
101
+ const name = "server";
102
+ const file = pluginManager.getFile({ name, extname: ".ts", pluginKey: plugin.key });
103
+ const jsonFile = pluginManager.getFile({ name: ".mcp", extname: ".json", pluginKey: plugin.key });
104
+ const operationsMapped = operations.map((operation) => {
105
+ return {
106
+ operationId: operation.getOperationId(),
107
+ description: operation.getDescription(),
108
+ mcp: {
109
+ name: getName(operation, {
110
+ type: "function",
111
+ suffix: "handler"
112
+ }),
113
+ file: getFile(operation)
114
+ },
115
+ zod: {
116
+ name: getName(operation, {
117
+ type: "function",
118
+ pluginKey: [pluginZodName]
119
+ }),
120
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" }),
121
+ file: getFile(operation, { pluginKey: [pluginZodName] })
122
+ },
123
+ type: {
124
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
125
+ }
126
+ };
127
+ });
128
+ const imports = operationsMapped.flatMap(({ mcp, zod }) => {
129
+ return [
130
+ /* @__PURE__ */ jsx(File.Import, { name: [mcp.name], root: file.path, path: mcp.file.path }, mcp.name),
131
+ /* @__PURE__ */ jsx(
132
+ File.Import,
133
+ {
134
+ name: [zod.schemas.request?.name, zod.schemas.pathParams?.name, zod.schemas.queryParams?.name, zod.schemas.headerParams?.name].filter(Boolean),
135
+ root: file.path,
136
+ path: zod.file.path
137
+ },
138
+ zod.name
139
+ )
140
+ ];
141
+ });
142
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
143
+ /* @__PURE__ */ jsxs(
144
+ File,
145
+ {
146
+ baseName: file.baseName,
147
+ path: file.path,
148
+ meta: file.meta,
149
+ banner: getBanner({ oas, output: options.output, config: pluginManager.config }),
150
+ footer: getFooter({ oas, output: options.output }),
151
+ children: [
152
+ /* @__PURE__ */ jsx(File.Import, { name: ["McpServer"], path: "@modelcontextprotocol/sdk/server/mcp" }),
153
+ /* @__PURE__ */ jsx(File.Import, { name: ["StdioServerTransport"], path: "@modelcontextprotocol/sdk/server/stdio" }),
154
+ imports,
155
+ /* @__PURE__ */ jsx(Server, { name, serverName: oas.api.info?.title, serverVersion: oas.getVersion(), operations: operationsMapped })
156
+ ]
157
+ }
158
+ ),
159
+ /* @__PURE__ */ jsx(File, { baseName: jsonFile.baseName, path: jsonFile.path, meta: jsonFile.meta, children: /* @__PURE__ */ jsx(File.Source, { name, children: `
160
+ {
161
+ "mcpServers": {
162
+ "${oas.api.info?.title || "server"}": {
163
+ "type": "stdio",
164
+ "command": "npx",
165
+ "args": ["tsx", "${file.path}"]
166
+ }
167
+ }
168
+ }
169
+ ` }) })
170
+ ] });
171
+ }
172
+ });
173
+
174
+ export { mcpGenerator, serverGenerator };
175
+ //# sourceMappingURL=chunk-WEY2R35B.js.map
176
+ //# sourceMappingURL=chunk-WEY2R35B.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","pluginTsName","jsx","File","jsxs","getBanner","getFooter"],"mappings":";;;;;;;;;;AAQO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAA,EAAQ,EAAE,OAAQ;AAAA,QAChB,MAAkB,EAAA;AACtB,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,GAAM,GAAA;AAAA,MACV,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,MAAM,UAAY,EAAA,MAAA,EAAQ,WAAW,CAAA;AAAA,MAChE,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,YAAY,GAAG,CAAA;AAAA,MACtD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAAC,YAAY,CAAA,EAAG,IAAM,EAAA,MAAA,EAAQ;AAAA,KAC5E;AAEA,IACE,uBAAA,IAAA;AAAA,MAAC,IAAA;AAAA,MAAA;AAAA,QACC,QAAA,EAAU,IAAI,IAAK,CAAA,QAAA;AAAA,QACnB,IAAA,EAAM,IAAI,IAAK,CAAA,IAAA;AAAA,QACf,IAAA,EAAM,IAAI,IAAK,CAAA,IAAA;AAA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AM,CAAC,sBAAsB,CAAG,EAAA,IAAA,EAAM,wCAA0C,EAAA,CAAA;AAAA,YAE5F,OAAA;AAAA,4BACDD,GAAAA,CAAC,MAAO,EAAA,EAAA,IAAA,EAAY,YAAY,GAAI,CAAA,GAAA,CAAI,IAAM,EAAA,KAAA,EAAO,aAAe,EAAA,GAAA,CAAI,UAAW,EAAA,EAAG,YAAY,gBAAkB,EAAA;AAAA;AAAA;AAAA,OACtH;AAAA,sBAEAA,GAACC,CAAAA,IAAAA,EAAA,EAAK,QAAU,EAAA,QAAA,CAAS,UAAU,IAAM,EAAA,QAAA,CAAS,IAAM,EAAA,IAAA,EAAM,SAAS,IACrE,EAAA,QAAA,kBAAAD,IAACC,IAAK,CAAA,MAAA,EAAL,EAAY,IACV,EAAA,QAAA,EAAA;AAAA;AAAA;AAAA,eAAA,EAGI,GAAI,CAAA,GAAA,CAAI,IAAM,EAAA,KAAA,IAAS,QAAQ,CAAA;AAAA;AAAA;AAAA,iCAAA,EAGb,KAAK,IAAI,CAAA;AAAA;AAAA;AAAA;AAAA,UAAA,CAAA,EAKlC,CACF,EAAA;AAAA,KACF,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-WEY2R35B.js","sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport type { PluginMcp } from '../types'\nimport { Client } from '@kubb/plugin-client/components'\n\nexport const mcpGenerator = createReactGenerator<PluginMcp>({\n name: 'mcp',\n Operation({ operation }) {\n const {\n plugin: { options },\n } = useApp<PluginMcp>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mcp = {\n name: getName(operation, { type: 'function', suffix: 'handler' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File\n baseName={mcp.file.baseName}\n path={mcp.file.path}\n meta={mcp.file.meta}\n banner={getBanner({ oas, output: options.output })}\n footer={getFooter({ oas, output: options.output })}\n >\n <File.Import name={['CallToolResult']} path={'@modelcontextprotocol/sdk/types'} isTypeOnly />\n <File.Import name={'client'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={mcp.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <Client\n name={mcp.name}\n isConfigurable={false}\n returnType={'Promise<CallToolResult>'}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={undefined}\n dataReturnType={options.client.dataReturnType}\n paramsType={'object'}\n paramsCasing={'camelcase'}\n pathParamsType={'object'}\n parser={'client'}\n >\n {options.client.dataReturnType === 'data' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res.data)\n }\n ]\n }`}\n {options.client.dataReturnType === 'full' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res)\n }\n ]\n }`}\n </Client>\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Server } from '../components/Server'\nimport type { PluginMcp } from '../types'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nexport const serverGenerator = createReactGenerator<PluginMcp>({\n name: 'operations',\n Operations({ operations, options }) {\n const { pluginManager, plugin } = useApp<PluginMcp>()\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager()\n\n const name = 'server'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: plugin.key })\n\n const jsonFile = pluginManager.getFile({ name: '.mcp', extname: '.json', pluginKey: plugin.key })\n\n const operationsMapped = operations.map((operation) => {\n return {\n operationId: operation.getOperationId(),\n description: operation.getDescription(),\n mcp: {\n name: getName(operation, {\n type: 'function',\n suffix: 'handler',\n }),\n file: getFile(operation),\n },\n zod: {\n name: getName(operation, {\n type: 'function',\n pluginKey: [pluginZodName],\n }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n },\n type: {\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n },\n }\n })\n\n const imports = operationsMapped.flatMap(({ mcp, zod }) => {\n return [\n <File.Import key={mcp.name} name={[mcp.name]} root={file.path} path={mcp.file.path} />,\n <File.Import\n key={zod.name}\n name={[zod.schemas.request?.name, zod.schemas.pathParams?.name, zod.schemas.queryParams?.name, zod.schemas.headerParams?.name].filter(Boolean)}\n root={file.path}\n path={zod.file.path}\n />,\n ]\n })\n\n return (\n <>\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: options.output })}\n >\n <File.Import name={['McpServer']} path={'@modelcontextprotocol/sdk/server/mcp'} />\n <File.Import name={['StdioServerTransport']} path={'@modelcontextprotocol/sdk/server/stdio'} />\n\n {imports}\n <Server name={name} serverName={oas.api.info?.title} serverVersion={oas.getVersion()} operations={operationsMapped} />\n </File>\n\n <File baseName={jsonFile.baseName} path={jsonFile.path} meta={jsonFile.meta}>\n <File.Source name={name}>\n {`\n {\n \"mcpServers\": {\n \"${oas.api.info?.title || 'server'}\": {\n \"type\": \"stdio\",\n \"command\": \"npx\",\n \"args\": [\"tsx\", \"${file.path}\"]\n }\n }\n }\n `}\n </File.Source>\n </File>\n </>\n )\n },\n})\n"]}
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var chunkRN55DM2O_cjs = require('./chunk-RN55DM2O.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "Server", {
8
+ enumerable: true,
9
+ get: function () { return chunkRN55DM2O_cjs.Server; }
10
+ });
11
+ //# sourceMappingURL=components.cjs.map
12
+ //# sourceMappingURL=components.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"components.cjs"}
@@ -0,0 +1,27 @@
1
+ import * as KubbFile from '@kubb/fs/types';
2
+ import { OperationSchemas } from '@kubb/plugin-oas';
3
+
4
+ type Props = {
5
+ name: string;
6
+ serverName: string;
7
+ serverVersion: string;
8
+ operations: Array<{
9
+ operationId: string;
10
+ description?: string;
11
+ mcp: {
12
+ name: string;
13
+ file: KubbFile.File;
14
+ };
15
+ zod: {
16
+ name: string;
17
+ file: KubbFile.File;
18
+ schemas: OperationSchemas;
19
+ };
20
+ type: {
21
+ schemas: OperationSchemas;
22
+ };
23
+ }>;
24
+ };
25
+ declare function Server({ name, serverName, serverVersion, operations }: Props): any;
26
+
27
+ export { Server };
@@ -0,0 +1,27 @@
1
+ import * as KubbFile from '@kubb/fs/types';
2
+ import { OperationSchemas } from '@kubb/plugin-oas';
3
+
4
+ type Props = {
5
+ name: string;
6
+ serverName: string;
7
+ serverVersion: string;
8
+ operations: Array<{
9
+ operationId: string;
10
+ description?: string;
11
+ mcp: {
12
+ name: string;
13
+ file: KubbFile.File;
14
+ };
15
+ zod: {
16
+ name: string;
17
+ file: KubbFile.File;
18
+ schemas: OperationSchemas;
19
+ };
20
+ type: {
21
+ schemas: OperationSchemas;
22
+ };
23
+ }>;
24
+ };
25
+ declare function Server({ name, serverName, serverVersion, operations }: Props): any;
26
+
27
+ export { Server };
@@ -0,0 +1,3 @@
1
+ export { Server } from './chunk-VPK2OEBV.js';
2
+ //# sourceMappingURL=components.js.map
3
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"components.js"}
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var chunk5AJXTSAA_cjs = require('./chunk-5AJXTSAA.cjs');
4
+ require('./chunk-RN55DM2O.cjs');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, "mcpGenerator", {
9
+ enumerable: true,
10
+ get: function () { return chunk5AJXTSAA_cjs.mcpGenerator; }
11
+ });
12
+ Object.defineProperty(exports, "serverGenerator", {
13
+ enumerable: true,
14
+ get: function () { return chunk5AJXTSAA_cjs.serverGenerator; }
15
+ });
16
+ //# sourceMappingURL=generators.cjs.map
17
+ //# sourceMappingURL=generators.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"generators.cjs"}
@@ -0,0 +1,11 @@
1
+ import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
+ import { P as PluginMcp } from './types-B4DlUSkU.cjs';
3
+ import '@kubb/core';
4
+ import '@kubb/oas';
5
+ import '@kubb/plugin-client';
6
+
7
+ declare const mcpGenerator: _kubb_plugin_oas.Generator<PluginMcp>;
8
+
9
+ declare const serverGenerator: _kubb_plugin_oas.Generator<PluginMcp>;
10
+
11
+ export { mcpGenerator, serverGenerator };
@@ -0,0 +1,11 @@
1
+ import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
+ import { P as PluginMcp } from './types-B4DlUSkU.js';
3
+ import '@kubb/core';
4
+ import '@kubb/oas';
5
+ import '@kubb/plugin-client';
6
+
7
+ declare const mcpGenerator: _kubb_plugin_oas.Generator<PluginMcp>;
8
+
9
+ declare const serverGenerator: _kubb_plugin_oas.Generator<PluginMcp>;
10
+
11
+ export { mcpGenerator, serverGenerator };
@@ -0,0 +1,4 @@
1
+ export { mcpGenerator, serverGenerator } from './chunk-WEY2R35B.js';
2
+ import './chunk-VPK2OEBV.js';
3
+ //# sourceMappingURL=generators.js.map
4
+ //# sourceMappingURL=generators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
package/dist/index.cjs ADDED
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ var chunk5AJXTSAA_cjs = require('./chunk-5AJXTSAA.cjs');
4
+ require('./chunk-RN55DM2O.cjs');
5
+ var path = require('path');
6
+ var core = require('@kubb/core');
7
+ var transformers = require('@kubb/core/transformers');
8
+ var pluginOas = require('@kubb/plugin-oas');
9
+ var pluginTs = require('@kubb/plugin-ts');
10
+ var pluginZod = require('@kubb/plugin-zod');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var path__default = /*#__PURE__*/_interopDefault(path);
15
+
16
+ var pluginMcpName = "plugin-mcp";
17
+ var pluginMcp = core.createPlugin((options) => {
18
+ const {
19
+ output = { path: "mcp", barrelType: "named" },
20
+ group,
21
+ exclude = [],
22
+ include,
23
+ override = [],
24
+ transformers: transformers$1 = {},
25
+ generators = [chunk5AJXTSAA_cjs.mcpGenerator, chunk5AJXTSAA_cjs.serverGenerator].filter(Boolean),
26
+ contentType
27
+ } = options;
28
+ return {
29
+ name: pluginMcpName,
30
+ options: {
31
+ output,
32
+ group,
33
+ client: {
34
+ importPath: "@kubb/plugin-client/clients/axios",
35
+ dataReturnType: "data",
36
+ ...options.client
37
+ }
38
+ },
39
+ pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, pluginZod.pluginZodName].filter(Boolean),
40
+ resolvePath(baseName, pathMode, options2) {
41
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
42
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
43
+ if (mode === "single") {
44
+ return path__default.default.resolve(root, output.path);
45
+ }
46
+ if (group && (options2?.group?.path || options2?.group?.tag)) {
47
+ const groupName = group?.name ? group.name : (ctx) => {
48
+ if (group?.type === "path") {
49
+ return `${ctx.group.split("/")[1]}`;
50
+ }
51
+ return `${transformers.camelCase(ctx.group)}Requests`;
52
+ };
53
+ return path__default.default.resolve(
54
+ root,
55
+ output.path,
56
+ groupName({
57
+ group: group.type === "path" ? options2.group.path : options2.group.tag
58
+ }),
59
+ baseName
60
+ );
61
+ }
62
+ return path__default.default.resolve(root, output.path, baseName);
63
+ },
64
+ resolveName(name, type) {
65
+ const resolvedName = transformers.camelCase(name, {
66
+ isFile: type === "file"
67
+ });
68
+ if (type) {
69
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
70
+ }
71
+ return resolvedName;
72
+ },
73
+ async buildStart() {
74
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
75
+ const oas = await swaggerPlugin.context.getOas();
76
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
77
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
78
+ const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
79
+ oas,
80
+ pluginManager: this.pluginManager,
81
+ plugin: this.plugin,
82
+ contentType,
83
+ exclude,
84
+ include,
85
+ override,
86
+ mode
87
+ });
88
+ const files = await operationGenerator.build(...generators);
89
+ await this.addFile(...files);
90
+ const barrelFiles = await this.fileManager.getBarrelFiles({
91
+ type: output.barrelType ?? "named",
92
+ root,
93
+ output,
94
+ files: this.fileManager.files,
95
+ meta: {
96
+ pluginKey: this.plugin.key
97
+ },
98
+ logger: this.logger
99
+ });
100
+ await this.addFile(...barrelFiles);
101
+ }
102
+ };
103
+ });
104
+
105
+ exports.pluginMcp = pluginMcp;
106
+ exports.pluginMcpName = pluginMcpName;
107
+ //# sourceMappingURL=index.cjs.map
108
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","mcpGenerator","serverGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;AAaO,IAAM,aAAgB,GAAA;AAEhB,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AAA,GAAOI,sBAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AACnE,MAAM,MAAA,IAAA,GAAOC,iBAAY,OAAQ,CAAAD,qBAAA,CAAK,QAAQ,IAAM,EAAA,MAAA,CAAO,IAAI,CAAC,CAAA;AAEhE,MAAA,MAAM,kBAAqB,GAAA,IAAII,4BAAmB,CAAA,IAAA,CAAK,OAAO,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA;AAAA,QACA,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { mcpGenerator, serverGenerator } from './generators'\nimport type { PluginMcp } from './types.ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\nexport const pluginMcp = createPlugin<PluginMcp>((options) => {\n const {\n output = { path: 'mcp', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n generators = [mcpGenerator, serverGenerator].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginMcpName,\n options: {\n output,\n group,\n client: {\n importPath: '@kubb/plugin-client/clients/axios',\n dataReturnType: 'data',\n ...options.client,\n },\n },\n pre: [pluginOasName, pluginTsName, pluginZodName].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Requests`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
@@ -0,0 +1,10 @@
1
+ import * as _kubb_core from '@kubb/core';
2
+ import { O as Options, P as PluginMcp } from './types-B4DlUSkU.cjs';
3
+ import '@kubb/oas';
4
+ import '@kubb/plugin-oas';
5
+ import '@kubb/plugin-client';
6
+
7
+ declare const pluginMcpName = "plugin-mcp";
8
+ declare const pluginMcp: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginMcp>;
9
+
10
+ export { PluginMcp, pluginMcp, pluginMcpName };
@@ -0,0 +1,10 @@
1
+ import * as _kubb_core from '@kubb/core';
2
+ import { O as Options, P as PluginMcp } from './types-B4DlUSkU.js';
3
+ import '@kubb/oas';
4
+ import '@kubb/plugin-oas';
5
+ import '@kubb/plugin-client';
6
+
7
+ declare const pluginMcpName = "plugin-mcp";
8
+ declare const pluginMcp: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginMcp>;
9
+
10
+ export { PluginMcp, pluginMcp, pluginMcpName };
package/dist/index.js ADDED
@@ -0,0 +1,101 @@
1
+ import { mcpGenerator, serverGenerator } from './chunk-WEY2R35B.js';
2
+ import './chunk-VPK2OEBV.js';
3
+ import path from 'node:path';
4
+ import { createPlugin, PluginManager, FileManager } from '@kubb/core';
5
+ import { camelCase } from '@kubb/core/transformers';
6
+ import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
7
+ import { pluginTsName } from '@kubb/plugin-ts';
8
+ import { pluginZodName } from '@kubb/plugin-zod';
9
+
10
+ var pluginMcpName = "plugin-mcp";
11
+ var pluginMcp = createPlugin((options) => {
12
+ const {
13
+ output = { path: "mcp", barrelType: "named" },
14
+ group,
15
+ exclude = [],
16
+ include,
17
+ override = [],
18
+ transformers = {},
19
+ generators = [mcpGenerator, serverGenerator].filter(Boolean),
20
+ contentType
21
+ } = options;
22
+ return {
23
+ name: pluginMcpName,
24
+ options: {
25
+ output,
26
+ group,
27
+ client: {
28
+ importPath: "@kubb/plugin-client/clients/axios",
29
+ dataReturnType: "data",
30
+ ...options.client
31
+ }
32
+ },
33
+ pre: [pluginOasName, pluginTsName, pluginZodName].filter(Boolean),
34
+ resolvePath(baseName, pathMode, options2) {
35
+ const root = path.resolve(this.config.root, this.config.output.path);
36
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
37
+ if (mode === "single") {
38
+ return path.resolve(root, output.path);
39
+ }
40
+ if (group && (options2?.group?.path || options2?.group?.tag)) {
41
+ const groupName = group?.name ? group.name : (ctx) => {
42
+ if (group?.type === "path") {
43
+ return `${ctx.group.split("/")[1]}`;
44
+ }
45
+ return `${camelCase(ctx.group)}Requests`;
46
+ };
47
+ return path.resolve(
48
+ root,
49
+ output.path,
50
+ groupName({
51
+ group: group.type === "path" ? options2.group.path : options2.group.tag
52
+ }),
53
+ baseName
54
+ );
55
+ }
56
+ return path.resolve(root, output.path, baseName);
57
+ },
58
+ resolveName(name, type) {
59
+ const resolvedName = camelCase(name, {
60
+ isFile: type === "file"
61
+ });
62
+ if (type) {
63
+ return transformers?.name?.(resolvedName, type) || resolvedName;
64
+ }
65
+ return resolvedName;
66
+ },
67
+ async buildStart() {
68
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
69
+ const oas = await swaggerPlugin.context.getOas();
70
+ const root = path.resolve(this.config.root, this.config.output.path);
71
+ const mode = FileManager.getMode(path.resolve(root, output.path));
72
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
73
+ oas,
74
+ pluginManager: this.pluginManager,
75
+ plugin: this.plugin,
76
+ contentType,
77
+ exclude,
78
+ include,
79
+ override,
80
+ mode
81
+ });
82
+ const files = await operationGenerator.build(...generators);
83
+ await this.addFile(...files);
84
+ const barrelFiles = await this.fileManager.getBarrelFiles({
85
+ type: output.barrelType ?? "named",
86
+ root,
87
+ output,
88
+ files: this.fileManager.files,
89
+ meta: {
90
+ pluginKey: this.plugin.key
91
+ },
92
+ logger: this.logger
93
+ });
94
+ await this.addFile(...barrelFiles);
95
+ }
96
+ };
97
+ });
98
+
99
+ export { pluginMcp, pluginMcpName };
100
+ //# sourceMappingURL=index.js.map
101
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;AAaO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAY,YAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,KAAA,EAAO,YAAY,OAAQ,EAAA;AAAA,IAC5C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,eAAe,EAAC;AAAA,IAChB,aAAa,CAAC,YAAA,EAAc,eAAe,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IAC3D;AAAA,GACE,GAAA,OAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,aAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,KAAA;AAAA,MACA,MAAQ,EAAA;AAAA,QACN,UAAY,EAAA,mCAAA;AAAA,QACZ,cAAgB,EAAA,MAAA;AAAA,QAChB,GAAG,OAAQ,CAAA;AAAA;AACb,KACF;AAAA,IACA,KAAK,CAAC,aAAA,EAAe,cAAc,aAAa,CAAA,CAAE,OAAO,OAAO,CAAA;A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A,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { mcpGenerator, serverGenerator } from './generators'\nimport type { PluginMcp } from './types.ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\nexport const pluginMcp = createPlugin<PluginMcp>((options) => {\n const {\n output = { path: 'mcp', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n generators = [mcpGenerator, serverGenerator].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginMcpName,\n options: {\n output,\n group,\n client: {\n importPath: '@kubb/plugin-client/clients/axios',\n dataReturnType: 'data',\n ...options.client,\n },\n },\n pre: [pluginOasName, pluginTsName, pluginZodName].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Requests`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}