@kubb/plugin-mcp 4.31.2 → 4.31.3
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-N9lWEnVE.cjs → Server-ChYBeu5B.cjs} +49 -21
- package/dist/Server-ChYBeu5B.cjs.map +1 -0
- package/dist/{Server-D3kNei96.js → Server-D45Pl-Hd.js} +50 -22
- package/dist/Server-D45Pl-Hd.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -0
- package/dist/components.js +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/{serverGenerator-A8IBI-18.cjs → serverGenerator-BT6PJrZw.cjs} +13 -5
- package/dist/serverGenerator-BT6PJrZw.cjs.map +1 -0
- package/dist/{serverGenerator-DfxZTxke.js → serverGenerator-TERvEwnw.js} +13 -5
- package/dist/serverGenerator-TERvEwnw.js.map +1 -0
- package/package.json +7 -7
- package/src/components/Server.tsx +65 -32
- package/src/generators/mcpGenerator.tsx +4 -2
- package/src/generators/serverGenerator.tsx +9 -1
- package/dist/Server-D3kNei96.js.map +0 -1
- package/dist/Server-N9lWEnVE.cjs.map +0 -1
- package/dist/serverGenerator-A8IBI-18.cjs.map +0 -1
- package/dist/serverGenerator-DfxZTxke.js.map +0 -1
|
@@ -29,33 +29,50 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
}) : target, mod));
|
|
30
30
|
|
|
31
31
|
//#endregion
|
|
32
|
+
let _kubb_core_transformers = require("@kubb/core/transformers");
|
|
32
33
|
let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
|
|
33
34
|
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
34
35
|
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
35
|
-
let _kubb_oas = require("@kubb/oas");
|
|
36
36
|
|
|
37
37
|
//#region src/components/Server.tsx
|
|
38
|
+
function zodExprFromOasSchema(schema) {
|
|
39
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
40
|
+
const baseType = types.find((t) => t && t !== "null");
|
|
41
|
+
const isNullableType = types.includes("null");
|
|
42
|
+
let expr;
|
|
43
|
+
switch (baseType) {
|
|
44
|
+
case "integer":
|
|
45
|
+
expr = "z.coerce.number()";
|
|
46
|
+
break;
|
|
47
|
+
case "number":
|
|
48
|
+
expr = "z.number()";
|
|
49
|
+
break;
|
|
50
|
+
case "boolean":
|
|
51
|
+
expr = "z.boolean()";
|
|
52
|
+
break;
|
|
53
|
+
case "array":
|
|
54
|
+
expr = "z.array(z.unknown())";
|
|
55
|
+
break;
|
|
56
|
+
default: expr = "z.string()";
|
|
57
|
+
}
|
|
58
|
+
if (isNullableType) expr = `${expr}.nullable()`;
|
|
59
|
+
return expr;
|
|
60
|
+
}
|
|
38
61
|
function getParams({ schemas, paramsCasing }) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
62
|
+
const pathParamProperties = schemas.pathParams?.schema?.properties ?? {};
|
|
63
|
+
const requiredFields = Array.isArray(schemas.pathParams?.schema?.required) ? schemas.pathParams.schema.required : [];
|
|
64
|
+
const pathParamEntries = Object.entries(pathParamProperties).reduce((acc, [originalKey, propSchema]) => {
|
|
65
|
+
const key = paramsCasing === "camelcase" || !(0, _kubb_core_transformers.isValidVarName)(originalKey) ? (0, _kubb_core_transformers.camelCase)(originalKey) : originalKey;
|
|
66
|
+
acc[key] = {
|
|
67
|
+
value: zodExprFromOasSchema(propSchema),
|
|
68
|
+
optional: !requiredFields.includes(originalKey)
|
|
69
|
+
};
|
|
70
|
+
return acc;
|
|
71
|
+
}, {});
|
|
43
72
|
return _kubb_react_fabric.FunctionParams.factory({ data: {
|
|
44
73
|
mode: "object",
|
|
45
74
|
children: {
|
|
46
|
-
...
|
|
47
|
-
if (param && schemas.pathParams?.name) {
|
|
48
|
-
let suffix = ".shape";
|
|
49
|
-
if ((0, _kubb_oas.isNullable)(schemas.pathParams.schema)) if ((0, _kubb_oas.isReference)(schemas.pathParams)) suffix = ".unwrap().schema.unwrap().shape";
|
|
50
|
-
else suffix = ".unwrap().shape";
|
|
51
|
-
else if ((0, _kubb_oas.isReference)(schemas.pathParams)) suffix = ".schema.shape";
|
|
52
|
-
param.value = `${schemas.pathParams?.name}${suffix}['${key}']`;
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
...acc,
|
|
56
|
-
[key]: param
|
|
57
|
-
};
|
|
58
|
-
}, {}),
|
|
75
|
+
...pathParamEntries,
|
|
59
76
|
data: schemas.request?.name ? {
|
|
60
77
|
value: schemas.request?.name,
|
|
61
78
|
optional: (0, _kubb_plugin_oas_utils.isOptional)(schemas.request?.schema)
|
|
@@ -92,13 +109,24 @@ function Server({ name, serverName, serverVersion, paramsCasing, operations }) {
|
|
|
92
109
|
schemas: zod.schemas,
|
|
93
110
|
paramsCasing
|
|
94
111
|
});
|
|
112
|
+
const outputSchema = zod.schemas.response?.name;
|
|
113
|
+
const config = [
|
|
114
|
+
tool.title ? `title: ${JSON.stringify(tool.title)}` : null,
|
|
115
|
+
`description: ${JSON.stringify(tool.description)}`,
|
|
116
|
+
outputSchema ? `outputSchema: { data: ${outputSchema} }` : null
|
|
117
|
+
].filter(Boolean).join(",\n ");
|
|
95
118
|
if (zod.schemas.request?.name || zod.schemas.headerParams?.name || zod.schemas.queryParams?.name || zod.schemas.pathParams?.name) return `
|
|
96
|
-
server.
|
|
119
|
+
server.registerTool(${JSON.stringify(tool.name)}, {
|
|
120
|
+
${config},
|
|
121
|
+
inputSchema: ${paramsClient.toObjectValue()},
|
|
122
|
+
}, async (${paramsClient.toObject()}) => {
|
|
97
123
|
return ${mcp.name}(${paramsClient.toObject()})
|
|
98
124
|
})
|
|
99
125
|
`;
|
|
100
126
|
return `
|
|
101
|
-
server.
|
|
127
|
+
server.registerTool(${JSON.stringify(tool.name)}, {
|
|
128
|
+
${config},
|
|
129
|
+
}, async () => {
|
|
102
130
|
return ${mcp.name}(${paramsClient.toObject()})
|
|
103
131
|
})
|
|
104
132
|
`;
|
|
@@ -138,4 +166,4 @@ Object.defineProperty(exports, '__toESM', {
|
|
|
138
166
|
return __toESM;
|
|
139
167
|
}
|
|
140
168
|
});
|
|
141
|
-
//# sourceMappingURL=Server-
|
|
169
|
+
//# sourceMappingURL=Server-ChYBeu5B.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server-ChYBeu5B.cjs","names":["FunctionParams","File","Const"],"sources":["../src/components/Server.tsx"],"sourcesContent":["import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { SchemaObject } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { isOptional } from '@kubb/plugin-oas/utils'\nimport { Const, File, FunctionParams } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n name: string\n serverName: string\n serverVersion: string\n paramsCasing?: 'camelcase'\n operations: Array<{\n tool: {\n name: string\n title?: 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 paramsCasing?: 'camelcase'\n}\n\nfunction zodExprFromOasSchema(schema: SchemaObject): string {\n const types = Array.isArray(schema.type) ? schema.type : [schema.type]\n const baseType = types.find((t) => t && t !== 'null')\n const isNullableType = types.includes('null')\n\n let expr: string\n switch (baseType) {\n case 'integer':\n expr = 'z.coerce.number()'\n break\n case 'number':\n expr = 'z.number()'\n break\n case 'boolean':\n expr = 'z.boolean()'\n break\n case 'array':\n expr = 'z.array(z.unknown())'\n break\n default:\n expr = 'z.string()'\n }\n\n if (isNullableType) {\n expr = `${expr}.nullable()`\n }\n\n return expr\n}\n\nfunction getParams({ schemas, paramsCasing }: GetParamsProps) {\n const pathParamProperties = schemas.pathParams?.schema?.properties ?? {}\n const requiredFields = Array.isArray(schemas.pathParams?.schema?.required) ? schemas.pathParams.schema.required : []\n\n const pathParamEntries = Object.entries(pathParamProperties).reduce<Record<string, { value: string; optional: boolean }>>(\n (acc, [originalKey, propSchema]) => {\n const key = paramsCasing === 'camelcase' || !isValidVarName(originalKey) ? camelCase(originalKey) : originalKey\n acc[key] = {\n value: zodExprFromOasSchema(propSchema as SchemaObject),\n optional: !requiredFields.includes(originalKey),\n }\n return acc\n },\n {},\n )\n\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...pathParamEntries,\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, paramsCasing, operations }: Props): FabricReactNode {\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, paramsCasing })\n const outputSchema = zod.schemas.response?.name\n\n const config = [\n tool.title ? `title: ${JSON.stringify(tool.title)}` : null,\n `description: ${JSON.stringify(tool.description)}`,\n outputSchema ? `outputSchema: { data: ${outputSchema} }` : null,\n ]\n .filter(Boolean)\n .join(',\\n ')\n\n if (zod.schemas.request?.name || zod.schemas.headerParams?.name || zod.schemas.queryParams?.name || zod.schemas.pathParams?.name) {\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n inputSchema: ${paramsClient.toObjectValue()},\n}, async (${paramsClient.toObject()}) => {\n return ${mcp.name}(${paramsClient.toObject()})\n})\n `\n }\n\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n}, async () => {\n return ${mcp.name}(${paramsClient.toObject()})\n})\n `\n })\n .filter(Boolean)}\n\n {`\nexport async 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`}\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAS,qBAAqB,QAA8B;CAC1D,MAAM,QAAQ,MAAM,QAAQ,OAAO,KAAK,GAAG,OAAO,OAAO,CAAC,OAAO,KAAK;CACtE,MAAM,WAAW,MAAM,MAAM,MAAM,KAAK,MAAM,OAAO;CACrD,MAAM,iBAAiB,MAAM,SAAS,OAAO;CAE7C,IAAI;AACJ,SAAQ,UAAR;EACE,KAAK;AACH,UAAO;AACP;EACF,KAAK;AACH,UAAO;AACP;EACF,KAAK;AACH,UAAO;AACP;EACF,KAAK;AACH,UAAO;AACP;EACF,QACE,QAAO;;AAGX,KAAI,eACF,QAAO,GAAG,KAAK;AAGjB,QAAO;;AAGT,SAAS,UAAU,EAAE,SAAS,gBAAgC;CAC5D,MAAM,sBAAsB,QAAQ,YAAY,QAAQ,cAAc,EAAE;CACxE,MAAM,iBAAiB,MAAM,QAAQ,QAAQ,YAAY,QAAQ,SAAS,GAAG,QAAQ,WAAW,OAAO,WAAW,EAAE;CAEpH,MAAM,mBAAmB,OAAO,QAAQ,oBAAoB,CAAC,QAC1D,KAAK,CAAC,aAAa,gBAAgB;EAClC,MAAM,MAAM,iBAAiB,eAAe,6CAAgB,YAAY,0CAAa,YAAY,GAAG;AACpG,MAAI,OAAO;GACT,OAAO,qBAAqB,WAA2B;GACvD,UAAU,CAAC,eAAe,SAAS,YAAY;GA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K,KAAK,CAAC;IAC5C,OAAO;;WAEA,IAAI,KAAK,GAAG,aAAa,UAAU,CAAC;;;KAGrC,CACD,OAAO,QAAQ;GAEjB;;;;;;;;;;;;;GAYW"}
|
|
@@ -1,31 +1,48 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-DKWOrOAv.js";
|
|
2
|
-
import {
|
|
2
|
+
import { camelCase, isValidVarName } from "@kubb/core/transformers";
|
|
3
|
+
import { isOptional } from "@kubb/plugin-oas/utils";
|
|
3
4
|
import { Const, File, FunctionParams } from "@kubb/react-fabric";
|
|
4
5
|
import { jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
|
|
5
|
-
import { isNullable, isReference } from "@kubb/oas";
|
|
6
6
|
|
|
7
7
|
//#region src/components/Server.tsx
|
|
8
|
+
function zodExprFromOasSchema(schema) {
|
|
9
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
10
|
+
const baseType = types.find((t) => t && t !== "null");
|
|
11
|
+
const isNullableType = types.includes("null");
|
|
12
|
+
let expr;
|
|
13
|
+
switch (baseType) {
|
|
14
|
+
case "integer":
|
|
15
|
+
expr = "z.coerce.number()";
|
|
16
|
+
break;
|
|
17
|
+
case "number":
|
|
18
|
+
expr = "z.number()";
|
|
19
|
+
break;
|
|
20
|
+
case "boolean":
|
|
21
|
+
expr = "z.boolean()";
|
|
22
|
+
break;
|
|
23
|
+
case "array":
|
|
24
|
+
expr = "z.array(z.unknown())";
|
|
25
|
+
break;
|
|
26
|
+
default: expr = "z.string()";
|
|
27
|
+
}
|
|
28
|
+
if (isNullableType) expr = `${expr}.nullable()`;
|
|
29
|
+
return expr;
|
|
30
|
+
}
|
|
8
31
|
function getParams({ schemas, paramsCasing }) {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
32
|
+
const pathParamProperties = schemas.pathParams?.schema?.properties ?? {};
|
|
33
|
+
const requiredFields = Array.isArray(schemas.pathParams?.schema?.required) ? schemas.pathParams.schema.required : [];
|
|
34
|
+
const pathParamEntries = Object.entries(pathParamProperties).reduce((acc, [originalKey, propSchema]) => {
|
|
35
|
+
const key = paramsCasing === "camelcase" || !isValidVarName(originalKey) ? camelCase(originalKey) : originalKey;
|
|
36
|
+
acc[key] = {
|
|
37
|
+
value: zodExprFromOasSchema(propSchema),
|
|
38
|
+
optional: !requiredFields.includes(originalKey)
|
|
39
|
+
};
|
|
40
|
+
return acc;
|
|
41
|
+
}, {});
|
|
13
42
|
return FunctionParams.factory({ data: {
|
|
14
43
|
mode: "object",
|
|
15
44
|
children: {
|
|
16
|
-
...
|
|
17
|
-
if (param && schemas.pathParams?.name) {
|
|
18
|
-
let suffix = ".shape";
|
|
19
|
-
if (isNullable(schemas.pathParams.schema)) if (isReference(schemas.pathParams)) suffix = ".unwrap().schema.unwrap().shape";
|
|
20
|
-
else suffix = ".unwrap().shape";
|
|
21
|
-
else if (isReference(schemas.pathParams)) suffix = ".schema.shape";
|
|
22
|
-
param.value = `${schemas.pathParams?.name}${suffix}['${key}']`;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
...acc,
|
|
26
|
-
[key]: param
|
|
27
|
-
};
|
|
28
|
-
}, {}),
|
|
45
|
+
...pathParamEntries,
|
|
29
46
|
data: schemas.request?.name ? {
|
|
30
47
|
value: schemas.request?.name,
|
|
31
48
|
optional: isOptional(schemas.request?.schema)
|
|
@@ -62,13 +79,24 @@ function Server({ name, serverName, serverVersion, paramsCasing, operations }) {
|
|
|
62
79
|
schemas: zod.schemas,
|
|
63
80
|
paramsCasing
|
|
64
81
|
});
|
|
82
|
+
const outputSchema = zod.schemas.response?.name;
|
|
83
|
+
const config = [
|
|
84
|
+
tool.title ? `title: ${JSON.stringify(tool.title)}` : null,
|
|
85
|
+
`description: ${JSON.stringify(tool.description)}`,
|
|
86
|
+
outputSchema ? `outputSchema: { data: ${outputSchema} }` : null
|
|
87
|
+
].filter(Boolean).join(",\n ");
|
|
65
88
|
if (zod.schemas.request?.name || zod.schemas.headerParams?.name || zod.schemas.queryParams?.name || zod.schemas.pathParams?.name) return `
|
|
66
|
-
server.
|
|
89
|
+
server.registerTool(${JSON.stringify(tool.name)}, {
|
|
90
|
+
${config},
|
|
91
|
+
inputSchema: ${paramsClient.toObjectValue()},
|
|
92
|
+
}, async (${paramsClient.toObject()}) => {
|
|
67
93
|
return ${mcp.name}(${paramsClient.toObject()})
|
|
68
94
|
})
|
|
69
95
|
`;
|
|
70
96
|
return `
|
|
71
|
-
server.
|
|
97
|
+
server.registerTool(${JSON.stringify(tool.name)}, {
|
|
98
|
+
${config},
|
|
99
|
+
}, async () => {
|
|
72
100
|
return ${mcp.name}(${paramsClient.toObject()})
|
|
73
101
|
})
|
|
74
102
|
`;
|
|
@@ -91,4 +119,4 @@ export async function startServer() {
|
|
|
91
119
|
|
|
92
120
|
//#endregion
|
|
93
121
|
export { Server as t };
|
|
94
|
-
//# sourceMappingURL=Server-
|
|
122
|
+
//# sourceMappingURL=Server-D45Pl-Hd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server-D45Pl-Hd.js","names":[],"sources":["../src/components/Server.tsx"],"sourcesContent":["import { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { SchemaObject } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { isOptional } from '@kubb/plugin-oas/utils'\nimport { Const, File, FunctionParams } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n name: string\n serverName: string\n serverVersion: string\n paramsCasing?: 'camelcase'\n operations: Array<{\n tool: {\n name: string\n title?: 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 paramsCasing?: 'camelcase'\n}\n\nfunction zodExprFromOasSchema(schema: SchemaObject): string {\n const types = Array.isArray(schema.type) ? schema.type : [schema.type]\n const baseType = types.find((t) => t && t !== 'null')\n const isNullableType = types.includes('null')\n\n let expr: string\n switch (baseType) {\n case 'integer':\n expr = 'z.coerce.number()'\n break\n case 'number':\n expr = 'z.number()'\n break\n case 'boolean':\n expr = 'z.boolean()'\n break\n case 'array':\n expr = 'z.array(z.unknown())'\n break\n default:\n expr = 'z.string()'\n }\n\n if (isNullableType) {\n expr = `${expr}.nullable()`\n }\n\n return expr\n}\n\nfunction getParams({ schemas, paramsCasing }: GetParamsProps) {\n const pathParamProperties = schemas.pathParams?.schema?.properties ?? {}\n const requiredFields = Array.isArray(schemas.pathParams?.schema?.required) ? schemas.pathParams.schema.required : []\n\n const pathParamEntries = Object.entries(pathParamProperties).reduce<Record<string, { value: string; optional: boolean }>>(\n (acc, [originalKey, propSchema]) => {\n const key = paramsCasing === 'camelcase' || !isValidVarName(originalKey) ? camelCase(originalKey) : originalKey\n acc[key] = {\n value: zodExprFromOasSchema(propSchema as SchemaObject),\n optional: !requiredFields.includes(originalKey),\n }\n return acc\n },\n {},\n )\n\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...pathParamEntries,\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, paramsCasing, operations }: Props): FabricReactNode {\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, paramsCasing })\n const outputSchema = zod.schemas.response?.name\n\n const config = [\n tool.title ? `title: ${JSON.stringify(tool.title)}` : null,\n `description: ${JSON.stringify(tool.description)}`,\n outputSchema ? `outputSchema: { data: ${outputSchema} }` : null,\n ]\n .filter(Boolean)\n .join(',\\n ')\n\n if (zod.schemas.request?.name || zod.schemas.headerParams?.name || zod.schemas.queryParams?.name || zod.schemas.pathParams?.name) {\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n inputSchema: ${paramsClient.toObjectValue()},\n}, async (${paramsClient.toObject()}) => {\n return ${mcp.name}(${paramsClient.toObject()})\n})\n `\n }\n\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n}, async () => {\n return ${mcp.name}(${paramsClient.toObject()})\n})\n `\n })\n .filter(Boolean)}\n\n {`\nexport async 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`}\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;AAuCA,SAAS,qBAAqB,QAA8B;CAC1D,MAAM,QAAQ,MAAM,QAAQ,OAAO,KAAK,GAAG,OAAO,OAAO,CAAC,OAAO,KAAK;CACtE,MAAM,WAAW,MAAM,MAAM,MAAM,KAAK,MAAM,OAAO;CACrD,MAAM,iBAAiB,MAAM,SAAS,OAAO;CAE7C,IAAI;AACJ,SAAQ,UAAR;EACE,KAAK;AACH,UAAO;AACP;EACF,KAAK;AACH,UAAO;AACP;EACF,KAAK;AACH,UAAO;AACP;EACF,KAAK;AACH,UAAO;AACP;EACF,QACE,QAAO;;AAGX,KAAI,eACF,QAAO,GAAG,KAAK;AAGjB,QAAO;;AAGT,SAAS,UAAU,EAAE,SAAS,gBAAgC;CAC5D,MAAM,sBAAsB,QAAQ,YAAY,QAAQ,cAAc,EAAE;CACxE,MAAM,iBAAiB,MAAM,QAAQ,QAAQ,YAAY,QAAQ,SAAS,GAAG,QAAQ,WAA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AAQ,IAAI,QAAQ,cAAc,QAAQ,IAAI,QAAQ,aAAa,QAAQ,IAAI,QAAQ,YAAY,KAC1H,QAAO;sBACG,KAAK,UAAU,KAAK,KAAK,CAAC;IAC5C,OAAO;iBACM,aAAa,eAAe,CAAC;YAClC,aAAa,UAAU,CAAC;WACzB,IAAI,KAAK,GAAG,aAAa,UAAU,CAAC;;;AAKrC,WAAO;sBACK,KAAK,UAAU,KAAK,KAAK,CAAC;IAC5C,OAAO;;WAEA,IAAI,KAAK,GAAG,aAAa,UAAU,CAAC;;;KAGrC,CACD,OAAO,QAAQ;GAEjB;;;;;;;;;;;;;GAYW"}
|
package/dist/components.cjs
CHANGED
package/dist/components.d.ts
CHANGED
package/dist/components.js
CHANGED
package/dist/generators.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_serverGenerator = require('./serverGenerator-
|
|
2
|
+
const require_serverGenerator = require('./serverGenerator-BT6PJrZw.cjs');
|
|
3
3
|
|
|
4
4
|
exports.mcpGenerator = require_serverGenerator.mcpGenerator;
|
|
5
5
|
exports.serverGenerator = require_serverGenerator.serverGenerator;
|
package/dist/generators.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { t as __name } from "./chunk-DKWOrOAv.js";
|
|
|
2
2
|
import { n as PluginMcp } from "./types-BTZNpUo1.js";
|
|
3
3
|
import { BaseGenerator, Config, FileMetaBase, Group, KubbEvents, Output, Plugin, PluginFactoryOptions, PluginManager, ResolveNameParams } from "@kubb/core";
|
|
4
4
|
import { Fabric } from "@kubb/react-fabric";
|
|
5
|
-
import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
|
|
6
5
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
7
6
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
7
|
+
import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
|
|
8
8
|
import { AsyncEventEmitter } from "@kubb/core/utils";
|
|
9
9
|
|
|
10
10
|
//#region ../plugin-oas/src/types.d.ts
|
package/dist/generators.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_Server = require('./Server-
|
|
3
|
-
const require_serverGenerator = require('./serverGenerator-
|
|
2
|
+
const require_Server = require('./Server-ChYBeu5B.cjs');
|
|
3
|
+
const require_serverGenerator = require('./serverGenerator-BT6PJrZw.cjs');
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_Server.__toESM(node_path);
|
|
6
6
|
let _kubb_core = require("@kubb/core");
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-DKWOrOAv.js";
|
|
2
|
-
import { n as mcpGenerator, t as serverGenerator } from "./serverGenerator-
|
|
2
|
+
import { n as mcpGenerator, t as serverGenerator } from "./serverGenerator-TERvEwnw.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
5
5
|
import { camelCase } from "@kubb/core/transformers";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_Server = require('./Server-
|
|
1
|
+
const require_Server = require('./Server-ChYBeu5B.cjs');
|
|
2
2
|
let node_path = require("node:path");
|
|
3
3
|
node_path = require_Server.__toESM(node_path);
|
|
4
4
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
@@ -129,14 +129,16 @@ const mcpGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
129
129
|
type: 'text',
|
|
130
130
|
text: JSON.stringify(res.data)
|
|
131
131
|
}
|
|
132
|
-
]
|
|
132
|
+
],
|
|
133
|
+
structuredContent: { data: res.data }
|
|
133
134
|
}`, options.client.dataReturnType === "full" && `return {
|
|
134
135
|
content: [
|
|
135
136
|
{
|
|
136
137
|
type: 'text',
|
|
137
138
|
text: JSON.stringify(res)
|
|
138
139
|
}
|
|
139
|
-
]
|
|
140
|
+
],
|
|
141
|
+
structuredContent: { data: res.data }
|
|
140
142
|
}`]
|
|
141
143
|
})
|
|
142
144
|
]
|
|
@@ -168,6 +170,7 @@ const serverGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
168
170
|
return {
|
|
169
171
|
tool: {
|
|
170
172
|
name: operation.getOperationId() || operation.getSummary() || `${operation.method.toUpperCase()} ${operation.path}`,
|
|
173
|
+
title: operation.getSummary() || void 0,
|
|
171
174
|
description: operation.getDescription() || `Make a ${operation.method.toUpperCase()} request to ${operation.path}`
|
|
172
175
|
},
|
|
173
176
|
mcp: {
|
|
@@ -204,7 +207,8 @@ const serverGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
204
207
|
zod.schemas.request?.name,
|
|
205
208
|
zod.schemas.pathParams?.name,
|
|
206
209
|
zod.schemas.queryParams?.name,
|
|
207
|
-
zod.schemas.headerParams?.name
|
|
210
|
+
zod.schemas.headerParams?.name,
|
|
211
|
+
zod.schemas.response?.name
|
|
208
212
|
].filter(Boolean),
|
|
209
213
|
root: file.path,
|
|
210
214
|
path: zod.file.path
|
|
@@ -228,6 +232,10 @@ const serverGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
228
232
|
name: ["McpServer"],
|
|
229
233
|
path: "@modelcontextprotocol/sdk/server/mcp"
|
|
230
234
|
}),
|
|
235
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
236
|
+
name: ["z"],
|
|
237
|
+
path: "zod"
|
|
238
|
+
}),
|
|
231
239
|
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
232
240
|
name: ["StdioServerTransport"],
|
|
233
241
|
path: "@modelcontextprotocol/sdk/server/stdio"
|
|
@@ -276,4 +284,4 @@ Object.defineProperty(exports, 'serverGenerator', {
|
|
|
276
284
|
return serverGenerator;
|
|
277
285
|
}
|
|
278
286
|
});
|
|
279
|
-
//# sourceMappingURL=serverGenerator-
|
|
287
|
+
//# sourceMappingURL=serverGenerator-BT6PJrZw.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverGenerator-BT6PJrZw.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={['Client', '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={['Client', '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={options.client?.paramsCasing || options.paramsCasing}\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 structuredContent: { data: res.data }\n }`}\n {options.client.dataReturnType === 'full' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res)\n }\n ],\n structuredContent: { data: res.data }\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 title: operation.getSummary() || undefined,\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={[\n zod.schemas.request?.name,\n zod.schemas.pathParams?.name,\n zod.schemas.queryParams?.name,\n zod.schemas.headerParams?.name,\n zod.schemas.response?.name,\n ].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={['z']} path={'zod'} />\n <File.Import name={['StdioServerTransport']} path={'@modelcontextprotocol/sdk/server/stdio'} />\n\n {imports}\n <Server\n name={name}\n serverName={oas.api.info?.title}\n serverVersion={oas.getVersion()}\n paramsCasing={options.paramsCasing}\n operations={operationsMapped}\n />\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;IAAQ,CAAC;;IAEjD,QAAQ,OAAO,aACd;KACE,wDAACA,wBAAK;MAAO,MAAM;MAAS,MAAM,QAAQ,OAAO;OAAc;KAC/D,wDAACA,wBAAK;MAAO,MAAM;OAAC;OAAU;OAAiB;OAAsB;MAAE,MAAM,QAAQ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N;;CAGR,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-DKWOrOAv.js";
|
|
2
|
-
import { t as Server } from "./Server-
|
|
2
|
+
import { t as Server } from "./Server-D45Pl-Hd.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
5
5
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
@@ -129,14 +129,16 @@ const mcpGenerator = createReactGenerator({
|
|
|
129
129
|
type: 'text',
|
|
130
130
|
text: JSON.stringify(res.data)
|
|
131
131
|
}
|
|
132
|
-
]
|
|
132
|
+
],
|
|
133
|
+
structuredContent: { data: res.data }
|
|
133
134
|
}`, options.client.dataReturnType === "full" && `return {
|
|
134
135
|
content: [
|
|
135
136
|
{
|
|
136
137
|
type: 'text',
|
|
137
138
|
text: JSON.stringify(res)
|
|
138
139
|
}
|
|
139
|
-
]
|
|
140
|
+
],
|
|
141
|
+
structuredContent: { data: res.data }
|
|
140
142
|
}`]
|
|
141
143
|
})
|
|
142
144
|
]
|
|
@@ -168,6 +170,7 @@ const serverGenerator = createReactGenerator({
|
|
|
168
170
|
return {
|
|
169
171
|
tool: {
|
|
170
172
|
name: operation.getOperationId() || operation.getSummary() || `${operation.method.toUpperCase()} ${operation.path}`,
|
|
173
|
+
title: operation.getSummary() || void 0,
|
|
171
174
|
description: operation.getDescription() || `Make a ${operation.method.toUpperCase()} request to ${operation.path}`
|
|
172
175
|
},
|
|
173
176
|
mcp: {
|
|
@@ -204,7 +207,8 @@ const serverGenerator = createReactGenerator({
|
|
|
204
207
|
zod.schemas.request?.name,
|
|
205
208
|
zod.schemas.pathParams?.name,
|
|
206
209
|
zod.schemas.queryParams?.name,
|
|
207
|
-
zod.schemas.headerParams?.name
|
|
210
|
+
zod.schemas.headerParams?.name,
|
|
211
|
+
zod.schemas.response?.name
|
|
208
212
|
].filter(Boolean),
|
|
209
213
|
root: file.path,
|
|
210
214
|
path: zod.file.path
|
|
@@ -228,6 +232,10 @@ const serverGenerator = createReactGenerator({
|
|
|
228
232
|
name: ["McpServer"],
|
|
229
233
|
path: "@modelcontextprotocol/sdk/server/mcp"
|
|
230
234
|
}),
|
|
235
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
236
|
+
name: ["z"],
|
|
237
|
+
path: "zod"
|
|
238
|
+
}),
|
|
231
239
|
/* @__PURE__ */ jsx(File.Import, {
|
|
232
240
|
name: ["StdioServerTransport"],
|
|
233
241
|
path: "@modelcontextprotocol/sdk/server/stdio"
|
|
@@ -265,4 +273,4 @@ const serverGenerator = createReactGenerator({
|
|
|
265
273
|
|
|
266
274
|
//#endregion
|
|
267
275
|
export { mcpGenerator as n, serverGenerator as t };
|
|
268
|
-
//# sourceMappingURL=serverGenerator-
|
|
276
|
+
//# sourceMappingURL=serverGenerator-TERvEwnw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverGenerator-TERvEwnw.js","names":[],"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={['Client', '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={['Client', '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={options.client?.paramsCasing || options.paramsCasing}\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 structuredContent: { data: res.data }\n }`}\n {options.client.dataReturnType === 'full' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res)\n }\n ],\n structuredContent: { data: res.data }\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 title: operation.getSummary() || undefined,\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={[\n zod.schemas.request?.name,\n zod.schemas.pathParams?.name,\n zod.schemas.queryParams?.name,\n zod.schemas.headerParams?.name,\n zod.schemas.response?.name,\n ].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={['z']} path={'zod'} />\n <File.Import name={['StdioServerTransport']} path={'@modelcontextprotocol/sdk/server/stdio'} />\n\n {imports}\n <Server\n name={name}\n serverName={oas.api.info?.title}\n serverVersion={oas.getVersion()}\n paramsCasing={options.paramsCasing}\n operations={operationsMapped}\n />\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,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EAAE,YAAY;EACpB,MAAM,MAAM,QAAQ;EAEpB,MAAM,EAAE,YAAY,SAAS,YAAY,oBAAoB,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,CAAC,aAAa,EAAE,CAAC;GACvD,SAAS,WAAW,WAAW;IAAE,WAAW,CAAC,aAAa;IAAE,MAAM;IAAQ,CAAC;GAC5E;AAED,SACE,qBAAC;GACC,UAA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K;KAAO,MAAM,CAAC,uBAAuB;KAAE,MAAM;MAA4C;IAE9F;IACD,oBAAC;KACO;KACN,YAAY,IAAI,IAAI,MAAM;KAC1B,eAAe,IAAI,YAAY;KAC/B,cAAc,QAAQ;KACtB,YAAY;MACZ;;IACG,EAEP,oBAAC;GAAK,UAAU,SAAS;GAAU,MAAM,SAAS;GAAM,MAAM,SAAS;aACrE,oBAAC,KAAK;IAAa;cAChB;;;iBAGI,IAAI,IAAI,MAAM,SAAS,SAAS;;;mCAGd,KAAK,KAAK;;;;;KAKrB;IACT,IACN;;CAGR,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-mcp",
|
|
3
|
-
"version": "4.31.
|
|
3
|
+
"version": "4.31.3",
|
|
4
4
|
"description": "Model Context Protocol (MCP) plugin for Kubb, generating MCP-compatible tools and schemas from OpenAPI specifications for AI assistants.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@kubb/react-fabric": "0.13.3",
|
|
77
|
-
"@kubb/core": "4.31.
|
|
78
|
-
"@kubb/oas": "4.31.
|
|
79
|
-
"@kubb/plugin-client": "4.31.
|
|
80
|
-
"@kubb/plugin-oas": "4.31.
|
|
81
|
-
"@kubb/plugin-ts": "4.31.
|
|
82
|
-
"@kubb/plugin-zod": "4.31.
|
|
77
|
+
"@kubb/core": "4.31.3",
|
|
78
|
+
"@kubb/oas": "4.31.3",
|
|
79
|
+
"@kubb/plugin-client": "4.31.3",
|
|
80
|
+
"@kubb/plugin-oas": "4.31.3",
|
|
81
|
+
"@kubb/plugin-ts": "4.31.3",
|
|
82
|
+
"@kubb/plugin-zod": "4.31.3"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {},
|
|
85
85
|
"engines": {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { camelCase, isValidVarName } from '@kubb/core/transformers'
|
|
1
2
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
2
|
-
import {
|
|
3
|
+
import type { SchemaObject } from '@kubb/oas'
|
|
3
4
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
4
|
-
import {
|
|
5
|
+
import { isOptional } from '@kubb/plugin-oas/utils'
|
|
5
6
|
import { Const, File, FunctionParams } from '@kubb/react-fabric'
|
|
6
7
|
import type { FabricReactNode } from '@kubb/react-fabric/types'
|
|
7
8
|
|
|
@@ -13,6 +14,7 @@ type Props = {
|
|
|
13
14
|
operations: Array<{
|
|
14
15
|
tool: {
|
|
15
16
|
name: string
|
|
17
|
+
title?: string
|
|
16
18
|
description: string
|
|
17
19
|
}
|
|
18
20
|
mcp: {
|
|
@@ -35,40 +37,57 @@ type GetParamsProps = {
|
|
|
35
37
|
paramsCasing?: 'camelcase'
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
function zodExprFromOasSchema(schema: SchemaObject): string {
|
|
41
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type]
|
|
42
|
+
const baseType = types.find((t) => t && t !== 'null')
|
|
43
|
+
const isNullableType = types.includes('null')
|
|
44
|
+
|
|
45
|
+
let expr: string
|
|
46
|
+
switch (baseType) {
|
|
47
|
+
case 'integer':
|
|
48
|
+
expr = 'z.coerce.number()'
|
|
49
|
+
break
|
|
50
|
+
case 'number':
|
|
51
|
+
expr = 'z.number()'
|
|
52
|
+
break
|
|
53
|
+
case 'boolean':
|
|
54
|
+
expr = 'z.boolean()'
|
|
55
|
+
break
|
|
56
|
+
case 'array':
|
|
57
|
+
expr = 'z.array(z.unknown())'
|
|
58
|
+
break
|
|
59
|
+
default:
|
|
60
|
+
expr = 'z.string()'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (isNullableType) {
|
|
64
|
+
expr = `${expr}.nullable()`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return expr
|
|
68
|
+
}
|
|
69
|
+
|
|
38
70
|
function getParams({ schemas, paramsCasing }: GetParamsProps) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
71
|
+
const pathParamProperties = schemas.pathParams?.schema?.properties ?? {}
|
|
72
|
+
const requiredFields = Array.isArray(schemas.pathParams?.schema?.required) ? schemas.pathParams.schema.required : []
|
|
73
|
+
|
|
74
|
+
const pathParamEntries = Object.entries(pathParamProperties).reduce<Record<string, { value: string; optional: boolean }>>(
|
|
75
|
+
(acc, [originalKey, propSchema]) => {
|
|
76
|
+
const key = paramsCasing === 'camelcase' || !isValidVarName(originalKey) ? camelCase(originalKey) : originalKey
|
|
77
|
+
acc[key] = {
|
|
78
|
+
value: zodExprFromOasSchema(propSchema as SchemaObject),
|
|
79
|
+
optional: !requiredFields.includes(originalKey),
|
|
80
|
+
}
|
|
81
|
+
return acc
|
|
82
|
+
},
|
|
83
|
+
{},
|
|
84
|
+
)
|
|
43
85
|
|
|
44
86
|
return FunctionParams.factory({
|
|
45
87
|
data: {
|
|
46
88
|
mode: 'object',
|
|
47
89
|
children: {
|
|
48
|
-
...
|
|
49
|
-
if (param && schemas.pathParams?.name) {
|
|
50
|
-
let suffix = '.shape'
|
|
51
|
-
|
|
52
|
-
if (isNullable(schemas.pathParams.schema)) {
|
|
53
|
-
if (isReference(schemas.pathParams)) {
|
|
54
|
-
suffix = '.unwrap().schema.unwrap().shape'
|
|
55
|
-
} else {
|
|
56
|
-
suffix = '.unwrap().shape'
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
if (isReference(schemas.pathParams)) {
|
|
60
|
-
suffix = '.schema.shape'
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
param.value = `${schemas.pathParams?.name}${suffix}['${key}']`
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
...acc,
|
|
69
|
-
[key]: param,
|
|
70
|
-
}
|
|
71
|
-
}, {}),
|
|
90
|
+
...pathParamEntries,
|
|
72
91
|
data: schemas.request?.name
|
|
73
92
|
? {
|
|
74
93
|
value: schemas.request?.name,
|
|
@@ -107,17 +126,31 @@ export function Server({ name, serverName, serverVersion, paramsCasing, operatio
|
|
|
107
126
|
{operations
|
|
108
127
|
.map(({ tool, mcp, zod }) => {
|
|
109
128
|
const paramsClient = getParams({ schemas: zod.schemas, paramsCasing })
|
|
129
|
+
const outputSchema = zod.schemas.response?.name
|
|
130
|
+
|
|
131
|
+
const config = [
|
|
132
|
+
tool.title ? `title: ${JSON.stringify(tool.title)}` : null,
|
|
133
|
+
`description: ${JSON.stringify(tool.description)}`,
|
|
134
|
+
outputSchema ? `outputSchema: { data: ${outputSchema} }` : null,
|
|
135
|
+
]
|
|
136
|
+
.filter(Boolean)
|
|
137
|
+
.join(',\n ')
|
|
110
138
|
|
|
111
139
|
if (zod.schemas.request?.name || zod.schemas.headerParams?.name || zod.schemas.queryParams?.name || zod.schemas.pathParams?.name) {
|
|
112
140
|
return `
|
|
113
|
-
server.
|
|
141
|
+
server.registerTool(${JSON.stringify(tool.name)}, {
|
|
142
|
+
${config},
|
|
143
|
+
inputSchema: ${paramsClient.toObjectValue()},
|
|
144
|
+
}, async (${paramsClient.toObject()}) => {
|
|
114
145
|
return ${mcp.name}(${paramsClient.toObject()})
|
|
115
146
|
})
|
|
116
147
|
`
|
|
117
148
|
}
|
|
118
149
|
|
|
119
150
|
return `
|
|
120
|
-
server.
|
|
151
|
+
server.registerTool(${JSON.stringify(tool.name)}, {
|
|
152
|
+
${config},
|
|
153
|
+
}, async () => {
|
|
121
154
|
return ${mcp.name}(${paramsClient.toObject()})
|
|
122
155
|
})
|
|
123
156
|
`
|
|
@@ -90,7 +90,8 @@ export const mcpGenerator = createReactGenerator<PluginMcp>({
|
|
|
90
90
|
type: 'text',
|
|
91
91
|
text: JSON.stringify(res.data)
|
|
92
92
|
}
|
|
93
|
-
]
|
|
93
|
+
],
|
|
94
|
+
structuredContent: { data: res.data }
|
|
94
95
|
}`}
|
|
95
96
|
{options.client.dataReturnType === 'full' &&
|
|
96
97
|
`return {
|
|
@@ -99,7 +100,8 @@ export const mcpGenerator = createReactGenerator<PluginMcp>({
|
|
|
99
100
|
type: 'text',
|
|
100
101
|
text: JSON.stringify(res)
|
|
101
102
|
}
|
|
102
|
-
]
|
|
103
|
+
],
|
|
104
|
+
structuredContent: { data: res.data }
|
|
103
105
|
}`}
|
|
104
106
|
</Client>
|
|
105
107
|
</File>
|
|
@@ -26,6 +26,7 @@ export const serverGenerator = createReactGenerator<PluginMcp>({
|
|
|
26
26
|
return {
|
|
27
27
|
tool: {
|
|
28
28
|
name: operation.getOperationId() || operation.getSummary() || `${operation.method.toUpperCase()} ${operation.path}`,
|
|
29
|
+
title: operation.getSummary() || undefined,
|
|
29
30
|
description: operation.getDescription() || `Make a ${operation.method.toUpperCase()} request to ${operation.path}`,
|
|
30
31
|
},
|
|
31
32
|
mcp: {
|
|
@@ -54,7 +55,13 @@ export const serverGenerator = createReactGenerator<PluginMcp>({
|
|
|
54
55
|
<File.Import key={mcp.name} name={[mcp.name]} root={file.path} path={mcp.file.path} />,
|
|
55
56
|
<File.Import
|
|
56
57
|
key={zod.name}
|
|
57
|
-
name={[
|
|
58
|
+
name={[
|
|
59
|
+
zod.schemas.request?.name,
|
|
60
|
+
zod.schemas.pathParams?.name,
|
|
61
|
+
zod.schemas.queryParams?.name,
|
|
62
|
+
zod.schemas.headerParams?.name,
|
|
63
|
+
zod.schemas.response?.name,
|
|
64
|
+
].filter(Boolean)}
|
|
58
65
|
root={file.path}
|
|
59
66
|
path={zod.file.path}
|
|
60
67
|
/>,
|
|
@@ -71,6 +78,7 @@ export const serverGenerator = createReactGenerator<PluginMcp>({
|
|
|
71
78
|
footer={getFooter({ oas, output: options.output })}
|
|
72
79
|
>
|
|
73
80
|
<File.Import name={['McpServer']} path={'@modelcontextprotocol/sdk/server/mcp'} />
|
|
81
|
+
<File.Import name={['z']} path={'zod'} />
|
|
74
82
|
<File.Import name={['StdioServerTransport']} path={'@modelcontextprotocol/sdk/server/stdio'} />
|
|
75
83
|
|
|
76
84
|
{imports}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Server-D3kNei96.js","names":[],"sources":["../src/components/Server.tsx"],"sourcesContent":["import 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 { FabricReactNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n name: string\n serverName: string\n serverVersion: string\n paramsCasing?: 'camelcase'\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 paramsCasing?: 'camelcase'\n}\n\nfunction getParams({ schemas, paramsCasing }: GetParamsProps) {\n const pathParams = getPathParams(schemas.pathParams, {\n typed: false,\n casing: paramsCasing,\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 [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, paramsCasing, operations }: Props): FabricReactNode {\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, paramsCasing })\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 {`\nexport async 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`}\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;AAqCA,SAAS,UAAU,EAAE,SAAS,gBAAgC;CAC5D,MAAM,aAAa,cAAc,QAAQ,YAAY;EACnD,OAAO;EACP,QAAQ;EACT,CAAC;AAEF,QAAO,eAAe,QAAQ,EAC5B,MAAM;EACJ,MAAM;EACN,UAAU;GACR,GAAG,OAAO,QAAQ,WAAW,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC1D,QAAI,SAAS,QAAQ,YAAY,MAAM;KACrC,IAAI,SAAS;AAEb,SAAI,WAAW,QAAQ,WAAW,OAAO,CACvC,KAAI,YAAY,QAAQ,WAAW,CACjC,UAAS;SAET,UAAS;cAGP,YA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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Server-N9lWEnVE.cjs","names":["FunctionParams","File","Const"],"sources":["../src/components/Server.tsx"],"sourcesContent":["import 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 { FabricReactNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n name: string\n serverName: string\n serverVersion: string\n paramsCasing?: 'camelcase'\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 paramsCasing?: 'camelcase'\n}\n\nfunction getParams({ schemas, paramsCasing }: GetParamsProps) {\n const pathParams = getPathParams(schemas.pathParams, {\n typed: false,\n casing: paramsCasing,\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 [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, paramsCasing, operations }: Props): FabricReactNode {\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, paramsCasing })\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 {`\nexport async 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`}\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAS,UAAU,EAAE,SAAS,gBAAgC;CAC5D,MAAM,uDAA2B,QAAQ,YAAY;EACnD,OAAO;EACP,QAAQ;EACT,CAAC;AAEF,QAAOA,kCAAe,QAAQ,EAC5B,MAAM;EACJ,MAAM;EACN,UAAU;GACR,GAAG,OAAO,QAAQ,WAAW,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;AAC1D,QAAI,SAAS,QAAQ,YAAY,MAAM;KACrC,IAAI,SAAS;AAEb,mCAAe,QAAQ,WAAW,OAAO,CACvC,gCAAgB,QAAQ,WAAW,CACjC,UAAS;SAET,UAAS;yCAGK,QAAQ,WAAW,CACjC,UAAS;AAIb,WAAM,QAAQ,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A8IBI-18.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={['Client', '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={['Client', '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={options.client?.paramsCasing || options.paramsCasing}\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\n name={name}\n serverName={oas.api.info?.title}\n serverVersion={oas.getVersion()}\n paramsCasing={options.paramsCasing}\n operations={operationsMapped}\n />\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\", \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,aAAa;KAAM,IAAI,QAAQ,cAAc;KAAK,CAAC,OAAO,QAAQ;IAC9I,MAAM,KAAK;IACX,MAAM,IAAI,KAAK;MAHV,IAAI,KAIT,CACH;IACD;AAEF,SACE,+GACE,yDAACA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,8CAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChF,8CAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;;IAElD,wDAACA,wBAAK;KAAO,MAAM,CAAC,YAAY;KAAE,MAAM;MAA0C;IAClF,wDAACA,wBAAK;KAAO,MAAM,CAAC,uBAAuB;KAAE,MAAM;MAA4C;IAE9F;IACD,wDAACC;KACO;KACN,YAAY,IAAI,IAAI,MAAM;KAC1B,eAAe,IAAI,YAAY;KAC/B,cAAc,QAAQ;KACtB,YAAY;MACZ;;IACG,EAEP,wDAACD;GAAK,UAAU,SAAS;GAAU,MAAM,SAAS;GAAM,MAAM,SAAS;aACrE,wDAACA,wBAAK;IAAa;cAChB;;;iBAGI,IAAI,IAAI,MAAM,SAAS,SAAS;;;mCAGd,KAAK,KAAK;;;;;KAKrB;IACT,IACN;;CAGR,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serverGenerator-DfxZTxke.js","names":[],"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={['Client', '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={['Client', '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={options.client?.paramsCasing || options.paramsCasing}\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\n name={name}\n serverName={oas.api.info?.title}\n serverVersion={oas.getVersion()}\n paramsCasing={options.paramsCasing}\n operations={operationsMapped}\n />\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,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EAAE,YAAY;EACpB,MAAM,MAAM,QAAQ;EAEpB,MAAM,EAAE,YAAY,SAAS,YAAY,oBAAoB,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,CAA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