@kubb/plugin-mcp 5.0.0-alpha.17 → 5.0.0-alpha.18
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-BXiZMmu8.cjs → Server-EjbvNRYy.cjs} +8 -1
- package/dist/Server-EjbvNRYy.cjs.map +1 -0
- package/dist/{Server-zYi6bZ4D.js → Server-kM1BVYP3.js} +8 -1
- package/dist/Server-kM1BVYP3.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-CP6ftHEB.cjs → generators-Br_cVPcG.cjs} +2 -2
- package/dist/{generators-CP6ftHEB.cjs.map → generators-Br_cVPcG.cjs.map} +1 -1
- package/dist/{generators-B8MpQcFC.js → generators-jjs2-iEm.js} +2 -2
- package/dist/{generators-B8MpQcFC.js.map → generators-jjs2-iEm.js.map} +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +4 -500
- package/dist/generators.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{types-DXZDZ3vf.d.ts → types-CblxgOvZ.d.ts} +3 -3
- package/package.json +8 -8
- package/dist/Server-BXiZMmu8.cjs.map +0 -1
- package/dist/Server-zYi6bZ4D.js.map +0 -1
|
@@ -73,6 +73,13 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
73
73
|
//#region ../../internals/utils/src/reserved.ts
|
|
74
74
|
/**
|
|
75
75
|
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* isValidVarName('status') // true
|
|
80
|
+
* isValidVarName('class') // false (reserved word)
|
|
81
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
82
|
+
* ```
|
|
76
83
|
*/
|
|
77
84
|
function isValidVarName(name) {
|
|
78
85
|
try {
|
|
@@ -221,4 +228,4 @@ Object.defineProperty(exports, "camelCase", {
|
|
|
221
228
|
}
|
|
222
229
|
});
|
|
223
230
|
|
|
224
|
-
//# sourceMappingURL=Server-
|
|
231
|
+
//# sourceMappingURL=Server-EjbvNRYy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server-EjbvNRYy.cjs","names":["FunctionParams","File","Const"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../src/components/Server.tsx"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import { camelCase, isValidVarName } from '@internals/utils'\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,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AA,+BAAA,MAACC,mBAAAA,KAAK,QAAN;EAAmB;EAAM,cAAA;EAAa,aAAA;YAAtC;GACE,iBAAA,GAAA,+BAAA,KAACC,mBAAAA,OAAD;IAAO,MAAM;IAAU,QAAA;cACpB;;WAEE,WAAW;cACR,cAAc;;;IAGd,CAAA;GAEP,WACE,KAAK,EAAE,MAAM,KAAK,UAAU;IAC3B,MAAM,eAAe,UAAU;KAAE,SAAS,IAAI;KAAS;KAAc,CAAC;IACtE,MAAM,eAAe,IAAI,QAAQ,UAAU;IAE3C,MAAM,SAAS;KACb,KAAK,QAAQ,UAAU,KAAK,UAAU,KAAK,MAAM,KAAK;KACtD,gBAAgB,KAAK,UAAU,KAAK,YAAY;KAChD,eAAe,yBAAyB,aAAa,MAAM;KAC5D,CACE,OAAO,QAAQ,CACf,KAAK,QAAQ;AAEhB,QAAI,IAAI,QAAQ,SAAS,QAAQ,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"}
|
|
@@ -48,6 +48,13 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
48
48
|
//#region ../../internals/utils/src/reserved.ts
|
|
49
49
|
/**
|
|
50
50
|
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* isValidVarName('status') // true
|
|
55
|
+
* isValidVarName('class') // false (reserved word)
|
|
56
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
57
|
+
* ```
|
|
51
58
|
*/
|
|
52
59
|
function isValidVarName(name) {
|
|
53
60
|
try {
|
|
@@ -173,4 +180,4 @@ export async function startServer() {
|
|
|
173
180
|
//#endregion
|
|
174
181
|
export { camelCase as n, Server as t };
|
|
175
182
|
|
|
176
|
-
//# sourceMappingURL=Server-
|
|
183
|
+
//# sourceMappingURL=Server-kM1BVYP3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server-kM1BVYP3.js","names":[],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../src/components/Server.tsx"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import { camelCase, isValidVarName } from '@internals/utils'\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('Fail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cAAc,cAAsC;AAC5G,QACE,qBAAC,KAAK,QAAN;EAAmB;EAAM,cAAA;EAAa,aAAA;YAAtC;GACE,oBAAC,OAAD;IAAO,MAAM;IAAU,QAAA;cACpB;;WAEE,WAAW;cACR,cAAc;;;IAGd,CAAA;GAEP,WACE,KAAK,EAAE,MAAM,KAAK,UAAU;IAC3B,MAAM,eAAe,UAAU;KAAE,SAAS,IAAI;KAAS;KAAc,CAAC;IACtE,MAAM,eAAe,IAAI,QAAQ,UAAU;IAE3C,MAAM,SAAS;KACb,KAAK,QAAQ,UAAU,KAAK,UAAU,KAAK,MAAM,KAAK;KACtD,gBAAgB,KAAK,UAAU,KAAK,YAAY;KAChD,eAAe,yBAAyB,aAAa,MAAM;KAC5D,CACE,OAAO,QAAQ,CACf,KAAK,QAAQ;AAEhB,QAAI,IAAI,QAAQ,SAAS,QAAQ,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.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as Server } from "./Server-
|
|
1
|
+
import { t as Server } from "./Server-kM1BVYP3.js";
|
|
2
2
|
export { Server };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_Server = require("./Server-
|
|
1
|
+
const require_Server = require("./Server-EjbvNRYy.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");
|
|
@@ -282,4 +282,4 @@ Object.defineProperty(exports, "serverGenerator", {
|
|
|
282
282
|
}
|
|
283
283
|
});
|
|
284
284
|
|
|
285
|
-
//# sourceMappingURL=generators-
|
|
285
|
+
//# sourceMappingURL=generators-Br_cVPcG.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators-CP6ftHEB.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, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: 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 { usePluginDriver } 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 driver = usePluginDriver()\n const { options } = plugin\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager(generator)\n\n const name = 'server'\n const file = driver.getFile({ name, extname: '.ts', pluginName: plugin.name })\n\n const jsonFile = driver.getFile({ name: '.mcp', extname: '.json', pluginName: plugin.name })\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 pluginName: pluginZodName,\n }),\n schemas: getSchemas(operation, { pluginName: pluginZodName, type: 'function' }),\n file: getFile(operation, { pluginName: pluginZodName }),\n },\n type: {\n schemas: getSchemas(operation, { pluginName: 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: driver.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,gBAAA,GAAA,4BAAA,sBAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EAAE,YAAY;EACpB,MAAM,OAAA,GAAA,uBAAA,SAAc;EAEpB,MAAM,EAAE,YAAY,SAAS,aAAA,GAAA,uBAAA,qBAAgC,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,YAAYA,gBAAAA,cAAc,CAAC;GACtD,SAAS,WAAW,WAAW;IAAE,YAAYA,gBAAAA;IAAc,MAAM;IAAQ,CAAC;GAC3E;AAED,SACE,iBAAA,GAAA,+BAAA,MAACC,mBAAAA,MAAD;GACE,UAAU,IAAI,KAAK;GACnB,MAAM,IAAI,KAAK;GACf,MAAM,IAAI,KAAK;GACf,SAAA,GAAA,uBAAA,WAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;GAClD,SAAA,GAAA,uBAAA,WAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;aALpD;IAOG,QAAQ,OAAO,aACd,iBAAA,GAA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C"}
|
|
1
|
+
{"version":3,"file":"generators-Br_cVPcG.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, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: 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 { usePluginDriver } 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 driver = usePluginDriver()\n const { options } = plugin\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager(generator)\n\n const name = 'server'\n const file = driver.getFile({ name, extname: '.ts', pluginName: plugin.name })\n\n const jsonFile = driver.getFile({ name: '.mcp', extname: '.json', pluginName: plugin.name })\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 pluginName: pluginZodName,\n }),\n schemas: getSchemas(operation, { pluginName: pluginZodName, type: 'function' }),\n file: getFile(operation, { pluginName: pluginZodName }),\n },\n type: {\n schemas: getSchemas(operation, { pluginName: 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: driver.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,gBAAA,GAAA,4BAAA,sBAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EAAE,YAAY;EACpB,MAAM,OAAA,GAAA,uBAAA,SAAc;EAEpB,MAAM,EAAE,YAAY,SAAS,aAAA,GAAA,uBAAA,qBAAgC,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,YAAYA,gBAAAA,cAAc,CAAC;GACtD,SAAS,WAAW,WAAW;IAAE,YAAYA,gBAAAA;IAAc,MAAM;IAAQ,CAAC;GAC3E;AAED,SACE,iBAAA,GAAA,+BAAA,MAACC,mBAAAA,MAAD;GACE,UAAU,IAAI,KAAK;GACnB,MAAM,IAAI,KAAK;GACf,MAAM,IAAI,KAAK;GACf,SAAA,GAAA,uBAAA,WAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;GAClD,SAAA,GAAA,uBAAA,WAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;aALpD;IAOG,QAAQ,OAAO,aACd,iBAAA,GAAA,+BAAA,MAAA,+BAAA,UAAA,EAAA,UAAA;KACE,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;MAAa,MAAM;MAAS,MAAM,QAAQ,OAAO;MAAc,CAAA;KAC/D,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;MAAa,MAAM;OAAC;OAAU;OAAiB;OAAsB;MAAE,M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,mBAAAA,MAAD;GACE,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,SAAA,GAAA,uBAAA,WAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,QAAQ,OAAO;IAAQ,CAAC;GACzE,SAAA,GAAA,uBAAA,WAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;aALpD;IAOE,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;KAAa,MAAM,CAAC,YAAY;KAAE,MAAM;KAA0C,CAAA;IAClF,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;KAAa,MAAM,CAAC,IAAI;KAAE,MAAM;KAAS,CAAA;IACzC,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;KAAa,MAAM,CAAC,uBAAuB;KAAE,MAAM;KAA4C,CAAA;IAE9F;IACD,iBAAA,GAAA,+BAAA,KAACC,eAAAA,QAAD;KACQ;KACN,YAAY,IAAI,IAAI,MAAM;KAC1B,eAAe,IAAI,YAAY;KAC/B,cAAc,QAAQ;KACtB,YAAY;KACZ,CAAA;IACG;MAEP,iBAAA,GAAA,+BAAA,KAACD,mBAAAA,MAAD;GAAM,UAAU,SAAS;GAAU,MAAM,SAAS;GAAM,MAAM,SAAS;aACrE,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;IAAmB;cAChB;;;iBAGI,IAAI,IAAI,MAAM,SAAS,SAAS;;;mCAGd,KAAK,KAAK;;;;;IAKrB,CAAA;GACT,CAAA,CACN,EAAA,CAAA;;CAGR,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { t as Server } from "./Server-
|
|
2
|
+
import { t as Server } from "./Server-kM1BVYP3.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
5
5
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
@@ -271,4 +271,4 @@ const serverGenerator = createReactGenerator({
|
|
|
271
271
|
//#endregion
|
|
272
272
|
export { mcpGenerator as n, serverGenerator as t };
|
|
273
273
|
|
|
274
|
-
//# sourceMappingURL=generators-
|
|
274
|
+
//# sourceMappingURL=generators-jjs2-iEm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators-B8MpQcFC.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, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: 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 { usePluginDriver } 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 driver = usePluginDriver()\n const { options } = plugin\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager(generator)\n\n const name = 'server'\n const file = driver.getFile({ name, extname: '.ts', pluginName: plugin.name })\n\n const jsonFile = driver.getFile({ name: '.mcp', extname: '.json', pluginName: plugin.name })\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 pluginName: pluginZodName,\n }),\n schemas: getSchemas(operation, { pluginName: pluginZodName, type: 'function' }),\n file: getFile(operation, { pluginName: pluginZodName }),\n },\n type: {\n schemas: getSchemas(operation, { pluginName: 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: driver.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,YAAY,cAAc,CAAC;GACtD,SAAS,WAAW,WAAW;IAAE,YAAY;IAAc,MAAM;IAAQ,CAAC;GAC3E;AAED,SACE,qBAAC,MAAD;GACE,UAAU,IAAI,KAAK;GACnB,MAAM,IAAI,KAAK;GACf,MAAM,IAAI,KAAK;GACf,QAAQ,UAAU;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;GAClD,QAAQ,UAAU;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;aALpD;IAOG,QAAQ,OAAO,aACd,qBAAA,UAAA,EAAA,UAAA;KACE,oBAAC,KAAK,QAAN;MAAa,MAAM;MAAS,MAAM,QAAQ,OAAO;MAAc,CAAA;KAC/D,oBAAC,KAAK,QAAN;MAAa,MAAM;OAAC;OAAU;OAAiB;OAAsB;MAAE,MAAM,QAAQ,OAAO;MAAY,YAAA;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I,YAAY;KAC/B,cAAc,QAAQ;KACtB,YAAY;KACZ,CAAA;IACG;MAEP,oBAAC,MAAD;GAAM,UAAU,SAAS;GAAU,MAAM,SAAS;GAAM,MAAM,SAAS;aACrE,oBAAC,KAAK,QAAN;IAAmB;cAChB;;;iBAGI,IAAI,IAAI,MAAM,SAAS,SAAS;;;mCAGd,KAAK,KAAK;;;;;IAKrB,CAAA;GACT,CAAA,CACN,EAAA,CAAA;;CAGR,CAAC"}
|
|
1
|
+
{"version":3,"file":"generators-jjs2-iEm.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, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: 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 { usePluginDriver } 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 driver = usePluginDriver()\n const { options } = plugin\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager(generator)\n\n const name = 'server'\n const file = driver.getFile({ name, extname: '.ts', pluginName: plugin.name })\n\n const jsonFile = driver.getFile({ name: '.mcp', extname: '.json', pluginName: plugin.name })\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 pluginName: pluginZodName,\n }),\n schemas: getSchemas(operation, { pluginName: pluginZodName, type: 'function' }),\n file: getFile(operation, { pluginName: pluginZodName }),\n },\n type: {\n schemas: getSchemas(operation, { pluginName: 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: driver.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,YAAY,cAAc,CAAC;GACtD,SAAS,WAAW,WAAW;IAAE,YAAY;IAAc,MAAM;IAAQ,CAAC;GAC3E;AAED,SACE,qBAAC,MAAD;GACE,UAAU,IAAI,KAAK;GACnB,MAAM,IAAI,KAAK;GACf,MAAM,IAAI,KAAK;GACf,QAAQ,UAAU;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;GAClD,QAAQ,UAAU;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;aALpD;IAOG,QAAQ,OAAO,aACd,qBAAA,UAAA,EAAA,UAAA;KACE,oBAAC,KAAK,QAAN;MAAa,MAAM;MAAS,MAAM,QAAQ,OAAO;MAAc,CAAA;KAC/D,oBAAC,KAAK,Q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AA;IAE9F;IACD,oBAAC,QAAD;KACQ;KACN,YAAY,IAAI,IAAI,MAAM;KAC1B,eAAe,IAAI,YAAY;KAC/B,cAAc,QAAQ;KACtB,YAAY;KACZ,CAAA;IACG;MAEP,oBAAC,MAAD;GAAM,UAAU,SAAS;GAAU,MAAM,SAAS;GAAM,MAAM,SAAS;aACrE,oBAAC,KAAK,QAAN;IAAmB;cAChB;;;iBAGI,IAAI,IAAI,MAAM,SAAS,SAAS;;;mCAGd,KAAK,KAAK;;;;;IAKrB,CAAA;GACT,CAAA,CACN,EAAA,CAAA;;CAGR,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generators = require("./generators-
|
|
2
|
+
const require_generators = require("./generators-Br_cVPcG.cjs");
|
|
3
3
|
exports.mcpGenerator = require_generators.mcpGenerator;
|
|
4
4
|
exports.serverGenerator = require_generators.serverGenerator;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,508 +1,12 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as PluginMcp } from "./types-
|
|
3
|
-
import
|
|
4
|
-
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
5
|
-
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
6
|
-
import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
|
|
2
|
+
import { n as PluginMcp } from "./types-CblxgOvZ.js";
|
|
3
|
+
import * as _kubb_plugin_oas_generators0 from "@kubb/plugin-oas/generators";
|
|
7
4
|
|
|
8
|
-
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
9
|
-
/** A function that can be registered as an event listener, synchronous or async. */
|
|
10
|
-
type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
|
|
11
|
-
/**
|
|
12
|
-
* A typed EventEmitter that awaits all async listeners before resolving.
|
|
13
|
-
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
14
|
-
*/
|
|
15
|
-
declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
|
|
16
|
-
#private;
|
|
17
|
-
/**
|
|
18
|
-
* `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.
|
|
19
|
-
* @default 10
|
|
20
|
-
*/
|
|
21
|
-
constructor(maxListener?: number);
|
|
22
|
-
/**
|
|
23
|
-
* Emits an event and awaits all registered listeners in parallel.
|
|
24
|
-
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
25
|
-
*/
|
|
26
|
-
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
27
|
-
/** Registers a persistent listener for the given event. */
|
|
28
|
-
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
29
|
-
/** Registers a one-shot listener that removes itself after the first invocation. */
|
|
30
|
-
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
31
|
-
/** Removes a previously registered listener. */
|
|
32
|
-
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
33
|
-
/** Removes all listeners from every event channel. */
|
|
34
|
-
removeAll(): void;
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region ../plugin-oas/src/types.d.ts
|
|
38
|
-
type GetOasOptions = {
|
|
39
|
-
validate?: boolean;
|
|
40
|
-
};
|
|
41
|
-
type Context$2 = {
|
|
42
|
-
getOas(options?: GetOasOptions): Promise<Oas>;
|
|
43
|
-
getBaseURL(): Promise<string | undefined>;
|
|
44
|
-
};
|
|
45
|
-
declare global {
|
|
46
|
-
namespace Kubb {
|
|
47
|
-
interface PluginContext extends Context$2 {}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* `propertyName` is the ref name + resolved with the nameResolver
|
|
52
|
-
* @example import { Pet } from './Pet'
|
|
53
|
-
*
|
|
54
|
-
* `originalName` is the original name used(in PascalCase), only used to remove duplicates
|
|
55
|
-
*
|
|
56
|
-
* `pluginName` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
|
|
57
|
-
* @example import a type(plugin-ts) for a mock file(swagger-faker)
|
|
58
|
-
*/
|
|
59
|
-
type Ref = {
|
|
60
|
-
propertyName: string;
|
|
61
|
-
originalName: string;
|
|
62
|
-
path: KubbFile.Path;
|
|
63
|
-
pluginName?: string;
|
|
64
|
-
};
|
|
65
|
-
type Refs = Record<string, Ref>;
|
|
66
|
-
type OperationSchema = {
|
|
67
|
-
/**
|
|
68
|
-
* Converted name, contains already `PathParams`, `QueryParams`, ...
|
|
69
|
-
*/
|
|
70
|
-
name: string;
|
|
71
|
-
schema: SchemaObject;
|
|
72
|
-
operation?: Operation;
|
|
73
|
-
/**
|
|
74
|
-
* OperationName in PascalCase, only being used in OperationGenerator
|
|
75
|
-
*/
|
|
76
|
-
operationName: string;
|
|
77
|
-
description?: string;
|
|
78
|
-
statusCode?: number;
|
|
79
|
-
keys?: string[];
|
|
80
|
-
keysToOmit?: string[];
|
|
81
|
-
withData?: boolean;
|
|
82
|
-
};
|
|
83
|
-
type OperationSchemas = {
|
|
84
|
-
pathParams?: OperationSchema & {
|
|
85
|
-
keysToOmit?: never;
|
|
86
|
-
};
|
|
87
|
-
queryParams?: OperationSchema & {
|
|
88
|
-
keysToOmit?: never;
|
|
89
|
-
};
|
|
90
|
-
headerParams?: OperationSchema & {
|
|
91
|
-
keysToOmit?: never;
|
|
92
|
-
};
|
|
93
|
-
request?: OperationSchema;
|
|
94
|
-
response: OperationSchema;
|
|
95
|
-
responses: Array<OperationSchema>;
|
|
96
|
-
statusCodes?: Array<OperationSchema>;
|
|
97
|
-
errors?: Array<OperationSchema>;
|
|
98
|
-
};
|
|
99
|
-
type ByTag = {
|
|
100
|
-
type: 'tag';
|
|
101
|
-
pattern: string | RegExp;
|
|
102
|
-
};
|
|
103
|
-
type ByOperationId = {
|
|
104
|
-
type: 'operationId';
|
|
105
|
-
pattern: string | RegExp;
|
|
106
|
-
};
|
|
107
|
-
type ByPath = {
|
|
108
|
-
type: 'path';
|
|
109
|
-
pattern: string | RegExp;
|
|
110
|
-
};
|
|
111
|
-
type ByMethod = {
|
|
112
|
-
type: 'method';
|
|
113
|
-
pattern: HttpMethod | RegExp;
|
|
114
|
-
};
|
|
115
|
-
type BySchemaName = {
|
|
116
|
-
type: 'schemaName';
|
|
117
|
-
pattern: string | RegExp;
|
|
118
|
-
};
|
|
119
|
-
type ByContentType = {
|
|
120
|
-
type: 'contentType';
|
|
121
|
-
pattern: string | RegExp;
|
|
122
|
-
};
|
|
123
|
-
type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
124
|
-
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
125
|
-
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
126
|
-
options: Partial<TOptions>;
|
|
127
|
-
};
|
|
128
|
-
//#endregion
|
|
129
|
-
//#region ../plugin-oas/src/OperationGenerator.d.ts
|
|
130
|
-
type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
131
|
-
fabric: Fabric;
|
|
132
|
-
oas: Oas;
|
|
133
|
-
exclude: Array<Exclude> | undefined;
|
|
134
|
-
include: Array<Include> | undefined;
|
|
135
|
-
override: Array<Override<TOptions>> | undefined;
|
|
136
|
-
contentType: contentType | undefined;
|
|
137
|
-
driver: PluginDriver;
|
|
138
|
-
events?: AsyncEventEmitter<KubbEvents>;
|
|
139
|
-
/**
|
|
140
|
-
* Current plugin
|
|
141
|
-
*/
|
|
142
|
-
plugin: Plugin<TPluginOptions>;
|
|
143
|
-
mode: KubbFile.Mode;
|
|
144
|
-
UNSTABLE_NAMING?: true;
|
|
145
|
-
};
|
|
146
|
-
declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
|
|
147
|
-
#private;
|
|
148
|
-
constructor(options: TPluginOptions['resolvedOptions'], context: Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>);
|
|
149
|
-
get options(): TPluginOptions['resolvedOptions'];
|
|
150
|
-
set options(options: TPluginOptions['resolvedOptions']);
|
|
151
|
-
get context(): Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>;
|
|
152
|
-
getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']>;
|
|
153
|
-
getSchemas(operation: Operation, {
|
|
154
|
-
resolveName
|
|
155
|
-
}?: {
|
|
156
|
-
resolveName?: (name: string) => string;
|
|
157
|
-
}): OperationSchemas;
|
|
158
|
-
getOperations(): Promise<Array<{
|
|
159
|
-
path: string;
|
|
160
|
-
method: HttpMethod;
|
|
161
|
-
operation: Operation;
|
|
162
|
-
}>>;
|
|
163
|
-
build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
164
|
-
}
|
|
165
|
-
//#endregion
|
|
166
|
-
//#region ../plugin-oas/src/SchemaMapper.d.ts
|
|
167
|
-
type SchemaKeywordMapper = {
|
|
168
|
-
object: {
|
|
169
|
-
keyword: 'object';
|
|
170
|
-
args: {
|
|
171
|
-
properties: {
|
|
172
|
-
[x: string]: Schema[];
|
|
173
|
-
};
|
|
174
|
-
additionalProperties: Schema[];
|
|
175
|
-
patternProperties?: Record<string, Schema[]>;
|
|
176
|
-
strict?: boolean;
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
url: {
|
|
180
|
-
keyword: 'url';
|
|
181
|
-
};
|
|
182
|
-
readOnly: {
|
|
183
|
-
keyword: 'readOnly';
|
|
184
|
-
};
|
|
185
|
-
writeOnly: {
|
|
186
|
-
keyword: 'writeOnly';
|
|
187
|
-
};
|
|
188
|
-
uuid: {
|
|
189
|
-
keyword: 'uuid';
|
|
190
|
-
};
|
|
191
|
-
email: {
|
|
192
|
-
keyword: 'email';
|
|
193
|
-
};
|
|
194
|
-
firstName: {
|
|
195
|
-
keyword: 'firstName';
|
|
196
|
-
};
|
|
197
|
-
lastName: {
|
|
198
|
-
keyword: 'lastName';
|
|
199
|
-
};
|
|
200
|
-
phone: {
|
|
201
|
-
keyword: 'phone';
|
|
202
|
-
};
|
|
203
|
-
password: {
|
|
204
|
-
keyword: 'password';
|
|
205
|
-
};
|
|
206
|
-
date: {
|
|
207
|
-
keyword: 'date';
|
|
208
|
-
args: {
|
|
209
|
-
type?: 'date' | 'string';
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
time: {
|
|
213
|
-
keyword: 'time';
|
|
214
|
-
args: {
|
|
215
|
-
type?: 'date' | 'string';
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
datetime: {
|
|
219
|
-
keyword: 'datetime';
|
|
220
|
-
args: {
|
|
221
|
-
offset?: boolean;
|
|
222
|
-
local?: boolean;
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
tuple: {
|
|
226
|
-
keyword: 'tuple';
|
|
227
|
-
args: {
|
|
228
|
-
items: Schema[];
|
|
229
|
-
min?: number;
|
|
230
|
-
max?: number;
|
|
231
|
-
rest?: Schema;
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
array: {
|
|
235
|
-
keyword: 'array';
|
|
236
|
-
args: {
|
|
237
|
-
items: Schema[];
|
|
238
|
-
min?: number;
|
|
239
|
-
max?: number;
|
|
240
|
-
unique?: boolean;
|
|
241
|
-
};
|
|
242
|
-
};
|
|
243
|
-
enum: {
|
|
244
|
-
keyword: 'enum';
|
|
245
|
-
args: {
|
|
246
|
-
name: string;
|
|
247
|
-
typeName: string;
|
|
248
|
-
asConst: boolean;
|
|
249
|
-
items: Array<{
|
|
250
|
-
name: string | number;
|
|
251
|
-
format: 'string' | 'number' | 'boolean';
|
|
252
|
-
value?: string | number | boolean;
|
|
253
|
-
}>;
|
|
254
|
-
};
|
|
255
|
-
};
|
|
256
|
-
and: {
|
|
257
|
-
keyword: 'and';
|
|
258
|
-
args: Schema[];
|
|
259
|
-
};
|
|
260
|
-
const: {
|
|
261
|
-
keyword: 'const';
|
|
262
|
-
args: {
|
|
263
|
-
name: string | number;
|
|
264
|
-
format: 'string' | 'number' | 'boolean';
|
|
265
|
-
value?: string | number | boolean;
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
union: {
|
|
269
|
-
keyword: 'union';
|
|
270
|
-
args: Schema[];
|
|
271
|
-
};
|
|
272
|
-
ref: {
|
|
273
|
-
keyword: 'ref';
|
|
274
|
-
args: {
|
|
275
|
-
name: string;
|
|
276
|
-
$ref: string;
|
|
277
|
-
/**
|
|
278
|
-
* Full qualified path.
|
|
279
|
-
*/
|
|
280
|
-
path: KubbFile.Path;
|
|
281
|
-
/**
|
|
282
|
-
* When true `File.Import` is used.
|
|
283
|
-
* When false a reference is used inside the current file.
|
|
284
|
-
*/
|
|
285
|
-
isImportable: boolean;
|
|
286
|
-
};
|
|
287
|
-
};
|
|
288
|
-
matches: {
|
|
289
|
-
keyword: 'matches';
|
|
290
|
-
args?: string;
|
|
291
|
-
};
|
|
292
|
-
boolean: {
|
|
293
|
-
keyword: 'boolean';
|
|
294
|
-
};
|
|
295
|
-
default: {
|
|
296
|
-
keyword: 'default';
|
|
297
|
-
args: string | number | boolean;
|
|
298
|
-
};
|
|
299
|
-
string: {
|
|
300
|
-
keyword: 'string';
|
|
301
|
-
};
|
|
302
|
-
integer: {
|
|
303
|
-
keyword: 'integer';
|
|
304
|
-
};
|
|
305
|
-
bigint: {
|
|
306
|
-
keyword: 'bigint';
|
|
307
|
-
};
|
|
308
|
-
number: {
|
|
309
|
-
keyword: 'number';
|
|
310
|
-
};
|
|
311
|
-
max: {
|
|
312
|
-
keyword: 'max';
|
|
313
|
-
args: number;
|
|
314
|
-
};
|
|
315
|
-
min: {
|
|
316
|
-
keyword: 'min';
|
|
317
|
-
args: number;
|
|
318
|
-
};
|
|
319
|
-
exclusiveMaximum: {
|
|
320
|
-
keyword: 'exclusiveMaximum';
|
|
321
|
-
args: number;
|
|
322
|
-
};
|
|
323
|
-
exclusiveMinimum: {
|
|
324
|
-
keyword: 'exclusiveMinimum';
|
|
325
|
-
args: number;
|
|
326
|
-
};
|
|
327
|
-
describe: {
|
|
328
|
-
keyword: 'describe';
|
|
329
|
-
args: string;
|
|
330
|
-
};
|
|
331
|
-
example: {
|
|
332
|
-
keyword: 'example';
|
|
333
|
-
args: string;
|
|
334
|
-
};
|
|
335
|
-
deprecated: {
|
|
336
|
-
keyword: 'deprecated';
|
|
337
|
-
};
|
|
338
|
-
optional: {
|
|
339
|
-
keyword: 'optional';
|
|
340
|
-
};
|
|
341
|
-
undefined: {
|
|
342
|
-
keyword: 'undefined';
|
|
343
|
-
};
|
|
344
|
-
nullish: {
|
|
345
|
-
keyword: 'nullish';
|
|
346
|
-
};
|
|
347
|
-
nullable: {
|
|
348
|
-
keyword: 'nullable';
|
|
349
|
-
};
|
|
350
|
-
null: {
|
|
351
|
-
keyword: 'null';
|
|
352
|
-
};
|
|
353
|
-
any: {
|
|
354
|
-
keyword: 'any';
|
|
355
|
-
};
|
|
356
|
-
unknown: {
|
|
357
|
-
keyword: 'unknown';
|
|
358
|
-
};
|
|
359
|
-
void: {
|
|
360
|
-
keyword: 'void';
|
|
361
|
-
};
|
|
362
|
-
blob: {
|
|
363
|
-
keyword: 'blob';
|
|
364
|
-
};
|
|
365
|
-
schema: {
|
|
366
|
-
keyword: 'schema';
|
|
367
|
-
args: {
|
|
368
|
-
type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
369
|
-
format?: string;
|
|
370
|
-
};
|
|
371
|
-
};
|
|
372
|
-
name: {
|
|
373
|
-
keyword: 'name';
|
|
374
|
-
args: string;
|
|
375
|
-
};
|
|
376
|
-
catchall: {
|
|
377
|
-
keyword: 'catchall';
|
|
378
|
-
};
|
|
379
|
-
interface: {
|
|
380
|
-
keyword: 'interface';
|
|
381
|
-
};
|
|
382
|
-
};
|
|
383
|
-
type Schema = {
|
|
384
|
-
keyword: string;
|
|
385
|
-
} | SchemaKeywordMapper[keyof SchemaKeywordMapper];
|
|
386
|
-
//#endregion
|
|
387
|
-
//#region ../plugin-oas/src/SchemaGenerator.d.ts
|
|
388
|
-
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
389
|
-
fabric: Fabric;
|
|
390
|
-
oas: Oas;
|
|
391
|
-
driver: PluginDriver;
|
|
392
|
-
events?: AsyncEventEmitter<KubbEvents>;
|
|
393
|
-
/**
|
|
394
|
-
* Current plugin
|
|
395
|
-
*/
|
|
396
|
-
plugin: Plugin<TPluginOptions>;
|
|
397
|
-
mode: KubbFile.Mode;
|
|
398
|
-
include?: Array<'schemas' | 'responses' | 'requestBodies'>;
|
|
399
|
-
override: Array<Override<TOptions>> | undefined;
|
|
400
|
-
contentType?: contentType;
|
|
401
|
-
output?: string;
|
|
402
|
-
};
|
|
403
|
-
type SchemaGeneratorOptions = {
|
|
404
|
-
dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
405
|
-
integerType?: 'number' | 'bigint';
|
|
406
|
-
unknownType: 'any' | 'unknown' | 'void';
|
|
407
|
-
emptySchemaType: 'any' | 'unknown' | 'void';
|
|
408
|
-
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
|
|
409
|
-
enumSuffix?: string;
|
|
410
|
-
/**
|
|
411
|
-
* @deprecated Will be removed in v5. Use `collisionDetection: true` instead to prevent enum name collisions.
|
|
412
|
-
* When `collisionDetection` is enabled, the rootName-based approach eliminates the need for numeric suffixes.
|
|
413
|
-
* @internal
|
|
414
|
-
*/
|
|
415
|
-
usedEnumNames?: Record<string, number>;
|
|
416
|
-
mapper?: Record<string, string>;
|
|
417
|
-
typed?: boolean;
|
|
418
|
-
transformers: {
|
|
419
|
-
/**
|
|
420
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
421
|
-
*/
|
|
422
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
423
|
-
/**
|
|
424
|
-
* Receive schema and name(propertyName) and return Schema array.
|
|
425
|
-
* Return `undefined` to fall through to default schema generation.
|
|
426
|
-
* @beta
|
|
427
|
-
*/
|
|
428
|
-
schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Array<Schema> | undefined;
|
|
429
|
-
};
|
|
430
|
-
};
|
|
431
|
-
type SchemaProps$1 = {
|
|
432
|
-
schema: SchemaObject | null;
|
|
433
|
-
name: string | null;
|
|
434
|
-
parentName: string | null;
|
|
435
|
-
rootName?: string | null;
|
|
436
|
-
};
|
|
437
|
-
declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
|
|
438
|
-
#private;
|
|
439
|
-
constructor(options: TOptions, context: Context<TOptions, TPluginOptions>);
|
|
440
|
-
get options(): TOptions;
|
|
441
|
-
set options(options: TOptions);
|
|
442
|
-
get context(): Context<TOptions, TPluginOptions>;
|
|
443
|
-
refs: Refs;
|
|
444
|
-
/**
|
|
445
|
-
* Creates a type node from a given schema.
|
|
446
|
-
* Delegates to getBaseTypeFromSchema internally and
|
|
447
|
-
* optionally adds a union with null.
|
|
448
|
-
*/
|
|
449
|
-
parse(props: SchemaProps$1): Schema[];
|
|
450
|
-
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
451
|
-
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
452
|
-
static combineObjects(tree: Schema[] | undefined): Schema[];
|
|
453
|
-
build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
454
|
-
}
|
|
455
|
-
//#endregion
|
|
456
|
-
//#region ../plugin-oas/src/generators/createGenerator.d.ts
|
|
457
|
-
type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
458
|
-
name: string;
|
|
459
|
-
type: 'core';
|
|
460
|
-
version: '1';
|
|
461
|
-
operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
462
|
-
operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
463
|
-
schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
464
|
-
};
|
|
465
|
-
//#endregion
|
|
466
|
-
//#region ../plugin-oas/src/generators/types.d.ts
|
|
467
|
-
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
468
|
-
config: Config;
|
|
469
|
-
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
470
|
-
plugin: Plugin<TOptions>;
|
|
471
|
-
operations: Array<Operation>;
|
|
472
|
-
};
|
|
473
|
-
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
474
|
-
config: Config;
|
|
475
|
-
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
476
|
-
plugin: Plugin<TOptions>;
|
|
477
|
-
operation: Operation;
|
|
478
|
-
};
|
|
479
|
-
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
480
|
-
config: Config;
|
|
481
|
-
generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
482
|
-
plugin: Plugin<TOptions>;
|
|
483
|
-
schema: {
|
|
484
|
-
name: string;
|
|
485
|
-
tree: Array<Schema>;
|
|
486
|
-
value: SchemaObject;
|
|
487
|
-
};
|
|
488
|
-
};
|
|
489
|
-
type Generator$1<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | Generator<TOptions>;
|
|
490
|
-
//#endregion
|
|
491
|
-
//#region ../plugin-oas/src/generators/createReactGenerator.d.ts
|
|
492
|
-
type ReactGenerator<TOptions extends PluginFactoryOptions> = {
|
|
493
|
-
name: string;
|
|
494
|
-
type: 'react';
|
|
495
|
-
version: '1';
|
|
496
|
-
Operations: (props: OperationsProps<TOptions>) => FabricReactNode;
|
|
497
|
-
Operation: (props: OperationProps<TOptions>) => FabricReactNode;
|
|
498
|
-
Schema: (props: SchemaProps<TOptions>) => FabricReactNode;
|
|
499
|
-
};
|
|
500
|
-
//#endregion
|
|
501
5
|
//#region src/generators/mcpGenerator.d.ts
|
|
502
|
-
declare const mcpGenerator: ReactGenerator<PluginMcp>;
|
|
6
|
+
declare const mcpGenerator: _kubb_plugin_oas_generators0.ReactGenerator<PluginMcp>;
|
|
503
7
|
//#endregion
|
|
504
8
|
//#region src/generators/serverGenerator.d.ts
|
|
505
|
-
declare const serverGenerator: ReactGenerator<PluginMcp>;
|
|
9
|
+
declare const serverGenerator: _kubb_plugin_oas_generators0.ReactGenerator<PluginMcp>;
|
|
506
10
|
//#endregion
|
|
507
11
|
export { mcpGenerator, serverGenerator };
|
|
508
12
|
//# sourceMappingURL=generators.d.ts.map
|
package/dist/generators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as mcpGenerator, t as serverGenerator } from "./generators-
|
|
1
|
+
import { n as mcpGenerator, t as serverGenerator } from "./generators-jjs2-iEm.js";
|
|
2
2
|
export { mcpGenerator, serverGenerator };
|
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_generators = require("./generators-
|
|
2
|
+
const require_Server = require("./Server-EjbvNRYy.cjs");
|
|
3
|
+
const require_generators = require("./generators-Br_cVPcG.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.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as camelCase } from "./Server-
|
|
3
|
-
import { n as mcpGenerator, t as serverGenerator } from "./generators-
|
|
2
|
+
import { n as camelCase } from "./Server-kM1BVYP3.js";
|
|
3
|
+
import { n as mcpGenerator, t as serverGenerator } from "./generators-jjs2-iEm.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { createPlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
6
6
|
import { pluginClientName } from "@kubb/plugin-client";
|
|
@@ -2,7 +2,7 @@ import { t as __name } from "./chunk--u3MIqq1.js";
|
|
|
2
2
|
import { Group, Output, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
|
|
3
3
|
import { ClientImportPath, PluginClient } from "@kubb/plugin-client";
|
|
4
4
|
import { Exclude, Include, Override, ResolvePathOptions } from "@kubb/plugin-oas";
|
|
5
|
-
import { Generator
|
|
5
|
+
import { Generator } from "@kubb/plugin-oas/generators";
|
|
6
6
|
import { Oas, contentType } from "@kubb/oas";
|
|
7
7
|
|
|
8
8
|
//#region src/types.d.ts
|
|
@@ -50,7 +50,7 @@ type Options = {
|
|
|
50
50
|
/**
|
|
51
51
|
* Define some generators next to the Mcp generators.
|
|
52
52
|
*/
|
|
53
|
-
generators?: Array<Generator
|
|
53
|
+
generators?: Array<Generator<PluginMcp>>;
|
|
54
54
|
};
|
|
55
55
|
type ResolvedOptions = {
|
|
56
56
|
output: Output<Oas>;
|
|
@@ -61,4 +61,4 @@ type ResolvedOptions = {
|
|
|
61
61
|
type PluginMcp = PluginFactoryOptions<'plugin-mcp', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
62
62
|
//#endregion
|
|
63
63
|
export { PluginMcp as n, Options as t };
|
|
64
|
-
//# sourceMappingURL=types-
|
|
64
|
+
//# sourceMappingURL=types-CblxgOvZ.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-mcp",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.18",
|
|
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",
|
|
@@ -73,13 +73,13 @@
|
|
|
73
73
|
}
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@kubb/react-fabric": "0.
|
|
77
|
-
"@kubb/core": "5.0.0-alpha.
|
|
78
|
-
"@kubb/oas": "5.0.0-alpha.
|
|
79
|
-
"@kubb/plugin-client": "5.0.0-alpha.
|
|
80
|
-
"@kubb/plugin-oas": "5.0.0-alpha.
|
|
81
|
-
"@kubb/plugin-ts": "5.0.0-alpha.
|
|
82
|
-
"@kubb/plugin-zod": "5.0.0-alpha.
|
|
76
|
+
"@kubb/react-fabric": "0.15.1",
|
|
77
|
+
"@kubb/core": "5.0.0-alpha.18",
|
|
78
|
+
"@kubb/oas": "5.0.0-alpha.18",
|
|
79
|
+
"@kubb/plugin-client": "5.0.0-alpha.18",
|
|
80
|
+
"@kubb/plugin-oas": "5.0.0-alpha.18",
|
|
81
|
+
"@kubb/plugin-ts": "5.0.0-alpha.18",
|
|
82
|
+
"@kubb/plugin-zod": "5.0.0-alpha.18"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@internals/utils": "0.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Server-BXiZMmu8.cjs","names":["FunctionParams","File","Const"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../src/components/Server.tsx"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes a word with `_` when it is a reserved JavaScript/Java identifier\n * or starts with a digit.\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n */\nexport function isValidVarName(name: string): boolean {\n try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import { camelCase, isValidVarName } from '@internals/utils'\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;;;;AAWjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,iBAAiB;AAC1C,QAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MA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AY,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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Server-zYi6bZ4D.js","names":[],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../src/components/Server.tsx"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes a word with `_` when it is a reserved JavaScript/Java identifier\n * or starts with a digit.\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n */\nexport function isValidVarName(name: string): boolean {\n try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import { camelCase, isValidVarName } from '@internals/utils'\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":";;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAA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