@orval/mcp 7.15.0 → 8.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +57 -104
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
package/dist/index.js
CHANGED
|
@@ -1,48 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
let __orval_core = require("@orval/core");
|
|
26
|
-
__orval_core = __toESM(__orval_core);
|
|
27
|
-
let __orval_fetch = require("@orval/fetch");
|
|
28
|
-
__orval_fetch = __toESM(__orval_fetch);
|
|
29
|
-
let __orval_zod = require("@orval/zod");
|
|
30
|
-
__orval_zod = __toESM(__orval_zod);
|
|
31
|
-
require("openapi3-ts/oas30");
|
|
1
|
+
import { camel, generateMutatorImports, getFileInfo, getFullRoute, jsDoc, pascal, upath } from "@orval/core";
|
|
2
|
+
import { generateClient, generateFetchHeader } from "@orval/fetch";
|
|
3
|
+
import { generateZod } from "@orval/zod";
|
|
32
4
|
|
|
33
5
|
//#region src/index.ts
|
|
34
6
|
const getHeader = (option, info) => {
|
|
35
7
|
if (!option) return "";
|
|
36
8
|
const header = option(info);
|
|
37
|
-
return Array.isArray(header) ?
|
|
9
|
+
return Array.isArray(header) ? jsDoc({ description: header }) : header;
|
|
38
10
|
};
|
|
39
11
|
const getMcpHeader = ({ verbOptions, output, clientImplementation }) => {
|
|
40
|
-
const targetInfo =
|
|
41
|
-
const schemaInfo =
|
|
42
|
-
const relativeSchemaImportPath = output.schemas ?
|
|
43
|
-
|
|
12
|
+
const targetInfo = getFileInfo(output.target);
|
|
13
|
+
const schemaInfo = getFileInfo(output.schemas);
|
|
14
|
+
const relativeSchemaImportPath = output.schemas ? upath.relativeSafe(targetInfo.dirname, schemaInfo.dirname) : "./" + targetInfo.filename + ".schemas";
|
|
15
|
+
return [`import {\n ${Object.values(verbOptions).flatMap((verbOption) => {
|
|
44
16
|
const imports = [];
|
|
45
|
-
const pascalOperationName =
|
|
17
|
+
const pascalOperationName = pascal(verbOption.operationName);
|
|
46
18
|
if (verbOption.queryParams) imports.push(`${pascalOperationName}Params`);
|
|
47
19
|
if (verbOption.body.definition) imports.push(`${pascalOperationName}Body`);
|
|
48
20
|
return imports;
|
|
@@ -50,20 +22,16 @@ const getMcpHeader = ({ verbOptions, output, clientImplementation }) => {
|
|
|
50
22
|
if (!acc.find((i) => i === name)) acc.push(name);
|
|
51
23
|
return acc;
|
|
52
24
|
}, []).join(",\n ")}\n} from '${relativeSchemaImportPath}';
|
|
53
|
-
|
|
54
|
-
const importFetchClientImplementation = `import {\n ${Object.values(verbOptions).flatMap((verbOption) => verbOption.operationName).reduce((acc, name) => {
|
|
25
|
+
`, `import {\n ${Object.values(verbOptions).flatMap((verbOption) => verbOption.operationName).reduce((acc, name) => {
|
|
55
26
|
if (!acc.find((i) => i === name)) acc.push(name);
|
|
56
27
|
return acc;
|
|
57
28
|
}, []).join(",\n ")}\n} from './http-client';
|
|
58
|
-
|
|
59
|
-
return [importSchemasImplementation, importFetchClientImplementation].join("\n") + "\n";
|
|
29
|
+
`].join("\n") + "\n";
|
|
60
30
|
};
|
|
61
31
|
const generateMcp = async (verbOptions, options) => {
|
|
62
32
|
const handlerArgsTypes = [];
|
|
63
33
|
const pathParamsType = verbOptions.params.map((param) => {
|
|
64
|
-
|
|
65
|
-
const paramType = param.implementation.split(": ")[1];
|
|
66
|
-
return ` ${paramName}: ${paramType}`;
|
|
34
|
+
return ` ${param.name.split(": ")[0]}: ${param.implementation.split(": ")[1]}`;
|
|
67
35
|
}).join(",\n");
|
|
68
36
|
if (pathParamsType) handlerArgsTypes.push(` pathParams: {\n${pathParamsType}\n };`);
|
|
69
37
|
if (verbOptions.queryParams) handlerArgsTypes.push(` queryParams: ${verbOptions.queryParams.schema.name};`);
|
|
@@ -83,7 +51,7 @@ ${handlerArgsTypes.join("\n")}
|
|
|
83
51
|
}
|
|
84
52
|
if (verbOptions.body.definition) fetchParams.push(`args.bodyParams`);
|
|
85
53
|
if (verbOptions.queryParams) fetchParams.push(`args.queryParams`);
|
|
86
|
-
const
|
|
54
|
+
const handlersImplementation = [handlerArgsImplementation, `
|
|
87
55
|
export const ${`${verbOptions.operationName}Handler`} = async (${handlerArgsTypes.length > 0 ? `args: ${handlerArgsName}` : ""}) => {
|
|
88
56
|
const res = await ${verbOptions.operationName}(${fetchParams.join(", ")});
|
|
89
57
|
|
|
@@ -95,8 +63,7 @@ export const ${`${verbOptions.operationName}Handler`} = async (${handlerArgsType
|
|
|
95
63
|
},
|
|
96
64
|
],
|
|
97
65
|
};
|
|
98
|
-
}
|
|
99
|
-
const handlersImplementation = [handlerArgsImplementation, handlerImplementation].join("");
|
|
66
|
+
};`].join("");
|
|
100
67
|
return {
|
|
101
68
|
implementation: handlersImplementation ? `${handlersImplementation}\n` : "",
|
|
102
69
|
imports: []
|
|
@@ -104,8 +71,8 @@ export const ${`${verbOptions.operationName}Handler`} = async (${handlerArgsType
|
|
|
104
71
|
};
|
|
105
72
|
const generateServer = async (verbOptions, output, context) => {
|
|
106
73
|
const info = context.specs[context.specKey].info;
|
|
107
|
-
const { extension, dirname } =
|
|
108
|
-
const serverPath =
|
|
74
|
+
const { extension, dirname } = getFileInfo(output.target);
|
|
75
|
+
const serverPath = upath.join(dirname, `server${extension}`);
|
|
109
76
|
const header = getHeader(output.override.header, info);
|
|
110
77
|
const toolImplementations = Object.values(verbOptions).map((verbOption) => {
|
|
111
78
|
const imputSchemaTypes = [];
|
|
@@ -130,28 +97,25 @@ server.tool(
|
|
|
130
97
|
if (verbOption.body.definition) imports.push(` ${verbOption.operationName}Body`);
|
|
131
98
|
return imports;
|
|
132
99
|
}).join(",\n")}\n} from './tool-schemas.zod';`;
|
|
133
|
-
|
|
134
|
-
|
|
100
|
+
return [{
|
|
101
|
+
content: [
|
|
102
|
+
header,
|
|
103
|
+
`import {
|
|
135
104
|
McpServer
|
|
136
105
|
} from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
137
106
|
|
|
138
107
|
import {
|
|
139
108
|
StdioServerTransport
|
|
140
109
|
} from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
141
|
-
|
|
142
|
-
|
|
110
|
+
`,
|
|
111
|
+
`import {\n${Object.values(verbOptions).filter((verbOption) => toolImplementations.includes(`${verbOption.operationName}Handler`)).map((verbOption) => ` ${verbOption.operationName}Handler`).join(`,\n`)}\n} from './handlers';`,
|
|
112
|
+
importToolSchemasImplementation,
|
|
113
|
+
`
|
|
143
114
|
const server = new McpServer({
|
|
144
|
-
name: '${
|
|
115
|
+
name: '${camel(info.title)}Server',
|
|
145
116
|
version: '1.0.0',
|
|
146
117
|
});
|
|
147
|
-
|
|
148
|
-
return [{
|
|
149
|
-
content: [
|
|
150
|
-
header,
|
|
151
|
-
importDependenciesImplementation,
|
|
152
|
-
importHandlersImplementation,
|
|
153
|
-
importToolSchemasImplementation,
|
|
154
|
-
newMcpServerImplementation,
|
|
118
|
+
`,
|
|
155
119
|
toolImplementations,
|
|
156
120
|
`
|
|
157
121
|
const transport = new StdioServerTransport();
|
|
@@ -165,9 +129,9 @@ server.connect(transport).then(() => {
|
|
|
165
129
|
}];
|
|
166
130
|
};
|
|
167
131
|
const generateZodFiles = async (verbOptions, output, context) => {
|
|
168
|
-
const { extension, dirname, filename } =
|
|
132
|
+
const { extension, dirname, filename } = getFileInfo(output.target);
|
|
169
133
|
const header = getHeader(output.override.header, context.specs[context.specKey].info);
|
|
170
|
-
const zods = await Promise.all(Object.values(verbOptions).map((verbOption) =>
|
|
134
|
+
const zods = await Promise.all(Object.values(verbOptions).map((verbOption) => generateZod(verbOption, {
|
|
171
135
|
route: verbOption.route,
|
|
172
136
|
pathRoute: verbOption.pathRoute,
|
|
173
137
|
override: output.override,
|
|
@@ -179,9 +143,8 @@ const generateZodFiles = async (verbOptions, output, context) => {
|
|
|
179
143
|
for (const mutator of z.mutators ?? []) acc[mutator.name] = mutator;
|
|
180
144
|
return acc;
|
|
181
145
|
}, {});
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const zodPath = __orval_core.upath.join(dirname, `tool-schemas.zod${extension}`);
|
|
146
|
+
let content = `${header}import { z as zod } from 'zod';\n${generateMutatorImports({ mutators: Object.values(allMutators) })}\n`;
|
|
147
|
+
const zodPath = upath.join(dirname, `tool-schemas.zod${extension}`);
|
|
185
148
|
content += zods.map((zod) => zod.implementation).join("\n");
|
|
186
149
|
return [{
|
|
187
150
|
content,
|
|
@@ -189,47 +152,42 @@ const generateZodFiles = async (verbOptions, output, context) => {
|
|
|
189
152
|
}];
|
|
190
153
|
};
|
|
191
154
|
const generateHttpClinetFiles = async (verbOptions, output, context) => {
|
|
192
|
-
const { extension, dirname, filename } =
|
|
155
|
+
const { extension, dirname, filename } = getFileInfo(output.target);
|
|
193
156
|
const header = getHeader(output.override.header, context.specs[context.specKey].info);
|
|
194
157
|
const clients = await Promise.all(Object.values(verbOptions).map((verbOption) => {
|
|
195
|
-
|
|
196
|
-
route:
|
|
158
|
+
return generateClient(verbOption, {
|
|
159
|
+
route: getFullRoute(verbOption.route, context.specs[context.specKey].servers, output.baseUrl),
|
|
197
160
|
pathRoute: verbOption.pathRoute,
|
|
198
161
|
override: output.override,
|
|
199
162
|
context,
|
|
200
163
|
mock: output.mock,
|
|
201
164
|
output: output.target
|
|
202
|
-
};
|
|
203
|
-
return (0, __orval_fetch.generateClient)(verbOption, options, output.client, output);
|
|
165
|
+
}, output.client, output);
|
|
204
166
|
}));
|
|
205
167
|
const clientImplementation = clients.map((client) => client.implementation).join("\n");
|
|
206
|
-
const relativeSchemasPath = output.schemas ?
|
|
207
|
-
const importImplementation = `import { ${clients.flatMap((client) => client.imports).reduce((acc, imp) => {
|
|
208
|
-
if (!acc.find((i) => i === imp.name)) acc.push(imp.name);
|
|
209
|
-
return acc;
|
|
210
|
-
}, []).join(",\n")} } from '${relativeSchemasPath}';`;
|
|
211
|
-
const fetchHeader = (0, __orval_fetch.generateFetchHeader)({
|
|
212
|
-
title: "",
|
|
213
|
-
isRequestOptions: false,
|
|
214
|
-
isMutator: false,
|
|
215
|
-
noFunction: false,
|
|
216
|
-
isGlobalMutator: false,
|
|
217
|
-
provideIn: false,
|
|
218
|
-
hasAwaitedType: false,
|
|
219
|
-
output,
|
|
220
|
-
verbOptions,
|
|
221
|
-
clientImplementation
|
|
222
|
-
});
|
|
223
|
-
const content = [
|
|
224
|
-
header,
|
|
225
|
-
importImplementation,
|
|
226
|
-
fetchHeader,
|
|
227
|
-
clientImplementation
|
|
228
|
-
].join("\n");
|
|
229
|
-
const outputPath = __orval_core.upath.join(dirname, `http-client${extension}`);
|
|
168
|
+
const relativeSchemasPath = output.schemas ? upath.relativeSafe(dirname, getFileInfo(output.schemas).dirname) : "./" + filename + ".schemas";
|
|
230
169
|
return [{
|
|
231
|
-
content
|
|
232
|
-
|
|
170
|
+
content: [
|
|
171
|
+
header,
|
|
172
|
+
`import { ${clients.flatMap((client) => client.imports).reduce((acc, imp) => {
|
|
173
|
+
if (!acc.find((i) => i === imp.name)) acc.push(imp.name);
|
|
174
|
+
return acc;
|
|
175
|
+
}, []).join(",\n")} } from '${relativeSchemasPath}';`,
|
|
176
|
+
generateFetchHeader({
|
|
177
|
+
title: "",
|
|
178
|
+
isRequestOptions: false,
|
|
179
|
+
isMutator: false,
|
|
180
|
+
noFunction: false,
|
|
181
|
+
isGlobalMutator: false,
|
|
182
|
+
provideIn: false,
|
|
183
|
+
hasAwaitedType: false,
|
|
184
|
+
output,
|
|
185
|
+
verbOptions,
|
|
186
|
+
clientImplementation
|
|
187
|
+
}),
|
|
188
|
+
clientImplementation
|
|
189
|
+
].join("\n"),
|
|
190
|
+
path: upath.join(dirname, `http-client${extension}`)
|
|
233
191
|
}];
|
|
234
192
|
};
|
|
235
193
|
const generateExtraFiles = async (verbOptions, output, context) => {
|
|
@@ -253,10 +211,5 @@ const builder = () => () => mcpClientBuilder;
|
|
|
253
211
|
var src_default = builder;
|
|
254
212
|
|
|
255
213
|
//#endregion
|
|
256
|
-
|
|
257
|
-
exports.default = src_default;
|
|
258
|
-
exports.generateExtraFiles = generateExtraFiles;
|
|
259
|
-
exports.generateMcp = generateMcp;
|
|
260
|
-
exports.generateServer = generateServer;
|
|
261
|
-
exports.getMcpHeader = getMcpHeader;
|
|
214
|
+
export { builder, src_default as default, generateExtraFiles, generateMcp, generateServer, getMcpHeader };
|
|
262
215
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["getMcpHeader: ClientHeaderBuilder","upath","generateMcp: ClientBuilder","generateExtraFiles: ClientExtraFilesBuilder","mcpClientBuilder: ClientGeneratorsBuilder"],"sources":["../src/index.ts"],"sourcesContent":["import {\n camel,\n ClientBuilder,\n ClientExtraFilesBuilder,\n ClientGeneratorsBuilder,\n ClientHeaderBuilder,\n ContextSpecs,\n generateMutatorImports,\n generateVerbImports,\n GeneratorMutator,\n GeneratorVerbOptions,\n getFileInfo,\n getFullRoute,\n jsDoc,\n NormalizedOutputOptions,\n pascal,\n upath,\n} from '@orval/core';\nimport {\n generateClient,\n generateFetchHeader,\n generateRequestFunction as generateFetchRequestFunction,\n} from '@orval/fetch';\nimport { generateZod } from '@orval/zod';\nimport { InfoObject } from 'openapi3-ts/oas30';\n\nconst getHeader = (\n option: false | ((info: InfoObject) => string | string[]),\n info: InfoObject,\n): string => {\n if (!option) {\n return '';\n }\n\n const header = option(info);\n\n return Array.isArray(header) ? jsDoc({ description: header }) : header;\n};\n\nexport const getMcpHeader: ClientHeaderBuilder = ({\n verbOptions,\n output,\n clientImplementation,\n}) => {\n const targetInfo = getFileInfo(output.target);\n const schemaInfo = getFileInfo(output.schemas);\n\n const relativeSchemaImportPath = output.schemas\n ? upath.relativeSafe(targetInfo.dirname, schemaInfo.dirname)\n : './' + targetInfo.filename + '.schemas';\n\n const importSchemaNames = Object.values(verbOptions)\n .flatMap((verbOption) => {\n const imports = [];\n const pascalOperationName = pascal(verbOption.operationName);\n\n if (verbOption.queryParams) {\n imports.push(`${pascalOperationName}Params`);\n }\n\n if (verbOption.body.definition) {\n imports.push(`${pascalOperationName}Body`);\n }\n\n return imports;\n })\n .reduce<string[]>((acc, name) => {\n if (!acc.find((i) => i === name)) {\n acc.push(name);\n }\n return acc;\n }, []);\n\n const importSchemasImplementation = `import {\\n ${importSchemaNames.join(\n ',\\n ',\n )}\\n} from '${relativeSchemaImportPath}';\n`;\n\n const relativeFetchClientPath = './http-client';\n const importFetchClientNames = Object.values(verbOptions)\n .flatMap((verbOption) => verbOption.operationName)\n .reduce<string[]>((acc, name) => {\n if (!acc.find((i) => i === name)) {\n acc.push(name);\n }\n\n return acc;\n }, []);\n\n const importFetchClientImplementation = `import {\\n ${importFetchClientNames.join(\n ',\\n ',\n )}\\n} from '${relativeFetchClientPath}';\n `;\n\n const content = [\n importSchemasImplementation,\n importFetchClientImplementation,\n ].join('\\n');\n\n return content + '\\n';\n};\n\nexport const generateMcp: ClientBuilder = async (verbOptions, options) => {\n const handlerArgsTypes = [];\n const pathParamsType = verbOptions.params\n .map((param) => {\n const paramName = param.name.split(': ')[0];\n const paramType = param.implementation.split(': ')[1];\n return ` ${paramName}: ${paramType}`;\n })\n .join(',\\n');\n if (pathParamsType) {\n handlerArgsTypes.push(` pathParams: {\\n${pathParamsType}\\n };`);\n }\n if (verbOptions.queryParams) {\n handlerArgsTypes.push(\n ` queryParams: ${verbOptions.queryParams.schema.name};`,\n );\n }\n if (verbOptions.body.definition) {\n handlerArgsTypes.push(` bodyParams: ${verbOptions.body.definition};`);\n }\n\n const handlerArgsName = `${verbOptions.operationName}Args`;\n const handlerArgsImplementation =\n handlerArgsTypes.length > 0\n ? `\nexport type ${handlerArgsName} = {\n${handlerArgsTypes.join('\\n')}\n}\n`\n : '';\n\n const fetchParams = [];\n if (verbOptions.params.length > 0) {\n const pathParamsArgs = verbOptions.params\n .map((param) => {\n const paramName = param.name.split(': ')[0];\n\n return `args.pathParams.${paramName}`;\n })\n .join(', ');\n\n fetchParams.push(pathParamsArgs);\n }\n if (verbOptions.body.definition) fetchParams.push(`args.bodyParams`);\n if (verbOptions.queryParams) fetchParams.push(`args.queryParams`);\n\n const handlerName = `${verbOptions.operationName}Handler`;\n const handlerImplementation = `\nexport const ${handlerName} = async (${handlerArgsTypes.length > 0 ? `args: ${handlerArgsName}` : ''}) => {\n const res = await ${verbOptions.operationName}(${fetchParams.join(', ')});\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(res),\n },\n ],\n };\n};`;\n\n const handlersImplementation = [\n handlerArgsImplementation,\n handlerImplementation,\n ].join('');\n\n return {\n implementation: handlersImplementation ? `${handlersImplementation}\\n` : '',\n imports: [],\n };\n};\n\nexport const generateServer = async (\n verbOptions: Record<string, GeneratorVerbOptions>,\n output: NormalizedOutputOptions,\n context: ContextSpecs,\n) => {\n const info = context.specs[context.specKey].info;\n const { extension, dirname } = getFileInfo(output.target);\n const serverPath = upath.join(dirname, `server${extension}`);\n const header = getHeader(output.override.header, info);\n\n const toolImplementations = Object.values(verbOptions)\n .map((verbOption) => {\n const imputSchemaTypes = [];\n if (verbOption.params.length > 0)\n imputSchemaTypes.push(\n ` pathParams: ${verbOption.operationName}Params`,\n );\n if (verbOption.queryParams)\n imputSchemaTypes.push(\n ` queryParams: ${verbOption.operationName}QueryParams`,\n );\n if (verbOption.body.definition)\n imputSchemaTypes.push(` bodyParams: ${verbOption.operationName}Body`);\n\n const imputSchemaImplementation =\n imputSchemaTypes.length > 0\n ? ` {\n ${imputSchemaTypes.join(',\\n ')}\n },`\n : '';\n\n const toolImplementation = `\nserver.tool(\n '${verbOption.operationName}',\n '${verbOption.summary}',${imputSchemaImplementation ? `\\n${imputSchemaImplementation}` : ''}\n ${verbOption.operationName}Handler\n);`;\n\n return toolImplementation;\n })\n .join('\\n');\n\n const importToolSchemas = Object.values(verbOptions)\n .flatMap((verbOption) => {\n const imports = [];\n\n if (verbOption.headers)\n imports.push(` ${verbOption.operationName}Header`);\n if (verbOption.params.length > 0)\n imports.push(` ${verbOption.operationName}Params`);\n if (verbOption.queryParams)\n imports.push(` ${verbOption.operationName}QueryParams`);\n if (verbOption.body.definition)\n imports.push(` ${verbOption.operationName}Body`);\n\n return imports;\n })\n .join(',\\n');\n const importToolSchemasImplementation = `import {\\n${importToolSchemas}\\n} from './tool-schemas.zod';`;\n\n const importHandlers = Object.values(verbOptions)\n .filter((verbOption) =>\n toolImplementations.includes(`${verbOption.operationName}Handler`),\n )\n .map((verbOption) => ` ${verbOption.operationName}Handler`)\n .join(`,\\n`);\n const importHandlersImplementation = `import {\\n${importHandlers}\\n} from './handlers';`;\n\n const importDependenciesImplementation = `import {\n McpServer\n} from '@modelcontextprotocol/sdk/server/mcp.js';\n \nimport {\n StdioServerTransport\n} from '@modelcontextprotocol/sdk/server/stdio.js'; \n`;\n const newMcpServerImplementation = `\nconst server = new McpServer({\n name: '${camel(info.title)}Server',\n version: '1.0.0',\n});\n`;\n const serverConnectImplementation = `\nconst transport = new StdioServerTransport();\n\nserver.connect(transport).then(() => {\n console.error('MCP server running on stdio');\n}).catch(console.error);\n`;\n\n const content = [\n header,\n importDependenciesImplementation,\n importHandlersImplementation,\n importToolSchemasImplementation,\n newMcpServerImplementation,\n toolImplementations,\n serverConnectImplementation,\n ].join('\\n');\n\n return [\n {\n content,\n path: serverPath,\n },\n ];\n};\n\nconst generateZodFiles = async (\n verbOptions: Record<string, GeneratorVerbOptions>,\n output: NormalizedOutputOptions,\n context: ContextSpecs,\n) => {\n const { extension, dirname, filename } = getFileInfo(output.target);\n\n const header = getHeader(\n output.override.header,\n context.specs[context.specKey].info,\n );\n\n const zods = await Promise.all(\n Object.values(verbOptions).map((verbOption) =>\n generateZod(\n verbOption,\n {\n route: verbOption.route,\n pathRoute: verbOption.pathRoute,\n override: output.override,\n context,\n mock: output.mock,\n output: output.target!,\n },\n output.client,\n ),\n ),\n );\n\n const allMutators = zods.reduce(\n (acc, z) => {\n for (const mutator of z.mutators ?? []) {\n acc[mutator.name] = mutator;\n }\n return acc;\n },\n {} as Record<string, GeneratorMutator>,\n );\n\n const mutatorsImports = generateMutatorImports({\n mutators: Object.values(allMutators),\n });\n\n let content = `${header}import { z as zod } from 'zod';\\n${mutatorsImports}\\n`;\n\n const zodPath = upath.join(dirname, `tool-schemas.zod${extension}`);\n\n content += zods.map((zod) => zod.implementation).join('\\n');\n\n return [\n {\n content,\n path: zodPath,\n },\n ];\n};\n\nconst generateHttpClinetFiles = async (\n verbOptions: Record<string, GeneratorVerbOptions>,\n output: NormalizedOutputOptions,\n context: ContextSpecs,\n) => {\n const { extension, dirname, filename } = getFileInfo(output.target);\n\n const header = getHeader(\n output.override.header,\n context.specs[context.specKey].info,\n );\n\n const clients = await Promise.all(\n Object.values(verbOptions).map((verbOption) => {\n const fullRoute = getFullRoute(\n verbOption.route,\n context.specs[context.specKey].servers,\n output.baseUrl,\n );\n\n const options = {\n route: fullRoute,\n pathRoute: verbOption.pathRoute,\n override: output.override,\n context,\n mock: output.mock,\n output: output.target!,\n };\n\n return generateClient(verbOption, options, output.client, output);\n }),\n );\n\n const clientImplementation = clients\n .map((client) => client.implementation)\n .join('\\n');\n\n const relativeSchemasPath = output.schemas\n ? upath.relativeSafe(dirname, getFileInfo(output.schemas).dirname)\n : './' + filename + '.schemas';\n const importNames = clients\n .flatMap((client) => client.imports)\n .reduce((acc, imp) => {\n if (!acc.find((i) => i === imp.name)) {\n acc.push(imp.name);\n }\n\n return acc;\n }, [] as string[]);\n const importImplementation = `import { ${importNames.join(\n ',\\n',\n )} } from '${relativeSchemasPath}';`;\n\n const fetchHeader = generateFetchHeader({\n title: '',\n isRequestOptions: false,\n isMutator: false,\n noFunction: false,\n isGlobalMutator: false,\n provideIn: false,\n hasAwaitedType: false,\n output,\n verbOptions,\n clientImplementation,\n });\n\n const content = [\n header,\n importImplementation,\n fetchHeader,\n clientImplementation,\n ].join('\\n');\n const outputPath = upath.join(dirname, `http-client${extension}`);\n\n return [\n {\n content,\n path: outputPath,\n },\n ];\n};\n\nexport const generateExtraFiles: ClientExtraFilesBuilder = async (\n verbOptions,\n output,\n context,\n) => {\n const [server, zods, httpClients] = await Promise.all([\n generateServer(verbOptions, output, context),\n generateZodFiles(verbOptions, output, context),\n generateHttpClinetFiles(verbOptions, output, context),\n ]);\n\n return [...server, ...zods, ...httpClients];\n};\n\nconst mcpClientBuilder: ClientGeneratorsBuilder = {\n client: generateMcp,\n header: getMcpHeader,\n extraFiles: generateExtraFiles,\n};\n\nexport const builder = () => () => mcpClientBuilder;\n\nexport default builder;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,aACJ,QACA,SACW;AACX,KAAI,CAAC,OACH,QAAO;CAGT,MAAM,SAA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AAY,SAAS,OAAO,QAAQ,OAAO;GACjE,CACH;CAED,MAAM,uBAAuB,QAC1B,KAAK,WAAW,OAAO,eAAe,CACtC,KAAK,KAAK;CAEb,MAAM,sBAAsB,OAAO,UAC/BA,mBAAM,aAAa,uCAAqB,OAAO,QAAQ,CAAC,QAAQ,GAChE,OAAO,WAAW;CAUtB,MAAM,uBAAuB,YATT,QACjB,SAAS,WAAW,OAAO,QAAQ,CACnC,QAAQ,KAAK,QAAQ;AACpB,MAAI,CAAC,IAAI,MAAM,MAAM,MAAM,IAAI,KAAK,CAClC,KAAI,KAAK,IAAI,KAAK;AAGpB,SAAO;IACN,EAAE,CAAa,CACiC,KACnD,MACD,CAAC,WAAW,oBAAoB;CAEjC,MAAM,qDAAkC;EACtC,OAAO;EACP,kBAAkB;EAClB,WAAW;EACX,YAAY;EACZ,iBAAiB;EACjB,WAAW;EACX,gBAAgB;EAChB;EACA;EACA;EACD,CAAC;CAEF,MAAM,UAAU;EACd;EACA;EACA;EACA;EACD,CAAC,KAAK,KAAK;CACZ,MAAM,aAAaA,mBAAM,KAAK,SAAS,cAAc,YAAY;AAEjE,QAAO,CACL;EACE;EACA,MAAM;EACP,CACF;;AAGH,MAAaE,qBAA8C,OACzD,aACA,QACA,YACG;CACH,MAAM,CAAC,QAAQ,MAAM,eAAe,MAAM,QAAQ,IAAI;EACpD,eAAe,aAAa,QAAQ,QAAQ;EAC5C,iBAAiB,aAAa,QAAQ,QAAQ;EAC9C,wBAAwB,aAAa,QAAQ,QAAQ;EACtD,CAAC;AAEF,QAAO;EAAC,GAAG;EAAQ,GAAG;EAAM,GAAG;EAAY;;AAG7C,MAAMC,mBAA4C;CAChD,QAAQ;CACR,QAAQ;CACR,YAAY;CACb;AAED,MAAa,sBAAsB;AAEnC,kBAAe"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["getMcpHeader: ClientHeaderBuilder","generateMcp: ClientBuilder","generateExtraFiles: ClientExtraFilesBuilder","mcpClientBuilder: ClientGeneratorsBuilder"],"sources":["../src/index.ts"],"sourcesContent":["import {\n camel,\n type ClientBuilder,\n type ClientExtraFilesBuilder,\n type ClientGeneratorsBuilder,\n type ClientHeaderBuilder,\n type ContextSpecs,\n generateMutatorImports,\n type GeneratorMutator,\n type GeneratorVerbOptions,\n getFileInfo,\n getFullRoute,\n jsDoc,\n type NormalizedOutputOptions,\n pascal,\n upath,\n} from '@orval/core';\nimport { generateClient, generateFetchHeader } from '@orval/fetch';\nimport { generateZod } from '@orval/zod';\nimport type { InfoObject } from 'openapi3-ts/oas30';\n\nconst getHeader = (\n option: false | ((info: InfoObject) => string | string[]),\n info: InfoObject,\n): string => {\n if (!option) {\n return '';\n }\n\n const header = option(info);\n\n return Array.isArray(header) ? jsDoc({ description: header }) : header;\n};\n\nexport const getMcpHeader: ClientHeaderBuilder = ({\n verbOptions,\n output,\n clientImplementation,\n}) => {\n const targetInfo = getFileInfo(output.target);\n const schemaInfo = getFileInfo(output.schemas);\n\n const relativeSchemaImportPath = output.schemas\n ? upath.relativeSafe(targetInfo.dirname, schemaInfo.dirname)\n : './' + targetInfo.filename + '.schemas';\n\n const importSchemaNames = Object.values(verbOptions)\n .flatMap((verbOption) => {\n const imports = [];\n const pascalOperationName = pascal(verbOption.operationName);\n\n if (verbOption.queryParams) {\n imports.push(`${pascalOperationName}Params`);\n }\n\n if (verbOption.body.definition) {\n imports.push(`${pascalOperationName}Body`);\n }\n\n return imports;\n })\n .reduce<string[]>((acc, name) => {\n if (!acc.find((i) => i === name)) {\n acc.push(name);\n }\n return acc;\n }, []);\n\n const importSchemasImplementation = `import {\\n ${importSchemaNames.join(\n ',\\n ',\n )}\\n} from '${relativeSchemaImportPath}';\n`;\n\n const relativeFetchClientPath = './http-client';\n const importFetchClientNames = Object.values(verbOptions)\n .flatMap((verbOption) => verbOption.operationName)\n .reduce<string[]>((acc, name) => {\n if (!acc.find((i) => i === name)) {\n acc.push(name);\n }\n\n return acc;\n }, []);\n\n const importFetchClientImplementation = `import {\\n ${importFetchClientNames.join(\n ',\\n ',\n )}\\n} from '${relativeFetchClientPath}';\n `;\n\n const content = [\n importSchemasImplementation,\n importFetchClientImplementation,\n ].join('\\n');\n\n return content + '\\n';\n};\n\nexport const generateMcp: ClientBuilder = async (verbOptions, options) => {\n const handlerArgsTypes = [];\n const pathParamsType = verbOptions.params\n .map((param) => {\n const paramName = param.name.split(': ')[0];\n const paramType = param.implementation.split(': ')[1];\n return ` ${paramName}: ${paramType}`;\n })\n .join(',\\n');\n if (pathParamsType) {\n handlerArgsTypes.push(` pathParams: {\\n${pathParamsType}\\n };`);\n }\n if (verbOptions.queryParams) {\n handlerArgsTypes.push(\n ` queryParams: ${verbOptions.queryParams.schema.name};`,\n );\n }\n if (verbOptions.body.definition) {\n handlerArgsTypes.push(` bodyParams: ${verbOptions.body.definition};`);\n }\n\n const handlerArgsName = `${verbOptions.operationName}Args`;\n const handlerArgsImplementation =\n handlerArgsTypes.length > 0\n ? `\nexport type ${handlerArgsName} = {\n${handlerArgsTypes.join('\\n')}\n}\n`\n : '';\n\n const fetchParams = [];\n if (verbOptions.params.length > 0) {\n const pathParamsArgs = verbOptions.params\n .map((param) => {\n const paramName = param.name.split(': ')[0];\n\n return `args.pathParams.${paramName}`;\n })\n .join(', ');\n\n fetchParams.push(pathParamsArgs);\n }\n if (verbOptions.body.definition) fetchParams.push(`args.bodyParams`);\n if (verbOptions.queryParams) fetchParams.push(`args.queryParams`);\n\n const handlerName = `${verbOptions.operationName}Handler`;\n const handlerImplementation = `\nexport const ${handlerName} = async (${handlerArgsTypes.length > 0 ? `args: ${handlerArgsName}` : ''}) => {\n const res = await ${verbOptions.operationName}(${fetchParams.join(', ')});\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(res),\n },\n ],\n };\n};`;\n\n const handlersImplementation = [\n handlerArgsImplementation,\n handlerImplementation,\n ].join('');\n\n return {\n implementation: handlersImplementation ? `${handlersImplementation}\\n` : '',\n imports: [],\n };\n};\n\nexport const generateServer = async (\n verbOptions: Record<string, GeneratorVerbOptions>,\n output: NormalizedOutputOptions,\n context: ContextSpecs,\n) => {\n const info = context.specs[context.specKey].info;\n const { extension, dirname } = getFileInfo(output.target);\n const serverPath = upath.join(dirname, `server${extension}`);\n const header = getHeader(output.override.header, info);\n\n const toolImplementations = Object.values(verbOptions)\n .map((verbOption) => {\n const imputSchemaTypes = [];\n if (verbOption.params.length > 0)\n imputSchemaTypes.push(\n ` pathParams: ${verbOption.operationName}Params`,\n );\n if (verbOption.queryParams)\n imputSchemaTypes.push(\n ` queryParams: ${verbOption.operationName}QueryParams`,\n );\n if (verbOption.body.definition)\n imputSchemaTypes.push(` bodyParams: ${verbOption.operationName}Body`);\n\n const imputSchemaImplementation =\n imputSchemaTypes.length > 0\n ? ` {\n ${imputSchemaTypes.join(',\\n ')}\n },`\n : '';\n\n const toolImplementation = `\nserver.tool(\n '${verbOption.operationName}',\n '${verbOption.summary}',${imputSchemaImplementation ? `\\n${imputSchemaImplementation}` : ''}\n ${verbOption.operationName}Handler\n);`;\n\n return toolImplementation;\n })\n .join('\\n');\n\n const importToolSchemas = Object.values(verbOptions)\n .flatMap((verbOption) => {\n const imports = [];\n\n if (verbOption.headers)\n imports.push(` ${verbOption.operationName}Header`);\n if (verbOption.params.length > 0)\n imports.push(` ${verbOption.operationName}Params`);\n if (verbOption.queryParams)\n imports.push(` ${verbOption.operationName}QueryParams`);\n if (verbOption.body.definition)\n imports.push(` ${verbOption.operationName}Body`);\n\n return imports;\n })\n .join(',\\n');\n const importToolSchemasImplementation = `import {\\n${importToolSchemas}\\n} from './tool-schemas.zod';`;\n\n const importHandlers = Object.values(verbOptions)\n .filter((verbOption) =>\n toolImplementations.includes(`${verbOption.operationName}Handler`),\n )\n .map((verbOption) => ` ${verbOption.operationName}Handler`)\n .join(`,\\n`);\n const importHandlersImplementation = `import {\\n${importHandlers}\\n} from './handlers';`;\n\n const importDependenciesImplementation = `import {\n McpServer\n} from '@modelcontextprotocol/sdk/server/mcp.js';\n \nimport {\n StdioServerTransport\n} from '@modelcontextprotocol/sdk/server/stdio.js'; \n`;\n const newMcpServerImplementation = `\nconst server = new McpServer({\n name: '${camel(info.title)}Server',\n version: '1.0.0',\n});\n`;\n const serverConnectImplementation = `\nconst transport = new StdioServerTransport();\n\nserver.connect(transport).then(() => {\n console.error('MCP server running on stdio');\n}).catch(console.error);\n`;\n\n const content = [\n header,\n importDependenciesImplementation,\n importHandlersImplementation,\n importToolSchemasImplementation,\n newMcpServerImplementation,\n toolImplementations,\n serverConnectImplementation,\n ].join('\\n');\n\n return [\n {\n content,\n path: serverPath,\n },\n ];\n};\n\nconst generateZodFiles = async (\n verbOptions: Record<string, GeneratorVerbOptions>,\n output: NormalizedOutputOptions,\n context: ContextSpecs,\n) => {\n const { extension, dirname, filename } = getFileInfo(output.target);\n\n const header = getHeader(\n output.override.header,\n context.specs[context.specKey].info,\n );\n\n const zods = await Promise.all(\n Object.values(verbOptions).map((verbOption) =>\n generateZod(\n verbOption,\n {\n route: verbOption.route,\n pathRoute: verbOption.pathRoute,\n override: output.override,\n context,\n mock: output.mock,\n output: output.target!,\n },\n output.client,\n ),\n ),\n );\n\n const allMutators = zods.reduce<Record<string, GeneratorMutator>>(\n (acc, z) => {\n for (const mutator of z.mutators ?? []) {\n acc[mutator.name] = mutator;\n }\n return acc;\n },\n {},\n );\n\n const mutatorsImports = generateMutatorImports({\n mutators: Object.values(allMutators),\n });\n\n let content = `${header}import { z as zod } from 'zod';\\n${mutatorsImports}\\n`;\n\n const zodPath = upath.join(dirname, `tool-schemas.zod${extension}`);\n\n content += zods.map((zod) => zod.implementation).join('\\n');\n\n return [\n {\n content,\n path: zodPath,\n },\n ];\n};\n\nconst generateHttpClinetFiles = async (\n verbOptions: Record<string, GeneratorVerbOptions>,\n output: NormalizedOutputOptions,\n context: ContextSpecs,\n) => {\n const { extension, dirname, filename } = getFileInfo(output.target);\n\n const header = getHeader(\n output.override.header,\n context.specs[context.specKey].info,\n );\n\n const clients = await Promise.all(\n Object.values(verbOptions).map((verbOption) => {\n const fullRoute = getFullRoute(\n verbOption.route,\n context.specs[context.specKey].servers,\n output.baseUrl,\n );\n\n const options = {\n route: fullRoute,\n pathRoute: verbOption.pathRoute,\n override: output.override,\n context,\n mock: output.mock,\n output: output.target!,\n };\n\n return generateClient(verbOption, options, output.client, output);\n }),\n );\n\n const clientImplementation = clients\n .map((client) => client.implementation)\n .join('\\n');\n\n const relativeSchemasPath = output.schemas\n ? upath.relativeSafe(dirname, getFileInfo(output.schemas).dirname)\n : './' + filename + '.schemas';\n const importNames = clients\n .flatMap((client) => client.imports)\n .reduce<string[]>((acc, imp) => {\n if (!acc.find((i) => i === imp.name)) {\n acc.push(imp.name);\n }\n\n return acc;\n }, []);\n const importImplementation = `import { ${importNames.join(\n ',\\n',\n )} } from '${relativeSchemasPath}';`;\n\n const fetchHeader = generateFetchHeader({\n title: '',\n isRequestOptions: false,\n isMutator: false,\n noFunction: false,\n isGlobalMutator: false,\n provideIn: false,\n hasAwaitedType: false,\n output,\n verbOptions,\n clientImplementation,\n });\n\n const content = [\n header,\n importImplementation,\n fetchHeader,\n clientImplementation,\n ].join('\\n');\n const outputPath = upath.join(dirname, `http-client${extension}`);\n\n return [\n {\n content,\n path: outputPath,\n },\n ];\n};\n\nexport const generateExtraFiles: ClientExtraFilesBuilder = async (\n verbOptions,\n output,\n context,\n) => {\n const [server, zods, httpClients] = await Promise.all([\n generateServer(verbOptions, output, context),\n generateZodFiles(verbOptions, output, context),\n generateHttpClinetFiles(verbOptions, output, context),\n ]);\n\n return [...server, ...zods, ...httpClients];\n};\n\nconst mcpClientBuilder: ClientGeneratorsBuilder = {\n client: generateMcp,\n header: getMcpHeader,\n extraFiles: generateExtraFiles,\n};\n\nexport const builder = () => () => mcpClientBuilder;\n\nexport default builder;\n"],"mappings":";;;;;AAqBA,MAAM,aACJ,QACA,SACW;AACX,KAAI,CAAC,OACH,QAAO;CAGT,MAAM,SAAS,OAAO,KAAK;AAE3B,QAAO,MAAM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Y,OAAO,QAAQ,CAAC,QAAQ,GAChE,OAAO,WAAW;AAmCtB,QAAO,CACL;EACE,SAVY;GACd;GAlB2B,YATT,QACjB,SAAS,WAAW,OAAO,QAAQ,CACnC,QAAkB,KAAK,QAAQ;AAC9B,QAAI,CAAC,IAAI,MAAM,MAAM,MAAM,IAAI,KAAK,CAClC,KAAI,KAAK,IAAI,KAAK;AAGpB,WAAO;MACN,EAAE,CAAC,CAC6C,KACnD,MACD,CAAC,WAAW,oBAAoB;GAEb,oBAAoB;IACtC,OAAO;IACP,kBAAkB;IAClB,WAAW;IACX,YAAY;IACZ,iBAAiB;IACjB,WAAW;IACX,gBAAgB;IAChB;IACA;IACA;IACD,CAAC;GAMA;GACD,CAAC,KAAK,KAAK;EAMR,MALe,MAAM,KAAK,SAAS,cAAc,YAAY;EAM9D,CACF;;AAGH,MAAaC,qBAA8C,OACzD,aACA,QACA,YACG;CACH,MAAM,CAAC,QAAQ,MAAM,eAAe,MAAM,QAAQ,IAAI;EACpD,eAAe,aAAa,QAAQ,QAAQ;EAC5C,iBAAiB,aAAa,QAAQ,QAAQ;EAC9C,wBAAwB,aAAa,QAAQ,QAAQ;EACtD,CAAC;AAEF,QAAO;EAAC,GAAG;EAAQ,GAAG;EAAM,GAAG;EAAY;;AAG7C,MAAMC,mBAA4C;CAChD,QAAQ;CACR,QAAQ;CACR,YAAY;CACb;AAED,MAAa,sBAAsB;AAEnC,kBAAe"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orval/mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"exports": {
|
|
6
|
-
"
|
|
7
|
+
"import": {
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"
|
|
9
|
+
"import": "./dist/index.js"
|
|
9
10
|
}
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
@@ -20,15 +21,16 @@
|
|
|
20
21
|
"nuke": "rimraf .turbo dist node_modules"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@orval/core": "
|
|
24
|
-
"@orval/fetch": "
|
|
25
|
-
"@orval/zod": "
|
|
24
|
+
"@orval/core": "8.0.0-rc.0",
|
|
25
|
+
"@orval/fetch": "8.0.0-rc.0",
|
|
26
|
+
"@orval/zod": "8.0.0-rc.0",
|
|
26
27
|
"openapi3-ts": "4.5.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"eslint": "^9.38.0",
|
|
30
31
|
"rimraf": "^6.0.1",
|
|
31
|
-
"tsdown": "^0.15.
|
|
32
|
+
"tsdown": "^0.15.9",
|
|
32
33
|
"typescript": "^5.9.3"
|
|
33
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"stableVersion": "7.15.0"
|
|
34
36
|
}
|