@kubb/plugin-mcp 4.12.3 → 4.12.4
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/{Server-CcPgHZ7c.cjs → Server-C21K-hQk.cjs} +17 -17
- package/dist/{Server-CcPgHZ7c.cjs.map → Server-C21K-hQk.cjs.map} +1 -1
- package/dist/components.cjs +1 -1
- package/dist/{generators-CG99elMi.cjs → generators-qFP0erXA.cjs} +49 -49
- package/dist/{generators-CG99elMi.cjs.map → generators-qFP0erXA.cjs.map} +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/index.cjs +21 -21
- package/dist/index.cjs.map +1 -1
- package/package.json +8 -8
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
const require_generators = require('./generators-
|
|
2
|
-
let
|
|
3
|
-
let
|
|
4
|
-
let
|
|
5
|
-
let
|
|
6
|
-
let
|
|
1
|
+
const require_generators = require('./generators-qFP0erXA.cjs');
|
|
2
|
+
let _kubb_core_transformers = require("@kubb/core/transformers");
|
|
3
|
+
let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
|
|
4
|
+
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
5
|
+
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
6
|
+
let _kubb_oas = require("@kubb/oas");
|
|
7
7
|
|
|
8
8
|
//#region src/components/Server.tsx
|
|
9
9
|
function getParams({ schemas }) {
|
|
10
|
-
const pathParams = (0,
|
|
11
|
-
return
|
|
10
|
+
const pathParams = (0, _kubb_plugin_oas_utils.getPathParams)(schemas.pathParams, { typed: false });
|
|
11
|
+
return _kubb_react_fabric.FunctionParams.factory({ data: {
|
|
12
12
|
mode: "object",
|
|
13
13
|
children: {
|
|
14
14
|
...Object.entries(pathParams).reduce((acc, [key, param]) => {
|
|
15
15
|
if (param && schemas.pathParams?.name) {
|
|
16
16
|
let suffix = ".shape";
|
|
17
|
-
if ((0,
|
|
17
|
+
if ((0, _kubb_oas.isNullable)(schemas.pathParams.schema)) if ((0, _kubb_oas.isReference)(schemas.pathParams)) suffix = ".unwrap().schema.unwrap().shape";
|
|
18
18
|
else suffix = ".unwrap().shape";
|
|
19
|
-
else if ((0,
|
|
19
|
+
else if ((0, _kubb_oas.isReference)(schemas.pathParams)) suffix = ".schema.shape";
|
|
20
20
|
param.value = `${schemas.pathParams?.name}${suffix}['${key}']`;
|
|
21
21
|
}
|
|
22
22
|
return {
|
|
23
23
|
...acc,
|
|
24
|
-
[(0,
|
|
24
|
+
[(0, _kubb_core_transformers.camelCase)(key)]: param
|
|
25
25
|
};
|
|
26
26
|
}, {}),
|
|
27
27
|
data: schemas.request?.name ? {
|
|
28
28
|
value: schemas.request?.name,
|
|
29
|
-
optional: (0,
|
|
29
|
+
optional: (0, _kubb_plugin_oas_utils.isOptional)(schemas.request?.schema)
|
|
30
30
|
} : void 0,
|
|
31
31
|
params: schemas.queryParams?.name ? {
|
|
32
32
|
value: schemas.queryParams?.name,
|
|
33
|
-
optional: (0,
|
|
33
|
+
optional: (0, _kubb_plugin_oas_utils.isOptional)(schemas.queryParams?.schema)
|
|
34
34
|
} : void 0,
|
|
35
35
|
headers: schemas.headerParams?.name ? {
|
|
36
36
|
value: schemas.headerParams?.name,
|
|
37
|
-
optional: (0,
|
|
37
|
+
optional: (0, _kubb_plugin_oas_utils.isOptional)(schemas.headerParams?.schema)
|
|
38
38
|
} : void 0
|
|
39
39
|
}
|
|
40
40
|
} });
|
|
41
41
|
}
|
|
42
42
|
function Server({ name, serverName, serverVersion, operations }) {
|
|
43
|
-
return /* @__PURE__ */ (0,
|
|
43
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File.Source, {
|
|
44
44
|
name,
|
|
45
45
|
isExportable: true,
|
|
46
46
|
isIndexable: true,
|
|
47
47
|
children: [
|
|
48
|
-
/* @__PURE__ */ (0,
|
|
48
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
|
|
49
49
|
name: "server",
|
|
50
50
|
export: true,
|
|
51
51
|
children: `
|
|
@@ -93,4 +93,4 @@ Object.defineProperty(exports, 'Server', {
|
|
|
93
93
|
return Server;
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
|
-
//# sourceMappingURL=Server-
|
|
96
|
+
//# sourceMappingURL=Server-C21K-hQk.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server-
|
|
1
|
+
{"version":3,"file":"Server-C21K-hQk.cjs","names":["FunctionParams","File","Const"],"sources":["../src/components/Server.tsx"],"sourcesContent":["import { camelCase } from '@kubb/core/transformers'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { isNullable, isReference } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getPathParams, isOptional } from '@kubb/plugin-oas/utils'\nimport { Const, File, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n name: string\n serverName: string\n serverVersion: string\n operations: Array<{\n tool: {\n name: string\n description: string\n }\n mcp: {\n name: string\n file: KubbFile.File\n }\n zod: {\n name: string\n file: KubbFile.File\n schemas: OperationSchemas\n }\n type: {\n schemas: OperationSchemas\n }\n }>\n}\n\ntype GetParamsProps = {\n schemas: OperationSchemas\n}\n\nfunction getParams({ schemas }: GetParamsProps) {\n const pathParams = getPathParams(schemas.pathParams, {\n typed: false,\n })\n\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...Object.entries(pathParams).reduce((acc, [key, param]) => {\n if (param && schemas.pathParams?.name) {\n let suffix = '.shape'\n\n if (isNullable(schemas.pathParams.schema)) {\n if (isReference(schemas.pathParams)) {\n suffix = '.unwrap().schema.unwrap().shape'\n } else {\n suffix = '.unwrap().shape'\n }\n } else {\n if (isReference(schemas.pathParams)) {\n suffix = '.schema.shape'\n }\n }\n\n param.value = `${schemas.pathParams?.name}${suffix}['${key}']`\n }\n\n return {\n ...acc,\n [camelCase(key)]: param,\n }\n }, {}),\n data: schemas.request?.name\n ? {\n value: schemas.request?.name,\n optional: isOptional(schemas.request?.schema),\n }\n : undefined,\n params: schemas.queryParams?.name\n ? {\n value: schemas.queryParams?.name,\n optional: isOptional(schemas.queryParams?.schema),\n }\n : undefined,\n headers: schemas.headerParams?.name\n ? {\n value: schemas.headerParams?.name,\n optional: isOptional(schemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n })\n}\n\nexport function Server({ name, serverName, serverVersion, operations }: Props): KubbNode {\n return (\n <File.Source name={name} isExportable isIndexable>\n <Const name={'server'} export>\n {`\n new McpServer({\n name: '${serverName}',\n version: '${serverVersion}',\n})\n `}\n </Const>\n\n {operations\n .map(({ tool, mcp, zod }) => {\n const paramsClient = getParams({ schemas: zod.schemas })\n\n if (zod.schemas.request?.name || zod.schemas.headerParams?.name || zod.schemas.queryParams?.name || zod.schemas.pathParams?.name) {\n return `\nserver.tool(${JSON.stringify(tool.name)}, ${JSON.stringify(tool.description)}, ${paramsClient.toObjectValue()}, async (${paramsClient.toObject()}) => {\n return ${mcp.name}(${paramsClient.toObject()})\n})\n `\n }\n\n return `\nserver.tool(${JSON.stringify(tool.name)}, ${JSON.stringify(tool.description)}, async () => {\n return ${mcp.name}(${paramsClient.toObject()})\n})\n `\n })\n .filter(Boolean)}\n\n {`\nasync function startServer() {\n try {\n const transport = new StdioServerTransport()\n await server.connect(transport)\n\n } catch (error) {\n console.error('Failed to start server:', error)\n process.exit(1)\n }\n}\n\nstartServer()\n`}\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;AAoCA,SAAS,UAAU,EAAE,WAA2B;CAC9C,MAAM,uDAA2B,QAAQ,YAAY,EACnD,OAAO,OACR,CAAC;AAEF,QAAOA,kCAAe,QAAQ,EAC5B,MAAM;EACJ,MAAM;EACN,UAAU;GACR,GAAG,OAAO,QAAQ,WAAW,CAAC,QAAQ,KAAK,CAAC,KAAK,W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AAI,KAAK,UAAU,KAAK,YAAY,CAAC;WAClE,IAAI,KAAK,GAAG,aAAa,UAAU,CAAC;;;KAGrC,CACD,OAAO,QAAQ;GAEjB;;;;;;;;;;;;;;;GAcW"}
|
package/dist/components.cjs
CHANGED
|
@@ -25,26 +25,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
const require_Server = require('./Server-
|
|
28
|
+
const require_Server = require('./Server-C21K-hQk.cjs');
|
|
29
29
|
let node_path = require("node:path");
|
|
30
30
|
node_path = __toESM(node_path);
|
|
31
|
-
let
|
|
32
|
-
let
|
|
33
|
-
let
|
|
34
|
-
let
|
|
35
|
-
let
|
|
36
|
-
let
|
|
37
|
-
let
|
|
38
|
-
let
|
|
39
|
-
let
|
|
31
|
+
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
32
|
+
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
33
|
+
let _kubb_plugin_client_components = require("@kubb/plugin-client/components");
|
|
34
|
+
let _kubb_plugin_oas_generators = require("@kubb/plugin-oas/generators");
|
|
35
|
+
let _kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
|
|
36
|
+
let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
|
|
37
|
+
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
38
|
+
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
39
|
+
let _kubb_core_hooks = require("@kubb/core/hooks");
|
|
40
40
|
|
|
41
41
|
//#region src/generators/mcpGenerator.tsx
|
|
42
|
-
const mcpGenerator = (0,
|
|
42
|
+
const mcpGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
43
43
|
name: "mcp",
|
|
44
44
|
Operation({ config, operation, generator, plugin }) {
|
|
45
45
|
const { options } = plugin;
|
|
46
|
-
const oas = (0,
|
|
47
|
-
const { getSchemas, getName, getFile } = (0,
|
|
46
|
+
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
47
|
+
const { getSchemas, getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
48
48
|
const mcp = {
|
|
49
49
|
name: getName(operation, {
|
|
50
50
|
type: "function",
|
|
@@ -53,70 +53,70 @@ const mcpGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
53
53
|
file: getFile(operation)
|
|
54
54
|
};
|
|
55
55
|
const type = {
|
|
56
|
-
file: getFile(operation, { pluginKey: [
|
|
56
|
+
file: getFile(operation, { pluginKey: [_kubb_plugin_ts.pluginTsName] }),
|
|
57
57
|
schemas: getSchemas(operation, {
|
|
58
|
-
pluginKey: [
|
|
58
|
+
pluginKey: [_kubb_plugin_ts.pluginTsName],
|
|
59
59
|
type: "type"
|
|
60
60
|
})
|
|
61
61
|
};
|
|
62
|
-
return /* @__PURE__ */ (0,
|
|
62
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
63
63
|
baseName: mcp.file.baseName,
|
|
64
64
|
path: mcp.file.path,
|
|
65
65
|
meta: mcp.file.meta,
|
|
66
|
-
banner: (0,
|
|
66
|
+
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
67
67
|
oas,
|
|
68
68
|
output: options.output
|
|
69
69
|
}),
|
|
70
|
-
footer: (0,
|
|
70
|
+
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
71
71
|
oas,
|
|
72
72
|
output: options.output
|
|
73
73
|
}),
|
|
74
74
|
children: [
|
|
75
|
-
options.client.importPath ? /* @__PURE__ */ (0,
|
|
76
|
-
/* @__PURE__ */ (0,
|
|
75
|
+
options.client.importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
|
|
76
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
77
77
|
name: "fetch",
|
|
78
78
|
path: options.client.importPath
|
|
79
79
|
}),
|
|
80
|
-
/* @__PURE__ */ (0,
|
|
80
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
81
81
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
82
82
|
path: options.client.importPath,
|
|
83
83
|
isTypeOnly: true
|
|
84
84
|
}),
|
|
85
|
-
options.client.dataReturnType === "full" && /* @__PURE__ */ (0,
|
|
85
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
86
86
|
name: ["ResponseConfig"],
|
|
87
87
|
path: options.client.importPath,
|
|
88
88
|
isTypeOnly: true
|
|
89
89
|
})
|
|
90
|
-
] }) : /* @__PURE__ */ (0,
|
|
91
|
-
/* @__PURE__ */ (0,
|
|
90
|
+
] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
|
|
91
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
92
92
|
name: ["fetch"],
|
|
93
93
|
root: mcp.file.path,
|
|
94
94
|
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
95
95
|
}),
|
|
96
|
-
/* @__PURE__ */ (0,
|
|
96
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
97
97
|
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
98
98
|
root: mcp.file.path,
|
|
99
99
|
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
|
|
100
100
|
isTypeOnly: true
|
|
101
101
|
}),
|
|
102
|
-
options.client.dataReturnType === "full" && /* @__PURE__ */ (0,
|
|
102
|
+
options.client.dataReturnType === "full" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
103
103
|
name: ["ResponseConfig"],
|
|
104
104
|
root: mcp.file.path,
|
|
105
105
|
path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
|
|
106
106
|
isTypeOnly: true
|
|
107
107
|
})
|
|
108
108
|
] }),
|
|
109
|
-
/* @__PURE__ */ (0,
|
|
109
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
110
110
|
name: ["buildFormData"],
|
|
111
111
|
root: mcp.file.path,
|
|
112
112
|
path: node_path.default.resolve(config.root, config.output.path, ".kubb/config.ts")
|
|
113
113
|
}),
|
|
114
|
-
/* @__PURE__ */ (0,
|
|
114
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
115
115
|
name: ["CallToolResult"],
|
|
116
116
|
path: "@modelcontextprotocol/sdk/types",
|
|
117
117
|
isTypeOnly: true
|
|
118
118
|
}),
|
|
119
|
-
/* @__PURE__ */ (0,
|
|
119
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
120
120
|
name: [
|
|
121
121
|
type.schemas.request?.name,
|
|
122
122
|
type.schemas.response.name,
|
|
@@ -129,7 +129,7 @@ const mcpGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
129
129
|
path: type.file.path,
|
|
130
130
|
isTypeOnly: true
|
|
131
131
|
}),
|
|
132
|
-
/* @__PURE__ */ (0,
|
|
132
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_plugin_client_components.Client, {
|
|
133
133
|
name: mcp.name,
|
|
134
134
|
isConfigurable: false,
|
|
135
135
|
returnType: "Promise<CallToolResult>",
|
|
@@ -165,13 +165,13 @@ const mcpGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
165
165
|
|
|
166
166
|
//#endregion
|
|
167
167
|
//#region src/generators/serverGenerator.tsx
|
|
168
|
-
const serverGenerator = (0,
|
|
168
|
+
const serverGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
169
169
|
name: "operations",
|
|
170
170
|
Operations({ operations, generator, plugin }) {
|
|
171
|
-
const pluginManager = (0,
|
|
171
|
+
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
|
|
172
172
|
const { options } = plugin;
|
|
173
|
-
const oas = (0,
|
|
174
|
-
const { getFile, getName, getSchemas } = (0,
|
|
173
|
+
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
174
|
+
const { getFile, getName, getSchemas } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
175
175
|
const name = "server";
|
|
176
176
|
const file = pluginManager.getFile({
|
|
177
177
|
name,
|
|
@@ -199,26 +199,26 @@ const serverGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
199
199
|
zod: {
|
|
200
200
|
name: getName(operation, {
|
|
201
201
|
type: "function",
|
|
202
|
-
pluginKey: [
|
|
202
|
+
pluginKey: [_kubb_plugin_zod.pluginZodName]
|
|
203
203
|
}),
|
|
204
204
|
schemas: getSchemas(operation, {
|
|
205
|
-
pluginKey: [
|
|
205
|
+
pluginKey: [_kubb_plugin_zod.pluginZodName],
|
|
206
206
|
type: "function"
|
|
207
207
|
}),
|
|
208
|
-
file: getFile(operation, { pluginKey: [
|
|
208
|
+
file: getFile(operation, { pluginKey: [_kubb_plugin_zod.pluginZodName] })
|
|
209
209
|
},
|
|
210
210
|
type: { schemas: getSchemas(operation, {
|
|
211
|
-
pluginKey: [
|
|
211
|
+
pluginKey: [_kubb_plugin_ts.pluginTsName],
|
|
212
212
|
type: "type"
|
|
213
213
|
}) }
|
|
214
214
|
};
|
|
215
215
|
});
|
|
216
216
|
const imports = operationsMapped.flatMap(({ mcp, zod }) => {
|
|
217
|
-
return [/* @__PURE__ */ (0,
|
|
217
|
+
return [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
218
218
|
name: [mcp.name],
|
|
219
219
|
root: file.path,
|
|
220
220
|
path: mcp.file.path
|
|
221
|
-
}, mcp.name), /* @__PURE__ */ (0,
|
|
221
|
+
}, mcp.name), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
222
222
|
name: [
|
|
223
223
|
zod.schemas.request?.name,
|
|
224
224
|
zod.schemas.pathParams?.name,
|
|
@@ -229,41 +229,41 @@ const serverGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
229
229
|
path: zod.file.path
|
|
230
230
|
}, zod.name)];
|
|
231
231
|
});
|
|
232
|
-
return /* @__PURE__ */ (0,
|
|
232
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
233
233
|
baseName: file.baseName,
|
|
234
234
|
path: file.path,
|
|
235
235
|
meta: file.meta,
|
|
236
|
-
banner: (0,
|
|
236
|
+
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
237
237
|
oas,
|
|
238
238
|
output: options.output,
|
|
239
239
|
config: pluginManager.config
|
|
240
240
|
}),
|
|
241
|
-
footer: (0,
|
|
241
|
+
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
242
242
|
oas,
|
|
243
243
|
output: options.output
|
|
244
244
|
}),
|
|
245
245
|
children: [
|
|
246
|
-
/* @__PURE__ */ (0,
|
|
246
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
247
247
|
name: ["McpServer"],
|
|
248
248
|
path: "@modelcontextprotocol/sdk/server/mcp"
|
|
249
249
|
}),
|
|
250
|
-
/* @__PURE__ */ (0,
|
|
250
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
251
251
|
name: ["StdioServerTransport"],
|
|
252
252
|
path: "@modelcontextprotocol/sdk/server/stdio"
|
|
253
253
|
}),
|
|
254
254
|
imports,
|
|
255
|
-
/* @__PURE__ */ (0,
|
|
255
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_Server.Server, {
|
|
256
256
|
name,
|
|
257
257
|
serverName: oas.api.info?.title,
|
|
258
258
|
serverVersion: oas.getVersion(),
|
|
259
259
|
operations: operationsMapped
|
|
260
260
|
})
|
|
261
261
|
]
|
|
262
|
-
}), /* @__PURE__ */ (0,
|
|
262
|
+
}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File, {
|
|
263
263
|
baseName: jsonFile.baseName,
|
|
264
264
|
path: jsonFile.path,
|
|
265
265
|
meta: jsonFile.meta,
|
|
266
|
-
children: /* @__PURE__ */ (0,
|
|
266
|
+
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
267
267
|
name,
|
|
268
268
|
children: `
|
|
269
269
|
{
|
|
@@ -300,4 +300,4 @@ Object.defineProperty(exports, 'serverGenerator', {
|
|
|
300
300
|
return serverGenerator;
|
|
301
301
|
}
|
|
302
302
|
});
|
|
303
|
-
//# sourceMappingURL=generators-
|
|
303
|
+
//# sourceMappingURL=generators-qFP0erXA.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators-CG99elMi.cjs","names":["pluginTsName","File","path","Client","pluginZodName","pluginTsName","File","Server"],"sources":["../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx"],"sourcesContent":["import path from 'node:path'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport type { PluginMcp } from '../types'\n\nexport const mcpGenerator = createReactGenerator<PluginMcp>({\n name: 'mcp',\n Operation({ config, operation, generator, plugin }) {\n const { options } = plugin\n const oas = useOas()\n\n const { getSchemas, getName, getFile } = useOperationManager(generator)\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 {options.client.importPath ? (\n <>\n <File.Import name={'fetch'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n </>\n ) : (\n <>\n <File.Import name={['fetch']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />\n <File.Import\n name={['RequestConfig', 'ResponseErrorConfig']}\n root={mcp.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}\n isTypeOnly\n />\n {options.client.dataReturnType === 'full' && (\n <File.Import name={['ResponseConfig']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} isTypeOnly />\n )}\n </>\n )}\n <File.Import name={['buildFormData']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/config.ts')} />\n <File.Import name={['CallToolResult']} path={'@modelcontextprotocol/sdk/types'} 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 || 'data'}\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 { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File } from '@kubb/react-fabric'\nimport { Server } from '../components/Server'\nimport type { PluginMcp } from '../types'\n\nexport const serverGenerator = createReactGenerator<PluginMcp>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const pluginManager = usePluginManager()\n const { options } = plugin\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager(generator)\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 tool: {\n name: operation.getOperationId() || operation.getSummary() || `${operation.method.toUpperCase()} ${operation.path}`,\n description: operation.getDescription() || `Make a ${operation.method.toUpperCase()} request to ${operation.path}`,\n },\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,sEAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EAAE,YAAY;EACpB,MAAM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Q,QAAQ;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChF,+CAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;;IAElD,yDAACA,yBAAK;KAAO,MAAM,CAAC,YAAY;KAAE,MAAM;MAA0C;IAClF,yDAACA,yBAAK;KAAO,MAAM,CAAC,uBAAuB;KAAE,MAAM;MAA4C;IAE9F;IACD,yDAACC;KAAa;KAAM,YAAY,IAAI,IAAI,MAAM;KAAO,eAAe,IAAI,YAAY;KAAE,YAAY;MAAoB;;IACjH,EAEP,yDAACD;GAAK,UAAU,SAAS;GAAU,MAAM,SAAS;GAAM,MAAM,SAAS;aACrE,yDAACA,yBAAK;IAAa;cAChB;;;iBAGI,IAAI,IAAI,MAAM,SAAS,SAAS;;;mCAGd,KAAK,KAAK;;;;;KAKrB;IACT,IACN;;CAGR,CAAC"}
|
|
1
|
+
{"version":3,"file":"generators-qFP0erXA.cjs","names":["pluginTsName","File","path","Client","pluginZodName","pluginTsName","File","Server"],"sources":["../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx"],"sourcesContent":["import path from 'node:path'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport type { PluginMcp } from '../types'\n\nexport const mcpGenerator = createReactGenerator<PluginMcp>({\n name: 'mcp',\n Operation({ config, operation, generator, plugin }) {\n const { options } = plugin\n const oas = useOas()\n\n const { getSchemas, getName, getFile } = useOperationManager(generator)\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 {options.client.importPath ? (\n <>\n <File.Import name={'fetch'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n </>\n ) : (\n <>\n <File.Import name={['fetch']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />\n <File.Import\n name={['RequestConfig', 'ResponseErrorConfig']}\n root={mcp.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}\n isTypeOnly\n />\n {options.client.dataReturnType === 'full' && (\n <File.Import name={['ResponseConfig']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} isTypeOnly />\n )}\n </>\n )}\n <File.Import name={['buildFormData']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/config.ts')} />\n <File.Import name={['CallToolResult']} path={'@modelcontextprotocol/sdk/types'} 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 || 'data'}\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 { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File } from '@kubb/react-fabric'\nimport { Server } from '../components/Server'\nimport type { PluginMcp } from '../types'\n\nexport const serverGenerator = createReactGenerator<PluginMcp>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const pluginManager = usePluginManager()\n const { options } = plugin\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager(generator)\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 tool: {\n name: operation.getOperationId() || operation.getSummary() || `${operation.method.toUpperCase()} ${operation.path}`,\n description: operation.getDescription() || `Make a ${operation.method.toUpperCase()} request to ${operation.path}`,\n },\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,qEAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EAAE,YAAY;EACpB,MAAM,0CAAc;EAEpB,MAAM,EAAE,YAAY,SAAS,4DAAgC,UAAU;EAEvE,MAAM,MAAM;GACV,MAAM,QAAQ,WAAW;IAAE,MAAM;IAAY,QAAQ;IAAW,CAAC;GACjE,MAAM,QAAQ,UAAU;GACzB;EAED,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,WAAW,CAACA,6BAAa,EAAE,CAAC;GACvD,SAAS,WAAW,WAAW;IAAE,WAAW,CAACA,6BAAa;IAAE,MAAM;IAAQ,CAAC;GAC5E;AAED,SACE,yDAACC;GACC,UAAU,IAAI,KAAK;GACnB,MAAM,IAAI,KAAK;GACf,MAAM,IAAI,KAAK;GACf,8CAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;GAClD,8CAAkB;IAAE;IAAK,QAAQ,QAAQ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rB;IACT,IACN;;CAGR,CAAC"}
|
package/dist/generators.cjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const require_generators = require('./generators-
|
|
1
|
+
const require_generators = require('./generators-qFP0erXA.cjs');
|
|
2
2
|
let node_path = require("node:path");
|
|
3
3
|
node_path = require_generators.__toESM(node_path);
|
|
4
|
-
let
|
|
5
|
-
let
|
|
6
|
-
let
|
|
7
|
-
let
|
|
8
|
-
let
|
|
9
|
-
let
|
|
10
|
-
let
|
|
4
|
+
let _kubb_core = require("@kubb/core");
|
|
5
|
+
let _kubb_core_transformers = require("@kubb/core/transformers");
|
|
6
|
+
let _kubb_core_utils = require("@kubb/core/utils");
|
|
7
|
+
let _kubb_plugin_client = require("@kubb/plugin-client");
|
|
8
|
+
let _kubb_plugin_oas = require("@kubb/plugin-oas");
|
|
9
|
+
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
10
|
+
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
11
11
|
|
|
12
12
|
//#region src/plugin.ts
|
|
13
13
|
const pluginMcpName = "plugin-mcp";
|
|
14
|
-
const pluginMcp = (0,
|
|
14
|
+
const pluginMcp = (0, _kubb_core.definePlugin)((options) => {
|
|
15
15
|
const { output = {
|
|
16
16
|
path: "mcp",
|
|
17
17
|
barrelType: "named"
|
|
@@ -32,13 +32,13 @@ const pluginMcp = (0, __kubb_core.definePlugin)((options) => {
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
pre: [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
_kubb_plugin_oas.pluginOasName,
|
|
36
|
+
_kubb_plugin_ts.pluginTsName,
|
|
37
|
+
_kubb_plugin_zod.pluginZodName
|
|
38
38
|
].filter(Boolean),
|
|
39
39
|
resolvePath(baseName, pathMode, options$1) {
|
|
40
40
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
41
|
-
if ((pathMode ?? (0,
|
|
41
|
+
if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
|
|
42
42
|
/**
|
|
43
43
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
44
44
|
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
@@ -47,30 +47,30 @@ const pluginMcp = (0, __kubb_core.definePlugin)((options) => {
|
|
|
47
47
|
if (group && (options$1?.group?.path || options$1?.group?.tag)) {
|
|
48
48
|
const groupName = group?.name ? group.name : (ctx) => {
|
|
49
49
|
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
50
|
-
return `${(0,
|
|
50
|
+
return `${(0, _kubb_core_transformers.camelCase)(ctx.group)}Requests`;
|
|
51
51
|
};
|
|
52
52
|
return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options$1.group.path : options$1.group.tag }), baseName);
|
|
53
53
|
}
|
|
54
54
|
return node_path.default.resolve(root, output.path, baseName);
|
|
55
55
|
},
|
|
56
56
|
resolveName(name, type) {
|
|
57
|
-
const resolvedName = (0,
|
|
57
|
+
const resolvedName = (0, _kubb_core_transformers.camelCase)(name, { isFile: type === "file" });
|
|
58
58
|
if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
59
59
|
return resolvedName;
|
|
60
60
|
},
|
|
61
61
|
async install() {
|
|
62
62
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
63
|
-
const mode = (0,
|
|
63
|
+
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
64
64
|
const oas = await this.getOas();
|
|
65
65
|
const baseURL = await this.getBaseURL();
|
|
66
66
|
if (baseURL) this.plugin.options.client.baseURL = baseURL;
|
|
67
|
-
const hasClientPlugin = !!this.pluginManager.getPluginByKey([
|
|
67
|
+
const hasClientPlugin = !!this.pluginManager.getPluginByKey([_kubb_plugin_client.pluginClientName]);
|
|
68
68
|
if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.addFile({
|
|
69
69
|
baseName: "fetch.ts",
|
|
70
70
|
path: node_path.default.resolve(root, ".kubb/fetch.ts"),
|
|
71
71
|
sources: [{
|
|
72
72
|
name: "fetch",
|
|
73
|
-
value: (0,
|
|
73
|
+
value: (0, _kubb_core_utils.resolveModuleSource)(this.plugin.options.client.client === "fetch" ? "@kubb/plugin-client/templates/clients/fetch" : "@kubb/plugin-client/templates/clients/axios").source,
|
|
74
74
|
isExportable: true,
|
|
75
75
|
isIndexable: true
|
|
76
76
|
}]
|
|
@@ -80,12 +80,12 @@ const pluginMcp = (0, __kubb_core.definePlugin)((options) => {
|
|
|
80
80
|
path: node_path.default.resolve(root, ".kubb/config.ts"),
|
|
81
81
|
sources: [{
|
|
82
82
|
name: "config",
|
|
83
|
-
value: (0,
|
|
83
|
+
value: (0, _kubb_core_utils.resolveModuleSource)("@kubb/plugin-client/templates/config").source,
|
|
84
84
|
isExportable: false,
|
|
85
85
|
isIndexable: false
|
|
86
86
|
}]
|
|
87
87
|
});
|
|
88
|
-
const files = await new
|
|
88
|
+
const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
89
89
|
fabric: this.fabric,
|
|
90
90
|
oas,
|
|
91
91
|
pluginManager: this.pluginManager,
|
|
@@ -98,7 +98,7 @@ const pluginMcp = (0, __kubb_core.definePlugin)((options) => {
|
|
|
98
98
|
mode
|
|
99
99
|
}).build(...generators);
|
|
100
100
|
await this.upsertFile(...files);
|
|
101
|
-
const barrelFiles = await (0,
|
|
101
|
+
const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
102
102
|
type: output.barrelType ?? "named",
|
|
103
103
|
root,
|
|
104
104
|
output,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["mcpGenerator","serverGenerator","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","pluginClientName","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator, serverGenerator } from './generators'\nimport type { PluginMcp } from './types.ts'\n\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\nexport const pluginMcp = definePlugin<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 client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginMcpName,\n options: {\n output,\n group,\n client: {\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.addFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n if (!hasClientPlugin) {\n await this.addFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\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.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,gBAAgB;AAE7B,MAAa,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["mcpGenerator","serverGenerator","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","pluginClientName","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator, serverGenerator } from './generators'\nimport type { PluginMcp } from './types.ts'\n\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\nexport const pluginMcp = definePlugin<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 client,\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginMcpName,\n options: {\n output,\n group,\n client: {\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.addFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n if (!hasClientPlugin) {\n await this.addFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\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.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,gBAAgB;AAE7B,MAAa,0CAAq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AM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-mcp",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.4",
|
|
4
4
|
"description": "Generator mcp",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -69,13 +69,13 @@
|
|
|
69
69
|
}
|
|
70
70
|
],
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@kubb/react-fabric": "0.7.
|
|
73
|
-
"@kubb/core": "4.12.
|
|
74
|
-
"@kubb/oas": "4.12.
|
|
75
|
-
"@kubb/plugin-client": "4.12.
|
|
76
|
-
"@kubb/plugin-oas": "4.12.
|
|
77
|
-
"@kubb/plugin-ts": "4.12.
|
|
78
|
-
"@kubb/plugin-zod": "4.12.
|
|
72
|
+
"@kubb/react-fabric": "0.7.1",
|
|
73
|
+
"@kubb/core": "4.12.4",
|
|
74
|
+
"@kubb/oas": "4.12.4",
|
|
75
|
+
"@kubb/plugin-client": "4.12.4",
|
|
76
|
+
"@kubb/plugin-oas": "4.12.4",
|
|
77
|
+
"@kubb/plugin-ts": "4.12.4",
|
|
78
|
+
"@kubb/plugin-zod": "4.12.4"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {},
|
|
81
81
|
"engines": {
|