@kubb/plugin-mcp 5.4.0 → 5.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -134,7 +134,7 @@ function getRequestGroupOptionality(node) {
134
134
  hasRequiredPath,
135
135
  hasRequiredQuery,
136
136
  hasRequiredHeader,
137
- isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !groups.body
137
+ isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !(groups.body && node.requestBody?.required === true)
138
138
  };
139
139
  }
140
140
  /**
@@ -177,6 +177,22 @@ function buildOperationComments(node, options = {}) {
177
177
  }
178
178
  const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
179
179
  /**
180
+ * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
181
+ * per property, typed and serialized like any other.
182
+ * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
183
+ */
184
+ function spreadQuerystring(param) {
185
+ const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
186
+ const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
187
+ if (schema?.type !== "object" || !formEncoded) return [param];
188
+ return schema.properties.map((property) => _kubb_kit.ast.factory.createParameter({
189
+ name: property.name,
190
+ in: "query",
191
+ schema: property.schema,
192
+ required: param.required && property.required
193
+ }));
194
+ }
195
+ /**
180
196
  * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
181
197
  * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
182
198
  * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
@@ -185,17 +201,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
185
201
  function getOperationParameters(node) {
186
202
  const cached = operationParameterGroupsByNode.get(node);
187
203
  if (cached) return cached;
188
- const group = (location) => {
204
+ const dedupe = (params) => {
189
205
  const seen = /* @__PURE__ */ new Set();
190
- return node.parameters.filter((param) => {
191
- if (param.in !== location || seen.has(param.name)) return false;
206
+ return params.filter((param) => {
207
+ if (seen.has(param.name)) return false;
192
208
  seen.add(param.name);
193
209
  return true;
194
210
  });
195
211
  };
212
+ const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
196
213
  const groups = {
197
214
  path: group("path"),
198
- query: group("query"),
215
+ query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
199
216
  header: group("header"),
200
217
  cookie: group("cookie")
201
218
  };
@@ -945,11 +962,11 @@ const serverGenerator = (0, _kubb_kit.defineGenerator)({
945
962
  });
946
963
  // kubb-extension.json
947
964
  var compatibility = {
948
- "kubb": ">=5.14.6",
965
+ "kubb": ">=5.16.0",
949
966
  "node": ">=22.22"
950
967
  };
951
968
  // package.json
952
- var version = "5.4.0";
969
+ var version = "5.4.2";
953
970
  // src/resolvers/resolverMcp.ts
954
971
  /**
955
972
  * Default resolver used by `@kubb/plugin-mcp`. Decides the names and file
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["Url","posix","camelCase","File","Function","File","Function","Const","pluginTsName","pluginZodName","Diagnostics","Diagnostics","path","defineGenerator","jsxRenderer","ast","File","defineGenerator","jsxRenderer","pluginZodName","path","ast","File","createResolver","camelCase","defineExtension","pluginTsName","pluginZodName","Resolver","useConfig"],"sources":["../../../internals/shared/src/operation.ts","../../../internals/utils/src/fs.ts","../../../internals/shared/src/resolver.ts","../../../internals/shared/src/group.ts","../src/components/McpHandler.tsx","../src/components/Server.tsx","../../../internals/client/src/resolveOperationTypes.ts","../../../internals/client/src/resolveClient.ts","../../../internals/client/src/resolveClientOperation.ts","../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx","../kubb-extension.json","../package.json","../src/resolvers/resolverMcp.ts","../src/plugin.ts"],"sourcesContent":["import { ast, type Group, type Memo, type Output, type Resolver, type ResolverFileParams, Url } from '@kubb/kit'\n\n/**\n * Builds the `ResolverFileParams` every operation generator passes to\n * `resolver.file`: a file named `name`, tagged by the operation's first\n * tag (or `'default'`), at the operation's path. Centralizes the entry object\n * that was repeated at dozens of call sites across the client and query plugins.\n *\n * @example\n * ```ts\n * resolver.file(operationFileEntry(node, node.operationId), { root, output, group })\n * ```\n */\nexport function operationFileEntry(node: ast.OperationNode, name: string, extname: ResolverFileParams['extname'] = '.ts'): ResolverFileParams {\n return {\n name,\n extname,\n tag: node.tags[0] ?? 'default',\n path: node.path,\n }\n}\n\n/**\n * Resolves a dependency plugin's generated file for `node.operationId`, cached in `memo` (the\n * build's `ctx.memo`) under the resolver's own plugin name and the operation. Several dependents reading the\n * same dependency for the same operation in one pass (a query plugin's several hook generators, the\n * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.\n *\n * @example Cache `plugin-ts`'s file for the current operation\n * ```ts\n * const fileTs = resolveDependencyOperationFile({ memo: ctx.memo, node, resolver: tsResolver, root, output })\n * ```\n */\nexport function resolveDependencyOperationFile(options: {\n memo: Memo\n node: ast.OperationNode\n resolver: Pick<Resolver, 'file' | 'pluginName'>\n root: string\n output: Output\n group?: Group | null\n}): ast.FileNode {\n const { memo, node, resolver, root, output, group } = options\n\n return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () =>\n resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),\n )\n}\n\nexport type ContentTypeInfo = {\n contentTypes: string[]\n isMultipleContentTypes: boolean\n contentTypeUnion: string\n defaultContentType: string\n hasFormData: boolean\n}\n\nexport type RequestConfigResolver = {\n response: {\n body(node: ast.OperationNode): string\n }\n}\n\nexport type ResponseStatusNameResolver = {\n response: {\n status(node: ast.OperationNode, statusCode: ast.StatusCode): string\n }\n}\n\nexport type ResponseNameResolver = ResponseStatusNameResolver & {\n response: {\n response(node: ast.OperationNode): string\n }\n}\n\nexport type OperationTypeNameResolver = RequestConfigResolver &\n ResponseNameResolver & {\n param: {\n path(node: ast.OperationNode, param: ast.ParameterNode): string\n query(node: ast.OperationNode, param: ast.ParameterNode): string\n headers(node: ast.OperationNode, param: ast.ParameterNode): string\n }\n }\n\nexport type OperationCommentLink = 'pathTemplate' | 'urlPath' | false | ((node: ast.OperationNode) => string | undefined)\n\nexport type BuildOperationCommentsOptions = {\n link?: OperationCommentLink\n linkPosition?: 'beforeDeprecated' | 'afterDeprecated'\n splitLines?: boolean\n}\n\ntype ResponseLike = {\n statusCode: ast.StatusCode | number | string\n}\n\nexport type OperationParameterGroups = Record<ast.ParameterNode['in'], Array<ast.ParameterNode>>\n\nexport type ResolveOperationTypeNameOptions = {\n responseStatusNames?: boolean | 'error'\n exclude?: ReadonlyArray<string | undefined>\n order?: 'params-first' | 'body-response-first'\n /**\n * Include the individual `Path`/`Query`/`Headers` group type names. Set to `false` for clients\n * that reference the grouped `Options` type instead of the per-group types.\n */\n includeParams?: boolean\n}\n\nfunction getOperationLink(node: ast.OperationNode, link: OperationCommentLink): string | null {\n if (!link) {\n return null\n }\n\n if (typeof link === 'function') {\n return link(node) ?? null\n }\n\n return node.path ? `{@link ${Url.toPath(node.path)}}` : null\n}\n\n/**\n * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several\n * are present and the union, default, and form-data flags the client uses to pick one.\n */\nfunction buildContentTypeInfo(contentTypes: string[]): ContentTypeInfo {\n const isMultipleContentTypes = contentTypes.length > 1\n\n return {\n contentTypes,\n isMultipleContentTypes,\n contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(' | ') : '',\n defaultContentType: contentTypes[0] ?? 'application/json',\n hasFormData: contentTypes.some((ct) => ct === 'multipart/form-data'),\n }\n}\n\nexport function getContentTypeInfo(node: ast.OperationNode): ContentTypeInfo {\n return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? [])\n}\n\n/**\n * The request-body counterpart for the primary success response: the content types it documents and\n * whether several are present, so the client can let a caller pick which one to accept.\n */\nexport function getResponseContentTypeInfo(node: ast.OperationNode): ContentTypeInfo {\n return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? [])\n}\n\nexport type ResponseType = 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n\n/**\n * Reads the single base content type of an operation's primary success response, lowercased and\n * stripped of any `; charset=...` suffix. Returns `undefined` when the response declares zero or\n * more than one content type, since neither case has a single type to act on.\n */\nfunction getPrimarySuccessContentType(node: ast.OperationNode): string | undefined {\n const contentTypes = getPrimarySuccessResponse(node)?.content?.map((entry) => entry.contentType) ?? []\n if (contentTypes.length !== 1) return undefined\n return contentTypes[0]!.split(';')[0]!.trim().toLowerCase()\n}\n\n/**\n * Whether an operation streams its primary success response as Server-Sent Events\n * (`text/event-stream`). The client generator uses this to return a typed event stream instead of a\n * one-shot `RequestResult`.\n */\nexport function isEventStream(node: ast.OperationNode): boolean {\n return getPrimarySuccessContentType(node) === 'text/event-stream'\n}\n\n/**\n * Derives the default `responseType` for an operation from its primary success response.\n *\n * Returns a value only when that response declares a single non-JSON content type. `text/event-stream`\n * and other binary types (`application/octet-stream`, `application/pdf`, `image/*`, `audio/*`,\n * `video/*`) map to a stream or `'blob'`, and other `text/*` maps to `'text'`. Otherwise `undefined`,\n * leaving the runtime client's `Content-Type` auto-detection in charge.\n */\nexport function getResponseType(node: ast.OperationNode): ResponseType | undefined {\n const baseType = getPrimarySuccessContentType(node)\n if (!baseType) return undefined\n\n if (baseType === 'application/json' || baseType.endsWith('+json') || baseType === 'text/json') return undefined\n if (baseType === 'text/event-stream') return 'stream'\n if (baseType.startsWith('text/')) return 'text'\n if (baseType === 'application/octet-stream' || baseType === 'application/pdf' || /^(image|audio|video)\\//.test(baseType)) return 'blob'\n return undefined\n}\n\n/**\n * Maps a content type to the PascalCase suffix used to name per-content-type variants\n * (e.g. `application/json` → `Json`, `application/xml` → `Xml`, `multipart/form-data` → `FormData`).\n */\nfunction getContentTypeSuffix(contentType: string): string {\n const baseType = contentType.split(';')[0]!.trim()\n if (baseType === 'application/json') return 'Json'\n if (baseType === 'multipart/form-data') return 'FormData'\n if (baseType === 'application/x-www-form-urlencoded') return 'FormUrlEncoded'\n const subtype = baseType.split('/').pop() ?? baseType\n const parts = subtype.split(/[^a-zA-Z0-9]+/).filter(Boolean)\n if (parts.length === 0) return 'Unknown'\n return parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join('')\n}\n\n/**\n * Appends a content-type suffix to a base name, keeping a trailing `Data` segment last\n * (e.g. `AddPetData` + `Json` → `AddPetJsonData`, `AddPetStatus200` + `Xml` → `AddPetStatus200Xml`).\n */\nexport function getPerContentTypeName(baseName: string, suffix: string): string {\n if (baseName.endsWith('Data')) {\n return suffix.endsWith('Data') ? baseName.slice(0, -4) + suffix : `${baseName.slice(0, -4)}${suffix}Data`\n }\n return baseName + suffix\n}\n\nexport type ContentVariantInput = { contentType: string; schema?: ast.SchemaNode | null; keysToOmit?: Array<string> | null }\nexport type ContentVariant = { name: string; suffix: string; schema: ast.SchemaNode; keysToOmit?: Array<string> | null; contentType: string }\n\n/**\n * Resolves per-content-type variant names for a set of content entries, deduplicating suffix\n * collisions with a numeric counter. Entries without a schema are skipped. The returned `suffix` is\n * the final (possibly counter-augmented) value, so callers can derive parallel names in another\n * namespace (e.g. plugin-faker deriving the matching plugin-ts type name).\n */\nexport function resolveContentTypeVariants(entries: Array<ContentVariantInput>, baseName: string): Array<ContentVariant> {\n const usedNames = new Set<string>()\n return entries\n .filter((entry) => entry.schema)\n .map((entry) => {\n const baseSuffix = getContentTypeSuffix(entry.contentType)\n let suffix = baseSuffix\n let name = getPerContentTypeName(baseName, suffix)\n let counter = 2\n while (usedNames.has(name)) {\n suffix = `${baseSuffix}${counter++}`\n name = getPerContentTypeName(baseName, suffix)\n }\n usedNames.add(name)\n return { name, suffix, schema: entry.schema!, keysToOmit: entry.keysToOmit, contentType: entry.contentType }\n })\n}\n\n// The request groups come from the grouped params, so `config` drops the data-shape keys to stay\n// assignable to `Options`, which omits them from `RequestConfig`.\nconst requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`\n\nexport function buildRequestConfigType(node: ast.OperationNode): string {\n const request = getContentTypeInfo(node)\n const response = getResponseContentTypeInfo(node)\n\n // Only the ambiguous side is offered: a single-type side has nothing to pick, so it stays baked in\n // the generated call.\n const members = [\n request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null,\n response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null,\n ].filter(Boolean)\n\n return members.length ? `${requestConfigBaseType} & { contentType?: { ${members.join('; ')} } }` : requestConfigBaseType\n}\n\n/**\n * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,\n * `useInfiniteQuery`, `useSWR`, ...). Unlike {@link buildRequestConfigType}, it never adds a\n * `contentType?:` member: query hooks wrap GET operations, which carry no request body to select a\n * content type for.\n */\nexport function buildClientOptionType(): string {\n return requestConfigBaseType\n}\n\nexport type RequestGroups = {\n path: boolean\n query: boolean\n body: boolean\n headers: boolean\n}\n\n/**\n * Which of the grouped request options an operation carries.\n */\nexport function getRequestGroups(node: ast.OperationNode): RequestGroups {\n const { path, query, header } = getOperationParameters(node)\n return {\n path: path.length > 0,\n query: query.length > 0,\n body: Boolean(node.requestBody?.content?.[0]?.schema),\n headers: header.length > 0,\n }\n}\n\nexport type RequestGroupOptionality = {\n groups: RequestGroups\n hasRequiredPath: boolean\n hasRequiredQuery: boolean\n hasRequiredHeader: boolean\n /**\n * Whether the grouped request parameter can default to `{}`. True only when no group carries a\n * required member, so every member is safe to omit.\n */\n isOptional: boolean\n}\n\n/**\n * Resolves which grouped request options an operation carries together with whether each group\n * holds a required member. The grouped parameter stays optional only when nothing inside it is\n * required, matching the generated `RequestConfig` type.\n */\nexport function getRequestGroupOptionality(node: ast.OperationNode): RequestGroupOptionality {\n const groups = getRequestGroups(node)\n const { path, query, header } = getOperationParameters(node)\n const hasRequiredPath = path.some((param) => param.required)\n const hasRequiredQuery = query.some((param) => param.required)\n const hasRequiredHeader = header.some((param) => param.required)\n\n return {\n groups,\n hasRequiredPath,\n hasRequiredQuery,\n hasRequiredHeader,\n isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !groups.body,\n }\n}\n\nexport type RequestOptionsNameResolver = RequestConfigResolver & {\n response: {\n options(node: ast.OperationNode): string\n }\n}\n\n/**\n * Builds the grouped `{ path, query, body, headers }` parameter for a generated client\n * function, typed from the operation's `Options` (minus `url`). Only the groups the\n * operation actually has are destructured. The trailing `config` parameter carries the\n * runtime `RequestConfig` overrides plus `client`.\n */\nexport function buildRequestParamsSignature(\n node: ast.OperationNode,\n resolver: RequestOptionsNameResolver,\n options: { isConfigurable?: boolean } = {},\n): { signature: string; groups: RequestGroups } {\n const { isConfigurable = true } = options\n const { groups, isOptional } = getRequestGroupOptionality(node)\n\n const names = (['path', 'query', 'body', 'headers'] as const).filter((key) => groups[key])\n\n // These callers never carry the `contentType` that several media types require.\n const optionsType = hasRequestContentTypeChoice(node)\n ? `Pick<${resolver.response.options(node)}, ${names.map((name) => `'${name}'`).join(' | ')}>`\n : resolver.response.options(node)\n const firstParam = names.length > 0 ? `{ ${names.join(', ')} }: ${optionsType}${isOptional ? ' = {}' : ''}` : null\n const configParam = isConfigurable ? `config: ${buildRequestConfigType(node)} = {}` : null\n\n return {\n signature: [firstParam, configParam].filter(Boolean).join(', '),\n groups,\n }\n}\n\nexport function buildOperationComments(node: ast.OperationNode, options: BuildOperationCommentsOptions = {}): Array<string> {\n const { link = 'pathTemplate', linkPosition = 'afterDeprecated', splitLines = false } = options\n const linkComment = getOperationLink(node, link)\n const comments =\n linkPosition === 'beforeDeprecated'\n ? [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, linkComment, node.deprecated && '@deprecated']\n : [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, node.deprecated && '@deprecated', linkComment]\n\n const filteredComments = comments.filter((comment): comment is string => Boolean(comment))\n\n if (!splitLines) {\n return filteredComments\n }\n\n return filteredComments.flatMap((text) => text.split(/\\r?\\n/).map((line) => line.trim())).filter((comment): comment is string => Boolean(comment))\n}\n\nconst operationParameterGroupsByNode = new WeakMap<ast.OperationNode, OperationParameterGroups>()\n\n/**\n * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each\n * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance\n * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the\n * same parameters once per plugin.\n */\nexport function getOperationParameters(node: ast.OperationNode): OperationParameterGroups {\n const cached = operationParameterGroupsByNode.get(node)\n if (cached) return cached\n\n // A malformed spec can declare the same name twice within one location. Both would resolve to the\n // same output property, so emitting both would yield an object type with a duplicate member,\n // which TypeScript rejects. Keep the first.\n const group = (location: ast.ParameterNode['in']) => {\n const seen = new Set<string>()\n\n return node.parameters.filter((param) => {\n if (param.in !== location || seen.has(param.name)) return false\n seen.add(param.name)\n return true\n })\n }\n\n const groups: OperationParameterGroups = { path: group('path'), query: group('query'), header: group('header'), cookie: group('cookie') }\n\n operationParameterGroupsByNode.set(node, groups)\n return groups\n}\n\n/**\n * Builds the combined `{ body, path, query, headers }` options object schema for an operation,\n * referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s\n * `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same\n * shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod\n * printer to emit `z.object(…)` rather than a record.\n */\nexport function hasRequestContentTypeChoice(node: ast.OperationNode): boolean {\n return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1\n}\n\n/**\n * Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.\n */\nexport function castToClientOptions(callArg: string, clientName: string, returnType: 'full' | 'data' | 'plain' = 'full'): string {\n return `${callArg} as Parameters<typeof ${clientName}${returnType === 'plain' ? '' : '<true>'}>[0]`\n}\n\nexport function buildOptionsSchema(node: ast.OperationNode, resolver: OperationTypeNameResolver, { pairContentTypes = false } = {}): ast.SchemaNode {\n const { path, query, header } = getOperationParameters(node)\n const hasBody = Boolean(node.requestBody?.content?.[0]?.schema)\n const createNever = () => ast.factory.createSchema({ type: 'never', primitive: undefined, optional: true })\n const groups = [\n { name: 'path', params: path, resolve: resolver.param.path },\n { name: 'query', params: query, resolve: resolver.param.query },\n { name: 'headers', params: header, resolve: resolver.param.headers },\n ] as const\n\n const createOptions = (body: ast.SchemaNode, extra: Array<ast.PropertyNode> = []) =>\n // NOTE(v5-stable): the fields were renamed from the legacy beta shape\n // (`data`/`pathParams`/`queryParams`/`headerParams`) to `body`/`path`/`query`/`headers` so the\n // type matches the runtime client. Drop this note once v5 leaves beta.\n ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n deprecated: node.deprecated,\n properties: [\n ast.factory.createProperty({ name: 'body', required: hasBody, schema: body }),\n ...groups.map(({ name, params, resolve }) => {\n const required = params.some((param) => param.required)\n\n return ast.factory.createProperty({\n name,\n required,\n schema:\n params.length > 0\n ? ast.factory.createSchema({ type: 'ref', name: resolve.call(resolver.param, node, params[0]!), optional: !required })\n : createNever(),\n })\n }),\n ...extra,\n ],\n })\n\n const variants =\n pairContentTypes && hasRequestContentTypeChoice(node) ? resolveContentTypeVariants(node.requestBody?.content ?? [], resolver.response.body(node)) : []\n if (variants.length < 2) {\n return createOptions(hasBody ? ast.factory.createSchema({ type: 'ref', name: resolver.response.body(node) }) : createNever())\n }\n\n // The first media type is the runtime default, so only the others must pass `contentType`.\n return ast.factory.createSchema({\n type: 'union',\n members: variants.map((variant, index) =>\n createOptions(ast.factory.createSchema({ type: 'ref', name: variant.name }), [\n ast.factory.createProperty({\n name: 'contentType',\n required: index > 0,\n schema: ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n ast.factory.createProperty({\n name: 'request',\n required: true,\n schema: ast.factory.createSchema({ type: 'enum', enumValues: [variant.contentType] }),\n }),\n ],\n }),\n }),\n ]),\n ),\n })\n}\n\n/**\n * The schema a status occupies in the `<Name>Responses` record. A status that documents several\n * content types becomes a `{ contentType; data }` union so the runtime can surface the negotiated type\n * on `result.parsed`, while the standalone `<Name>StatusNNN` alias stays the plain body union that the\n * query hooks and `result.data` use.\n */\nfunction buildResponseRecordEntry(node: ast.OperationNode, res: ast.ResponseNode, resolver: ResponseStatusNameResolver): ast.SchemaNode {\n const statusName = resolver.response.status(node, res.statusCode)\n const variants = (res.content ?? []).filter((entry) => entry.schema)\n if (variants.length <= 1) {\n return ast.factory.createSchema({ type: 'ref', name: statusName })\n }\n\n return ast.factory.createSchema({\n type: 'union',\n members: resolveContentTypeVariants(variants, statusName).map((variant) =>\n ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n ast.factory.createProperty({\n name: 'contentType',\n required: true,\n schema: ast.factory.createSchema({ type: 'enum', enumValues: [variant.contentType] }),\n }),\n ast.factory.createProperty({\n name: 'data',\n required: true,\n schema: ast.factory.createSchema({ type: 'ref', name: variant.name }),\n }),\n ],\n }),\n ),\n })\n}\n\n/**\n * Builds the per-status `<Name>Responses` record for an operation, referencing the already-resolved\n * `<Name>StatusNNN` names. Shared by `@kubb/plugin-ts`'s `Responses` type and `@kubb/plugin-zod`'s\n * inferred responses schema, so both emit the same shape from the same inputs.\n *\n * Always emits the keyed record, even when an operation declares no responses. An operation with no\n * responses renders as an empty object, which keeps every consumer's import (for example the axios\n * SDK's `RequestResult<XResponses>`) resolvable instead of pointing at a missing export.\n */\nexport function buildResponses(node: ast.OperationNode, resolver: ResponseStatusNameResolver): ast.SchemaNode {\n return ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: node.responses.map((res) =>\n ast.factory.createProperty({\n name: String(res.statusCode),\n required: true,\n schema: buildResponseRecordEntry(node, res, resolver),\n }),\n ),\n })\n}\n\nexport function getStatusCodeNumber(statusCode: ast.StatusCode | number | string): number | null {\n const code = Number(statusCode)\n\n return Number.isNaN(code) ? null : code\n}\n\nexport function isSuccessStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== null && code >= 200 && code < 300\n}\n\nexport function isErrorStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== null && code >= 400\n}\n\nexport function getSuccessResponses<TResponse extends ResponseLike>(responses: ReadonlyArray<TResponse>): Array<TResponse> {\n return responses.filter((response) => isSuccessStatusCode(response.statusCode))\n}\n\nexport function getOperationSuccessResponses(node: ast.OperationNode): Array<ast.ResponseNode> {\n return getSuccessResponses(node.responses)\n}\n\nexport function getPrimarySuccessResponse(node: ast.OperationNode): ast.ResponseNode | null {\n return getOperationSuccessResponses(node)[0] ?? null\n}\n\nexport function resolveErrorNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode))\n}\n\nexport function resolveSuccessNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode))\n}\n\nexport function resolveStatusCodeNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.map((response) => resolver.response.status(node, response.statusCode))\n}\n\n/**\n * Lists the type names an operation's types file declares, computed once per resolver and `options` so every\n * dependent reads the same list.\n */\nexport function resolveOperationTypeNames(\n node: ast.OperationNode,\n resolver: OperationTypeNameResolver & Pick<Resolver, 'memo'>,\n options: ResolveOperationTypeNameOptions = {},\n): string[] {\n const key = `${node.operationId}\\0${options.order ?? ''}\\0${options.responseStatusNames ?? ''}\\0${options.includeParams === false ? 'noparams' : ''}\\0${(options.exclude ?? []).join(',')}`\n return resolver.memo(`operationTypeNames:${key}`, () => {\n const { path, query, header } = getOperationParameters(node)\n const responseStatusNames =\n options.responseStatusNames === 'error'\n ? resolveErrorNames(node, resolver)\n : options.responseStatusNames === false\n ? []\n : resolveStatusCodeNames(node, resolver)\n const exclude = new Set(options.exclude ?? [])\n const paramNames =\n options.includeParams === false\n ? []\n : [\n ...path.map((param) => resolver.param.path(node, param)),\n ...query.map((param) => resolver.param.query(node, param)),\n ...header.map((param) => resolver.param.headers(node, param)),\n ]\n const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)]\n const names =\n options.order === 'body-response-first'\n ? [...bodyAndResponseNames, ...paramNames, ...responseStatusNames]\n : [...paramNames, ...bodyAndResponseNames, ...responseStatusNames]\n\n return names.filter((name): name is string => Boolean(name) && !exclude.has(name as string))\n })\n}\n\nexport function resolveResponseTypes(node: ast.OperationNode, resolver: ResponseNameResolver): Array<[statusCode: number | 'default', typeName: string]> {\n const types: Array<[number | 'default', string]> = []\n\n for (const response of node.responses) {\n if (response.statusCode === 'default') {\n types.push(['default', resolver.response.response(node)])\n continue\n }\n\n const code = getStatusCodeNumber(response.statusCode)\n if (code === null) {\n continue\n }\n\n types.push([code, isSuccessStatusCode(code) ? resolver.response.response(node) : resolver.response.status(node, response.statusCode)])\n }\n\n return types\n}\n","import { posix } from 'node:path'\nimport { camelCase } from '@kubb/kit'\n\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir: string, filePath: string): string {\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Builds a nested file path from a dotted name. Splits on dots that precede a letter\n * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases\n * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.\n *\n * Empty segments are dropped before joining. They arise when the name starts with a dot\n * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to\n * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an\n * absolute path, letting generated files escape the configured output directory.\n *\n * @example Nested path from a dotted name\n * `toFilePath('pet.petId') // 'pet/petId'`\n *\n * @example PascalCase the final segment\n * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`\n *\n * @example Suffix applied to the final segment only\n * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`\n */\nexport function toFilePath(name: string, caseLast: (part: string) => string = camelCase): string {\n const parts = name.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => (i === parts.length - 1 ? caseLast(part) : camelCase(part)))\n .filter(Boolean)\n .join('/')\n}\n","import { ensureValidVarName, toFilePath } from '@internals/utils'\nimport { ast, camelCase } from '@kubb/kit'\nimport type { GeneratorContext, Resolver, ResolverFile } from '@kubb/kit'\n\n/**\n * The shared top-level `name` of the operation plugins, computed once per operation name and build.\n */\nexport function resolveOperationName(this: Resolver, name: string): string {\n return this.memo(`operation:${name}`, () => ensureValidVarName(camelCase(name)))\n}\n\n/**\n * Builds the allocation key for a declaration an operation owns. `scope` names which declaration\n * it is, so two of them never share an allocation even when a custom resolver gives both the same\n * name. Leave `scope` empty for the operation's own declaration.\n *\n * @example\n * ```ts\n * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })\n * ```\n */\nexport function operationKey(node: ast.OperationNode, ...scope: Array<string | number>): Array<string | undefined> {\n return ['operation', node.method, node.path, ...scope.map(String)]\n}\n\n/**\n * The `param` namespace shared by the schema-producing plugins (ts, zod, faker):\n * per-parameter names plus the grouped `Path`/`Query`/`Headers` names, all routed\n * through the plugin's top-level `name` casing.\n */\nexport type OperationParamResolver = {\n name(this: Resolver, node: ast.OperationNode, param: ast.ParameterNode): string\n path(this: Resolver, node: ast.OperationNode): string\n query(this: Resolver, node: ast.OperationNode): string\n headers(this: Resolver, node: ast.OperationNode): string\n}\n\n/**\n * The `response` namespace shared by the schema-producing plugins: per-status,\n * body, and combined response names, all routed through the plugin's top-level\n * `name` casing.\n */\nexport type OperationResponseResolver = {\n status(this: Resolver, node: ast.OperationNode, statusCode: ast.StatusCode): string\n body(this: Resolver, node: ast.OperationNode): string\n responses(this: Resolver, node: ast.OperationNode): string\n response(this: Resolver, node: ast.OperationNode): string\n}\n\n/**\n * Builds the shared `param` namespace. Spread the result into `createResolver`\n * and override individual methods next to it when a plugin deviates.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ param: createOperationParamResolver(), ... })\n * ```\n */\nexport function createOperationParamResolver(): OperationParamResolver {\n return {\n name(node, param) {\n const name = this.name(`${node.operationId} ${param.in} ${param.name}`)\n return this.resolveName({ key: operationKey(node, 'param', 'name', param.in, param.name), name })\n },\n path(node) {\n const name = this.name(`${node.operationId} Path`)\n return this.resolveName({ key: operationKey(node, 'param', 'path'), name })\n },\n query(node) {\n const name = this.name(`${node.operationId} Query`)\n return this.resolveName({ key: operationKey(node, 'param', 'query'), name })\n },\n headers(node) {\n const name = this.name(`${node.operationId} Headers`)\n return this.resolveName({ key: operationKey(node, 'param', 'headers'), name })\n },\n }\n}\n\n/**\n * Builds the shared `response` namespace. Spread the result into\n * `createResolver` and add plugin-specific methods (`options`, `error`) next\n * to it.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ response: { ...createOperationResponseResolver(), options(node) {...} }, ... })\n * ```\n */\nexport function createOperationResponseResolver(): OperationResponseResolver {\n return {\n status(node, statusCode) {\n const name = this.name(`${node.operationId} Status ${statusCode}`)\n return this.resolveName({ key: operationKey(node, 'response', 'status', statusCode), name })\n },\n body(node) {\n const name = this.name(`${node.operationId} Body`)\n return this.resolveName({ key: operationKey(node, 'response', 'body'), name })\n },\n responses(node) {\n const name = this.name(`${node.operationId} Responses`)\n return this.resolveName({ key: operationKey(node, 'response', 'responses'), name })\n },\n response(node) {\n const name = this.name(`${node.operationId} Response`)\n return this.resolveName({ key: operationKey(node, 'response', 'response'), name })\n },\n }\n}\n\n/**\n * Builds a resolver `file` override whose base name runs every path segment\n * through `toFilePath`, casing the final segment with `caseLast`.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ file: createCasedFile(pascalCase), ... })\n * ```\n */\nexport function createCasedFile(caseLast: (part: string) => string): ResolverFile {\n return {\n baseName({ name, extname }) {\n return this.memo(`file:${name}\\0${extname}`, (): ast.FileNode['baseName'] => `${toFilePath(name, caseLast)}${extname}`)\n },\n }\n}\n\ntype SchemaIndexContext = Pick<GeneratorContext, 'memo' | 'driver'>\n\n/**\n * Names of the schemas in a circular reference chain, computed once per build.\n */\nexport function getCircularNames(ctx: SchemaIndexContext): ReadonlySet<string> {\n return ctx.memo('circularNames:set', () => ast.findCircularSchemas(ctx.driver.inputNode?.schemas ?? []))\n}\n\n/**\n * Names of the schemas whose type is `enum`, computed once per build.\n */\nexport function getEnumNames(ctx: SchemaIndexContext): ReadonlySet<string> {\n return ctx.memo(\n 'enumNames:set',\n () => new Set((ctx.driver.inputNode?.schemas ?? []).flatMap((schema) => (schema.type === 'enum' && schema.name ? [schema.name] : []))),\n )\n}\n\ndeclare global {\n namespace Kubb {\n interface MemoRegistry {\n operation: string\n file: ast.FileNode['baseName']\n operationTypeNames: Array<string>\n }\n }\n}\n","import { camelCase, type Group } from '@kubb/kit'\n\n/**\n * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the\n * shared default naming so every plugin groups output consistently:\n *\n * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).\n * - other groups use the camelCased group (`pet store` → `petStore`).\n *\n * A user-provided `group.name` always wins over the default namer, so callers stay in\n * control of their output folders. Returns `null` when grouping is disabled, matching the\n * per-plugin convention.\n *\n * @param group - The user-supplied group option, or `undefined` to disable grouping.\n *\n * @example\n * ```ts\n * createGroupConfig(group) // shared across every plugin\n * ```\n */\nexport function createGroupConfig(group: Group | undefined): Group | null {\n if (!group) {\n return null\n }\n\n const defaultName = (ctx: { group: string }): string => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return camelCase(ctx.group)\n }\n\n return {\n ...group,\n name: group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { buildOperationComments, buildRequestParamsSignature, castToClientOptions, hasRequestContentTypeChoice } from '@internals/shared'\nimport type { ast } from '@kubb/kit'\nimport type { ResolverTs } from '@kubb/plugin-ts'\nimport { File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx'\n\ntype Props = {\n /**\n * Name of the handler function.\n */\n name: string\n /**\n * Name of the contract client `<op>` the handler calls.\n */\n clientName: string\n /**\n * AST operation node.\n */\n node: ast.HttpOperationNode\n /**\n * TypeScript resolver for resolving param/data/response type names.\n */\n resolver: ResolverTs\n /**\n * The registered client plugin's `returnType`, read by the caller off `resolveClientOperation`.\n */\n returnType?: 'full' | 'data' | 'plain'\n}\n\nconst requestGroupOrder = ['path', 'query', 'headers', 'body'] as const\n\nexport function McpHandler({ name, clientName, node, resolver, returnType = 'full' }: Props): KubbReactNode {\n const { signature, groups } = buildRequestParamsSignature(node, resolver, { isConfigurable: false })\n const paramsSignature = [signature, 'ctx: ServerContext'].filter(Boolean).join(', ')\n\n // Forward the grouped config and MCP cancellation signal through the contract client. `throwOnError: true`\n // pins the result shape, since `throwOnErrorDefault: false` would otherwise resolve to the full result.\n const callArgs = requestGroupOrder.filter((key) => groups[key])\n const callConfig = `{ ${[...callArgs, 'signal: ctx.mcpReq.signal', 'throwOnError: true'].join(', ')} }`\n // Tool arguments carry no media type, so the call takes the client's default one.\n const callArg = hasRequestContentTypeChoice(node) ? castToClientOptions(callConfig, clientName, returnType) : callConfig\n const body = returnType === 'data' ? 'res' : 'res.data'\n\n const callToolResult = `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(${body})\n }\n ],\n structuredContent: { data: ${body} }\n}`\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n async\n export\n params={paramsSignature}\n JSDoc={{\n comments: buildOperationComments(node),\n }}\n returnType={'CallToolResult'}\n >\n {`const res = await ${clientName}(${callArg})`}\n <br />\n {callToolResult}\n </Function>\n </File.Source>\n )\n}\n","import type { ast } from '@kubb/kit'\nimport { Const, File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx'\n\ntype ZodParam = {\n name: string\n schemaName: string\n}\n\n/**\n * Composes individual param schemas into `z.object({ ... })`.\n */\nconst zodObject = (params: Array<ZodParam>) => `z.object({ ${params.map((p) => `${JSON.stringify(p.name)}: ${p.schemaName}`).join(', ')} })`\n\ntype Props = {\n /**\n * Human-readable server name passed to `new McpServer({ name })`.\n */\n serverName: string\n /**\n * Semantic version string passed to `new McpServer({ version })`.\n */\n serverVersion: string\n /**\n * Operations to register as MCP tools, each carrying its handler,\n * zod schema, and AST node metadata.\n */\n operations: Array<{\n tool: {\n name: string\n title?: string\n description: string\n }\n mcp: {\n name: string\n file: ast.FileNode\n }\n zod: {\n pathParams: Array<ZodParam>\n /**\n * Query params — individual schemas to compose into `z.object({ ... })`.\n */\n queryParams?: Array<ZodParam> | null\n /**\n * Header params — individual schemas to compose into `z.object({ ... })`.\n */\n headerParams?: Array<ZodParam> | null\n requestName?: string | null\n responseName?: string | null\n }\n }>\n}\n\nexport function Server({ serverName, serverVersion, operations }: Props): KubbReactNode {\n const registrations = operations\n .map(({ tool, mcp, zod }) => {\n // Group params into the same `{ path, query, headers, body }` shape the contract `<op>`\n // expects, so the MCP tool input mirrors every other client consumer.\n const entries: Array<{ key: string; value: string }> = []\n\n if (zod.pathParams.length) {\n entries.push({ key: 'path', value: zodObject(zod.pathParams) })\n }\n\n if (zod.queryParams) {\n entries.push({ key: 'query', value: zodObject(zod.queryParams) })\n }\n\n if (zod.headerParams) {\n entries.push({ key: 'headers', value: zodObject(zod.headerParams) })\n }\n\n if (zod.requestName) {\n entries.push({ key: 'body', value: zod.requestName })\n }\n\n const destructured = `{ ${entries.map((e) => e.key).join(', ')} }`\n const inputSchema = entries.length ? `z.object({ ${entries.map((e) => `${e.key}: ${e.value}`).join(', ')} })` : null\n const outputSchema = zod.responseName\n\n const config = [\n tool.title ? `title: ${JSON.stringify(tool.title)}` : null,\n `description: ${JSON.stringify(tool.description)}`,\n outputSchema ? `outputSchema: z.object({ data: ${outputSchema} })` : null,\n ]\n .filter(Boolean)\n .join(',\\n ')\n\n if (inputSchema) {\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n inputSchema: ${inputSchema},\n}, async (${destructured}, ctx) => {\n return ${mcp.name}(${destructured}, ctx)\n})\n `\n }\n\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n}, async (ctx) => {\n return ${mcp.name}(ctx)\n})\n `\n })\n .filter(Boolean)\n .join('\\n')\n\n return (\n <>\n <File.Source name=\"getServer\" isExportable isIndexable>\n <Function name=\"getServer\" export>\n {`const server = new McpServer({\n name: '${serverName}',\n version: '${serverVersion}',\n})\n${registrations}\nreturn server`}\n </Function>\n </File.Source>\n\n <File.Source name=\"server\" isExportable isIndexable>\n <Const name={'server'} export>\n {'getServer()'}\n </Const>\n </File.Source>\n\n <File.Source name=\"startServer\" isExportable isIndexable>\n <Function name=\"startServer\" async export>\n {`return serveStdio(getServer, {\n onerror: (error) => console.error('MCP server error:', error),\n })`}\n </Function>\n </File.Source>\n </>\n )\n}\n","import { type ast, Diagnostics, type Generator, type Group, type Output } from '@kubb/kit'\nimport { pluginTsName, type ResolverTs } from '@kubb/plugin-ts'\nimport { pluginZodName, type ResolverZod } from '@kubb/plugin-zod'\nimport type { ContractClientFactory } from './types.ts'\n\ntype GeneratorDriver = Parameters<NonNullable<Generator<ContractClientFactory>['operations']>>[1]['driver']\n\n/**\n * The two per-operation type names a generated client references: the grouped input and the\n * per-status responses record its `RequestResult` is keyed on.\n */\nexport type OperationTypeNames = {\n response: {\n /**\n * Resolves the name of the operation's grouped `{ body, path, query, headers }` input type.\n */\n options(node: ast.OperationNode): string\n /**\n * Resolves the name of the operation's per-status responses record type.\n */\n responses(node: ast.OperationNode): string\n }\n}\n\n/**\n * Where a generated client sources its operation types, plus the resolver and output the file\n * declaring them is resolved with.\n */\nexport type OperationTypeSource = OperationTypeNames & {\n /**\n * `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.\n */\n resolver: ResolverTs\n /**\n * The supplying plugin's own `output`, when it configured one.\n */\n output: Output | undefined\n /**\n * The supplying plugin's own `group`, when it configured one.\n */\n group: Group | undefined\n}\n\n/**\n * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`\n * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.\n */\nfunction toZodTypeResolver(resolver: ResolverZod): ResolverTs {\n const type = (name: string) => resolver.schema.type(name)\n\n return {\n ...resolver,\n // Class methods, so a spread drops them. `file` reads private fields, and `memo` gets its own key\n // space so these type names never share an entry with the zod names.\n file: resolver.file.bind(resolver),\n memo: (key: string, compute: () => unknown) => resolver.memo(`zodTypes:${key}`, compute),\n param: {\n name: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.name(node, p)),\n path: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.path(node, p)),\n query: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.query(node, p)),\n headers: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.headers(node, p)),\n },\n response: {\n body: (node: ast.OperationNode) => type(resolver.response.body(node)),\n status: (node: ast.OperationNode, statusCode: ast.StatusCode) => type(resolver.response.status(node, statusCode)),\n response: (node: ast.OperationNode) => type(resolver.response.response(node)),\n responses: (node: ast.OperationNode) => type(resolver.response.responses(node)),\n options: (node: ast.OperationNode) => resolver.response.options(node),\n },\n } as unknown as ResolverTs\n}\n\n/**\n * Picks the plugin generated clients, query hooks, and MCP handlers take their operation types from.\n *\n * `pluginZod({ inferred: 'codec' })` wins, so a codec param takes its domain value. Otherwise `plugin-ts`\n * wins when it is in the pipeline, and without it any `pluginZod({ inferred })`. Throws\n * `KUBB_MISSING_DEPENDENCY` for `pluginName` when neither is available.\n *\n * @example\n * ```ts\n * const types = resolveOperationTypes(ctx.driver, ctx.plugin.name)\n * types.response.options(node) // 'GetPetByIdOptions', or 'GetPetByIdOptionsSchemaType' from zod\n * ```\n */\nexport function resolveOperationTypes(driver: GeneratorDriver, pluginName: string): OperationTypeSource {\n return driver.memo(`operationTypes:${pluginName}`, () => {\n const pluginTs = driver.getPlugin(pluginTsName)\n const pluginZod = driver.getPlugin(pluginZodName)\n\n if (pluginTs && pluginZod?.options?.inferred !== 'codec') {\n const resolver = driver.getResolver(pluginTsName)\n return { response: resolver.response, resolver, output: pluginTs.options?.output, group: pluginTs.options?.group ?? undefined }\n }\n\n if (!pluginZod?.options?.inferred) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.missingDependency,\n severity: 'error',\n message: `Plugin \"${pluginName}\" has no source for operation types.`,\n help: `Add \\`pluginTs()\\` before \"${pluginName}\", or add \\`pluginZod({ inferred: true })\\`.`,\n location: { kind: 'config' },\n plugin: pluginName,\n })\n }\n\n const resolver = toZodTypeResolver(driver.getResolver(pluginZodName))\n return { response: resolver.response, resolver, output: pluginZod.options.output, group: pluginZod.options.group ?? undefined }\n })\n}\n\ndeclare global {\n namespace Kubb {\n interface MemoRegistry {\n operationTypes: OperationTypeSource\n /**\n * Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.\n */\n zodTypes: unknown\n }\n }\n}\n","/**\n * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an\n * operation, shared so the selection rules and diagnostics stay in one place.\n *\n * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered\n * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own\n * inline client:\n *\n * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer\n * imports and calls them.\n * - `error` — no client plugin is registered, several are registered without a selector, the\n * requested one is missing, or `client` is not a known selector.\n *\n * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a\n * lone registered contract client plugin is picked up automatically.\n */\n\nimport { Diagnostics } from '@kubb/kit'\n\n// Canonical plugin names. They mirror the `pluginFetchName` / `pluginAxiosName` / `pluginClientName`\n// consts the plugins export, kept as literals so this internal needs no plugin install deps.\nconst pluginFetchName = 'plugin-fetch'\nconst pluginAxiosName = 'plugin-axios'\nconst pluginClientName = 'plugin-client'\n\n/**\n * The client selector accepted by a consumer's `client` option. Each calls a registered contract\n * client plugin.\n */\nexport type ClientSelector = 'fetch' | 'axios' | 'client'\n\n/**\n * The resolved client strategy stored in a consumer plugin's options: the generated code always\n * imports and calls a registered contract client plugin's `<op>`. The client runtime lives in\n * plugin-axios / plugin-fetch, so nothing is bundled by the consumer.\n */\nexport type ResolvedContractClient = { kind: 'contract'; pluginName: string }\n\n/**\n * The outcome of {@link resolveClient}.\n *\n * - `contract` names the contract client plugin whose `<op>` functions the consumer imports.\n * - `error` carries a setup diagnostic: its code, what is wrong, and how to fix it.\n */\nexport type ResolveClientResult =\n | ResolvedContractClient\n | { kind: 'error'; code: typeof Diagnostics.code.missingDependency | typeof Diagnostics.code.invalidPluginOptions; message: string; help: string }\n\nconst selectorToPlugin: Record<ClientSelector, string> = {\n fetch: pluginFetchName,\n axios: pluginAxiosName,\n client: pluginClientName,\n}\n\n// Every contract client plugin, in auto-detect priority order.\nconst contractPlugins = [pluginFetchName, pluginAxiosName, pluginClientName] as const\n\n/**\n * Applies the `client` resolution rules. See the module comment for the strategy shape.\n *\n * @example\n * ```ts\n * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })\n * // { kind: 'contract', pluginName: 'plugin-fetch' }\n * ```\n *\n * @example\n * ```ts\n * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })\n * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }\n * ```\n */\nexport function resolveClient(options: { client: ClientSelector | undefined; pluginNames: ReadonlyArray<string> }): ResolveClientResult {\n const { client, pluginNames } = options\n const has = (name: string) => pluginNames.includes(name)\n\n if (client === 'fetch' || client === 'axios' || client === 'client') {\n const pluginName = selectorToPlugin[client]\n if (!has(pluginName)) {\n return {\n kind: 'error',\n code: Diagnostics.code.missingDependency,\n message: `\\`client: '${client}'\\` is set but \\`@kubb/plugin-${client}\\` is not registered in \\`plugins\\`.`,\n help: `Add \\`@kubb/plugin-${client}\\` to \\`plugins\\`, or drop \\`client\\` to use a different client plugin.`,\n }\n }\n return { kind: 'contract', pluginName }\n }\n\n // A JS config bypasses the `ClientSelector` type, so reject unknown selectors instead of auto-detecting.\n if (client !== undefined) {\n return {\n kind: 'error',\n code: Diagnostics.code.invalidPluginOptions,\n message: `Option \\`client\\` is ${typeof client === 'string' ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,\n help: 'Set `client` to one of those values, or drop it to use the registered client plugin.',\n }\n }\n\n // `client` unset: auto-detect a lone registered contract client plugin.\n const registered = contractPlugins.filter(has)\n if (registered.length === 1) {\n return { kind: 'contract', pluginName: registered[0]! }\n }\n if (registered.length > 1) {\n return {\n kind: 'error',\n code: Diagnostics.code.invalidPluginOptions,\n message: `Multiple client plugins are registered (${registered.map((name) => `\\`@kubb/${name}\\``).join(', ')}) and \\`client\\` is not set.`,\n help: \"Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin.\",\n }\n }\n\n return {\n kind: 'error',\n code: Diagnostics.code.missingDependency,\n message: 'No client plugin is registered.',\n help: 'Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call.',\n }\n}\n\n/**\n * Resolves the contract client during a consumer plugin's setup hook.\n * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.\n * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer\n * fails fast with the same message.\n */\nexport function resolveContractClient(options: {\n plugin: string\n client: ClientSelector | undefined\n plugins?: ReadonlyArray<unknown>\n}): ResolvedContractClient {\n const { plugin, client, plugins = [] } = options\n const pluginNames = plugins.map((plugin) => (plugin as { name?: string }).name).filter((name): name is string => Boolean(name))\n const resolved = resolveClient({ client, pluginNames })\n if (resolved.kind === 'error') {\n const { code, message, help } = resolved\n throw new Diagnostics.Error({ code, severity: 'error', message, help, location: { kind: 'config' }, plugin })\n }\n return resolved\n}\n","import path from 'node:path'\nimport { operationFileEntry, operationKey } from '@internals/shared'\nimport type { ast, Exclude, Group, Include, Memo, Output, Override, Resolver } from '@kubb/kit'\nimport type { ReturnTypeOption } from './types.ts'\n\n/**\n * The resolved contract `<op>` for one operation: the generated function name, the file it lives in,\n * the client module path (where `RequestConfig` / `ResponseErrorConfig` come from), and the\n * registered client plugin's `returnType`.\n *\n * `clientPath` is the absolute `.kubb/client.ts` path for plugin-fetch / plugin-axios, or\n * plugin-client's `importPath`: a relative one is resolved against the `<op>` file to an absolute\n * path, a package name or alias is kept verbatim. `clientPathIsFile` tells a consumer whether to\n * make it relative to the importing file.\n */\nexport type ClientOperation = { name: string; path: string; clientPath: string; clientPathIsFile: boolean; returnType: ReturnTypeOption }\n\n/**\n * The client plugin options a dependent reads, including the filters that scope them per operation.\n */\ntype ClientPluginOptions = {\n output?: Output\n group?: Group | null\n returnType?: ReturnTypeOption\n importPath?: string\n exclude?: Array<Exclude>\n include?: Array<Include>\n override?: Array<Override<Omit<ClientPluginOptions, 'override'>>>\n}\n\nfunction isRelativeImport(importPath: string): boolean {\n return importPath.startsWith('.')\n}\n\n// plugin-client resolves a relative `importPath` from its `<op>` file, so do the same here.\nfunction resolveImportPath(options: { importPath: string; operationFile: string }): string {\n const { importPath, operationFile } = options\n return isRelativeImport(importPath) ? path.resolve(path.dirname(operationFile), importPath) : importPath\n}\n\n/**\n * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up\n * the registered contract client plugin's resolver and output. Works for any contract client plugin\n * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline\n * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then\n * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global\n * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.\n * With plugin-client they come from the user's `importPath` module instead.\n *\n * The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,\n * so several dependents reading the same client plugin for one operation in a single pass\n * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share\n * one computed result instead of each re-deriving the name and path.\n *\n * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its\n * `override` entries, the same resolution its own generator sees. A dependent's generated call body\n * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.\n */\nexport function resolveClientOperation(options: {\n clientPlugin: { pluginName: string } | null\n driver: {\n getPlugin: (name: string) => { options?: ClientPluginOptions } | undefined\n getResolver: (name: string) => Resolver\n }\n node: ast.OperationNode\n root: string\n output: Output\n memo: Memo\n}): ClientOperation | null {\n const { clientPlugin, driver, node, root, output, memo } = options\n if (!clientPlugin) return null\n\n return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {\n const resolver = driver.getResolver(clientPlugin.pluginName)\n const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {}\n const { exclude, include, override } = pluginOptions\n const hasOperationOptions = Boolean(exclude?.length || include?.length || override?.length)\n // Kubb's resolver always has `default`; the fallback keeps partial or custom resolvers working.\n const operationOptions =\n hasOperationOptions && resolver.default ? resolver.default.options(node, { options: pluginOptions, exclude, include, override }) : pluginOptions\n if (!operationOptions) return null\n\n const file = resolver.file({\n ...operationFileEntry(node, node.operationId),\n root,\n output: operationOptions.output ?? output,\n group: operationOptions.group ?? undefined,\n })\n\n const { importPath } = operationOptions\n const name = resolver.name(node.operationId)\n\n return {\n name: resolver.resolveName({ key: operationKey(node), name }),\n path: file.path,\n clientPath: importPath === undefined ? path.resolve(root, '.kubb/client.ts') : resolveImportPath({ importPath, operationFile: file.path }),\n clientPathIsFile: importPath === undefined || isRelativeImport(importPath),\n returnType: operationOptions.returnType ?? 'full',\n }\n })\n}\n","import { resolveClientOperation, resolveOperationTypes } from '@internals/client'\nimport { operationFileEntry, resolveDependencyOperationFile } from '@internals/shared'\nimport { ast, defineGenerator } from '@kubb/kit'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { McpHandler } from '../components/McpHandler.tsx'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Built-in operation generator for `@kubb/plugin-mcp`. Emits one MCP tool\n * handler per OpenAPI operation. The handler takes the grouped `{ path, query,\n * headers, body }` config and forwards it to the registered client plugin's\n * (`@kubb/plugin-axios` / `@kubb/plugin-fetch`) `<op>` function.\n */\nexport const mcpGenerator = defineGenerator<PluginMcp>({\n name: 'mcp',\n renderer: jsxRenderer,\n operation(node, ctx) {\n if (!ast.isHttpOperationNode(node)) return null\n const { resolver, driver, root, config } = ctx\n const { output, client, group } = ctx.options\n\n const types = resolveOperationTypes(driver, resolver.pluginName)\n const tsResolver = types.resolver\n\n // The registered contract client plugin owns the `<op>` the handler imports and calls.\n const contractOp = resolveClientOperation({ clientPlugin: { pluginName: client.pluginName }, driver, node, root, output, memo: ctx.memo })\n if (!contractOp) {\n return null\n }\n\n // The handler signature references the grouped `<Name>Options`.\n const optionsName = tsResolver.response.options(node)\n\n const meta = {\n name: resolver.handler.name(node),\n file: resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),\n fileTs: resolveDependencyOperationFile({\n memo: ctx.memo,\n node,\n resolver: tsResolver,\n root,\n output: types.output ?? output,\n group: types.group,\n }),\n } as const\n\n return (\n <File\n baseName={meta.file.baseName}\n path={meta.file.path}\n meta={meta.file.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}\n >\n {meta.fileTs && optionsName && <File.Import name={[optionsName]} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />}\n <File.Import name={['CallToolResult', 'ServerContext']} path={'@modelcontextprotocol/server'} isTypeOnly />\n\n <File.Import name={[contractOp.name]} root={meta.file.path} path={contractOp.path} />\n\n <McpHandler name={meta.name} clientName={contractOp.name} node={node} resolver={tsResolver} returnType={contractOp.returnType} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { getOperationParameters, getPrimarySuccessResponse, operationFileEntry } from '@internals/shared'\nimport { getRelativePath } from '@internals/utils'\nimport { ast, defineGenerator } from '@kubb/kit'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { Server } from '../components/Server.tsx'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Default v5 server generator for `@kubb/plugin-mcp`.\n *\n * Uses individual zod schemas for each param (e.g. `createPetsPathUuidSchema`, `createPetsQueryOffsetSchema`)\n * and `resolveResponseStatusName` for per-status response schemas.\n * Query and header params are composed into `z.object({ ... })` from individual schemas.\n */\nexport const serverGenerator = defineGenerator<PluginMcp>({\n name: 'operations',\n renderer: jsxRenderer,\n operations(nodes, ctx) {\n const { config, resolver, plugin, driver, root } = ctx\n const { output, group } = ctx.options\n\n const pluginZod = ctx.requirePlugin(pluginZodName)\n\n const zodResolver = driver.getResolver(pluginZodName)\n\n const fileAt = <TName extends `${string}.${string}`>(baseName: TName) => ({\n baseName,\n path: path.resolve(root, output.path, baseName),\n meta: { pluginName: plugin.name },\n })\n const serverFile = fileAt('server.ts')\n const startFile = fileAt('start.ts')\n const jsonFile = fileAt('.mcp.json')\n\n // MCP clients spawn the command from their own working directory, usually the project root,\n // so `args` points at `start.ts` relative to `config.root` instead of the `.mcp.json` folder.\n const mcpConfig = {\n mcpServers: {\n [ctx.meta.title || 'server']: {\n type: 'stdio',\n command: 'npx',\n args: ['tsx', getRelativePath(path.resolve(config.root), startFile.path)],\n },\n },\n }\n\n const operationsMapped = nodes.filter(ast.isHttpOperationNode).map((node) => {\n const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node)\n\n const fileEntry = operationFileEntry(node, node.operationId)\n const mcpFile = resolver.file({ ...fileEntry, root, output, group: group ?? undefined })\n const zodFile = zodResolver.file({\n ...fileEntry,\n root,\n output: pluginZod.options?.output ?? output,\n group: pluginZod.options?.group ?? undefined,\n })\n\n const requestName = node.requestBody?.content?.[0]?.schema ? zodResolver.response.body(node) : null\n const successStatus = getPrimarySuccessResponse(node)?.statusCode\n const responseName = successStatus ? zodResolver.response.status(node, successStatus) : null\n\n const resolveParams = (params: typeof pathParams) => params.map((p) => ({ name: p.name, schemaName: zodResolver.param.name(node, p) }))\n\n return {\n tool: {\n name: node.operationId,\n title: node.summary || undefined,\n description: node.description || `Make a ${node.method.toUpperCase()} request to ${node.path}`,\n },\n mcp: {\n name: resolver.handler.name(node),\n file: mcpFile,\n },\n zod: {\n pathParams: resolveParams(pathParams),\n queryParams: queryParams.length ? resolveParams(queryParams) : null,\n headerParams: headerParams.length ? resolveParams(headerParams) : null,\n requestName,\n responseName,\n file: zodFile,\n },\n }\n })\n\n const imports = operationsMapped.flatMap(({ mcp, zod }) => {\n const zodNames = [\n ...zod.pathParams.map((p) => p.schemaName),\n ...(zod.queryParams ?? []).map((p) => p.schemaName),\n ...(zod.headerParams ?? []).map((p) => p.schemaName),\n zod.requestName,\n zod.responseName,\n ].filter((name): name is string => Boolean(name))\n\n const uniqueNames = [...new Set(zodNames)].sort()\n\n return [\n <File.Import key={mcp.name} name={[mcp.name]} root={serverFile.path} path={mcp.file.path} />,\n uniqueNames.length > 0 && <File.Import key={`zod-${mcp.name}`} name={uniqueNames} root={serverFile.path} path={zod.file.path} />,\n ].filter(Boolean)\n })\n\n return (\n <>\n <File\n baseName={serverFile.baseName}\n path={serverFile.path}\n meta={serverFile.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: serverFile.path, baseName: serverFile.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: serverFile.path, baseName: serverFile.baseName } })}\n >\n <File.Import name={['McpServer']} path={'@modelcontextprotocol/server'} />\n <File.Import name={['serveStdio']} path={'@modelcontextprotocol/server/stdio'} />\n <File.Import name={['z']} path={'zod'} />\n\n {imports}\n <Server serverName={ctx.meta.title ?? 'server'} serverVersion={ctx.meta.version ?? '0.0.0'} operations={operationsMapped} />\n </File>\n\n <File\n baseName={startFile.baseName}\n path={startFile.path}\n meta={startFile.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: startFile.path, baseName: startFile.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: startFile.path, baseName: startFile.baseName } })}\n >\n <File.Import name={['startServer']} root={startFile.path} path={serverFile.path} />\n {/* Not indexable: barrels must not re-export this entry, importing it starts the server. */}\n <File.Source name=\"start\">{'void startServer()'}</File.Source>\n </File>\n\n <File baseName={jsonFile.baseName} path={jsonFile.path} meta={jsonFile.meta}>\n <File.Source name=\"server\">{`${JSON.stringify(mcpConfig, null, 2)}\\n`}</File.Source>\n </File>\n </>\n )\n },\n})\n","","","import { operationKey } from '@internals/shared'\nimport { camelCase, createResolver } from '@kubb/kit'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Default resolver used by `@kubb/plugin-mcp`. Decides the names and file\n * paths for every generated MCP tool handler. Function names get a `Handler`\n * suffix so an operation `addPet` becomes `addPetHandler`.\n *\n * @example Resolve a handler name\n * ```ts\n * import { resolverMcp } from '@kubb/plugin-mcp'\n *\n * resolverMcp.name('addPet') // 'addPetHandler'\n * ```\n */\nexport const resolverMcp = createResolver<PluginMcp>({\n pluginName: 'plugin-mcp',\n name(name) {\n return this.memo(`name:${name}`, () => camelCase(name, { suffix: 'handler' }))\n },\n handler: {\n name(node) {\n const name = this.name(node.operationId)\n return this.resolveName({ key: operationKey(node, 'handler', 'name'), name })\n },\n },\n})\n","import { createGroupConfig } from '@internals/shared'\n\nimport { resolveContractClient } from '@internals/client'\nimport { addGenerator, defineExtension, Resolver, setMacros, setResolver, useConfig } from '@kubb/kit'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator } from './generators/mcpGenerator.tsx'\nimport { serverGenerator } from './generators/serverGenerator.tsx'\nimport { resolverMcp } from './resolvers/resolverMcp.ts'\nimport type { PluginMcp, ResolverMcp } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-mcp`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\n/**\n * Generates a Model Context Protocol (MCP) server from an OpenAPI spec. Every\n * operation becomes a typed MCP tool that AI assistants (Claude Desktop, Claude\n * Code, MCP-compatible clients) can call directly. Each handler calls a contract\n * client `<op>` from a registered `@kubb/plugin-axios` or `@kubb/plugin-fetch`.\n * Next to the handlers it writes `server.ts`, a `start.ts` entry that serves the\n * tools over stdio, and a `.mcp.json` that runs `start.ts` with `tsx`.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb/config'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginZod } from '@kubb/plugin-zod'\n * import { pluginFetch } from '@kubb/plugin-fetch'\n * import { pluginMcp } from '@kubb/plugin-mcp'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginZod(),\n * pluginFetch({ baseURL: 'https://petstore.swagger.io/v2' }),\n * pluginMcp({ output: { path: 'mcp' } }),\n * ],\n * })\n * ```\n */\nexport const pluginMcp = defineExtension<PluginMcp>({\n kind: 'plugin',\n meta: { name: pluginMcpName, version, compatibility },\n dependencies: { [pluginTsName]: { optional: true }, [pluginZodName]: {} },\n setup(options) {\n const {\n output = { path: 'mcp', barrel: { type: 'named' } },\n group,\n exclude = [],\n include,\n override = [],\n client,\n resolver: userResolver,\n macros: userMacros,\n } = options\n\n const resolver = userResolver ? Resolver.merge<ResolverMcp>(resolverMcp, userResolver) : resolverMcp\n\n setResolver(resolver)\n if (userMacros?.length) {\n setMacros(userMacros)\n }\n addGenerator(mcpGenerator, serverGenerator)\n\n return {\n output,\n exclude,\n include,\n override,\n group: createGroupConfig(group),\n client: resolveContractClient({ plugin: pluginMcpName, client, plugins: useConfig().plugins }),\n resolver,\n }\n },\n})\n\nexport default pluginMcp\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,MAAyB,MAAc,UAAyC,OAA2B;CAC5I,OAAO;EACL;EACA;EACA,KAAK,KAAK,KAAK,MAAM;EACrB,MAAM,KAAK;CACb;AACF;;;;;;;;;;;;AAaA,SAAgB,+BAA+B,SAO9B;CACf,MAAM,EAAE,MAAM,MAAM,UAAU,MAAM,QAAQ,UAAU;CAEtD,OAAO,KAAK,GAAG,SAAS,WAAW,iBAAiB,KAAK,qBACvD,SAAS,KAAK;EAAE,GAAG,mBAAmB,MAAM,KAAK,WAAW;EAAG;EAAM;EAAQ,OAAO,SAAS,KAAA;CAAU,CAAC,CAC1G;AACF;AA8DA,SAAS,iBAAiB,MAAyB,MAA2C;CAC5F,IAAI,CAAC,MACH,OAAO;CAGT,IAAI,OAAO,SAAS,YAClB,OAAO,KAAK,IAAI,KAAK;CAGvB,OAAO,KAAK,OAAO,UAAUA,UAAAA,IAAI,OAAO,KAAK,IAAI,EAAE,KAAK;AAC1D;;;;;AAMA,SAAS,qBAAqB,cAAyC;CACrE,MAAM,yBAAyB,aAAa,SAAS;CAErD,OAAO;EACL;EACA;EACA,kBAAkB,yBAAyB,aAAa,KAAK,OAAO,KAAK,UAAU,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI;EACtG,oBAAoB,aAAa,MAAM;EACvC,aAAa,aAAa,MAAM,OAAO,OAAO,qBAAqB;CACrE;AACF;AAEA,SAAgB,mBAAmB,MAA0C;CAC3E,OAAO,qBAAqB,KAAK,aAAa,SAAS,KA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M,WAAW,MAAM;GAAG;EAAK,CAAC;CAC9E,EACF;AACF,CAAC;;;;;;ACVD,MAAa,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B7B,MAAa,aAAA,GAAYC,UAAAA,gBAAAA,CAA2B;CAClD,MAAM;CACN,MAAM;EAAE,MAAM;EAAe;EAAS;CAAc;CACpD,cAAc;GAAGC,gBAAAA,eAAe,EAAE,UAAU,KAAK;GAAIC,iBAAAA,gBAAgB,CAAC;CAAE;CACxE,MAAM,SAAS;EACb,MAAM,EACJ,SAAS;GAAE,MAAM;GAAO,QAAQ,EAAE,MAAM,QAAQ;EAAE,GAClD,OACA,UAAU,CAAC,GACX,SACA,WAAW,CAAC,GACZ,QACA,UAAU,cACV,QAAQ,eACN;EAEJ,MAAM,WAAW,eAAeC,UAAAA,SAAS,MAAmB,aAAa,YAAY,IAAI;EAEzF,CAAA,GAAA,UAAA,YAAA,CAAY,QAAQ;EACpB,IAAI,YAAY,QACd,CAAA,GAAA,UAAA,UAAA,CAAU,UAAU;EAEtB,CAAA,GAAA,UAAA,aAAA,CAAa,cAAc,eAAe;EAE1C,OAAO;GACL;GACA;GACA;GACA;GACA,OAAO,kBAAkB,KAAK;GAC9B,QAAQ,sBAAsB;IAAE,QAAQ;IAAe;IAAQ,UAAA,GAASC,UAAAA,UAAAA,CAAU,CAAC,CAAC;GAAQ,CAAC;GAC7F;EACF;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"index.cjs","names":["Url","ast","posix","camelCase","File","Function","File","Function","Const","pluginTsName","pluginZodName","Diagnostics","Diagnostics","path","defineGenerator","jsxRenderer","ast","File","defineGenerator","jsxRenderer","pluginZodName","path","ast","File","createResolver","camelCase","defineExtension","pluginTsName","pluginZodName","Resolver","useConfig"],"sources":["../../../internals/shared/src/operation.ts","../../../internals/utils/src/fs.ts","../../../internals/shared/src/resolver.ts","../../../internals/shared/src/group.ts","../src/components/McpHandler.tsx","../src/components/Server.tsx","../../../internals/client/src/resolveOperationTypes.ts","../../../internals/client/src/resolveClient.ts","../../../internals/client/src/resolveClientOperation.ts","../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx","../kubb-extension.json","../package.json","../src/resolvers/resolverMcp.ts","../src/plugin.ts"],"sourcesContent":["import { ast, type Group, type Memo, type Output, type Resolver, type ResolverFileParams, Url } from '@kubb/kit'\n\n/**\n * Builds the `ResolverFileParams` every operation generator passes to\n * `resolver.file`: a file named `name`, tagged by the operation's first\n * tag (or `'default'`), at the operation's path. Centralizes the entry object\n * that was repeated at dozens of call sites across the client and query plugins.\n *\n * @example\n * ```ts\n * resolver.file(operationFileEntry(node, node.operationId), { root, output, group })\n * ```\n */\nexport function operationFileEntry(node: ast.OperationNode, name: string, extname: ResolverFileParams['extname'] = '.ts'): ResolverFileParams {\n return {\n name,\n extname,\n tag: node.tags[0] ?? 'default',\n path: node.path,\n }\n}\n\n/**\n * Resolves a dependency plugin's generated file for `node.operationId`, cached in `memo` (the\n * build's `ctx.memo`) under the resolver's own plugin name and the operation. Several dependents reading the\n * same dependency for the same operation in one pass (a query plugin's several hook generators, the\n * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.\n *\n * @example Cache `plugin-ts`'s file for the current operation\n * ```ts\n * const fileTs = resolveDependencyOperationFile({ memo: ctx.memo, node, resolver: tsResolver, root, output })\n * ```\n */\nexport function resolveDependencyOperationFile(options: {\n memo: Memo\n node: ast.OperationNode\n resolver: Pick<Resolver, 'file' | 'pluginName'>\n root: string\n output: Output\n group?: Group | null\n}): ast.FileNode {\n const { memo, node, resolver, root, output, group } = options\n\n return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () =>\n resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),\n )\n}\n\nexport type ContentTypeInfo = {\n contentTypes: string[]\n isMultipleContentTypes: boolean\n contentTypeUnion: string\n defaultContentType: string\n hasFormData: boolean\n}\n\nexport type RequestConfigResolver = {\n response: {\n body(node: ast.OperationNode): string\n }\n}\n\nexport type ResponseStatusNameResolver = {\n response: {\n status(node: ast.OperationNode, statusCode: ast.StatusCode): string\n }\n}\n\nexport type ResponseNameResolver = ResponseStatusNameResolver & {\n response: {\n response(node: ast.OperationNode): string\n }\n}\n\nexport type OperationTypeNameResolver = RequestConfigResolver &\n ResponseNameResolver & {\n param: {\n path(node: ast.OperationNode, param: ast.ParameterNode): string\n query(node: ast.OperationNode, param: ast.ParameterNode): string\n headers(node: ast.OperationNode, param: ast.ParameterNode): string\n }\n }\n\nexport type OperationCommentLink = 'pathTemplate' | 'urlPath' | false | ((node: ast.OperationNode) => string | undefined)\n\nexport type BuildOperationCommentsOptions = {\n link?: OperationCommentLink\n linkPosition?: 'beforeDeprecated' | 'afterDeprecated'\n splitLines?: boolean\n}\n\ntype ResponseLike = {\n statusCode: ast.StatusCode | number | string\n}\n\nexport type OperationParameterGroups = Record<Exclude<ast.ParameterNode['in'], 'querystring'>, Array<ast.ParameterNode>>\n\nexport type ResolveOperationTypeNameOptions = {\n responseStatusNames?: boolean | 'error'\n exclude?: ReadonlyArray<string | undefined>\n order?: 'params-first' | 'body-response-first'\n /**\n * Include the individual `Path`/`Query`/`Headers` group type names. Set to `false` for clients\n * that reference the grouped `Options` type instead of the per-group types.\n */\n includeParams?: boolean\n}\n\nfunction getOperationLink(node: ast.OperationNode, link: OperationCommentLink): string | null {\n if (!link) {\n return null\n }\n\n if (typeof link === 'function') {\n return link(node) ?? null\n }\n\n return node.path ? `{@link ${Url.toPath(node.path)}}` : null\n}\n\n/**\n * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several\n * are present and the union, default, and form-data flags the client uses to pick one.\n */\nfunction buildContentTypeInfo(contentTypes: string[]): ContentTypeInfo {\n const isMultipleContentTypes = contentTypes.length > 1\n\n return {\n contentTypes,\n isMultipleContentTypes,\n contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(' | ') : '',\n defaultContentType: contentTypes[0] ?? 'application/json',\n hasFormData: contentTypes.some((ct) => ct === 'multipart/form-data'),\n }\n}\n\nexport function getContentTypeInfo(node: ast.OperationNode): ContentTypeInfo {\n return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? [])\n}\n\n/**\n * The request-body counterpart for the primary success response: the content types it documents and\n * whether several are present, so the client can let a caller pick which one to accept.\n */\nexport function getResponseContentTypeInfo(node: ast.OperationNode): ContentTypeInfo {\n return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? [])\n}\n\nexport type ResponseType = 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n\n/**\n * Reads the single base content type of an operation's primary success response, lowercased and\n * stripped of any `; charset=...` suffix. Returns `undefined` when the response declares zero or\n * more than one content type, since neither case has a single type to act on.\n */\nfunction getPrimarySuccessContentType(node: ast.OperationNode): string | undefined {\n const contentTypes = getPrimarySuccessResponse(node)?.content?.map((entry) => entry.contentType) ?? []\n if (contentTypes.length !== 1) return undefined\n return contentTypes[0]!.split(';')[0]!.trim().toLowerCase()\n}\n\n/**\n * The `text/event-stream` content of the primary success response, when it is the only content type. A response that also\n * declares another type stays a normal call with its query hooks.\n */\nfunction getEventStreamContent(node: ast.OperationNode): ast.ContentNode | undefined {\n return getPrimarySuccessContentType(node) === 'text/event-stream' ? getPrimarySuccessResponse(node)?.content?.[0] : undefined\n}\n\n/**\n * Whether an operation streams its primary success response as Server-Sent Events (`text/event-stream`). The client\n * generator uses this to return a typed event stream instead of a one-shot `RequestResult`.\n */\nexport function isEventStream(node: ast.OperationNode): boolean {\n return getEventStreamContent(node) !== undefined\n}\n\n/**\n * How the document types a `text/event-stream` response, as the adapter read it from `itemSchema`: `event` when each item is\n * the parsed event with its own `event` and `data`, `data` when it is only the payload. Returns `null` without an event stream.\n */\nexport function getEventStream(node: ast.OperationNode): 'event' | 'data' | null {\n const content = getEventStreamContent(node)\n return content ? (content.stream?.shape ?? 'data') : null\n}\n\nfunction baseContentType(contentType: string): string {\n return contentType.split(';')[0]!.trim().toLowerCase()\n}\n\nfunction isJsonContentType(baseType: string): boolean {\n return baseType === 'application/json' || baseType.endsWith('+json') || baseType === 'text/json'\n}\n\n/**\n * Parser for one response content entry.\n *\n * JSON stays unset so the runtime detects it. `text/event-stream` is a stream. A binary schema\n * (`format: binary` / `contentMediaType`) is a blob even when the media type is not a well-known\n * binary type. Other `text/*` is text, and `application/octet-stream`, `application/pdf`,\n * `image/*`, `audio/*`, and `video/*` are blobs.\n */\nfunction responseTypeForContent(contentType: string, schema?: ast.SchemaNode | null): ResponseType | undefined {\n const baseType = baseContentType(contentType)\n if (!baseType) return undefined\n if (isJsonContentType(baseType)) return undefined\n if (baseType === 'text/event-stream') return 'stream'\n if (schema?.type === 'blob') return 'blob'\n if (baseType.startsWith('text/')) return 'text'\n if (baseType === 'application/octet-stream' || baseType === 'application/pdf' || /^(image|audio|video)\\//.test(baseType)) return 'blob'\n return undefined\n}\n\n/**\n * Derives the default `responseType` string for an operation from its primary success response.\n *\n * One content type uses {@link responseTypeForContent}. Several content types that all use the same\n * parser collapse to that string, so a call can keep `responseType: 'blob'`. Mixed parsers return\n * `undefined`; {@link getResponseTypeMap} carries the per-type choice.\n */\nexport function getResponseType(node: ast.OperationNode): ResponseType | undefined {\n const entries = getPrimarySuccessResponse(node)?.content ?? []\n if (entries.length === 0) return undefined\n\n const responseTypes = entries.map((entry) => responseTypeForContent(entry.contentType, entry.schema))\n const first = responseTypes[0]\n if (!first) return undefined\n if (responseTypes.every((responseType) => responseType === first)) return first\n return undefined\n}\n\n/**\n * Maps each base content type of a primary success response to its parser when those parsers differ.\n *\n * Keys are lowercased and stripped of parameters. JSON entries are kept as `'json'` so a catch-all\n * entry cannot claim a JSON response. Returns `undefined` when {@link getResponseType} already\n * covers the response with one string, or when no content type needs a parser other than JSON.\n * The runtime matches the response `Content-Type` against this map instead of guessing from the media type.\n */\nexport function getResponseTypeMap(node: ast.OperationNode): Record<string, ResponseType> | undefined {\n if (getResponseType(node)) return undefined\n\n const entries = getPrimarySuccessResponse(node)?.content ?? []\n if (entries.length <= 1) return undefined\n\n const map: Record<string, ResponseType> = {}\n for (const entry of entries) {\n const baseType = baseContentType(entry.contentType)\n const responseType = responseTypeForContent(entry.contentType, entry.schema) ?? (isJsonContentType(baseType) ? 'json' : undefined)\n if (baseType && responseType) map[baseType] = responseType\n }\n\n return Object.values(map).some((responseType) => responseType !== 'json') ? map : undefined\n}\n\n/**\n * Maps a content type to the PascalCase suffix used to name per-content-type variants\n * (e.g. `application/json` → `Json`, `application/xml` → `Xml`, `multipart/form-data` → `FormData`).\n */\nfunction getContentTypeSuffix(contentType: string): string {\n const baseType = contentType.split(';')[0]!.trim()\n if (baseType === 'application/json') return 'Json'\n if (baseType === 'multipart/form-data') return 'FormData'\n if (baseType === 'application/x-www-form-urlencoded') return 'FormUrlEncoded'\n const subtype = baseType.split('/').pop() ?? baseType\n const parts = subtype.split(/[^a-zA-Z0-9]+/).filter(Boolean)\n if (parts.length === 0) return 'Unknown'\n return parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join('')\n}\n\n/**\n * Appends a content-type suffix to a base name, keeping a trailing `Data` segment last\n * (e.g. `AddPetData` + `Json` → `AddPetJsonData`, `AddPetStatus200` + `Xml` → `AddPetStatus200Xml`).\n */\nexport function getPerContentTypeName(baseName: string, suffix: string): string {\n if (baseName.endsWith('Data')) {\n return suffix.endsWith('Data') ? baseName.slice(0, -4) + suffix : `${baseName.slice(0, -4)}${suffix}Data`\n }\n return baseName + suffix\n}\n\nexport type ContentVariantInput = { contentType: string; schema?: ast.SchemaNode | null; keysToOmit?: Array<string> | null }\nexport type ContentVariant = { name: string; suffix: string; schema: ast.SchemaNode; keysToOmit?: Array<string> | null; contentType: string }\n\n/**\n * Resolves per-content-type variant names for a set of content entries, deduplicating suffix\n * collisions with a numeric counter. Entries without a schema are skipped. The returned `suffix` is\n * the final (possibly counter-augmented) value, so callers can derive parallel names in another\n * namespace (e.g. plugin-faker deriving the matching plugin-ts type name).\n */\nexport function resolveContentTypeVariants(entries: Array<ContentVariantInput>, baseName: string): Array<ContentVariant> {\n const usedNames = new Set<string>()\n return entries\n .filter((entry) => entry.schema)\n .map((entry) => {\n const baseSuffix = getContentTypeSuffix(entry.contentType)\n let suffix = baseSuffix\n let name = getPerContentTypeName(baseName, suffix)\n let counter = 2\n while (usedNames.has(name)) {\n suffix = `${baseSuffix}${counter++}`\n name = getPerContentTypeName(baseName, suffix)\n }\n usedNames.add(name)\n return { name, suffix, schema: entry.schema!, keysToOmit: entry.keysToOmit, contentType: entry.contentType }\n })\n}\n\n// The request groups come from the grouped params, so `config` drops the data-shape keys to stay\n// assignable to `Options`, which omits them from `RequestConfig`.\nconst requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`\n\nexport function buildRequestConfigType(node: ast.OperationNode): string {\n const request = getContentTypeInfo(node)\n const response = getResponseContentTypeInfo(node)\n\n // Only the ambiguous side is offered: a single-type side has nothing to pick, so it stays baked in\n // the generated call.\n const members = [\n request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null,\n response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null,\n ].filter(Boolean)\n\n return members.length ? `${requestConfigBaseType} & { contentType?: { ${members.join('; ')} } }` : requestConfigBaseType\n}\n\n/**\n * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,\n * `useInfiniteQuery`, `useSWR`, ...). Unlike {@link buildRequestConfigType}, it never adds a\n * `contentType?:` member: query hooks wrap GET operations, which carry no request body to select a\n * content type for.\n */\nexport function buildClientOptionType(): string {\n return requestConfigBaseType\n}\n\nexport type RequestGroups = {\n path: boolean\n query: boolean\n body: boolean\n headers: boolean\n}\n\n/**\n * Which of the grouped request options an operation carries.\n */\nexport function getRequestGroups(node: ast.OperationNode): RequestGroups {\n const { path, query, header } = getOperationParameters(node)\n return {\n path: path.length > 0,\n query: query.length > 0,\n body: Boolean(node.requestBody?.content?.[0]?.schema),\n headers: header.length > 0,\n }\n}\n\nexport type RequestGroupOptionality = {\n groups: RequestGroups\n hasRequiredPath: boolean\n hasRequiredQuery: boolean\n hasRequiredHeader: boolean\n /**\n * Whether the grouped request parameter can default to `{}`. True only when no group carries a\n * required member, so every member is safe to omit.\n */\n isOptional: boolean\n}\n\n/**\n * Resolves which grouped request options an operation carries together with whether each group\n * holds a required member. The grouped parameter stays optional only when nothing inside it is\n * required, matching the generated `RequestConfig` type.\n */\nexport function getRequestGroupOptionality(node: ast.OperationNode): RequestGroupOptionality {\n const groups = getRequestGroups(node)\n const { path, query, header } = getOperationParameters(node)\n const hasRequiredPath = path.some((param) => param.required)\n const hasRequiredQuery = query.some((param) => param.required)\n const hasRequiredHeader = header.some((param) => param.required)\n\n return {\n groups,\n hasRequiredPath,\n hasRequiredQuery,\n hasRequiredHeader,\n isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !(groups.body && node.requestBody?.required === true),\n }\n}\n\nexport type RequestOptionsNameResolver = RequestConfigResolver & {\n response: {\n options(node: ast.OperationNode): string\n }\n}\n\n/**\n * Builds the grouped `{ path, query, body, headers }` parameter for a generated client\n * function, typed from the operation's `Options` (minus `url`). Only the groups the\n * operation actually has are destructured. The trailing `config` parameter carries the\n * runtime `RequestConfig` overrides plus `client`.\n */\nexport function buildRequestParamsSignature(\n node: ast.OperationNode,\n resolver: RequestOptionsNameResolver,\n options: { isConfigurable?: boolean } = {},\n): { signature: string; groups: RequestGroups } {\n const { isConfigurable = true } = options\n const { groups, isOptional } = getRequestGroupOptionality(node)\n\n const names = (['path', 'query', 'body', 'headers'] as const).filter((key) => groups[key])\n\n // These callers never carry the `contentType` that several media types require.\n const optionsType = hasRequestContentTypeChoice(node)\n ? `Pick<${resolver.response.options(node)}, ${names.map((name) => `'${name}'`).join(' | ')}>`\n : resolver.response.options(node)\n const firstParam = names.length > 0 ? `{ ${names.join(', ')} }: ${optionsType}${isOptional ? ' = {}' : ''}` : null\n const configParam = isConfigurable ? `config: ${buildRequestConfigType(node)} = {}` : null\n\n return {\n signature: [firstParam, configParam].filter(Boolean).join(', '),\n groups,\n }\n}\n\nexport function buildOperationComments(node: ast.OperationNode, options: BuildOperationCommentsOptions = {}): Array<string> {\n const { link = 'pathTemplate', linkPosition = 'afterDeprecated', splitLines = false } = options\n const linkComment = getOperationLink(node, link)\n const comments =\n linkPosition === 'beforeDeprecated'\n ? [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, linkComment, node.deprecated && '@deprecated']\n : [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, node.deprecated && '@deprecated', linkComment]\n\n const filteredComments = comments.filter((comment): comment is string => Boolean(comment))\n\n if (!splitLines) {\n return filteredComments\n }\n\n return filteredComments.flatMap((text) => text.split(/\\r?\\n/).map((line) => line.trim())).filter((comment): comment is string => Boolean(comment))\n}\n\nconst operationParameterGroupsByNode = new WeakMap<ast.OperationNode, OperationParameterGroups>()\n\n/**\n * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter\n * per property, typed and serialized like any other.\n * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.\n */\nfunction spreadQuerystring(param: ast.ParameterNode): Array<ast.ParameterNode> {\n const schema = param.schema.type === 'ref' ? param.schema.schema : param.schema\n const formEncoded = !param.contentType || param.contentType.split(';')[0]!.trim().toLowerCase() === 'application/x-www-form-urlencoded'\n if (schema?.type !== 'object' || !formEncoded) return [param]\n return schema.properties.map((property) =>\n ast.factory.createParameter({ name: property.name, in: 'query', schema: property.schema, required: param.required && property.required }),\n )\n}\n\n/**\n * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each\n * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance\n * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the\n * same parameters once per plugin.\n */\nexport function getOperationParameters(node: ast.OperationNode): OperationParameterGroups {\n const cached = operationParameterGroupsByNode.get(node)\n if (cached) return cached\n\n // A malformed spec can declare the same name twice within one location. Both would resolve to the\n // same output property, so emitting both would yield an object type with a duplicate member,\n // which TypeScript rejects. Keep the first.\n const dedupe = (params: Array<ast.ParameterNode>) => {\n const seen = new Set<string>()\n return params.filter((param) => {\n if (seen.has(param.name)) return false\n seen.add(param.name)\n return true\n })\n }\n const group = (location: ast.ParameterNode['in']) => dedupe(node.parameters.filter((param) => param.in === location))\n\n const groups: OperationParameterGroups = {\n path: group('path'),\n query: dedupe([...group('query'), ...group('querystring').flatMap(spreadQuerystring)]),\n header: group('header'),\n cookie: group('cookie'),\n }\n\n operationParameterGroupsByNode.set(node, groups)\n return groups\n}\n\n/**\n * Builds the combined `{ body, path, query, headers }` options object schema for an operation,\n * referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s\n * `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same\n * shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod\n * printer to emit `z.object(…)` rather than a record.\n */\nexport function hasRequestContentTypeChoice(node: ast.OperationNode): boolean {\n return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1\n}\n\n/**\n * Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.\n */\nexport function castToClientOptions(callArg: string, clientName: string, returnType: 'full' | 'data' | 'plain' = 'full'): string {\n return `${callArg} as Parameters<typeof ${clientName}${returnType === 'plain' ? '' : '<true>'}>[0]`\n}\n\nexport function buildOptionsSchema(node: ast.OperationNode, resolver: OperationTypeNameResolver, { pairContentTypes = false } = {}): ast.SchemaNode {\n const { path, query, header } = getOperationParameters(node)\n const hasBody = Boolean(node.requestBody?.content?.[0]?.schema)\n const createNever = () => ast.factory.createSchema({ type: 'never', primitive: undefined, optional: true })\n const groups = [\n { name: 'path', params: path, resolve: resolver.param.path },\n { name: 'query', params: query, resolve: resolver.param.query },\n { name: 'headers', params: header, resolve: resolver.param.headers },\n ] as const\n\n const createOptions = (body: ast.SchemaNode, extra: Array<ast.PropertyNode> = []) =>\n // NOTE(v5-stable): the fields were renamed from the legacy beta shape\n // (`data`/`pathParams`/`queryParams`/`headerParams`) to `body`/`path`/`query`/`headers` so the\n // type matches the runtime client. Drop this note once v5 leaves beta.\n ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n deprecated: node.deprecated,\n properties: [\n ast.factory.createProperty({ name: 'body', required: hasBody && node.requestBody?.required === true, schema: body }),\n ...groups.map(({ name, params, resolve }) => {\n const required = params.some((param) => param.required)\n\n return ast.factory.createProperty({\n name,\n required,\n schema:\n params.length > 0\n ? ast.factory.createSchema({ type: 'ref', name: resolve.call(resolver.param, node, params[0]!), optional: !required })\n : createNever(),\n })\n }),\n ...extra,\n ],\n })\n\n const variants =\n pairContentTypes && hasRequestContentTypeChoice(node) ? resolveContentTypeVariants(node.requestBody?.content ?? [], resolver.response.body(node)) : []\n if (variants.length < 2) {\n return createOptions(hasBody ? ast.factory.createSchema({ type: 'ref', name: resolver.response.body(node) }) : createNever())\n }\n\n // The first media type is the runtime default, so only the others must pass `contentType`.\n return ast.factory.createSchema({\n type: 'union',\n members: variants.map((variant, index) =>\n createOptions(ast.factory.createSchema({ type: 'ref', name: variant.name }), [\n ast.factory.createProperty({\n name: 'contentType',\n required: index > 0,\n schema: ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n ast.factory.createProperty({\n name: 'request',\n required: true,\n schema: ast.factory.createSchema({ type: 'enum', enumValues: [variant.contentType] }),\n }),\n ],\n }),\n }),\n ]),\n ),\n })\n}\n\n/**\n * The schema a status occupies in the `<Name>Responses` record. A status that documents several\n * content types becomes a `{ contentType; data }` union so the runtime can surface the negotiated type\n * on `result.parsed`, while the standalone `<Name>StatusNNN` alias stays the plain body union that the\n * query hooks and `result.data` use.\n */\nfunction buildResponseRecordEntry(node: ast.OperationNode, res: ast.ResponseNode, resolver: ResponseStatusNameResolver): ast.SchemaNode {\n const statusName = resolver.response.status(node, res.statusCode)\n const variants = (res.content ?? []).filter((entry) => entry.schema)\n if (variants.length <= 1) {\n return ast.factory.createSchema({ type: 'ref', name: statusName })\n }\n\n return ast.factory.createSchema({\n type: 'union',\n members: resolveContentTypeVariants(variants, statusName).map((variant) =>\n ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n ast.factory.createProperty({\n name: 'contentType',\n required: true,\n schema: ast.factory.createSchema({ type: 'enum', enumValues: [variant.contentType] }),\n }),\n ast.factory.createProperty({\n name: 'data',\n required: true,\n schema: ast.factory.createSchema({ type: 'ref', name: variant.name }),\n }),\n ],\n }),\n ),\n })\n}\n\n/**\n * Builds the per-status `<Name>Responses` record for an operation, referencing the already-resolved\n * `<Name>StatusNNN` names. Shared by `@kubb/plugin-ts`'s `Responses` type and `@kubb/plugin-zod`'s\n * inferred responses schema, so both emit the same shape from the same inputs.\n *\n * Always emits the keyed record, even when an operation declares no responses. An operation with no\n * responses renders as an empty object, which keeps every consumer's import (for example the axios\n * SDK's `RequestResult<XResponses>`) resolvable instead of pointing at a missing export.\n */\nexport function buildResponses(node: ast.OperationNode, resolver: ResponseStatusNameResolver): ast.SchemaNode {\n return ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: node.responses.map((res) =>\n ast.factory.createProperty({\n name: String(res.statusCode),\n required: true,\n schema: buildResponseRecordEntry(node, res, resolver),\n }),\n ),\n })\n}\n\nexport function getStatusCodeNumber(statusCode: ast.StatusCode | number | string): number | null {\n const code = Number(statusCode)\n\n return Number.isNaN(code) ? null : code\n}\n\nexport function isSuccessStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== null && code >= 200 && code < 300\n}\n\nexport function isErrorStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== null && code >= 400\n}\n\nexport function getSuccessResponses<TResponse extends ResponseLike>(responses: ReadonlyArray<TResponse>): Array<TResponse> {\n return responses.filter((response) => isSuccessStatusCode(response.statusCode))\n}\n\nexport function getOperationSuccessResponses(node: ast.OperationNode): Array<ast.ResponseNode> {\n return getSuccessResponses(node.responses)\n}\n\nexport function getPrimarySuccessResponse(node: ast.OperationNode): ast.ResponseNode | null {\n return getOperationSuccessResponses(node)[0] ?? null\n}\n\nexport function resolveErrorNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode))\n}\n\nexport function resolveSuccessNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode))\n}\n\nexport function resolveStatusCodeNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.map((response) => resolver.response.status(node, response.statusCode))\n}\n\n/**\n * Lists the type names an operation's types file declares, computed once per resolver and `options` so every\n * dependent reads the same list.\n */\nexport function resolveOperationTypeNames(\n node: ast.OperationNode,\n resolver: OperationTypeNameResolver & Pick<Resolver, 'memo'>,\n options: ResolveOperationTypeNameOptions = {},\n): string[] {\n const key = `${node.operationId}\\0${options.order ?? ''}\\0${options.responseStatusNames ?? ''}\\0${options.includeParams === false ? 'noparams' : ''}\\0${(options.exclude ?? []).join(',')}`\n return resolver.memo(`operationTypeNames:${key}`, () => {\n const { path, query, header } = getOperationParameters(node)\n const responseStatusNames =\n options.responseStatusNames === 'error'\n ? resolveErrorNames(node, resolver)\n : options.responseStatusNames === false\n ? []\n : resolveStatusCodeNames(node, resolver)\n const exclude = new Set(options.exclude ?? [])\n const paramNames =\n options.includeParams === false\n ? []\n : [\n ...path.map((param) => resolver.param.path(node, param)),\n ...query.map((param) => resolver.param.query(node, param)),\n ...header.map((param) => resolver.param.headers(node, param)),\n ]\n const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)]\n const names =\n options.order === 'body-response-first'\n ? [...bodyAndResponseNames, ...paramNames, ...responseStatusNames]\n : [...paramNames, ...bodyAndResponseNames, ...responseStatusNames]\n\n return names.filter((name): name is string => Boolean(name) && !exclude.has(name as string))\n })\n}\n\nexport function resolveResponseTypes(node: ast.OperationNode, resolver: ResponseNameResolver): Array<[statusCode: number | 'default', typeName: string]> {\n const types: Array<[number | 'default', string]> = []\n\n for (const response of node.responses) {\n if (response.statusCode === 'default') {\n types.push(['default', resolver.response.response(node)])\n continue\n }\n\n const code = getStatusCodeNumber(response.statusCode)\n if (code === null) {\n continue\n }\n\n types.push([code, isSuccessStatusCode(code) ? resolver.response.response(node) : resolver.response.status(node, response.statusCode)])\n }\n\n return types\n}\n","import { posix } from 'node:path'\nimport { camelCase } from '@kubb/kit'\n\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir: string, filePath: string): string {\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Builds a nested file path from a dotted name. Splits on dots that precede a letter\n * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases\n * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.\n *\n * Empty segments are dropped before joining. They arise when the name starts with a dot\n * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to\n * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an\n * absolute path, letting generated files escape the configured output directory.\n *\n * @example Nested path from a dotted name\n * `toFilePath('pet.petId') // 'pet/petId'`\n *\n * @example PascalCase the final segment\n * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`\n *\n * @example Suffix applied to the final segment only\n * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`\n */\nexport function toFilePath(name: string, caseLast: (part: string) => string = camelCase): string {\n const parts = name.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => (i === parts.length - 1 ? caseLast(part) : camelCase(part)))\n .filter(Boolean)\n .join('/')\n}\n","import { ensureValidVarName, toFilePath } from '@internals/utils'\nimport { ast, camelCase } from '@kubb/kit'\nimport type { GeneratorContext, Resolver, ResolverFile } from '@kubb/kit'\n\n/**\n * The shared top-level `name` of the operation plugins, computed once per operation name and build.\n */\nexport function resolveOperationName(this: Resolver, name: string): string {\n return this.memo(`operation:${name}`, () => ensureValidVarName(camelCase(name)))\n}\n\n/**\n * Builds the allocation key for a declaration an operation owns. `scope` names which declaration\n * it is, so two of them never share an allocation even when a custom resolver gives both the same\n * name. Leave `scope` empty for the operation's own declaration.\n *\n * @example\n * ```ts\n * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })\n * ```\n */\nexport function operationKey(node: ast.OperationNode, ...scope: Array<string | number>): Array<string | undefined> {\n return ['operation', node.method, node.path, ...scope.map(String)]\n}\n\n/**\n * The `param` namespace shared by the schema-producing plugins (ts, zod, faker):\n * per-parameter names plus the grouped `Path`/`Query`/`Headers` names, all routed\n * through the plugin's top-level `name` casing.\n */\nexport type OperationParamResolver = {\n name(this: Resolver, node: ast.OperationNode, param: ast.ParameterNode): string\n path(this: Resolver, node: ast.OperationNode): string\n query(this: Resolver, node: ast.OperationNode): string\n headers(this: Resolver, node: ast.OperationNode): string\n}\n\n/**\n * The `response` namespace shared by the schema-producing plugins: per-status,\n * body, and combined response names, all routed through the plugin's top-level\n * `name` casing.\n */\nexport type OperationResponseResolver = {\n status(this: Resolver, node: ast.OperationNode, statusCode: ast.StatusCode): string\n body(this: Resolver, node: ast.OperationNode): string\n responses(this: Resolver, node: ast.OperationNode): string\n response(this: Resolver, node: ast.OperationNode): string\n}\n\n/**\n * Builds the shared `param` namespace. Spread the result into `createResolver`\n * and override individual methods next to it when a plugin deviates.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ param: createOperationParamResolver(), ... })\n * ```\n */\nexport function createOperationParamResolver(): OperationParamResolver {\n return {\n name(node, param) {\n const name = this.name(`${node.operationId} ${param.in} ${param.name}`)\n return this.resolveName({ key: operationKey(node, 'param', 'name', param.in, param.name), name })\n },\n path(node) {\n const name = this.name(`${node.operationId} Path`)\n return this.resolveName({ key: operationKey(node, 'param', 'path'), name })\n },\n query(node) {\n const name = this.name(`${node.operationId} Query`)\n return this.resolveName({ key: operationKey(node, 'param', 'query'), name })\n },\n headers(node) {\n const name = this.name(`${node.operationId} Headers`)\n return this.resolveName({ key: operationKey(node, 'param', 'headers'), name })\n },\n }\n}\n\n/**\n * Builds the shared `response` namespace. Spread the result into\n * `createResolver` and add plugin-specific methods (`options`, `error`) next\n * to it.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ response: { ...createOperationResponseResolver(), options(node) {...} }, ... })\n * ```\n */\nexport function createOperationResponseResolver(): OperationResponseResolver {\n return {\n status(node, statusCode) {\n const name = this.name(`${node.operationId} Status ${statusCode}`)\n return this.resolveName({ key: operationKey(node, 'response', 'status', statusCode), name })\n },\n body(node) {\n const name = this.name(`${node.operationId} Body`)\n return this.resolveName({ key: operationKey(node, 'response', 'body'), name })\n },\n responses(node) {\n const name = this.name(`${node.operationId} Responses`)\n return this.resolveName({ key: operationKey(node, 'response', 'responses'), name })\n },\n response(node) {\n const name = this.name(`${node.operationId} Response`)\n return this.resolveName({ key: operationKey(node, 'response', 'response'), name })\n },\n }\n}\n\n/**\n * Builds a resolver `file` override whose base name runs every path segment\n * through `toFilePath`, casing the final segment with `caseLast`.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ file: createCasedFile(pascalCase), ... })\n * ```\n */\nexport function createCasedFile(caseLast: (part: string) => string): ResolverFile {\n return {\n baseName({ name, extname }) {\n return this.memo(`file:${name}\\0${extname}`, (): ast.FileNode['baseName'] => `${toFilePath(name, caseLast)}${extname}`)\n },\n }\n}\n\ntype SchemaIndexContext = Pick<GeneratorContext, 'memo' | 'driver'>\n\n/**\n * Names of the schemas in a circular reference chain, computed once per build.\n */\nexport function getCircularNames(ctx: SchemaIndexContext): ReadonlySet<string> {\n return ctx.memo('circularNames:set', () => ast.findCircularSchemas(ctx.driver.inputNode?.schemas ?? []))\n}\n\n/**\n * Names of the schemas whose type is `enum`, computed once per build.\n */\nexport function getEnumNames(ctx: SchemaIndexContext): ReadonlySet<string> {\n return ctx.memo(\n 'enumNames:set',\n () => new Set((ctx.driver.inputNode?.schemas ?? []).flatMap((schema) => (schema.type === 'enum' && schema.name ? [schema.name] : []))),\n )\n}\n\ndeclare global {\n namespace Kubb {\n interface MemoRegistry {\n operation: string\n file: ast.FileNode['baseName']\n operationTypeNames: Array<string>\n }\n }\n}\n","import { camelCase, type Group } from '@kubb/kit'\n\n/**\n * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the\n * shared default naming so every plugin groups output consistently:\n *\n * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).\n * - other groups use the camelCased group (`pet store` → `petStore`).\n *\n * A user-provided `group.name` always wins over the default namer, so callers stay in\n * control of their output folders. Returns `null` when grouping is disabled, matching the\n * per-plugin convention.\n *\n * @param group - The user-supplied group option, or `undefined` to disable grouping.\n *\n * @example\n * ```ts\n * createGroupConfig(group) // shared across every plugin\n * ```\n */\nexport function createGroupConfig(group: Group | undefined): Group | null {\n if (!group) {\n return null\n }\n\n const defaultName = (ctx: { group: string }): string => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return camelCase(ctx.group)\n }\n\n return {\n ...group,\n name: group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { buildOperationComments, buildRequestParamsSignature, castToClientOptions, hasRequestContentTypeChoice } from '@internals/shared'\nimport type { ast } from '@kubb/kit'\nimport type { ResolverTs } from '@kubb/plugin-ts'\nimport { File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx'\n\ntype Props = {\n /**\n * Name of the handler function.\n */\n name: string\n /**\n * Name of the contract client `<op>` the handler calls.\n */\n clientName: string\n /**\n * AST operation node.\n */\n node: ast.HttpOperationNode\n /**\n * TypeScript resolver for resolving param/data/response type names.\n */\n resolver: ResolverTs\n /**\n * The registered client plugin's `returnType`, read by the caller off `resolveClientOperation`.\n */\n returnType?: 'full' | 'data' | 'plain'\n}\n\nconst requestGroupOrder = ['path', 'query', 'headers', 'body'] as const\n\nexport function McpHandler({ name, clientName, node, resolver, returnType = 'full' }: Props): KubbReactNode {\n const { signature, groups } = buildRequestParamsSignature(node, resolver, { isConfigurable: false })\n const paramsSignature = [signature, 'ctx: ServerContext'].filter(Boolean).join(', ')\n\n // Forward the grouped config and MCP cancellation signal through the contract client. `throwOnError: true`\n // pins the result shape, since `throwOnErrorDefault: false` would otherwise resolve to the full result.\n const callArgs = requestGroupOrder.filter((key) => groups[key])\n const callConfig = `{ ${[...callArgs, 'signal: ctx.mcpReq.signal', 'throwOnError: true'].join(', ')} }`\n // Tool arguments carry no media type, so the call takes the client's default one.\n const callArg = hasRequestContentTypeChoice(node) ? castToClientOptions(callConfig, clientName, returnType) : callConfig\n const body = returnType === 'data' ? 'res' : 'res.data'\n\n const callToolResult = `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(${body})\n }\n ],\n structuredContent: { data: ${body} }\n}`\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n async\n export\n params={paramsSignature}\n JSDoc={{\n comments: buildOperationComments(node),\n }}\n returnType={'CallToolResult'}\n >\n {`const res = await ${clientName}(${callArg})`}\n <br />\n {callToolResult}\n </Function>\n </File.Source>\n )\n}\n","import type { ast } from '@kubb/kit'\nimport { Const, File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx'\n\ntype ZodParam = {\n name: string\n schemaName: string\n}\n\n/**\n * Composes individual param schemas into `z.object({ ... })`.\n */\nconst zodObject = (params: Array<ZodParam>) => `z.object({ ${params.map((p) => `${JSON.stringify(p.name)}: ${p.schemaName}`).join(', ')} })`\n\ntype Props = {\n /**\n * Human-readable server name passed to `new McpServer({ name })`.\n */\n serverName: string\n /**\n * Semantic version string passed to `new McpServer({ version })`.\n */\n serverVersion: string\n /**\n * Operations to register as MCP tools, each carrying its handler,\n * zod schema, and AST node metadata.\n */\n operations: Array<{\n tool: {\n name: string\n title?: string\n description: string\n }\n mcp: {\n name: string\n file: ast.FileNode\n }\n zod: {\n pathParams: Array<ZodParam>\n /**\n * Query params — individual schemas to compose into `z.object({ ... })`.\n */\n queryParams?: Array<ZodParam> | null\n /**\n * Header params — individual schemas to compose into `z.object({ ... })`.\n */\n headerParams?: Array<ZodParam> | null\n requestName?: string | null\n responseName?: string | null\n }\n }>\n}\n\nexport function Server({ serverName, serverVersion, operations }: Props): KubbReactNode {\n const registrations = operations\n .map(({ tool, mcp, zod }) => {\n // Group params into the same `{ path, query, headers, body }` shape the contract `<op>`\n // expects, so the MCP tool input mirrors every other client consumer.\n const entries: Array<{ key: string; value: string }> = []\n\n if (zod.pathParams.length) {\n entries.push({ key: 'path', value: zodObject(zod.pathParams) })\n }\n\n if (zod.queryParams) {\n entries.push({ key: 'query', value: zodObject(zod.queryParams) })\n }\n\n if (zod.headerParams) {\n entries.push({ key: 'headers', value: zodObject(zod.headerParams) })\n }\n\n if (zod.requestName) {\n entries.push({ key: 'body', value: zod.requestName })\n }\n\n const destructured = `{ ${entries.map((e) => e.key).join(', ')} }`\n const inputSchema = entries.length ? `z.object({ ${entries.map((e) => `${e.key}: ${e.value}`).join(', ')} })` : null\n const outputSchema = zod.responseName\n\n const config = [\n tool.title ? `title: ${JSON.stringify(tool.title)}` : null,\n `description: ${JSON.stringify(tool.description)}`,\n outputSchema ? `outputSchema: z.object({ data: ${outputSchema} })` : null,\n ]\n .filter(Boolean)\n .join(',\\n ')\n\n if (inputSchema) {\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n inputSchema: ${inputSchema},\n}, async (${destructured}, ctx) => {\n return ${mcp.name}(${destructured}, ctx)\n})\n `\n }\n\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n}, async (ctx) => {\n return ${mcp.name}(ctx)\n})\n `\n })\n .filter(Boolean)\n .join('\\n')\n\n return (\n <>\n <File.Source name=\"getServer\" isExportable isIndexable>\n <Function name=\"getServer\" export>\n {`const server = new McpServer({\n name: '${serverName}',\n version: '${serverVersion}',\n})\n${registrations}\nreturn server`}\n </Function>\n </File.Source>\n\n <File.Source name=\"server\" isExportable isIndexable>\n <Const name={'server'} export>\n {'getServer()'}\n </Const>\n </File.Source>\n\n <File.Source name=\"startServer\" isExportable isIndexable>\n <Function name=\"startServer\" async export>\n {`return serveStdio(getServer, {\n onerror: (error) => console.error('MCP server error:', error),\n })`}\n </Function>\n </File.Source>\n </>\n )\n}\n","import { type ast, Diagnostics, type Generator, type Group, type Output } from '@kubb/kit'\nimport { pluginTsName, type ResolverTs } from '@kubb/plugin-ts'\nimport { pluginZodName, type ResolverZod } from '@kubb/plugin-zod'\nimport type { ContractClientFactory } from './types.ts'\n\ntype GeneratorDriver = Parameters<NonNullable<Generator<ContractClientFactory>['operations']>>[1]['driver']\n\n/**\n * The two per-operation type names a generated client references: the grouped input and the\n * per-status responses record its `RequestResult` is keyed on.\n */\nexport type OperationTypeNames = {\n response: {\n /**\n * Resolves the name of the operation's grouped `{ body, path, query, headers }` input type.\n */\n options(node: ast.OperationNode): string\n /**\n * Resolves the name of the operation's per-status responses record type.\n */\n responses(node: ast.OperationNode): string\n }\n}\n\n/**\n * Where a generated client sources its operation types, plus the resolver and output the file\n * declaring them is resolved with.\n */\nexport type OperationTypeSource = OperationTypeNames & {\n /**\n * `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.\n */\n resolver: ResolverTs\n /**\n * The supplying plugin's own `output`, when it configured one.\n */\n output: Output | undefined\n /**\n * The supplying plugin's own `group`, when it configured one.\n */\n group: Group | undefined\n}\n\n/**\n * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`\n * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.\n */\nfunction toZodTypeResolver(resolver: ResolverZod): ResolverTs {\n const type = (name: string) => resolver.schema.type(name)\n\n return {\n ...resolver,\n // Class methods, so a spread drops them. `file` reads private fields, and `memo` gets its own key\n // space so these type names never share an entry with the zod names.\n file: resolver.file.bind(resolver),\n memo: (key: string, compute: () => unknown) => resolver.memo(`zodTypes:${key}`, compute),\n param: {\n name: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.name(node, p)),\n path: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.path(node, p)),\n query: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.query(node, p)),\n headers: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.headers(node, p)),\n },\n response: {\n body: (node: ast.OperationNode) => type(resolver.response.body(node)),\n status: (node: ast.OperationNode, statusCode: ast.StatusCode) => type(resolver.response.status(node, statusCode)),\n response: (node: ast.OperationNode) => type(resolver.response.response(node)),\n responses: (node: ast.OperationNode) => type(resolver.response.responses(node)),\n options: (node: ast.OperationNode) => resolver.response.options(node),\n },\n } as unknown as ResolverTs\n}\n\n/**\n * Picks the plugin generated clients, query hooks, and MCP handlers take their operation types from.\n *\n * `pluginZod({ inferred: 'codec' })` wins, so a codec param takes its domain value. Otherwise `plugin-ts`\n * wins when it is in the pipeline, and without it any `pluginZod({ inferred })`. Throws\n * `KUBB_MISSING_DEPENDENCY` for `pluginName` when neither is available.\n *\n * @example\n * ```ts\n * const types = resolveOperationTypes(ctx.driver, ctx.plugin.name)\n * types.response.options(node) // 'GetPetByIdOptions', or 'GetPetByIdOptionsSchemaType' from zod\n * ```\n */\nexport function resolveOperationTypes(driver: GeneratorDriver, pluginName: string): OperationTypeSource {\n return driver.memo(`operationTypes:${pluginName}`, () => {\n const pluginTs = driver.getPlugin(pluginTsName)\n const pluginZod = driver.getPlugin(pluginZodName)\n\n if (pluginTs && pluginZod?.options?.inferred !== 'codec') {\n const resolver = driver.getResolver(pluginTsName)\n return { response: resolver.response, resolver, output: pluginTs.options?.output, group: pluginTs.options?.group ?? undefined }\n }\n\n if (!pluginZod?.options?.inferred) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.missingDependency,\n severity: 'error',\n message: `Plugin \"${pluginName}\" has no source for operation types.`,\n help: `Add \\`pluginTs()\\` before \"${pluginName}\", or add \\`pluginZod({ inferred: true })\\`.`,\n location: { kind: 'config' },\n plugin: pluginName,\n })\n }\n\n const resolver = toZodTypeResolver(driver.getResolver(pluginZodName))\n return { response: resolver.response, resolver, output: pluginZod.options.output, group: pluginZod.options.group ?? undefined }\n })\n}\n\ndeclare global {\n namespace Kubb {\n interface MemoRegistry {\n operationTypes: OperationTypeSource\n /**\n * Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.\n */\n zodTypes: unknown\n }\n }\n}\n","/**\n * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an\n * operation, shared so the selection rules and diagnostics stay in one place.\n *\n * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered\n * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own\n * inline client:\n *\n * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer\n * imports and calls them.\n * - `error` — no client plugin is registered, several are registered without a selector, the\n * requested one is missing, or `client` is not a known selector.\n *\n * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a\n * lone registered contract client plugin is picked up automatically.\n */\n\nimport { Diagnostics } from '@kubb/kit'\n\n// Canonical plugin names. They mirror the `pluginFetchName` / `pluginAxiosName` / `pluginClientName`\n// consts the plugins export, kept as literals so this internal needs no plugin install deps.\nconst pluginFetchName = 'plugin-fetch'\nconst pluginAxiosName = 'plugin-axios'\nconst pluginClientName = 'plugin-client'\n\n/**\n * The client selector accepted by a consumer's `client` option. Each calls a registered contract\n * client plugin.\n */\nexport type ClientSelector = 'fetch' | 'axios' | 'client'\n\n/**\n * The resolved client strategy stored in a consumer plugin's options: the generated code always\n * imports and calls a registered contract client plugin's `<op>`. The client runtime lives in\n * plugin-axios / plugin-fetch, so nothing is bundled by the consumer.\n */\nexport type ResolvedContractClient = { kind: 'contract'; pluginName: string }\n\n/**\n * The outcome of {@link resolveClient}.\n *\n * - `contract` names the contract client plugin whose `<op>` functions the consumer imports.\n * - `error` carries a setup diagnostic: its code, what is wrong, and how to fix it.\n */\nexport type ResolveClientResult =\n | ResolvedContractClient\n | { kind: 'error'; code: typeof Diagnostics.code.missingDependency | typeof Diagnostics.code.invalidPluginOptions; message: string; help: string }\n\nconst selectorToPlugin: Record<ClientSelector, string> = {\n fetch: pluginFetchName,\n axios: pluginAxiosName,\n client: pluginClientName,\n}\n\n// Every contract client plugin, in auto-detect priority order.\nconst contractPlugins = [pluginFetchName, pluginAxiosName, pluginClientName] as const\n\n/**\n * Applies the `client` resolution rules. See the module comment for the strategy shape.\n *\n * @example\n * ```ts\n * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })\n * // { kind: 'contract', pluginName: 'plugin-fetch' }\n * ```\n *\n * @example\n * ```ts\n * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })\n * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }\n * ```\n */\nexport function resolveClient(options: { client: ClientSelector | undefined; pluginNames: ReadonlyArray<string> }): ResolveClientResult {\n const { client, pluginNames } = options\n const has = (name: string) => pluginNames.includes(name)\n\n if (client === 'fetch' || client === 'axios' || client === 'client') {\n const pluginName = selectorToPlugin[client]\n if (!has(pluginName)) {\n return {\n kind: 'error',\n code: Diagnostics.code.missingDependency,\n message: `\\`client: '${client}'\\` is set but \\`@kubb/plugin-${client}\\` is not registered in \\`plugins\\`.`,\n help: `Add \\`@kubb/plugin-${client}\\` to \\`plugins\\`, or drop \\`client\\` to use a different client plugin.`,\n }\n }\n return { kind: 'contract', pluginName }\n }\n\n // A JS config bypasses the `ClientSelector` type, so reject unknown selectors instead of auto-detecting.\n if (client !== undefined) {\n return {\n kind: 'error',\n code: Diagnostics.code.invalidPluginOptions,\n message: `Option \\`client\\` is ${typeof client === 'string' ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,\n help: 'Set `client` to one of those values, or drop it to use the registered client plugin.',\n }\n }\n\n // `client` unset: auto-detect a lone registered contract client plugin.\n const registered = contractPlugins.filter(has)\n if (registered.length === 1) {\n return { kind: 'contract', pluginName: registered[0]! }\n }\n if (registered.length > 1) {\n return {\n kind: 'error',\n code: Diagnostics.code.invalidPluginOptions,\n message: `Multiple client plugins are registered (${registered.map((name) => `\\`@kubb/${name}\\``).join(', ')}) and \\`client\\` is not set.`,\n help: \"Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin.\",\n }\n }\n\n return {\n kind: 'error',\n code: Diagnostics.code.missingDependency,\n message: 'No client plugin is registered.',\n help: 'Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call.',\n }\n}\n\n/**\n * Resolves the contract client during a consumer plugin's setup hook.\n * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.\n * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer\n * fails fast with the same message.\n */\nexport function resolveContractClient(options: {\n plugin: string\n client: ClientSelector | undefined\n plugins?: ReadonlyArray<unknown>\n}): ResolvedContractClient {\n const { plugin, client, plugins = [] } = options\n const pluginNames = plugins.map((plugin) => (plugin as { name?: string }).name).filter((name): name is string => Boolean(name))\n const resolved = resolveClient({ client, pluginNames })\n if (resolved.kind === 'error') {\n const { code, message, help } = resolved\n throw new Diagnostics.Error({ code, severity: 'error', message, help, location: { kind: 'config' }, plugin })\n }\n return resolved\n}\n","import path from 'node:path'\nimport { operationFileEntry, operationKey } from '@internals/shared'\nimport type { ast, Exclude, Group, Include, Memo, Output, Override, Resolver } from '@kubb/kit'\nimport type { ReturnTypeOption } from './types.ts'\n\n/**\n * The resolved contract `<op>` for one operation: the generated function name, the file it lives in,\n * the client module path (where `RequestConfig` / `ResponseErrorConfig` come from), and the\n * registered client plugin's `returnType`.\n *\n * `clientPath` is the absolute `.kubb/client.ts` path for plugin-fetch / plugin-axios, or\n * plugin-client's `importPath`: a relative one is resolved against the `<op>` file to an absolute\n * path, a package name or alias is kept verbatim. `clientPathIsFile` tells a consumer whether to\n * make it relative to the importing file.\n */\nexport type ClientOperation = { name: string; path: string; clientPath: string; clientPathIsFile: boolean; returnType: ReturnTypeOption }\n\n/**\n * The client plugin options a dependent reads, including the filters that scope them per operation.\n */\ntype ClientPluginOptions = {\n output?: Output\n group?: Group | null\n returnType?: ReturnTypeOption\n importPath?: string\n exclude?: Array<Exclude>\n include?: Array<Include>\n override?: Array<Override<Omit<ClientPluginOptions, 'override'>>>\n}\n\nfunction isRelativeImport(importPath: string): boolean {\n return importPath.startsWith('.')\n}\n\n// plugin-client resolves a relative `importPath` from its `<op>` file, so do the same here.\nfunction resolveImportPath(options: { importPath: string; operationFile: string }): string {\n const { importPath, operationFile } = options\n return isRelativeImport(importPath) ? path.resolve(path.dirname(operationFile), importPath) : importPath\n}\n\n/**\n * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up\n * the registered contract client plugin's resolver and output. Works for any contract client plugin\n * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline\n * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then\n * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global\n * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.\n * With plugin-client they come from the user's `importPath` module instead.\n *\n * The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,\n * so several dependents reading the same client plugin for one operation in a single pass\n * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share\n * one computed result instead of each re-deriving the name and path.\n *\n * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its\n * `override` entries, the same resolution its own generator sees. A dependent's generated call body\n * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.\n */\nexport function resolveClientOperation(options: {\n clientPlugin: { pluginName: string } | null\n driver: {\n getPlugin: (name: string) => { options?: ClientPluginOptions } | undefined\n getResolver: (name: string) => Resolver\n }\n node: ast.OperationNode\n root: string\n output: Output\n memo: Memo\n}): ClientOperation | null {\n const { clientPlugin, driver, node, root, output, memo } = options\n if (!clientPlugin) return null\n\n return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {\n const resolver = driver.getResolver(clientPlugin.pluginName)\n const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {}\n const { exclude, include, override } = pluginOptions\n const hasOperationOptions = Boolean(exclude?.length || include?.length || override?.length)\n // Kubb's resolver always has `default`; the fallback keeps partial or custom resolvers working.\n const operationOptions =\n hasOperationOptions && resolver.default ? resolver.default.options(node, { options: pluginOptions, exclude, include, override }) : pluginOptions\n if (!operationOptions) return null\n\n const file = resolver.file({\n ...operationFileEntry(node, node.operationId),\n root,\n output: operationOptions.output ?? output,\n group: operationOptions.group ?? undefined,\n })\n\n const { importPath } = operationOptions\n const name = resolver.name(node.operationId)\n\n return {\n name: resolver.resolveName({ key: operationKey(node), name }),\n path: file.path,\n clientPath: importPath === undefined ? path.resolve(root, '.kubb/client.ts') : resolveImportPath({ importPath, operationFile: file.path }),\n clientPathIsFile: importPath === undefined || isRelativeImport(importPath),\n returnType: operationOptions.returnType ?? 'full',\n }\n })\n}\n","import { resolveClientOperation, resolveOperationTypes } from '@internals/client'\nimport { operationFileEntry, resolveDependencyOperationFile } from '@internals/shared'\nimport { ast, defineGenerator } from '@kubb/kit'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { McpHandler } from '../components/McpHandler.tsx'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Built-in operation generator for `@kubb/plugin-mcp`. Emits one MCP tool\n * handler per OpenAPI operation. The handler takes the grouped `{ path, query,\n * headers, body }` config and forwards it to the registered client plugin's\n * (`@kubb/plugin-axios` / `@kubb/plugin-fetch`) `<op>` function.\n */\nexport const mcpGenerator = defineGenerator<PluginMcp>({\n name: 'mcp',\n renderer: jsxRenderer,\n operation(node, ctx) {\n if (!ast.isHttpOperationNode(node)) return null\n const { resolver, driver, root, config } = ctx\n const { output, client, group } = ctx.options\n\n const types = resolveOperationTypes(driver, resolver.pluginName)\n const tsResolver = types.resolver\n\n // The registered contract client plugin owns the `<op>` the handler imports and calls.\n const contractOp = resolveClientOperation({ clientPlugin: { pluginName: client.pluginName }, driver, node, root, output, memo: ctx.memo })\n if (!contractOp) {\n return null\n }\n\n // The handler signature references the grouped `<Name>Options`.\n const optionsName = tsResolver.response.options(node)\n\n const meta = {\n name: resolver.handler.name(node),\n file: resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),\n fileTs: resolveDependencyOperationFile({\n memo: ctx.memo,\n node,\n resolver: tsResolver,\n root,\n output: types.output ?? output,\n group: types.group,\n }),\n } as const\n\n return (\n <File\n baseName={meta.file.baseName}\n path={meta.file.path}\n meta={meta.file.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}\n >\n {meta.fileTs && optionsName && <File.Import name={[optionsName]} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />}\n <File.Import name={['CallToolResult', 'ServerContext']} path={'@modelcontextprotocol/server'} isTypeOnly />\n\n <File.Import name={[contractOp.name]} root={meta.file.path} path={contractOp.path} />\n\n <McpHandler name={meta.name} clientName={contractOp.name} node={node} resolver={tsResolver} returnType={contractOp.returnType} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { getOperationParameters, getPrimarySuccessResponse, operationFileEntry } from '@internals/shared'\nimport { getRelativePath } from '@internals/utils'\nimport { ast, defineGenerator } from '@kubb/kit'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { Server } from '../components/Server.tsx'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Default v5 server generator for `@kubb/plugin-mcp`.\n *\n * Uses individual zod schemas for each param (e.g. `createPetsPathUuidSchema`, `createPetsQueryOffsetSchema`)\n * and `resolveResponseStatusName` for per-status response schemas.\n * Query and header params are composed into `z.object({ ... })` from individual schemas.\n */\nexport const serverGenerator = defineGenerator<PluginMcp>({\n name: 'operations',\n renderer: jsxRenderer,\n operations(nodes, ctx) {\n const { config, resolver, plugin, driver, root } = ctx\n const { output, group } = ctx.options\n\n const pluginZod = ctx.requirePlugin(pluginZodName)\n\n const zodResolver = driver.getResolver(pluginZodName)\n\n const fileAt = <TName extends `${string}.${string}`>(baseName: TName) => ({\n baseName,\n path: path.resolve(root, output.path, baseName),\n meta: { pluginName: plugin.name },\n })\n const serverFile = fileAt('server.ts')\n const startFile = fileAt('start.ts')\n const jsonFile = fileAt('.mcp.json')\n\n // MCP clients spawn the command from their own working directory, usually the project root,\n // so `args` points at `start.ts` relative to `config.root` instead of the `.mcp.json` folder.\n const mcpConfig = {\n mcpServers: {\n [ctx.meta.title || 'server']: {\n type: 'stdio',\n command: 'npx',\n args: ['tsx', getRelativePath(path.resolve(config.root), startFile.path)],\n },\n },\n }\n\n const operationsMapped = nodes.filter(ast.isHttpOperationNode).map((node) => {\n const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node)\n\n const fileEntry = operationFileEntry(node, node.operationId)\n const mcpFile = resolver.file({ ...fileEntry, root, output, group: group ?? undefined })\n const zodFile = zodResolver.file({\n ...fileEntry,\n root,\n output: pluginZod.options?.output ?? output,\n group: pluginZod.options?.group ?? undefined,\n })\n\n const requestName = node.requestBody?.content?.[0]?.schema ? zodResolver.response.body(node) : null\n const successStatus = getPrimarySuccessResponse(node)?.statusCode\n const responseName = successStatus ? zodResolver.response.status(node, successStatus) : null\n\n const resolveParams = (params: typeof pathParams) => params.map((p) => ({ name: p.name, schemaName: zodResolver.param.name(node, p) }))\n\n return {\n tool: {\n name: node.operationId,\n title: node.summary || undefined,\n description: node.description || `Make a ${node.method.toUpperCase()} request to ${node.path}`,\n },\n mcp: {\n name: resolver.handler.name(node),\n file: mcpFile,\n },\n zod: {\n pathParams: resolveParams(pathParams),\n queryParams: queryParams.length ? resolveParams(queryParams) : null,\n headerParams: headerParams.length ? resolveParams(headerParams) : null,\n requestName,\n responseName,\n file: zodFile,\n },\n }\n })\n\n const imports = operationsMapped.flatMap(({ mcp, zod }) => {\n const zodNames = [\n ...zod.pathParams.map((p) => p.schemaName),\n ...(zod.queryParams ?? []).map((p) => p.schemaName),\n ...(zod.headerParams ?? []).map((p) => p.schemaName),\n zod.requestName,\n zod.responseName,\n ].filter((name): name is string => Boolean(name))\n\n const uniqueNames = [...new Set(zodNames)].sort()\n\n return [\n <File.Import key={mcp.name} name={[mcp.name]} root={serverFile.path} path={mcp.file.path} />,\n uniqueNames.length > 0 && <File.Import key={`zod-${mcp.name}`} name={uniqueNames} root={serverFile.path} path={zod.file.path} />,\n ].filter(Boolean)\n })\n\n return (\n <>\n <File\n baseName={serverFile.baseName}\n path={serverFile.path}\n meta={serverFile.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: serverFile.path, baseName: serverFile.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: serverFile.path, baseName: serverFile.baseName } })}\n >\n <File.Import name={['McpServer']} path={'@modelcontextprotocol/server'} />\n <File.Import name={['serveStdio']} path={'@modelcontextprotocol/server/stdio'} />\n <File.Import name={['z']} path={'zod'} />\n\n {imports}\n <Server serverName={ctx.meta.title ?? 'server'} serverVersion={ctx.meta.version ?? '0.0.0'} operations={operationsMapped} />\n </File>\n\n <File\n baseName={startFile.baseName}\n path={startFile.path}\n meta={startFile.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: startFile.path, baseName: startFile.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: startFile.path, baseName: startFile.baseName } })}\n >\n <File.Import name={['startServer']} root={startFile.path} path={serverFile.path} />\n {/* Not indexable: barrels must not re-export this entry, importing it starts the server. */}\n <File.Source name=\"start\">{'void startServer()'}</File.Source>\n </File>\n\n <File baseName={jsonFile.baseName} path={jsonFile.path} meta={jsonFile.meta}>\n <File.Source name=\"server\">{`${JSON.stringify(mcpConfig, null, 2)}\\n`}</File.Source>\n </File>\n </>\n )\n },\n})\n","","","import { operationKey } from '@internals/shared'\nimport { camelCase, createResolver } from '@kubb/kit'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Default resolver used by `@kubb/plugin-mcp`. Decides the names and file\n * paths for every generated MCP tool handler. Function names get a `Handler`\n * suffix so an operation `addPet` becomes `addPetHandler`.\n *\n * @example Resolve a handler name\n * ```ts\n * import { resolverMcp } from '@kubb/plugin-mcp'\n *\n * resolverMcp.name('addPet') // 'addPetHandler'\n * ```\n */\nexport const resolverMcp = createResolver<PluginMcp>({\n pluginName: 'plugin-mcp',\n name(name) {\n return this.memo(`name:${name}`, () => camelCase(name, { suffix: 'handler' }))\n },\n handler: {\n name(node) {\n const name = this.name(node.operationId)\n return this.resolveName({ key: operationKey(node, 'handler', 'name'), name })\n },\n },\n})\n","import { createGroupConfig } from '@internals/shared'\n\nimport { resolveContractClient } from '@internals/client'\nimport { addGenerator, defineExtension, Resolver, setMacros, setResolver, useConfig } from '@kubb/kit'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator } from './generators/mcpGenerator.tsx'\nimport { serverGenerator } from './generators/serverGenerator.tsx'\nimport { resolverMcp } from './resolvers/resolverMcp.ts'\nimport type { PluginMcp, ResolverMcp } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-mcp`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\n/**\n * Generates a Model Context Protocol (MCP) server from an OpenAPI spec. Every\n * operation becomes a typed MCP tool that AI assistants (Claude Desktop, Claude\n * Code, MCP-compatible clients) can call directly. Each handler calls a contract\n * client `<op>` from a registered `@kubb/plugin-axios` or `@kubb/plugin-fetch`.\n * Next to the handlers it writes `server.ts`, a `start.ts` entry that serves the\n * tools over stdio, and a `.mcp.json` that runs `start.ts` with `tsx`.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb/config'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginZod } from '@kubb/plugin-zod'\n * import { pluginFetch } from '@kubb/plugin-fetch'\n * import { pluginMcp } from '@kubb/plugin-mcp'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginZod(),\n * pluginFetch({ baseURL: 'https://petstore.swagger.io/v2' }),\n * pluginMcp({ output: { path: 'mcp' } }),\n * ],\n * })\n * ```\n */\nexport const pluginMcp = defineExtension<PluginMcp>({\n kind: 'plugin',\n meta: { name: pluginMcpName, version, compatibility },\n dependencies: { [pluginTsName]: { optional: true }, [pluginZodName]: {} },\n setup(options) {\n const {\n output = { path: 'mcp', barrel: { type: 'named' } },\n group,\n exclude = [],\n include,\n override = [],\n client,\n resolver: userResolver,\n macros: userMacros,\n } = options\n\n const resolver = userResolver ? Resolver.merge<ResolverMcp>(resolverMcp, userResolver) : resolverMcp\n\n setResolver(resolver)\n if (userMacros?.length) {\n setMacros(userMacros)\n }\n addGenerator(mcpGenerator, serverGenerator)\n\n return {\n output,\n exclude,\n include,\n override,\n group: createGroupConfig(group),\n client: resolveContractClient({ plugin: pluginMcpName, client, plugins: useConfig().plugins }),\n resolver,\n }\n },\n})\n\nexport default pluginMcp\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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/dist/index.js CHANGED
@@ -108,7 +108,7 @@ function getRequestGroupOptionality(node) {
108
108
  hasRequiredPath,
109
109
  hasRequiredQuery,
110
110
  hasRequiredHeader,
111
- isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !groups.body
111
+ isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !(groups.body && node.requestBody?.required === true)
112
112
  };
113
113
  }
114
114
  /**
@@ -151,6 +151,22 @@ function buildOperationComments(node, options = {}) {
151
151
  }
152
152
  const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
153
153
  /**
154
+ * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
155
+ * per property, typed and serialized like any other.
156
+ * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
157
+ */
158
+ function spreadQuerystring(param) {
159
+ const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
160
+ const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
161
+ if (schema?.type !== "object" || !formEncoded) return [param];
162
+ return schema.properties.map((property) => ast.factory.createParameter({
163
+ name: property.name,
164
+ in: "query",
165
+ schema: property.schema,
166
+ required: param.required && property.required
167
+ }));
168
+ }
169
+ /**
154
170
  * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
155
171
  * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
156
172
  * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
@@ -159,17 +175,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
159
175
  function getOperationParameters(node) {
160
176
  const cached = operationParameterGroupsByNode.get(node);
161
177
  if (cached) return cached;
162
- const group = (location) => {
178
+ const dedupe = (params) => {
163
179
  const seen = /* @__PURE__ */ new Set();
164
- return node.parameters.filter((param) => {
165
- if (param.in !== location || seen.has(param.name)) return false;
180
+ return params.filter((param) => {
181
+ if (seen.has(param.name)) return false;
166
182
  seen.add(param.name);
167
183
  return true;
168
184
  });
169
185
  };
186
+ const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
170
187
  const groups = {
171
188
  path: group("path"),
172
- query: group("query"),
189
+ query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
173
190
  header: group("header"),
174
191
  cookie: group("cookie")
175
192
  };
@@ -919,11 +936,11 @@ const serverGenerator = defineGenerator({
919
936
  });
920
937
  // kubb-extension.json
921
938
  var compatibility = {
922
- "kubb": ">=5.14.6",
939
+ "kubb": ">=5.16.0",
923
940
  "node": ">=22.22"
924
941
  };
925
942
  // package.json
926
- var version = "5.4.0";
943
+ var version = "5.4.2";
927
944
  // src/resolvers/resolverMcp.ts
928
945
  /**
929
946
  * Default resolver used by `@kubb/plugin-mcp`. Decides the names and file
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../internals/shared/src/operation.ts","../../../internals/utils/src/fs.ts","../../../internals/shared/src/resolver.ts","../../../internals/shared/src/group.ts","../src/components/McpHandler.tsx","../src/components/Server.tsx","../../../internals/client/src/resolveOperationTypes.ts","../../../internals/client/src/resolveClient.ts","../../../internals/client/src/resolveClientOperation.ts","../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx","../kubb-extension.json","../package.json","../src/resolvers/resolverMcp.ts","../src/plugin.ts"],"sourcesContent":["import { ast, type Group, type Memo, type Output, type Resolver, type ResolverFileParams, Url } from '@kubb/kit'\n\n/**\n * Builds the `ResolverFileParams` every operation generator passes to\n * `resolver.file`: a file named `name`, tagged by the operation's first\n * tag (or `'default'`), at the operation's path. Centralizes the entry object\n * that was repeated at dozens of call sites across the client and query plugins.\n *\n * @example\n * ```ts\n * resolver.file(operationFileEntry(node, node.operationId), { root, output, group })\n * ```\n */\nexport function operationFileEntry(node: ast.OperationNode, name: string, extname: ResolverFileParams['extname'] = '.ts'): ResolverFileParams {\n return {\n name,\n extname,\n tag: node.tags[0] ?? 'default',\n path: node.path,\n }\n}\n\n/**\n * Resolves a dependency plugin's generated file for `node.operationId`, cached in `memo` (the\n * build's `ctx.memo`) under the resolver's own plugin name and the operation. Several dependents reading the\n * same dependency for the same operation in one pass (a query plugin's several hook generators, the\n * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.\n *\n * @example Cache `plugin-ts`'s file for the current operation\n * ```ts\n * const fileTs = resolveDependencyOperationFile({ memo: ctx.memo, node, resolver: tsResolver, root, output })\n * ```\n */\nexport function resolveDependencyOperationFile(options: {\n memo: Memo\n node: ast.OperationNode\n resolver: Pick<Resolver, 'file' | 'pluginName'>\n root: string\n output: Output\n group?: Group | null\n}): ast.FileNode {\n const { memo, node, resolver, root, output, group } = options\n\n return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () =>\n resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),\n )\n}\n\nexport type ContentTypeInfo = {\n contentTypes: string[]\n isMultipleContentTypes: boolean\n contentTypeUnion: string\n defaultContentType: string\n hasFormData: boolean\n}\n\nexport type RequestConfigResolver = {\n response: {\n body(node: ast.OperationNode): string\n }\n}\n\nexport type ResponseStatusNameResolver = {\n response: {\n status(node: ast.OperationNode, statusCode: ast.StatusCode): string\n }\n}\n\nexport type ResponseNameResolver = ResponseStatusNameResolver & {\n response: {\n response(node: ast.OperationNode): string\n }\n}\n\nexport type OperationTypeNameResolver = RequestConfigResolver &\n ResponseNameResolver & {\n param: {\n path(node: ast.OperationNode, param: ast.ParameterNode): string\n query(node: ast.OperationNode, param: ast.ParameterNode): string\n headers(node: ast.OperationNode, param: ast.ParameterNode): string\n }\n }\n\nexport type OperationCommentLink = 'pathTemplate' | 'urlPath' | false | ((node: ast.OperationNode) => string | undefined)\n\nexport type BuildOperationCommentsOptions = {\n link?: OperationCommentLink\n linkPosition?: 'beforeDeprecated' | 'afterDeprecated'\n splitLines?: boolean\n}\n\ntype ResponseLike = {\n statusCode: ast.StatusCode | number | string\n}\n\nexport type OperationParameterGroups = Record<ast.ParameterNode['in'], Array<ast.ParameterNode>>\n\nexport type ResolveOperationTypeNameOptions = {\n responseStatusNames?: boolean | 'error'\n exclude?: ReadonlyArray<string | undefined>\n order?: 'params-first' | 'body-response-first'\n /**\n * Include the individual `Path`/`Query`/`Headers` group type names. Set to `false` for clients\n * that reference the grouped `Options` type instead of the per-group types.\n */\n includeParams?: boolean\n}\n\nfunction getOperationLink(node: ast.OperationNode, link: OperationCommentLink): string | null {\n if (!link) {\n return null\n }\n\n if (typeof link === 'function') {\n return link(node) ?? null\n }\n\n return node.path ? `{@link ${Url.toPath(node.path)}}` : null\n}\n\n/**\n * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several\n * are present and the union, default, and form-data flags the client uses to pick one.\n */\nfunction buildContentTypeInfo(contentTypes: string[]): ContentTypeInfo {\n const isMultipleContentTypes = contentTypes.length > 1\n\n return {\n contentTypes,\n isMultipleContentTypes,\n contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(' | ') : '',\n defaultContentType: contentTypes[0] ?? 'application/json',\n hasFormData: contentTypes.some((ct) => ct === 'multipart/form-data'),\n }\n}\n\nexport function getContentTypeInfo(node: ast.OperationNode): ContentTypeInfo {\n return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? [])\n}\n\n/**\n * The request-body counterpart for the primary success response: the content types it documents and\n * whether several are present, so the client can let a caller pick which one to accept.\n */\nexport function getResponseContentTypeInfo(node: ast.OperationNode): ContentTypeInfo {\n return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? [])\n}\n\nexport type ResponseType = 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n\n/**\n * Reads the single base content type of an operation's primary success response, lowercased and\n * stripped of any `; charset=...` suffix. Returns `undefined` when the response declares zero or\n * more than one content type, since neither case has a single type to act on.\n */\nfunction getPrimarySuccessContentType(node: ast.OperationNode): string | undefined {\n const contentTypes = getPrimarySuccessResponse(node)?.content?.map((entry) => entry.contentType) ?? []\n if (contentTypes.length !== 1) return undefined\n return contentTypes[0]!.split(';')[0]!.trim().toLowerCase()\n}\n\n/**\n * Whether an operation streams its primary success response as Server-Sent Events\n * (`text/event-stream`). The client generator uses this to return a typed event stream instead of a\n * one-shot `RequestResult`.\n */\nexport function isEventStream(node: ast.OperationNode): boolean {\n return getPrimarySuccessContentType(node) === 'text/event-stream'\n}\n\n/**\n * Derives the default `responseType` for an operation from its primary success response.\n *\n * Returns a value only when that response declares a single non-JSON content type. `text/event-stream`\n * and other binary types (`application/octet-stream`, `application/pdf`, `image/*`, `audio/*`,\n * `video/*`) map to a stream or `'blob'`, and other `text/*` maps to `'text'`. Otherwise `undefined`,\n * leaving the runtime client's `Content-Type` auto-detection in charge.\n */\nexport function getResponseType(node: ast.OperationNode): ResponseType | undefined {\n const baseType = getPrimarySuccessContentType(node)\n if (!baseType) return undefined\n\n if (baseType === 'application/json' || baseType.endsWith('+json') || baseType === 'text/json') return undefined\n if (baseType === 'text/event-stream') return 'stream'\n if (baseType.startsWith('text/')) return 'text'\n if (baseType === 'application/octet-stream' || baseType === 'application/pdf' || /^(image|audio|video)\\//.test(baseType)) return 'blob'\n return undefined\n}\n\n/**\n * Maps a content type to the PascalCase suffix used to name per-content-type variants\n * (e.g. `application/json` → `Json`, `application/xml` → `Xml`, `multipart/form-data` → `FormData`).\n */\nfunction getContentTypeSuffix(contentType: string): string {\n const baseType = contentType.split(';')[0]!.trim()\n if (baseType === 'application/json') return 'Json'\n if (baseType === 'multipart/form-data') return 'FormData'\n if (baseType === 'application/x-www-form-urlencoded') return 'FormUrlEncoded'\n const subtype = baseType.split('/').pop() ?? baseType\n const parts = subtype.split(/[^a-zA-Z0-9]+/).filter(Boolean)\n if (parts.length === 0) return 'Unknown'\n return parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join('')\n}\n\n/**\n * Appends a content-type suffix to a base name, keeping a trailing `Data` segment last\n * (e.g. `AddPetData` + `Json` → `AddPetJsonData`, `AddPetStatus200` + `Xml` → `AddPetStatus200Xml`).\n */\nexport function getPerContentTypeName(baseName: string, suffix: string): string {\n if (baseName.endsWith('Data')) {\n return suffix.endsWith('Data') ? baseName.slice(0, -4) + suffix : `${baseName.slice(0, -4)}${suffix}Data`\n }\n return baseName + suffix\n}\n\nexport type ContentVariantInput = { contentType: string; schema?: ast.SchemaNode | null; keysToOmit?: Array<string> | null }\nexport type ContentVariant = { name: string; suffix: string; schema: ast.SchemaNode; keysToOmit?: Array<string> | null; contentType: string }\n\n/**\n * Resolves per-content-type variant names for a set of content entries, deduplicating suffix\n * collisions with a numeric counter. Entries without a schema are skipped. The returned `suffix` is\n * the final (possibly counter-augmented) value, so callers can derive parallel names in another\n * namespace (e.g. plugin-faker deriving the matching plugin-ts type name).\n */\nexport function resolveContentTypeVariants(entries: Array<ContentVariantInput>, baseName: string): Array<ContentVariant> {\n const usedNames = new Set<string>()\n return entries\n .filter((entry) => entry.schema)\n .map((entry) => {\n const baseSuffix = getContentTypeSuffix(entry.contentType)\n let suffix = baseSuffix\n let name = getPerContentTypeName(baseName, suffix)\n let counter = 2\n while (usedNames.has(name)) {\n suffix = `${baseSuffix}${counter++}`\n name = getPerContentTypeName(baseName, suffix)\n }\n usedNames.add(name)\n return { name, suffix, schema: entry.schema!, keysToOmit: entry.keysToOmit, contentType: entry.contentType }\n })\n}\n\n// The request groups come from the grouped params, so `config` drops the data-shape keys to stay\n// assignable to `Options`, which omits them from `RequestConfig`.\nconst requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`\n\nexport function buildRequestConfigType(node: ast.OperationNode): string {\n const request = getContentTypeInfo(node)\n const response = getResponseContentTypeInfo(node)\n\n // Only the ambiguous side is offered: a single-type side has nothing to pick, so it stays baked in\n // the generated call.\n const members = [\n request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null,\n response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null,\n ].filter(Boolean)\n\n return members.length ? `${requestConfigBaseType} & { contentType?: { ${members.join('; ')} } }` : requestConfigBaseType\n}\n\n/**\n * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,\n * `useInfiniteQuery`, `useSWR`, ...). Unlike {@link buildRequestConfigType}, it never adds a\n * `contentType?:` member: query hooks wrap GET operations, which carry no request body to select a\n * content type for.\n */\nexport function buildClientOptionType(): string {\n return requestConfigBaseType\n}\n\nexport type RequestGroups = {\n path: boolean\n query: boolean\n body: boolean\n headers: boolean\n}\n\n/**\n * Which of the grouped request options an operation carries.\n */\nexport function getRequestGroups(node: ast.OperationNode): RequestGroups {\n const { path, query, header } = getOperationParameters(node)\n return {\n path: path.length > 0,\n query: query.length > 0,\n body: Boolean(node.requestBody?.content?.[0]?.schema),\n headers: header.length > 0,\n }\n}\n\nexport type RequestGroupOptionality = {\n groups: RequestGroups\n hasRequiredPath: boolean\n hasRequiredQuery: boolean\n hasRequiredHeader: boolean\n /**\n * Whether the grouped request parameter can default to `{}`. True only when no group carries a\n * required member, so every member is safe to omit.\n */\n isOptional: boolean\n}\n\n/**\n * Resolves which grouped request options an operation carries together with whether each group\n * holds a required member. The grouped parameter stays optional only when nothing inside it is\n * required, matching the generated `RequestConfig` type.\n */\nexport function getRequestGroupOptionality(node: ast.OperationNode): RequestGroupOptionality {\n const groups = getRequestGroups(node)\n const { path, query, header } = getOperationParameters(node)\n const hasRequiredPath = path.some((param) => param.required)\n const hasRequiredQuery = query.some((param) => param.required)\n const hasRequiredHeader = header.some((param) => param.required)\n\n return {\n groups,\n hasRequiredPath,\n hasRequiredQuery,\n hasRequiredHeader,\n isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !groups.body,\n }\n}\n\nexport type RequestOptionsNameResolver = RequestConfigResolver & {\n response: {\n options(node: ast.OperationNode): string\n }\n}\n\n/**\n * Builds the grouped `{ path, query, body, headers }` parameter for a generated client\n * function, typed from the operation's `Options` (minus `url`). Only the groups the\n * operation actually has are destructured. The trailing `config` parameter carries the\n * runtime `RequestConfig` overrides plus `client`.\n */\nexport function buildRequestParamsSignature(\n node: ast.OperationNode,\n resolver: RequestOptionsNameResolver,\n options: { isConfigurable?: boolean } = {},\n): { signature: string; groups: RequestGroups } {\n const { isConfigurable = true } = options\n const { groups, isOptional } = getRequestGroupOptionality(node)\n\n const names = (['path', 'query', 'body', 'headers'] as const).filter((key) => groups[key])\n\n // These callers never carry the `contentType` that several media types require.\n const optionsType = hasRequestContentTypeChoice(node)\n ? `Pick<${resolver.response.options(node)}, ${names.map((name) => `'${name}'`).join(' | ')}>`\n : resolver.response.options(node)\n const firstParam = names.length > 0 ? `{ ${names.join(', ')} }: ${optionsType}${isOptional ? ' = {}' : ''}` : null\n const configParam = isConfigurable ? `config: ${buildRequestConfigType(node)} = {}` : null\n\n return {\n signature: [firstParam, configParam].filter(Boolean).join(', '),\n groups,\n }\n}\n\nexport function buildOperationComments(node: ast.OperationNode, options: BuildOperationCommentsOptions = {}): Array<string> {\n const { link = 'pathTemplate', linkPosition = 'afterDeprecated', splitLines = false } = options\n const linkComment = getOperationLink(node, link)\n const comments =\n linkPosition === 'beforeDeprecated'\n ? [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, linkComment, node.deprecated && '@deprecated']\n : [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, node.deprecated && '@deprecated', linkComment]\n\n const filteredComments = comments.filter((comment): comment is string => Boolean(comment))\n\n if (!splitLines) {\n return filteredComments\n }\n\n return filteredComments.flatMap((text) => text.split(/\\r?\\n/).map((line) => line.trim())).filter((comment): comment is string => Boolean(comment))\n}\n\nconst operationParameterGroupsByNode = new WeakMap<ast.OperationNode, OperationParameterGroups>()\n\n/**\n * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each\n * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance\n * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the\n * same parameters once per plugin.\n */\nexport function getOperationParameters(node: ast.OperationNode): OperationParameterGroups {\n const cached = operationParameterGroupsByNode.get(node)\n if (cached) return cached\n\n // A malformed spec can declare the same name twice within one location. Both would resolve to the\n // same output property, so emitting both would yield an object type with a duplicate member,\n // which TypeScript rejects. Keep the first.\n const group = (location: ast.ParameterNode['in']) => {\n const seen = new Set<string>()\n\n return node.parameters.filter((param) => {\n if (param.in !== location || seen.has(param.name)) return false\n seen.add(param.name)\n return true\n })\n }\n\n const groups: OperationParameterGroups = { path: group('path'), query: group('query'), header: group('header'), cookie: group('cookie') }\n\n operationParameterGroupsByNode.set(node, groups)\n return groups\n}\n\n/**\n * Builds the combined `{ body, path, query, headers }` options object schema for an operation,\n * referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s\n * `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same\n * shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod\n * printer to emit `z.object(…)` rather than a record.\n */\nexport function hasRequestContentTypeChoice(node: ast.OperationNode): boolean {\n return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1\n}\n\n/**\n * Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.\n */\nexport function castToClientOptions(callArg: string, clientName: string, returnType: 'full' | 'data' | 'plain' = 'full'): string {\n return `${callArg} as Parameters<typeof ${clientName}${returnType === 'plain' ? '' : '<true>'}>[0]`\n}\n\nexport function buildOptionsSchema(node: ast.OperationNode, resolver: OperationTypeNameResolver, { pairContentTypes = false } = {}): ast.SchemaNode {\n const { path, query, header } = getOperationParameters(node)\n const hasBody = Boolean(node.requestBody?.content?.[0]?.schema)\n const createNever = () => ast.factory.createSchema({ type: 'never', primitive: undefined, optional: true })\n const groups = [\n { name: 'path', params: path, resolve: resolver.param.path },\n { name: 'query', params: query, resolve: resolver.param.query },\n { name: 'headers', params: header, resolve: resolver.param.headers },\n ] as const\n\n const createOptions = (body: ast.SchemaNode, extra: Array<ast.PropertyNode> = []) =>\n // NOTE(v5-stable): the fields were renamed from the legacy beta shape\n // (`data`/`pathParams`/`queryParams`/`headerParams`) to `body`/`path`/`query`/`headers` so the\n // type matches the runtime client. Drop this note once v5 leaves beta.\n ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n deprecated: node.deprecated,\n properties: [\n ast.factory.createProperty({ name: 'body', required: hasBody, schema: body }),\n ...groups.map(({ name, params, resolve }) => {\n const required = params.some((param) => param.required)\n\n return ast.factory.createProperty({\n name,\n required,\n schema:\n params.length > 0\n ? ast.factory.createSchema({ type: 'ref', name: resolve.call(resolver.param, node, params[0]!), optional: !required })\n : createNever(),\n })\n }),\n ...extra,\n ],\n })\n\n const variants =\n pairContentTypes && hasRequestContentTypeChoice(node) ? resolveContentTypeVariants(node.requestBody?.content ?? [], resolver.response.body(node)) : []\n if (variants.length < 2) {\n return createOptions(hasBody ? ast.factory.createSchema({ type: 'ref', name: resolver.response.body(node) }) : createNever())\n }\n\n // The first media type is the runtime default, so only the others must pass `contentType`.\n return ast.factory.createSchema({\n type: 'union',\n members: variants.map((variant, index) =>\n createOptions(ast.factory.createSchema({ type: 'ref', name: variant.name }), [\n ast.factory.createProperty({\n name: 'contentType',\n required: index > 0,\n schema: ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n ast.factory.createProperty({\n name: 'request',\n required: true,\n schema: ast.factory.createSchema({ type: 'enum', enumValues: [variant.contentType] }),\n }),\n ],\n }),\n }),\n ]),\n ),\n })\n}\n\n/**\n * The schema a status occupies in the `<Name>Responses` record. A status that documents several\n * content types becomes a `{ contentType; data }` union so the runtime can surface the negotiated type\n * on `result.parsed`, while the standalone `<Name>StatusNNN` alias stays the plain body union that the\n * query hooks and `result.data` use.\n */\nfunction buildResponseRecordEntry(node: ast.OperationNode, res: ast.ResponseNode, resolver: ResponseStatusNameResolver): ast.SchemaNode {\n const statusName = resolver.response.status(node, res.statusCode)\n const variants = (res.content ?? []).filter((entry) => entry.schema)\n if (variants.length <= 1) {\n return ast.factory.createSchema({ type: 'ref', name: statusName })\n }\n\n return ast.factory.createSchema({\n type: 'union',\n members: resolveContentTypeVariants(variants, statusName).map((variant) =>\n ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n ast.factory.createProperty({\n name: 'contentType',\n required: true,\n schema: ast.factory.createSchema({ type: 'enum', enumValues: [variant.contentType] }),\n }),\n ast.factory.createProperty({\n name: 'data',\n required: true,\n schema: ast.factory.createSchema({ type: 'ref', name: variant.name }),\n }),\n ],\n }),\n ),\n })\n}\n\n/**\n * Builds the per-status `<Name>Responses` record for an operation, referencing the already-resolved\n * `<Name>StatusNNN` names. Shared by `@kubb/plugin-ts`'s `Responses` type and `@kubb/plugin-zod`'s\n * inferred responses schema, so both emit the same shape from the same inputs.\n *\n * Always emits the keyed record, even when an operation declares no responses. An operation with no\n * responses renders as an empty object, which keeps every consumer's import (for example the axios\n * SDK's `RequestResult<XResponses>`) resolvable instead of pointing at a missing export.\n */\nexport function buildResponses(node: ast.OperationNode, resolver: ResponseStatusNameResolver): ast.SchemaNode {\n return ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: node.responses.map((res) =>\n ast.factory.createProperty({\n name: String(res.statusCode),\n required: true,\n schema: buildResponseRecordEntry(node, res, resolver),\n }),\n ),\n })\n}\n\nexport function getStatusCodeNumber(statusCode: ast.StatusCode | number | string): number | null {\n const code = Number(statusCode)\n\n return Number.isNaN(code) ? null : code\n}\n\nexport function isSuccessStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== null && code >= 200 && code < 300\n}\n\nexport function isErrorStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== null && code >= 400\n}\n\nexport function getSuccessResponses<TResponse extends ResponseLike>(responses: ReadonlyArray<TResponse>): Array<TResponse> {\n return responses.filter((response) => isSuccessStatusCode(response.statusCode))\n}\n\nexport function getOperationSuccessResponses(node: ast.OperationNode): Array<ast.ResponseNode> {\n return getSuccessResponses(node.responses)\n}\n\nexport function getPrimarySuccessResponse(node: ast.OperationNode): ast.ResponseNode | null {\n return getOperationSuccessResponses(node)[0] ?? null\n}\n\nexport function resolveErrorNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode))\n}\n\nexport function resolveSuccessNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode))\n}\n\nexport function resolveStatusCodeNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.map((response) => resolver.response.status(node, response.statusCode))\n}\n\n/**\n * Lists the type names an operation's types file declares, computed once per resolver and `options` so every\n * dependent reads the same list.\n */\nexport function resolveOperationTypeNames(\n node: ast.OperationNode,\n resolver: OperationTypeNameResolver & Pick<Resolver, 'memo'>,\n options: ResolveOperationTypeNameOptions = {},\n): string[] {\n const key = `${node.operationId}\\0${options.order ?? ''}\\0${options.responseStatusNames ?? ''}\\0${options.includeParams === false ? 'noparams' : ''}\\0${(options.exclude ?? []).join(',')}`\n return resolver.memo(`operationTypeNames:${key}`, () => {\n const { path, query, header } = getOperationParameters(node)\n const responseStatusNames =\n options.responseStatusNames === 'error'\n ? resolveErrorNames(node, resolver)\n : options.responseStatusNames === false\n ? []\n : resolveStatusCodeNames(node, resolver)\n const exclude = new Set(options.exclude ?? [])\n const paramNames =\n options.includeParams === false\n ? []\n : [\n ...path.map((param) => resolver.param.path(node, param)),\n ...query.map((param) => resolver.param.query(node, param)),\n ...header.map((param) => resolver.param.headers(node, param)),\n ]\n const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)]\n const names =\n options.order === 'body-response-first'\n ? [...bodyAndResponseNames, ...paramNames, ...responseStatusNames]\n : [...paramNames, ...bodyAndResponseNames, ...responseStatusNames]\n\n return names.filter((name): name is string => Boolean(name) && !exclude.has(name as string))\n })\n}\n\nexport function resolveResponseTypes(node: ast.OperationNode, resolver: ResponseNameResolver): Array<[statusCode: number | 'default', typeName: string]> {\n const types: Array<[number | 'default', string]> = []\n\n for (const response of node.responses) {\n if (response.statusCode === 'default') {\n types.push(['default', resolver.response.response(node)])\n continue\n }\n\n const code = getStatusCodeNumber(response.statusCode)\n if (code === null) {\n continue\n }\n\n types.push([code, isSuccessStatusCode(code) ? resolver.response.response(node) : resolver.response.status(node, response.statusCode)])\n }\n\n return types\n}\n","import { posix } from 'node:path'\nimport { camelCase } from '@kubb/kit'\n\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir: string, filePath: string): string {\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Builds a nested file path from a dotted name. Splits on dots that precede a letter\n * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases\n * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.\n *\n * Empty segments are dropped before joining. They arise when the name starts with a dot\n * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to\n * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an\n * absolute path, letting generated files escape the configured output directory.\n *\n * @example Nested path from a dotted name\n * `toFilePath('pet.petId') // 'pet/petId'`\n *\n * @example PascalCase the final segment\n * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`\n *\n * @example Suffix applied to the final segment only\n * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`\n */\nexport function toFilePath(name: string, caseLast: (part: string) => string = camelCase): string {\n const parts = name.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => (i === parts.length - 1 ? caseLast(part) : camelCase(part)))\n .filter(Boolean)\n .join('/')\n}\n","import { ensureValidVarName, toFilePath } from '@internals/utils'\nimport { ast, camelCase } from '@kubb/kit'\nimport type { GeneratorContext, Resolver, ResolverFile } from '@kubb/kit'\n\n/**\n * The shared top-level `name` of the operation plugins, computed once per operation name and build.\n */\nexport function resolveOperationName(this: Resolver, name: string): string {\n return this.memo(`operation:${name}`, () => ensureValidVarName(camelCase(name)))\n}\n\n/**\n * Builds the allocation key for a declaration an operation owns. `scope` names which declaration\n * it is, so two of them never share an allocation even when a custom resolver gives both the same\n * name. Leave `scope` empty for the operation's own declaration.\n *\n * @example\n * ```ts\n * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })\n * ```\n */\nexport function operationKey(node: ast.OperationNode, ...scope: Array<string | number>): Array<string | undefined> {\n return ['operation', node.method, node.path, ...scope.map(String)]\n}\n\n/**\n * The `param` namespace shared by the schema-producing plugins (ts, zod, faker):\n * per-parameter names plus the grouped `Path`/`Query`/`Headers` names, all routed\n * through the plugin's top-level `name` casing.\n */\nexport type OperationParamResolver = {\n name(this: Resolver, node: ast.OperationNode, param: ast.ParameterNode): string\n path(this: Resolver, node: ast.OperationNode): string\n query(this: Resolver, node: ast.OperationNode): string\n headers(this: Resolver, node: ast.OperationNode): string\n}\n\n/**\n * The `response` namespace shared by the schema-producing plugins: per-status,\n * body, and combined response names, all routed through the plugin's top-level\n * `name` casing.\n */\nexport type OperationResponseResolver = {\n status(this: Resolver, node: ast.OperationNode, statusCode: ast.StatusCode): string\n body(this: Resolver, node: ast.OperationNode): string\n responses(this: Resolver, node: ast.OperationNode): string\n response(this: Resolver, node: ast.OperationNode): string\n}\n\n/**\n * Builds the shared `param` namespace. Spread the result into `createResolver`\n * and override individual methods next to it when a plugin deviates.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ param: createOperationParamResolver(), ... })\n * ```\n */\nexport function createOperationParamResolver(): OperationParamResolver {\n return {\n name(node, param) {\n const name = this.name(`${node.operationId} ${param.in} ${param.name}`)\n return this.resolveName({ key: operationKey(node, 'param', 'name', param.in, param.name), name })\n },\n path(node) {\n const name = this.name(`${node.operationId} Path`)\n return this.resolveName({ key: operationKey(node, 'param', 'path'), name })\n },\n query(node) {\n const name = this.name(`${node.operationId} Query`)\n return this.resolveName({ key: operationKey(node, 'param', 'query'), name })\n },\n headers(node) {\n const name = this.name(`${node.operationId} Headers`)\n return this.resolveName({ key: operationKey(node, 'param', 'headers'), name })\n },\n }\n}\n\n/**\n * Builds the shared `response` namespace. Spread the result into\n * `createResolver` and add plugin-specific methods (`options`, `error`) next\n * to it.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ response: { ...createOperationResponseResolver(), options(node) {...} }, ... })\n * ```\n */\nexport function createOperationResponseResolver(): OperationResponseResolver {\n return {\n status(node, statusCode) {\n const name = this.name(`${node.operationId} Status ${statusCode}`)\n return this.resolveName({ key: operationKey(node, 'response', 'status', statusCode), name })\n },\n body(node) {\n const name = this.name(`${node.operationId} Body`)\n return this.resolveName({ key: operationKey(node, 'response', 'body'), name })\n },\n responses(node) {\n const name = this.name(`${node.operationId} Responses`)\n return this.resolveName({ key: operationKey(node, 'response', 'responses'), name })\n },\n response(node) {\n const name = this.name(`${node.operationId} Response`)\n return this.resolveName({ key: operationKey(node, 'response', 'response'), name })\n },\n }\n}\n\n/**\n * Builds a resolver `file` override whose base name runs every path segment\n * through `toFilePath`, casing the final segment with `caseLast`.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ file: createCasedFile(pascalCase), ... })\n * ```\n */\nexport function createCasedFile(caseLast: (part: string) => string): ResolverFile {\n return {\n baseName({ name, extname }) {\n return this.memo(`file:${name}\\0${extname}`, (): ast.FileNode['baseName'] => `${toFilePath(name, caseLast)}${extname}`)\n },\n }\n}\n\ntype SchemaIndexContext = Pick<GeneratorContext, 'memo' | 'driver'>\n\n/**\n * Names of the schemas in a circular reference chain, computed once per build.\n */\nexport function getCircularNames(ctx: SchemaIndexContext): ReadonlySet<string> {\n return ctx.memo('circularNames:set', () => ast.findCircularSchemas(ctx.driver.inputNode?.schemas ?? []))\n}\n\n/**\n * Names of the schemas whose type is `enum`, computed once per build.\n */\nexport function getEnumNames(ctx: SchemaIndexContext): ReadonlySet<string> {\n return ctx.memo(\n 'enumNames:set',\n () => new Set((ctx.driver.inputNode?.schemas ?? []).flatMap((schema) => (schema.type === 'enum' && schema.name ? [schema.name] : []))),\n )\n}\n\ndeclare global {\n namespace Kubb {\n interface MemoRegistry {\n operation: string\n file: ast.FileNode['baseName']\n operationTypeNames: Array<string>\n }\n }\n}\n","import { camelCase, type Group } from '@kubb/kit'\n\n/**\n * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the\n * shared default naming so every plugin groups output consistently:\n *\n * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).\n * - other groups use the camelCased group (`pet store` → `petStore`).\n *\n * A user-provided `group.name` always wins over the default namer, so callers stay in\n * control of their output folders. Returns `null` when grouping is disabled, matching the\n * per-plugin convention.\n *\n * @param group - The user-supplied group option, or `undefined` to disable grouping.\n *\n * @example\n * ```ts\n * createGroupConfig(group) // shared across every plugin\n * ```\n */\nexport function createGroupConfig(group: Group | undefined): Group | null {\n if (!group) {\n return null\n }\n\n const defaultName = (ctx: { group: string }): string => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return camelCase(ctx.group)\n }\n\n return {\n ...group,\n name: group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { buildOperationComments, buildRequestParamsSignature, castToClientOptions, hasRequestContentTypeChoice } from '@internals/shared'\nimport type { ast } from '@kubb/kit'\nimport type { ResolverTs } from '@kubb/plugin-ts'\nimport { File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx'\n\ntype Props = {\n /**\n * Name of the handler function.\n */\n name: string\n /**\n * Name of the contract client `<op>` the handler calls.\n */\n clientName: string\n /**\n * AST operation node.\n */\n node: ast.HttpOperationNode\n /**\n * TypeScript resolver for resolving param/data/response type names.\n */\n resolver: ResolverTs\n /**\n * The registered client plugin's `returnType`, read by the caller off `resolveClientOperation`.\n */\n returnType?: 'full' | 'data' | 'plain'\n}\n\nconst requestGroupOrder = ['path', 'query', 'headers', 'body'] as const\n\nexport function McpHandler({ name, clientName, node, resolver, returnType = 'full' }: Props): KubbReactNode {\n const { signature, groups } = buildRequestParamsSignature(node, resolver, { isConfigurable: false })\n const paramsSignature = [signature, 'ctx: ServerContext'].filter(Boolean).join(', ')\n\n // Forward the grouped config and MCP cancellation signal through the contract client. `throwOnError: true`\n // pins the result shape, since `throwOnErrorDefault: false` would otherwise resolve to the full result.\n const callArgs = requestGroupOrder.filter((key) => groups[key])\n const callConfig = `{ ${[...callArgs, 'signal: ctx.mcpReq.signal', 'throwOnError: true'].join(', ')} }`\n // Tool arguments carry no media type, so the call takes the client's default one.\n const callArg = hasRequestContentTypeChoice(node) ? castToClientOptions(callConfig, clientName, returnType) : callConfig\n const body = returnType === 'data' ? 'res' : 'res.data'\n\n const callToolResult = `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(${body})\n }\n ],\n structuredContent: { data: ${body} }\n}`\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n async\n export\n params={paramsSignature}\n JSDoc={{\n comments: buildOperationComments(node),\n }}\n returnType={'CallToolResult'}\n >\n {`const res = await ${clientName}(${callArg})`}\n <br />\n {callToolResult}\n </Function>\n </File.Source>\n )\n}\n","import type { ast } from '@kubb/kit'\nimport { Const, File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx'\n\ntype ZodParam = {\n name: string\n schemaName: string\n}\n\n/**\n * Composes individual param schemas into `z.object({ ... })`.\n */\nconst zodObject = (params: Array<ZodParam>) => `z.object({ ${params.map((p) => `${JSON.stringify(p.name)}: ${p.schemaName}`).join(', ')} })`\n\ntype Props = {\n /**\n * Human-readable server name passed to `new McpServer({ name })`.\n */\n serverName: string\n /**\n * Semantic version string passed to `new McpServer({ version })`.\n */\n serverVersion: string\n /**\n * Operations to register as MCP tools, each carrying its handler,\n * zod schema, and AST node metadata.\n */\n operations: Array<{\n tool: {\n name: string\n title?: string\n description: string\n }\n mcp: {\n name: string\n file: ast.FileNode\n }\n zod: {\n pathParams: Array<ZodParam>\n /**\n * Query params — individual schemas to compose into `z.object({ ... })`.\n */\n queryParams?: Array<ZodParam> | null\n /**\n * Header params — individual schemas to compose into `z.object({ ... })`.\n */\n headerParams?: Array<ZodParam> | null\n requestName?: string | null\n responseName?: string | null\n }\n }>\n}\n\nexport function Server({ serverName, serverVersion, operations }: Props): KubbReactNode {\n const registrations = operations\n .map(({ tool, mcp, zod }) => {\n // Group params into the same `{ path, query, headers, body }` shape the contract `<op>`\n // expects, so the MCP tool input mirrors every other client consumer.\n const entries: Array<{ key: string; value: string }> = []\n\n if (zod.pathParams.length) {\n entries.push({ key: 'path', value: zodObject(zod.pathParams) })\n }\n\n if (zod.queryParams) {\n entries.push({ key: 'query', value: zodObject(zod.queryParams) })\n }\n\n if (zod.headerParams) {\n entries.push({ key: 'headers', value: zodObject(zod.headerParams) })\n }\n\n if (zod.requestName) {\n entries.push({ key: 'body', value: zod.requestName })\n }\n\n const destructured = `{ ${entries.map((e) => e.key).join(', ')} }`\n const inputSchema = entries.length ? `z.object({ ${entries.map((e) => `${e.key}: ${e.value}`).join(', ')} })` : null\n const outputSchema = zod.responseName\n\n const config = [\n tool.title ? `title: ${JSON.stringify(tool.title)}` : null,\n `description: ${JSON.stringify(tool.description)}`,\n outputSchema ? `outputSchema: z.object({ data: ${outputSchema} })` : null,\n ]\n .filter(Boolean)\n .join(',\\n ')\n\n if (inputSchema) {\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n inputSchema: ${inputSchema},\n}, async (${destructured}, ctx) => {\n return ${mcp.name}(${destructured}, ctx)\n})\n `\n }\n\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n}, async (ctx) => {\n return ${mcp.name}(ctx)\n})\n `\n })\n .filter(Boolean)\n .join('\\n')\n\n return (\n <>\n <File.Source name=\"getServer\" isExportable isIndexable>\n <Function name=\"getServer\" export>\n {`const server = new McpServer({\n name: '${serverName}',\n version: '${serverVersion}',\n})\n${registrations}\nreturn server`}\n </Function>\n </File.Source>\n\n <File.Source name=\"server\" isExportable isIndexable>\n <Const name={'server'} export>\n {'getServer()'}\n </Const>\n </File.Source>\n\n <File.Source name=\"startServer\" isExportable isIndexable>\n <Function name=\"startServer\" async export>\n {`return serveStdio(getServer, {\n onerror: (error) => console.error('MCP server error:', error),\n })`}\n </Function>\n </File.Source>\n </>\n )\n}\n","import { type ast, Diagnostics, type Generator, type Group, type Output } from '@kubb/kit'\nimport { pluginTsName, type ResolverTs } from '@kubb/plugin-ts'\nimport { pluginZodName, type ResolverZod } from '@kubb/plugin-zod'\nimport type { ContractClientFactory } from './types.ts'\n\ntype GeneratorDriver = Parameters<NonNullable<Generator<ContractClientFactory>['operations']>>[1]['driver']\n\n/**\n * The two per-operation type names a generated client references: the grouped input and the\n * per-status responses record its `RequestResult` is keyed on.\n */\nexport type OperationTypeNames = {\n response: {\n /**\n * Resolves the name of the operation's grouped `{ body, path, query, headers }` input type.\n */\n options(node: ast.OperationNode): string\n /**\n * Resolves the name of the operation's per-status responses record type.\n */\n responses(node: ast.OperationNode): string\n }\n}\n\n/**\n * Where a generated client sources its operation types, plus the resolver and output the file\n * declaring them is resolved with.\n */\nexport type OperationTypeSource = OperationTypeNames & {\n /**\n * `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.\n */\n resolver: ResolverTs\n /**\n * The supplying plugin's own `output`, when it configured one.\n */\n output: Output | undefined\n /**\n * The supplying plugin's own `group`, when it configured one.\n */\n group: Group | undefined\n}\n\n/**\n * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`\n * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.\n */\nfunction toZodTypeResolver(resolver: ResolverZod): ResolverTs {\n const type = (name: string) => resolver.schema.type(name)\n\n return {\n ...resolver,\n // Class methods, so a spread drops them. `file` reads private fields, and `memo` gets its own key\n // space so these type names never share an entry with the zod names.\n file: resolver.file.bind(resolver),\n memo: (key: string, compute: () => unknown) => resolver.memo(`zodTypes:${key}`, compute),\n param: {\n name: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.name(node, p)),\n path: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.path(node, p)),\n query: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.query(node, p)),\n headers: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.headers(node, p)),\n },\n response: {\n body: (node: ast.OperationNode) => type(resolver.response.body(node)),\n status: (node: ast.OperationNode, statusCode: ast.StatusCode) => type(resolver.response.status(node, statusCode)),\n response: (node: ast.OperationNode) => type(resolver.response.response(node)),\n responses: (node: ast.OperationNode) => type(resolver.response.responses(node)),\n options: (node: ast.OperationNode) => resolver.response.options(node),\n },\n } as unknown as ResolverTs\n}\n\n/**\n * Picks the plugin generated clients, query hooks, and MCP handlers take their operation types from.\n *\n * `pluginZod({ inferred: 'codec' })` wins, so a codec param takes its domain value. Otherwise `plugin-ts`\n * wins when it is in the pipeline, and without it any `pluginZod({ inferred })`. Throws\n * `KUBB_MISSING_DEPENDENCY` for `pluginName` when neither is available.\n *\n * @example\n * ```ts\n * const types = resolveOperationTypes(ctx.driver, ctx.plugin.name)\n * types.response.options(node) // 'GetPetByIdOptions', or 'GetPetByIdOptionsSchemaType' from zod\n * ```\n */\nexport function resolveOperationTypes(driver: GeneratorDriver, pluginName: string): OperationTypeSource {\n return driver.memo(`operationTypes:${pluginName}`, () => {\n const pluginTs = driver.getPlugin(pluginTsName)\n const pluginZod = driver.getPlugin(pluginZodName)\n\n if (pluginTs && pluginZod?.options?.inferred !== 'codec') {\n const resolver = driver.getResolver(pluginTsName)\n return { response: resolver.response, resolver, output: pluginTs.options?.output, group: pluginTs.options?.group ?? undefined }\n }\n\n if (!pluginZod?.options?.inferred) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.missingDependency,\n severity: 'error',\n message: `Plugin \"${pluginName}\" has no source for operation types.`,\n help: `Add \\`pluginTs()\\` before \"${pluginName}\", or add \\`pluginZod({ inferred: true })\\`.`,\n location: { kind: 'config' },\n plugin: pluginName,\n })\n }\n\n const resolver = toZodTypeResolver(driver.getResolver(pluginZodName))\n return { response: resolver.response, resolver, output: pluginZod.options.output, group: pluginZod.options.group ?? undefined }\n })\n}\n\ndeclare global {\n namespace Kubb {\n interface MemoRegistry {\n operationTypes: OperationTypeSource\n /**\n * Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.\n */\n zodTypes: unknown\n }\n }\n}\n","/**\n * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an\n * operation, shared so the selection rules and diagnostics stay in one place.\n *\n * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered\n * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own\n * inline client:\n *\n * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer\n * imports and calls them.\n * - `error` — no client plugin is registered, several are registered without a selector, the\n * requested one is missing, or `client` is not a known selector.\n *\n * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a\n * lone registered contract client plugin is picked up automatically.\n */\n\nimport { Diagnostics } from '@kubb/kit'\n\n// Canonical plugin names. They mirror the `pluginFetchName` / `pluginAxiosName` / `pluginClientName`\n// consts the plugins export, kept as literals so this internal needs no plugin install deps.\nconst pluginFetchName = 'plugin-fetch'\nconst pluginAxiosName = 'plugin-axios'\nconst pluginClientName = 'plugin-client'\n\n/**\n * The client selector accepted by a consumer's `client` option. Each calls a registered contract\n * client plugin.\n */\nexport type ClientSelector = 'fetch' | 'axios' | 'client'\n\n/**\n * The resolved client strategy stored in a consumer plugin's options: the generated code always\n * imports and calls a registered contract client plugin's `<op>`. The client runtime lives in\n * plugin-axios / plugin-fetch, so nothing is bundled by the consumer.\n */\nexport type ResolvedContractClient = { kind: 'contract'; pluginName: string }\n\n/**\n * The outcome of {@link resolveClient}.\n *\n * - `contract` names the contract client plugin whose `<op>` functions the consumer imports.\n * - `error` carries a setup diagnostic: its code, what is wrong, and how to fix it.\n */\nexport type ResolveClientResult =\n | ResolvedContractClient\n | { kind: 'error'; code: typeof Diagnostics.code.missingDependency | typeof Diagnostics.code.invalidPluginOptions; message: string; help: string }\n\nconst selectorToPlugin: Record<ClientSelector, string> = {\n fetch: pluginFetchName,\n axios: pluginAxiosName,\n client: pluginClientName,\n}\n\n// Every contract client plugin, in auto-detect priority order.\nconst contractPlugins = [pluginFetchName, pluginAxiosName, pluginClientName] as const\n\n/**\n * Applies the `client` resolution rules. See the module comment for the strategy shape.\n *\n * @example\n * ```ts\n * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })\n * // { kind: 'contract', pluginName: 'plugin-fetch' }\n * ```\n *\n * @example\n * ```ts\n * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })\n * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }\n * ```\n */\nexport function resolveClient(options: { client: ClientSelector | undefined; pluginNames: ReadonlyArray<string> }): ResolveClientResult {\n const { client, pluginNames } = options\n const has = (name: string) => pluginNames.includes(name)\n\n if (client === 'fetch' || client === 'axios' || client === 'client') {\n const pluginName = selectorToPlugin[client]\n if (!has(pluginName)) {\n return {\n kind: 'error',\n code: Diagnostics.code.missingDependency,\n message: `\\`client: '${client}'\\` is set but \\`@kubb/plugin-${client}\\` is not registered in \\`plugins\\`.`,\n help: `Add \\`@kubb/plugin-${client}\\` to \\`plugins\\`, or drop \\`client\\` to use a different client plugin.`,\n }\n }\n return { kind: 'contract', pluginName }\n }\n\n // A JS config bypasses the `ClientSelector` type, so reject unknown selectors instead of auto-detecting.\n if (client !== undefined) {\n return {\n kind: 'error',\n code: Diagnostics.code.invalidPluginOptions,\n message: `Option \\`client\\` is ${typeof client === 'string' ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,\n help: 'Set `client` to one of those values, or drop it to use the registered client plugin.',\n }\n }\n\n // `client` unset: auto-detect a lone registered contract client plugin.\n const registered = contractPlugins.filter(has)\n if (registered.length === 1) {\n return { kind: 'contract', pluginName: registered[0]! }\n }\n if (registered.length > 1) {\n return {\n kind: 'error',\n code: Diagnostics.code.invalidPluginOptions,\n message: `Multiple client plugins are registered (${registered.map((name) => `\\`@kubb/${name}\\``).join(', ')}) and \\`client\\` is not set.`,\n help: \"Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin.\",\n }\n }\n\n return {\n kind: 'error',\n code: Diagnostics.code.missingDependency,\n message: 'No client plugin is registered.',\n help: 'Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call.',\n }\n}\n\n/**\n * Resolves the contract client during a consumer plugin's setup hook.\n * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.\n * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer\n * fails fast with the same message.\n */\nexport function resolveContractClient(options: {\n plugin: string\n client: ClientSelector | undefined\n plugins?: ReadonlyArray<unknown>\n}): ResolvedContractClient {\n const { plugin, client, plugins = [] } = options\n const pluginNames = plugins.map((plugin) => (plugin as { name?: string }).name).filter((name): name is string => Boolean(name))\n const resolved = resolveClient({ client, pluginNames })\n if (resolved.kind === 'error') {\n const { code, message, help } = resolved\n throw new Diagnostics.Error({ code, severity: 'error', message, help, location: { kind: 'config' }, plugin })\n }\n return resolved\n}\n","import path from 'node:path'\nimport { operationFileEntry, operationKey } from '@internals/shared'\nimport type { ast, Exclude, Group, Include, Memo, Output, Override, Resolver } from '@kubb/kit'\nimport type { ReturnTypeOption } from './types.ts'\n\n/**\n * The resolved contract `<op>` for one operation: the generated function name, the file it lives in,\n * the client module path (where `RequestConfig` / `ResponseErrorConfig` come from), and the\n * registered client plugin's `returnType`.\n *\n * `clientPath` is the absolute `.kubb/client.ts` path for plugin-fetch / plugin-axios, or\n * plugin-client's `importPath`: a relative one is resolved against the `<op>` file to an absolute\n * path, a package name or alias is kept verbatim. `clientPathIsFile` tells a consumer whether to\n * make it relative to the importing file.\n */\nexport type ClientOperation = { name: string; path: string; clientPath: string; clientPathIsFile: boolean; returnType: ReturnTypeOption }\n\n/**\n * The client plugin options a dependent reads, including the filters that scope them per operation.\n */\ntype ClientPluginOptions = {\n output?: Output\n group?: Group | null\n returnType?: ReturnTypeOption\n importPath?: string\n exclude?: Array<Exclude>\n include?: Array<Include>\n override?: Array<Override<Omit<ClientPluginOptions, 'override'>>>\n}\n\nfunction isRelativeImport(importPath: string): boolean {\n return importPath.startsWith('.')\n}\n\n// plugin-client resolves a relative `importPath` from its `<op>` file, so do the same here.\nfunction resolveImportPath(options: { importPath: string; operationFile: string }): string {\n const { importPath, operationFile } = options\n return isRelativeImport(importPath) ? path.resolve(path.dirname(operationFile), importPath) : importPath\n}\n\n/**\n * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up\n * the registered contract client plugin's resolver and output. Works for any contract client plugin\n * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline\n * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then\n * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global\n * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.\n * With plugin-client they come from the user's `importPath` module instead.\n *\n * The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,\n * so several dependents reading the same client plugin for one operation in a single pass\n * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share\n * one computed result instead of each re-deriving the name and path.\n *\n * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its\n * `override` entries, the same resolution its own generator sees. A dependent's generated call body\n * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.\n */\nexport function resolveClientOperation(options: {\n clientPlugin: { pluginName: string } | null\n driver: {\n getPlugin: (name: string) => { options?: ClientPluginOptions } | undefined\n getResolver: (name: string) => Resolver\n }\n node: ast.OperationNode\n root: string\n output: Output\n memo: Memo\n}): ClientOperation | null {\n const { clientPlugin, driver, node, root, output, memo } = options\n if (!clientPlugin) return null\n\n return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {\n const resolver = driver.getResolver(clientPlugin.pluginName)\n const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {}\n const { exclude, include, override } = pluginOptions\n const hasOperationOptions = Boolean(exclude?.length || include?.length || override?.length)\n // Kubb's resolver always has `default`; the fallback keeps partial or custom resolvers working.\n const operationOptions =\n hasOperationOptions && resolver.default ? resolver.default.options(node, { options: pluginOptions, exclude, include, override }) : pluginOptions\n if (!operationOptions) return null\n\n const file = resolver.file({\n ...operationFileEntry(node, node.operationId),\n root,\n output: operationOptions.output ?? output,\n group: operationOptions.group ?? undefined,\n })\n\n const { importPath } = operationOptions\n const name = resolver.name(node.operationId)\n\n return {\n name: resolver.resolveName({ key: operationKey(node), name }),\n path: file.path,\n clientPath: importPath === undefined ? path.resolve(root, '.kubb/client.ts') : resolveImportPath({ importPath, operationFile: file.path }),\n clientPathIsFile: importPath === undefined || isRelativeImport(importPath),\n returnType: operationOptions.returnType ?? 'full',\n }\n })\n}\n","import { resolveClientOperation, resolveOperationTypes } from '@internals/client'\nimport { operationFileEntry, resolveDependencyOperationFile } from '@internals/shared'\nimport { ast, defineGenerator } from '@kubb/kit'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { McpHandler } from '../components/McpHandler.tsx'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Built-in operation generator for `@kubb/plugin-mcp`. Emits one MCP tool\n * handler per OpenAPI operation. The handler takes the grouped `{ path, query,\n * headers, body }` config and forwards it to the registered client plugin's\n * (`@kubb/plugin-axios` / `@kubb/plugin-fetch`) `<op>` function.\n */\nexport const mcpGenerator = defineGenerator<PluginMcp>({\n name: 'mcp',\n renderer: jsxRenderer,\n operation(node, ctx) {\n if (!ast.isHttpOperationNode(node)) return null\n const { resolver, driver, root, config } = ctx\n const { output, client, group } = ctx.options\n\n const types = resolveOperationTypes(driver, resolver.pluginName)\n const tsResolver = types.resolver\n\n // The registered contract client plugin owns the `<op>` the handler imports and calls.\n const contractOp = resolveClientOperation({ clientPlugin: { pluginName: client.pluginName }, driver, node, root, output, memo: ctx.memo })\n if (!contractOp) {\n return null\n }\n\n // The handler signature references the grouped `<Name>Options`.\n const optionsName = tsResolver.response.options(node)\n\n const meta = {\n name: resolver.handler.name(node),\n file: resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),\n fileTs: resolveDependencyOperationFile({\n memo: ctx.memo,\n node,\n resolver: tsResolver,\n root,\n output: types.output ?? output,\n group: types.group,\n }),\n } as const\n\n return (\n <File\n baseName={meta.file.baseName}\n path={meta.file.path}\n meta={meta.file.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}\n >\n {meta.fileTs && optionsName && <File.Import name={[optionsName]} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />}\n <File.Import name={['CallToolResult', 'ServerContext']} path={'@modelcontextprotocol/server'} isTypeOnly />\n\n <File.Import name={[contractOp.name]} root={meta.file.path} path={contractOp.path} />\n\n <McpHandler name={meta.name} clientName={contractOp.name} node={node} resolver={tsResolver} returnType={contractOp.returnType} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { getOperationParameters, getPrimarySuccessResponse, operationFileEntry } from '@internals/shared'\nimport { getRelativePath } from '@internals/utils'\nimport { ast, defineGenerator } from '@kubb/kit'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { Server } from '../components/Server.tsx'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Default v5 server generator for `@kubb/plugin-mcp`.\n *\n * Uses individual zod schemas for each param (e.g. `createPetsPathUuidSchema`, `createPetsQueryOffsetSchema`)\n * and `resolveResponseStatusName` for per-status response schemas.\n * Query and header params are composed into `z.object({ ... })` from individual schemas.\n */\nexport const serverGenerator = defineGenerator<PluginMcp>({\n name: 'operations',\n renderer: jsxRenderer,\n operations(nodes, ctx) {\n const { config, resolver, plugin, driver, root } = ctx\n const { output, group } = ctx.options\n\n const pluginZod = ctx.requirePlugin(pluginZodName)\n\n const zodResolver = driver.getResolver(pluginZodName)\n\n const fileAt = <TName extends `${string}.${string}`>(baseName: TName) => ({\n baseName,\n path: path.resolve(root, output.path, baseName),\n meta: { pluginName: plugin.name },\n })\n const serverFile = fileAt('server.ts')\n const startFile = fileAt('start.ts')\n const jsonFile = fileAt('.mcp.json')\n\n // MCP clients spawn the command from their own working directory, usually the project root,\n // so `args` points at `start.ts` relative to `config.root` instead of the `.mcp.json` folder.\n const mcpConfig = {\n mcpServers: {\n [ctx.meta.title || 'server']: {\n type: 'stdio',\n command: 'npx',\n args: ['tsx', getRelativePath(path.resolve(config.root), startFile.path)],\n },\n },\n }\n\n const operationsMapped = nodes.filter(ast.isHttpOperationNode).map((node) => {\n const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node)\n\n const fileEntry = operationFileEntry(node, node.operationId)\n const mcpFile = resolver.file({ ...fileEntry, root, output, group: group ?? undefined })\n const zodFile = zodResolver.file({\n ...fileEntry,\n root,\n output: pluginZod.options?.output ?? output,\n group: pluginZod.options?.group ?? undefined,\n })\n\n const requestName = node.requestBody?.content?.[0]?.schema ? zodResolver.response.body(node) : null\n const successStatus = getPrimarySuccessResponse(node)?.statusCode\n const responseName = successStatus ? zodResolver.response.status(node, successStatus) : null\n\n const resolveParams = (params: typeof pathParams) => params.map((p) => ({ name: p.name, schemaName: zodResolver.param.name(node, p) }))\n\n return {\n tool: {\n name: node.operationId,\n title: node.summary || undefined,\n description: node.description || `Make a ${node.method.toUpperCase()} request to ${node.path}`,\n },\n mcp: {\n name: resolver.handler.name(node),\n file: mcpFile,\n },\n zod: {\n pathParams: resolveParams(pathParams),\n queryParams: queryParams.length ? resolveParams(queryParams) : null,\n headerParams: headerParams.length ? resolveParams(headerParams) : null,\n requestName,\n responseName,\n file: zodFile,\n },\n }\n })\n\n const imports = operationsMapped.flatMap(({ mcp, zod }) => {\n const zodNames = [\n ...zod.pathParams.map((p) => p.schemaName),\n ...(zod.queryParams ?? []).map((p) => p.schemaName),\n ...(zod.headerParams ?? []).map((p) => p.schemaName),\n zod.requestName,\n zod.responseName,\n ].filter((name): name is string => Boolean(name))\n\n const uniqueNames = [...new Set(zodNames)].sort()\n\n return [\n <File.Import key={mcp.name} name={[mcp.name]} root={serverFile.path} path={mcp.file.path} />,\n uniqueNames.length > 0 && <File.Import key={`zod-${mcp.name}`} name={uniqueNames} root={serverFile.path} path={zod.file.path} />,\n ].filter(Boolean)\n })\n\n return (\n <>\n <File\n baseName={serverFile.baseName}\n path={serverFile.path}\n meta={serverFile.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: serverFile.path, baseName: serverFile.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: serverFile.path, baseName: serverFile.baseName } })}\n >\n <File.Import name={['McpServer']} path={'@modelcontextprotocol/server'} />\n <File.Import name={['serveStdio']} path={'@modelcontextprotocol/server/stdio'} />\n <File.Import name={['z']} path={'zod'} />\n\n {imports}\n <Server serverName={ctx.meta.title ?? 'server'} serverVersion={ctx.meta.version ?? '0.0.0'} operations={operationsMapped} />\n </File>\n\n <File\n baseName={startFile.baseName}\n path={startFile.path}\n meta={startFile.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: startFile.path, baseName: startFile.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: startFile.path, baseName: startFile.baseName } })}\n >\n <File.Import name={['startServer']} root={startFile.path} path={serverFile.path} />\n {/* Not indexable: barrels must not re-export this entry, importing it starts the server. */}\n <File.Source name=\"start\">{'void startServer()'}</File.Source>\n </File>\n\n <File baseName={jsonFile.baseName} path={jsonFile.path} meta={jsonFile.meta}>\n <File.Source name=\"server\">{`${JSON.stringify(mcpConfig, null, 2)}\\n`}</File.Source>\n </File>\n </>\n )\n },\n})\n","","","import { operationKey } from '@internals/shared'\nimport { camelCase, createResolver } from '@kubb/kit'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Default resolver used by `@kubb/plugin-mcp`. Decides the names and file\n * paths for every generated MCP tool handler. Function names get a `Handler`\n * suffix so an operation `addPet` becomes `addPetHandler`.\n *\n * @example Resolve a handler name\n * ```ts\n * import { resolverMcp } from '@kubb/plugin-mcp'\n *\n * resolverMcp.name('addPet') // 'addPetHandler'\n * ```\n */\nexport const resolverMcp = createResolver<PluginMcp>({\n pluginName: 'plugin-mcp',\n name(name) {\n return this.memo(`name:${name}`, () => camelCase(name, { suffix: 'handler' }))\n },\n handler: {\n name(node) {\n const name = this.name(node.operationId)\n return this.resolveName({ key: operationKey(node, 'handler', 'name'), name })\n },\n },\n})\n","import { createGroupConfig } from '@internals/shared'\n\nimport { resolveContractClient } from '@internals/client'\nimport { addGenerator, defineExtension, Resolver, setMacros, setResolver, useConfig } from '@kubb/kit'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator } from './generators/mcpGenerator.tsx'\nimport { serverGenerator } from './generators/serverGenerator.tsx'\nimport { resolverMcp } from './resolvers/resolverMcp.ts'\nimport type { PluginMcp, ResolverMcp } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-mcp`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\n/**\n * Generates a Model Context Protocol (MCP) server from an OpenAPI spec. Every\n * operation becomes a typed MCP tool that AI assistants (Claude Desktop, Claude\n * Code, MCP-compatible clients) can call directly. Each handler calls a contract\n * client `<op>` from a registered `@kubb/plugin-axios` or `@kubb/plugin-fetch`.\n * Next to the handlers it writes `server.ts`, a `start.ts` entry that serves the\n * tools over stdio, and a `.mcp.json` that runs `start.ts` with `tsx`.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb/config'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginZod } from '@kubb/plugin-zod'\n * import { pluginFetch } from '@kubb/plugin-fetch'\n * import { pluginMcp } from '@kubb/plugin-mcp'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginZod(),\n * pluginFetch({ baseURL: 'https://petstore.swagger.io/v2' }),\n * pluginMcp({ output: { path: 'mcp' } }),\n * ],\n * })\n * ```\n */\nexport const pluginMcp = defineExtension<PluginMcp>({\n kind: 'plugin',\n meta: { name: pluginMcpName, version, compatibility },\n dependencies: { [pluginTsName]: { optional: true }, [pluginZodName]: {} },\n setup(options) {\n const {\n output = { path: 'mcp', barrel: { type: 'named' } },\n group,\n exclude = [],\n include,\n override = [],\n client,\n resolver: userResolver,\n macros: userMacros,\n } = options\n\n const resolver = userResolver ? Resolver.merge<ResolverMcp>(resolverMcp, userResolver) : resolverMcp\n\n setResolver(resolver)\n if (userMacros?.length) {\n setMacros(userMacros)\n }\n addGenerator(mcpGenerator, serverGenerator)\n\n return {\n output,\n exclude,\n include,\n override,\n group: createGroupConfig(group),\n client: resolveContractClient({ plugin: pluginMcpName, client, plugins: useConfig().plugins }),\n resolver,\n }\n },\n})\n\nexport default pluginMcp\n"],"mappings":";;;;;;;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,MAAyB,M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,EAAE,MAAM,QAAQ;EAAE,GAClD,OACA,UAAU,CAAC,GACX,SACA,WAAW,CAAC,GACZ,QACA,UAAU,cACV,QAAQ,eACN;EAEJ,MAAM,WAAW,eAAe,SAAS,MAAmB,aAAa,YAAY,IAAI;EAEzF,YAAY,QAAQ;EACpB,IAAI,YAAY,QACd,UAAU,UAAU;EAEtB,aAAa,cAAc,eAAe;EAE1C,OAAO;GACL;GACA;GACA;GACA;GACA,OAAO,kBAAkB,KAAK;GAC9B,QAAQ,sBAAsB;IAAE,QAAQ;IAAe;IAAQ,SAAS,UAAU,CAAC,CAAC;GAAQ,CAAC;GAC7F;EACF;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../internals/shared/src/operation.ts","../../../internals/utils/src/fs.ts","../../../internals/shared/src/resolver.ts","../../../internals/shared/src/group.ts","../src/components/McpHandler.tsx","../src/components/Server.tsx","../../../internals/client/src/resolveOperationTypes.ts","../../../internals/client/src/resolveClient.ts","../../../internals/client/src/resolveClientOperation.ts","../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx","../kubb-extension.json","../package.json","../src/resolvers/resolverMcp.ts","../src/plugin.ts"],"sourcesContent":["import { ast, type Group, type Memo, type Output, type Resolver, type ResolverFileParams, Url } from '@kubb/kit'\n\n/**\n * Builds the `ResolverFileParams` every operation generator passes to\n * `resolver.file`: a file named `name`, tagged by the operation's first\n * tag (or `'default'`), at the operation's path. Centralizes the entry object\n * that was repeated at dozens of call sites across the client and query plugins.\n *\n * @example\n * ```ts\n * resolver.file(operationFileEntry(node, node.operationId), { root, output, group })\n * ```\n */\nexport function operationFileEntry(node: ast.OperationNode, name: string, extname: ResolverFileParams['extname'] = '.ts'): ResolverFileParams {\n return {\n name,\n extname,\n tag: node.tags[0] ?? 'default',\n path: node.path,\n }\n}\n\n/**\n * Resolves a dependency plugin's generated file for `node.operationId`, cached in `memo` (the\n * build's `ctx.memo`) under the resolver's own plugin name and the operation. Several dependents reading the\n * same dependency for the same operation in one pass (a query plugin's several hook generators, the\n * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.\n *\n * @example Cache `plugin-ts`'s file for the current operation\n * ```ts\n * const fileTs = resolveDependencyOperationFile({ memo: ctx.memo, node, resolver: tsResolver, root, output })\n * ```\n */\nexport function resolveDependencyOperationFile(options: {\n memo: Memo\n node: ast.OperationNode\n resolver: Pick<Resolver, 'file' | 'pluginName'>\n root: string\n output: Output\n group?: Group | null\n}): ast.FileNode {\n const { memo, node, resolver, root, output, group } = options\n\n return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () =>\n resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),\n )\n}\n\nexport type ContentTypeInfo = {\n contentTypes: string[]\n isMultipleContentTypes: boolean\n contentTypeUnion: string\n defaultContentType: string\n hasFormData: boolean\n}\n\nexport type RequestConfigResolver = {\n response: {\n body(node: ast.OperationNode): string\n }\n}\n\nexport type ResponseStatusNameResolver = {\n response: {\n status(node: ast.OperationNode, statusCode: ast.StatusCode): string\n }\n}\n\nexport type ResponseNameResolver = ResponseStatusNameResolver & {\n response: {\n response(node: ast.OperationNode): string\n }\n}\n\nexport type OperationTypeNameResolver = RequestConfigResolver &\n ResponseNameResolver & {\n param: {\n path(node: ast.OperationNode, param: ast.ParameterNode): string\n query(node: ast.OperationNode, param: ast.ParameterNode): string\n headers(node: ast.OperationNode, param: ast.ParameterNode): string\n }\n }\n\nexport type OperationCommentLink = 'pathTemplate' | 'urlPath' | false | ((node: ast.OperationNode) => string | undefined)\n\nexport type BuildOperationCommentsOptions = {\n link?: OperationCommentLink\n linkPosition?: 'beforeDeprecated' | 'afterDeprecated'\n splitLines?: boolean\n}\n\ntype ResponseLike = {\n statusCode: ast.StatusCode | number | string\n}\n\nexport type OperationParameterGroups = Record<Exclude<ast.ParameterNode['in'], 'querystring'>, Array<ast.ParameterNode>>\n\nexport type ResolveOperationTypeNameOptions = {\n responseStatusNames?: boolean | 'error'\n exclude?: ReadonlyArray<string | undefined>\n order?: 'params-first' | 'body-response-first'\n /**\n * Include the individual `Path`/`Query`/`Headers` group type names. Set to `false` for clients\n * that reference the grouped `Options` type instead of the per-group types.\n */\n includeParams?: boolean\n}\n\nfunction getOperationLink(node: ast.OperationNode, link: OperationCommentLink): string | null {\n if (!link) {\n return null\n }\n\n if (typeof link === 'function') {\n return link(node) ?? null\n }\n\n return node.path ? `{@link ${Url.toPath(node.path)}}` : null\n}\n\n/**\n * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several\n * are present and the union, default, and form-data flags the client uses to pick one.\n */\nfunction buildContentTypeInfo(contentTypes: string[]): ContentTypeInfo {\n const isMultipleContentTypes = contentTypes.length > 1\n\n return {\n contentTypes,\n isMultipleContentTypes,\n contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(' | ') : '',\n defaultContentType: contentTypes[0] ?? 'application/json',\n hasFormData: contentTypes.some((ct) => ct === 'multipart/form-data'),\n }\n}\n\nexport function getContentTypeInfo(node: ast.OperationNode): ContentTypeInfo {\n return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? [])\n}\n\n/**\n * The request-body counterpart for the primary success response: the content types it documents and\n * whether several are present, so the client can let a caller pick which one to accept.\n */\nexport function getResponseContentTypeInfo(node: ast.OperationNode): ContentTypeInfo {\n return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? [])\n}\n\nexport type ResponseType = 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'\n\n/**\n * Reads the single base content type of an operation's primary success response, lowercased and\n * stripped of any `; charset=...` suffix. Returns `undefined` when the response declares zero or\n * more than one content type, since neither case has a single type to act on.\n */\nfunction getPrimarySuccessContentType(node: ast.OperationNode): string | undefined {\n const contentTypes = getPrimarySuccessResponse(node)?.content?.map((entry) => entry.contentType) ?? []\n if (contentTypes.length !== 1) return undefined\n return contentTypes[0]!.split(';')[0]!.trim().toLowerCase()\n}\n\n/**\n * The `text/event-stream` content of the primary success response, when it is the only content type. A response that also\n * declares another type stays a normal call with its query hooks.\n */\nfunction getEventStreamContent(node: ast.OperationNode): ast.ContentNode | undefined {\n return getPrimarySuccessContentType(node) === 'text/event-stream' ? getPrimarySuccessResponse(node)?.content?.[0] : undefined\n}\n\n/**\n * Whether an operation streams its primary success response as Server-Sent Events (`text/event-stream`). The client\n * generator uses this to return a typed event stream instead of a one-shot `RequestResult`.\n */\nexport function isEventStream(node: ast.OperationNode): boolean {\n return getEventStreamContent(node) !== undefined\n}\n\n/**\n * How the document types a `text/event-stream` response, as the adapter read it from `itemSchema`: `event` when each item is\n * the parsed event with its own `event` and `data`, `data` when it is only the payload. Returns `null` without an event stream.\n */\nexport function getEventStream(node: ast.OperationNode): 'event' | 'data' | null {\n const content = getEventStreamContent(node)\n return content ? (content.stream?.shape ?? 'data') : null\n}\n\nfunction baseContentType(contentType: string): string {\n return contentType.split(';')[0]!.trim().toLowerCase()\n}\n\nfunction isJsonContentType(baseType: string): boolean {\n return baseType === 'application/json' || baseType.endsWith('+json') || baseType === 'text/json'\n}\n\n/**\n * Parser for one response content entry.\n *\n * JSON stays unset so the runtime detects it. `text/event-stream` is a stream. A binary schema\n * (`format: binary` / `contentMediaType`) is a blob even when the media type is not a well-known\n * binary type. Other `text/*` is text, and `application/octet-stream`, `application/pdf`,\n * `image/*`, `audio/*`, and `video/*` are blobs.\n */\nfunction responseTypeForContent(contentType: string, schema?: ast.SchemaNode | null): ResponseType | undefined {\n const baseType = baseContentType(contentType)\n if (!baseType) return undefined\n if (isJsonContentType(baseType)) return undefined\n if (baseType === 'text/event-stream') return 'stream'\n if (schema?.type === 'blob') return 'blob'\n if (baseType.startsWith('text/')) return 'text'\n if (baseType === 'application/octet-stream' || baseType === 'application/pdf' || /^(image|audio|video)\\//.test(baseType)) return 'blob'\n return undefined\n}\n\n/**\n * Derives the default `responseType` string for an operation from its primary success response.\n *\n * One content type uses {@link responseTypeForContent}. Several content types that all use the same\n * parser collapse to that string, so a call can keep `responseType: 'blob'`. Mixed parsers return\n * `undefined`; {@link getResponseTypeMap} carries the per-type choice.\n */\nexport function getResponseType(node: ast.OperationNode): ResponseType | undefined {\n const entries = getPrimarySuccessResponse(node)?.content ?? []\n if (entries.length === 0) return undefined\n\n const responseTypes = entries.map((entry) => responseTypeForContent(entry.contentType, entry.schema))\n const first = responseTypes[0]\n if (!first) return undefined\n if (responseTypes.every((responseType) => responseType === first)) return first\n return undefined\n}\n\n/**\n * Maps each base content type of a primary success response to its parser when those parsers differ.\n *\n * Keys are lowercased and stripped of parameters. JSON entries are kept as `'json'` so a catch-all\n * entry cannot claim a JSON response. Returns `undefined` when {@link getResponseType} already\n * covers the response with one string, or when no content type needs a parser other than JSON.\n * The runtime matches the response `Content-Type` against this map instead of guessing from the media type.\n */\nexport function getResponseTypeMap(node: ast.OperationNode): Record<string, ResponseType> | undefined {\n if (getResponseType(node)) return undefined\n\n const entries = getPrimarySuccessResponse(node)?.content ?? []\n if (entries.length <= 1) return undefined\n\n const map: Record<string, ResponseType> = {}\n for (const entry of entries) {\n const baseType = baseContentType(entry.contentType)\n const responseType = responseTypeForContent(entry.contentType, entry.schema) ?? (isJsonContentType(baseType) ? 'json' : undefined)\n if (baseType && responseType) map[baseType] = responseType\n }\n\n return Object.values(map).some((responseType) => responseType !== 'json') ? map : undefined\n}\n\n/**\n * Maps a content type to the PascalCase suffix used to name per-content-type variants\n * (e.g. `application/json` → `Json`, `application/xml` → `Xml`, `multipart/form-data` → `FormData`).\n */\nfunction getContentTypeSuffix(contentType: string): string {\n const baseType = contentType.split(';')[0]!.trim()\n if (baseType === 'application/json') return 'Json'\n if (baseType === 'multipart/form-data') return 'FormData'\n if (baseType === 'application/x-www-form-urlencoded') return 'FormUrlEncoded'\n const subtype = baseType.split('/').pop() ?? baseType\n const parts = subtype.split(/[^a-zA-Z0-9]+/).filter(Boolean)\n if (parts.length === 0) return 'Unknown'\n return parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join('')\n}\n\n/**\n * Appends a content-type suffix to a base name, keeping a trailing `Data` segment last\n * (e.g. `AddPetData` + `Json` → `AddPetJsonData`, `AddPetStatus200` + `Xml` → `AddPetStatus200Xml`).\n */\nexport function getPerContentTypeName(baseName: string, suffix: string): string {\n if (baseName.endsWith('Data')) {\n return suffix.endsWith('Data') ? baseName.slice(0, -4) + suffix : `${baseName.slice(0, -4)}${suffix}Data`\n }\n return baseName + suffix\n}\n\nexport type ContentVariantInput = { contentType: string; schema?: ast.SchemaNode | null; keysToOmit?: Array<string> | null }\nexport type ContentVariant = { name: string; suffix: string; schema: ast.SchemaNode; keysToOmit?: Array<string> | null; contentType: string }\n\n/**\n * Resolves per-content-type variant names for a set of content entries, deduplicating suffix\n * collisions with a numeric counter. Entries without a schema are skipped. The returned `suffix` is\n * the final (possibly counter-augmented) value, so callers can derive parallel names in another\n * namespace (e.g. plugin-faker deriving the matching plugin-ts type name).\n */\nexport function resolveContentTypeVariants(entries: Array<ContentVariantInput>, baseName: string): Array<ContentVariant> {\n const usedNames = new Set<string>()\n return entries\n .filter((entry) => entry.schema)\n .map((entry) => {\n const baseSuffix = getContentTypeSuffix(entry.contentType)\n let suffix = baseSuffix\n let name = getPerContentTypeName(baseName, suffix)\n let counter = 2\n while (usedNames.has(name)) {\n suffix = `${baseSuffix}${counter++}`\n name = getPerContentTypeName(baseName, suffix)\n }\n usedNames.add(name)\n return { name, suffix, schema: entry.schema!, keysToOmit: entry.keysToOmit, contentType: entry.contentType }\n })\n}\n\n// The request groups come from the grouped params, so `config` drops the data-shape keys to stay\n// assignable to `Options`, which omits them from `RequestConfig`.\nconst requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`\n\nexport function buildRequestConfigType(node: ast.OperationNode): string {\n const request = getContentTypeInfo(node)\n const response = getResponseContentTypeInfo(node)\n\n // Only the ambiguous side is offered: a single-type side has nothing to pick, so it stays baked in\n // the generated call.\n const members = [\n request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null,\n response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null,\n ].filter(Boolean)\n\n return members.length ? `${requestConfigBaseType} & { contentType?: { ${members.join('; ')} } }` : requestConfigBaseType\n}\n\n/**\n * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,\n * `useInfiniteQuery`, `useSWR`, ...). Unlike {@link buildRequestConfigType}, it never adds a\n * `contentType?:` member: query hooks wrap GET operations, which carry no request body to select a\n * content type for.\n */\nexport function buildClientOptionType(): string {\n return requestConfigBaseType\n}\n\nexport type RequestGroups = {\n path: boolean\n query: boolean\n body: boolean\n headers: boolean\n}\n\n/**\n * Which of the grouped request options an operation carries.\n */\nexport function getRequestGroups(node: ast.OperationNode): RequestGroups {\n const { path, query, header } = getOperationParameters(node)\n return {\n path: path.length > 0,\n query: query.length > 0,\n body: Boolean(node.requestBody?.content?.[0]?.schema),\n headers: header.length > 0,\n }\n}\n\nexport type RequestGroupOptionality = {\n groups: RequestGroups\n hasRequiredPath: boolean\n hasRequiredQuery: boolean\n hasRequiredHeader: boolean\n /**\n * Whether the grouped request parameter can default to `{}`. True only when no group carries a\n * required member, so every member is safe to omit.\n */\n isOptional: boolean\n}\n\n/**\n * Resolves which grouped request options an operation carries together with whether each group\n * holds a required member. The grouped parameter stays optional only when nothing inside it is\n * required, matching the generated `RequestConfig` type.\n */\nexport function getRequestGroupOptionality(node: ast.OperationNode): RequestGroupOptionality {\n const groups = getRequestGroups(node)\n const { path, query, header } = getOperationParameters(node)\n const hasRequiredPath = path.some((param) => param.required)\n const hasRequiredQuery = query.some((param) => param.required)\n const hasRequiredHeader = header.some((param) => param.required)\n\n return {\n groups,\n hasRequiredPath,\n hasRequiredQuery,\n hasRequiredHeader,\n isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !(groups.body && node.requestBody?.required === true),\n }\n}\n\nexport type RequestOptionsNameResolver = RequestConfigResolver & {\n response: {\n options(node: ast.OperationNode): string\n }\n}\n\n/**\n * Builds the grouped `{ path, query, body, headers }` parameter for a generated client\n * function, typed from the operation's `Options` (minus `url`). Only the groups the\n * operation actually has are destructured. The trailing `config` parameter carries the\n * runtime `RequestConfig` overrides plus `client`.\n */\nexport function buildRequestParamsSignature(\n node: ast.OperationNode,\n resolver: RequestOptionsNameResolver,\n options: { isConfigurable?: boolean } = {},\n): { signature: string; groups: RequestGroups } {\n const { isConfigurable = true } = options\n const { groups, isOptional } = getRequestGroupOptionality(node)\n\n const names = (['path', 'query', 'body', 'headers'] as const).filter((key) => groups[key])\n\n // These callers never carry the `contentType` that several media types require.\n const optionsType = hasRequestContentTypeChoice(node)\n ? `Pick<${resolver.response.options(node)}, ${names.map((name) => `'${name}'`).join(' | ')}>`\n : resolver.response.options(node)\n const firstParam = names.length > 0 ? `{ ${names.join(', ')} }: ${optionsType}${isOptional ? ' = {}' : ''}` : null\n const configParam = isConfigurable ? `config: ${buildRequestConfigType(node)} = {}` : null\n\n return {\n signature: [firstParam, configParam].filter(Boolean).join(', '),\n groups,\n }\n}\n\nexport function buildOperationComments(node: ast.OperationNode, options: BuildOperationCommentsOptions = {}): Array<string> {\n const { link = 'pathTemplate', linkPosition = 'afterDeprecated', splitLines = false } = options\n const linkComment = getOperationLink(node, link)\n const comments =\n linkPosition === 'beforeDeprecated'\n ? [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, linkComment, node.deprecated && '@deprecated']\n : [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, node.deprecated && '@deprecated', linkComment]\n\n const filteredComments = comments.filter((comment): comment is string => Boolean(comment))\n\n if (!splitLines) {\n return filteredComments\n }\n\n return filteredComments.flatMap((text) => text.split(/\\r?\\n/).map((line) => line.trim())).filter((comment): comment is string => Boolean(comment))\n}\n\nconst operationParameterGroupsByNode = new WeakMap<ast.OperationNode, OperationParameterGroups>()\n\n/**\n * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter\n * per property, typed and serialized like any other.\n * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.\n */\nfunction spreadQuerystring(param: ast.ParameterNode): Array<ast.ParameterNode> {\n const schema = param.schema.type === 'ref' ? param.schema.schema : param.schema\n const formEncoded = !param.contentType || param.contentType.split(';')[0]!.trim().toLowerCase() === 'application/x-www-form-urlencoded'\n if (schema?.type !== 'object' || !formEncoded) return [param]\n return schema.properties.map((property) =>\n ast.factory.createParameter({ name: property.name, in: 'query', schema: property.schema, required: param.required && property.required }),\n )\n}\n\n/**\n * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each\n * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance\n * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the\n * same parameters once per plugin.\n */\nexport function getOperationParameters(node: ast.OperationNode): OperationParameterGroups {\n const cached = operationParameterGroupsByNode.get(node)\n if (cached) return cached\n\n // A malformed spec can declare the same name twice within one location. Both would resolve to the\n // same output property, so emitting both would yield an object type with a duplicate member,\n // which TypeScript rejects. Keep the first.\n const dedupe = (params: Array<ast.ParameterNode>) => {\n const seen = new Set<string>()\n return params.filter((param) => {\n if (seen.has(param.name)) return false\n seen.add(param.name)\n return true\n })\n }\n const group = (location: ast.ParameterNode['in']) => dedupe(node.parameters.filter((param) => param.in === location))\n\n const groups: OperationParameterGroups = {\n path: group('path'),\n query: dedupe([...group('query'), ...group('querystring').flatMap(spreadQuerystring)]),\n header: group('header'),\n cookie: group('cookie'),\n }\n\n operationParameterGroupsByNode.set(node, groups)\n return groups\n}\n\n/**\n * Builds the combined `{ body, path, query, headers }` options object schema for an operation,\n * referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s\n * `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same\n * shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod\n * printer to emit `z.object(…)` rather than a record.\n */\nexport function hasRequestContentTypeChoice(node: ast.OperationNode): boolean {\n return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1\n}\n\n/**\n * Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.\n */\nexport function castToClientOptions(callArg: string, clientName: string, returnType: 'full' | 'data' | 'plain' = 'full'): string {\n return `${callArg} as Parameters<typeof ${clientName}${returnType === 'plain' ? '' : '<true>'}>[0]`\n}\n\nexport function buildOptionsSchema(node: ast.OperationNode, resolver: OperationTypeNameResolver, { pairContentTypes = false } = {}): ast.SchemaNode {\n const { path, query, header } = getOperationParameters(node)\n const hasBody = Boolean(node.requestBody?.content?.[0]?.schema)\n const createNever = () => ast.factory.createSchema({ type: 'never', primitive: undefined, optional: true })\n const groups = [\n { name: 'path', params: path, resolve: resolver.param.path },\n { name: 'query', params: query, resolve: resolver.param.query },\n { name: 'headers', params: header, resolve: resolver.param.headers },\n ] as const\n\n const createOptions = (body: ast.SchemaNode, extra: Array<ast.PropertyNode> = []) =>\n // NOTE(v5-stable): the fields were renamed from the legacy beta shape\n // (`data`/`pathParams`/`queryParams`/`headerParams`) to `body`/`path`/`query`/`headers` so the\n // type matches the runtime client. Drop this note once v5 leaves beta.\n ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n deprecated: node.deprecated,\n properties: [\n ast.factory.createProperty({ name: 'body', required: hasBody && node.requestBody?.required === true, schema: body }),\n ...groups.map(({ name, params, resolve }) => {\n const required = params.some((param) => param.required)\n\n return ast.factory.createProperty({\n name,\n required,\n schema:\n params.length > 0\n ? ast.factory.createSchema({ type: 'ref', name: resolve.call(resolver.param, node, params[0]!), optional: !required })\n : createNever(),\n })\n }),\n ...extra,\n ],\n })\n\n const variants =\n pairContentTypes && hasRequestContentTypeChoice(node) ? resolveContentTypeVariants(node.requestBody?.content ?? [], resolver.response.body(node)) : []\n if (variants.length < 2) {\n return createOptions(hasBody ? ast.factory.createSchema({ type: 'ref', name: resolver.response.body(node) }) : createNever())\n }\n\n // The first media type is the runtime default, so only the others must pass `contentType`.\n return ast.factory.createSchema({\n type: 'union',\n members: variants.map((variant, index) =>\n createOptions(ast.factory.createSchema({ type: 'ref', name: variant.name }), [\n ast.factory.createProperty({\n name: 'contentType',\n required: index > 0,\n schema: ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n ast.factory.createProperty({\n name: 'request',\n required: true,\n schema: ast.factory.createSchema({ type: 'enum', enumValues: [variant.contentType] }),\n }),\n ],\n }),\n }),\n ]),\n ),\n })\n}\n\n/**\n * The schema a status occupies in the `<Name>Responses` record. A status that documents several\n * content types becomes a `{ contentType; data }` union so the runtime can surface the negotiated type\n * on `result.parsed`, while the standalone `<Name>StatusNNN` alias stays the plain body union that the\n * query hooks and `result.data` use.\n */\nfunction buildResponseRecordEntry(node: ast.OperationNode, res: ast.ResponseNode, resolver: ResponseStatusNameResolver): ast.SchemaNode {\n const statusName = resolver.response.status(node, res.statusCode)\n const variants = (res.content ?? []).filter((entry) => entry.schema)\n if (variants.length <= 1) {\n return ast.factory.createSchema({ type: 'ref', name: statusName })\n }\n\n return ast.factory.createSchema({\n type: 'union',\n members: resolveContentTypeVariants(variants, statusName).map((variant) =>\n ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n ast.factory.createProperty({\n name: 'contentType',\n required: true,\n schema: ast.factory.createSchema({ type: 'enum', enumValues: [variant.contentType] }),\n }),\n ast.factory.createProperty({\n name: 'data',\n required: true,\n schema: ast.factory.createSchema({ type: 'ref', name: variant.name }),\n }),\n ],\n }),\n ),\n })\n}\n\n/**\n * Builds the per-status `<Name>Responses` record for an operation, referencing the already-resolved\n * `<Name>StatusNNN` names. Shared by `@kubb/plugin-ts`'s `Responses` type and `@kubb/plugin-zod`'s\n * inferred responses schema, so both emit the same shape from the same inputs.\n *\n * Always emits the keyed record, even when an operation declares no responses. An operation with no\n * responses renders as an empty object, which keeps every consumer's import (for example the axios\n * SDK's `RequestResult<XResponses>`) resolvable instead of pointing at a missing export.\n */\nexport function buildResponses(node: ast.OperationNode, resolver: ResponseStatusNameResolver): ast.SchemaNode {\n return ast.factory.createSchema({\n type: 'object',\n primitive: 'object',\n properties: node.responses.map((res) =>\n ast.factory.createProperty({\n name: String(res.statusCode),\n required: true,\n schema: buildResponseRecordEntry(node, res, resolver),\n }),\n ),\n })\n}\n\nexport function getStatusCodeNumber(statusCode: ast.StatusCode | number | string): number | null {\n const code = Number(statusCode)\n\n return Number.isNaN(code) ? null : code\n}\n\nexport function isSuccessStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== null && code >= 200 && code < 300\n}\n\nexport function isErrorStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== null && code >= 400\n}\n\nexport function getSuccessResponses<TResponse extends ResponseLike>(responses: ReadonlyArray<TResponse>): Array<TResponse> {\n return responses.filter((response) => isSuccessStatusCode(response.statusCode))\n}\n\nexport function getOperationSuccessResponses(node: ast.OperationNode): Array<ast.ResponseNode> {\n return getSuccessResponses(node.responses)\n}\n\nexport function getPrimarySuccessResponse(node: ast.OperationNode): ast.ResponseNode | null {\n return getOperationSuccessResponses(node)[0] ?? null\n}\n\nexport function resolveErrorNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode))\n}\n\nexport function resolveSuccessNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode))\n}\n\nexport function resolveStatusCodeNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.map((response) => resolver.response.status(node, response.statusCode))\n}\n\n/**\n * Lists the type names an operation's types file declares, computed once per resolver and `options` so every\n * dependent reads the same list.\n */\nexport function resolveOperationTypeNames(\n node: ast.OperationNode,\n resolver: OperationTypeNameResolver & Pick<Resolver, 'memo'>,\n options: ResolveOperationTypeNameOptions = {},\n): string[] {\n const key = `${node.operationId}\\0${options.order ?? ''}\\0${options.responseStatusNames ?? ''}\\0${options.includeParams === false ? 'noparams' : ''}\\0${(options.exclude ?? []).join(',')}`\n return resolver.memo(`operationTypeNames:${key}`, () => {\n const { path, query, header } = getOperationParameters(node)\n const responseStatusNames =\n options.responseStatusNames === 'error'\n ? resolveErrorNames(node, resolver)\n : options.responseStatusNames === false\n ? []\n : resolveStatusCodeNames(node, resolver)\n const exclude = new Set(options.exclude ?? [])\n const paramNames =\n options.includeParams === false\n ? []\n : [\n ...path.map((param) => resolver.param.path(node, param)),\n ...query.map((param) => resolver.param.query(node, param)),\n ...header.map((param) => resolver.param.headers(node, param)),\n ]\n const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)]\n const names =\n options.order === 'body-response-first'\n ? [...bodyAndResponseNames, ...paramNames, ...responseStatusNames]\n : [...paramNames, ...bodyAndResponseNames, ...responseStatusNames]\n\n return names.filter((name): name is string => Boolean(name) && !exclude.has(name as string))\n })\n}\n\nexport function resolveResponseTypes(node: ast.OperationNode, resolver: ResponseNameResolver): Array<[statusCode: number | 'default', typeName: string]> {\n const types: Array<[number | 'default', string]> = []\n\n for (const response of node.responses) {\n if (response.statusCode === 'default') {\n types.push(['default', resolver.response.response(node)])\n continue\n }\n\n const code = getStatusCodeNumber(response.statusCode)\n if (code === null) {\n continue\n }\n\n types.push([code, isSuccessStatusCode(code) ? resolver.response.response(node) : resolver.response.status(node, response.statusCode)])\n }\n\n return types\n}\n","import { posix } from 'node:path'\nimport { camelCase } from '@kubb/kit'\n\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir: string, filePath: string): string {\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Builds a nested file path from a dotted name. Splits on dots that precede a letter\n * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases\n * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.\n *\n * Empty segments are dropped before joining. They arise when the name starts with a dot\n * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to\n * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an\n * absolute path, letting generated files escape the configured output directory.\n *\n * @example Nested path from a dotted name\n * `toFilePath('pet.petId') // 'pet/petId'`\n *\n * @example PascalCase the final segment\n * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`\n *\n * @example Suffix applied to the final segment only\n * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`\n */\nexport function toFilePath(name: string, caseLast: (part: string) => string = camelCase): string {\n const parts = name.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => (i === parts.length - 1 ? caseLast(part) : camelCase(part)))\n .filter(Boolean)\n .join('/')\n}\n","import { ensureValidVarName, toFilePath } from '@internals/utils'\nimport { ast, camelCase } from '@kubb/kit'\nimport type { GeneratorContext, Resolver, ResolverFile } from '@kubb/kit'\n\n/**\n * The shared top-level `name` of the operation plugins, computed once per operation name and build.\n */\nexport function resolveOperationName(this: Resolver, name: string): string {\n return this.memo(`operation:${name}`, () => ensureValidVarName(camelCase(name)))\n}\n\n/**\n * Builds the allocation key for a declaration an operation owns. `scope` names which declaration\n * it is, so two of them never share an allocation even when a custom resolver gives both the same\n * name. Leave `scope` empty for the operation's own declaration.\n *\n * @example\n * ```ts\n * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })\n * ```\n */\nexport function operationKey(node: ast.OperationNode, ...scope: Array<string | number>): Array<string | undefined> {\n return ['operation', node.method, node.path, ...scope.map(String)]\n}\n\n/**\n * The `param` namespace shared by the schema-producing plugins (ts, zod, faker):\n * per-parameter names plus the grouped `Path`/`Query`/`Headers` names, all routed\n * through the plugin's top-level `name` casing.\n */\nexport type OperationParamResolver = {\n name(this: Resolver, node: ast.OperationNode, param: ast.ParameterNode): string\n path(this: Resolver, node: ast.OperationNode): string\n query(this: Resolver, node: ast.OperationNode): string\n headers(this: Resolver, node: ast.OperationNode): string\n}\n\n/**\n * The `response` namespace shared by the schema-producing plugins: per-status,\n * body, and combined response names, all routed through the plugin's top-level\n * `name` casing.\n */\nexport type OperationResponseResolver = {\n status(this: Resolver, node: ast.OperationNode, statusCode: ast.StatusCode): string\n body(this: Resolver, node: ast.OperationNode): string\n responses(this: Resolver, node: ast.OperationNode): string\n response(this: Resolver, node: ast.OperationNode): string\n}\n\n/**\n * Builds the shared `param` namespace. Spread the result into `createResolver`\n * and override individual methods next to it when a plugin deviates.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ param: createOperationParamResolver(), ... })\n * ```\n */\nexport function createOperationParamResolver(): OperationParamResolver {\n return {\n name(node, param) {\n const name = this.name(`${node.operationId} ${param.in} ${param.name}`)\n return this.resolveName({ key: operationKey(node, 'param', 'name', param.in, param.name), name })\n },\n path(node) {\n const name = this.name(`${node.operationId} Path`)\n return this.resolveName({ key: operationKey(node, 'param', 'path'), name })\n },\n query(node) {\n const name = this.name(`${node.operationId} Query`)\n return this.resolveName({ key: operationKey(node, 'param', 'query'), name })\n },\n headers(node) {\n const name = this.name(`${node.operationId} Headers`)\n return this.resolveName({ key: operationKey(node, 'param', 'headers'), name })\n },\n }\n}\n\n/**\n * Builds the shared `response` namespace. Spread the result into\n * `createResolver` and add plugin-specific methods (`options`, `error`) next\n * to it.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ response: { ...createOperationResponseResolver(), options(node) {...} }, ... })\n * ```\n */\nexport function createOperationResponseResolver(): OperationResponseResolver {\n return {\n status(node, statusCode) {\n const name = this.name(`${node.operationId} Status ${statusCode}`)\n return this.resolveName({ key: operationKey(node, 'response', 'status', statusCode), name })\n },\n body(node) {\n const name = this.name(`${node.operationId} Body`)\n return this.resolveName({ key: operationKey(node, 'response', 'body'), name })\n },\n responses(node) {\n const name = this.name(`${node.operationId} Responses`)\n return this.resolveName({ key: operationKey(node, 'response', 'responses'), name })\n },\n response(node) {\n const name = this.name(`${node.operationId} Response`)\n return this.resolveName({ key: operationKey(node, 'response', 'response'), name })\n },\n }\n}\n\n/**\n * Builds a resolver `file` override whose base name runs every path segment\n * through `toFilePath`, casing the final segment with `caseLast`.\n *\n * @example\n * ```ts\n * createResolver<PluginTs>({ file: createCasedFile(pascalCase), ... })\n * ```\n */\nexport function createCasedFile(caseLast: (part: string) => string): ResolverFile {\n return {\n baseName({ name, extname }) {\n return this.memo(`file:${name}\\0${extname}`, (): ast.FileNode['baseName'] => `${toFilePath(name, caseLast)}${extname}`)\n },\n }\n}\n\ntype SchemaIndexContext = Pick<GeneratorContext, 'memo' | 'driver'>\n\n/**\n * Names of the schemas in a circular reference chain, computed once per build.\n */\nexport function getCircularNames(ctx: SchemaIndexContext): ReadonlySet<string> {\n return ctx.memo('circularNames:set', () => ast.findCircularSchemas(ctx.driver.inputNode?.schemas ?? []))\n}\n\n/**\n * Names of the schemas whose type is `enum`, computed once per build.\n */\nexport function getEnumNames(ctx: SchemaIndexContext): ReadonlySet<string> {\n return ctx.memo(\n 'enumNames:set',\n () => new Set((ctx.driver.inputNode?.schemas ?? []).flatMap((schema) => (schema.type === 'enum' && schema.name ? [schema.name] : []))),\n )\n}\n\ndeclare global {\n namespace Kubb {\n interface MemoRegistry {\n operation: string\n file: ast.FileNode['baseName']\n operationTypeNames: Array<string>\n }\n }\n}\n","import { camelCase, type Group } from '@kubb/kit'\n\n/**\n * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the\n * shared default naming so every plugin groups output consistently:\n *\n * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).\n * - other groups use the camelCased group (`pet store` → `petStore`).\n *\n * A user-provided `group.name` always wins over the default namer, so callers stay in\n * control of their output folders. Returns `null` when grouping is disabled, matching the\n * per-plugin convention.\n *\n * @param group - The user-supplied group option, or `undefined` to disable grouping.\n *\n * @example\n * ```ts\n * createGroupConfig(group) // shared across every plugin\n * ```\n */\nexport function createGroupConfig(group: Group | undefined): Group | null {\n if (!group) {\n return null\n }\n\n const defaultName = (ctx: { group: string }): string => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return camelCase(ctx.group)\n }\n\n return {\n ...group,\n name: group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { buildOperationComments, buildRequestParamsSignature, castToClientOptions, hasRequestContentTypeChoice } from '@internals/shared'\nimport type { ast } from '@kubb/kit'\nimport type { ResolverTs } from '@kubb/plugin-ts'\nimport { File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx'\n\ntype Props = {\n /**\n * Name of the handler function.\n */\n name: string\n /**\n * Name of the contract client `<op>` the handler calls.\n */\n clientName: string\n /**\n * AST operation node.\n */\n node: ast.HttpOperationNode\n /**\n * TypeScript resolver for resolving param/data/response type names.\n */\n resolver: ResolverTs\n /**\n * The registered client plugin's `returnType`, read by the caller off `resolveClientOperation`.\n */\n returnType?: 'full' | 'data' | 'plain'\n}\n\nconst requestGroupOrder = ['path', 'query', 'headers', 'body'] as const\n\nexport function McpHandler({ name, clientName, node, resolver, returnType = 'full' }: Props): KubbReactNode {\n const { signature, groups } = buildRequestParamsSignature(node, resolver, { isConfigurable: false })\n const paramsSignature = [signature, 'ctx: ServerContext'].filter(Boolean).join(', ')\n\n // Forward the grouped config and MCP cancellation signal through the contract client. `throwOnError: true`\n // pins the result shape, since `throwOnErrorDefault: false` would otherwise resolve to the full result.\n const callArgs = requestGroupOrder.filter((key) => groups[key])\n const callConfig = `{ ${[...callArgs, 'signal: ctx.mcpReq.signal', 'throwOnError: true'].join(', ')} }`\n // Tool arguments carry no media type, so the call takes the client's default one.\n const callArg = hasRequestContentTypeChoice(node) ? castToClientOptions(callConfig, clientName, returnType) : callConfig\n const body = returnType === 'data' ? 'res' : 'res.data'\n\n const callToolResult = `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(${body})\n }\n ],\n structuredContent: { data: ${body} }\n}`\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n async\n export\n params={paramsSignature}\n JSDoc={{\n comments: buildOperationComments(node),\n }}\n returnType={'CallToolResult'}\n >\n {`const res = await ${clientName}(${callArg})`}\n <br />\n {callToolResult}\n </Function>\n </File.Source>\n )\n}\n","import type { ast } from '@kubb/kit'\nimport { Const, File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx'\n\ntype ZodParam = {\n name: string\n schemaName: string\n}\n\n/**\n * Composes individual param schemas into `z.object({ ... })`.\n */\nconst zodObject = (params: Array<ZodParam>) => `z.object({ ${params.map((p) => `${JSON.stringify(p.name)}: ${p.schemaName}`).join(', ')} })`\n\ntype Props = {\n /**\n * Human-readable server name passed to `new McpServer({ name })`.\n */\n serverName: string\n /**\n * Semantic version string passed to `new McpServer({ version })`.\n */\n serverVersion: string\n /**\n * Operations to register as MCP tools, each carrying its handler,\n * zod schema, and AST node metadata.\n */\n operations: Array<{\n tool: {\n name: string\n title?: string\n description: string\n }\n mcp: {\n name: string\n file: ast.FileNode\n }\n zod: {\n pathParams: Array<ZodParam>\n /**\n * Query params — individual schemas to compose into `z.object({ ... })`.\n */\n queryParams?: Array<ZodParam> | null\n /**\n * Header params — individual schemas to compose into `z.object({ ... })`.\n */\n headerParams?: Array<ZodParam> | null\n requestName?: string | null\n responseName?: string | null\n }\n }>\n}\n\nexport function Server({ serverName, serverVersion, operations }: Props): KubbReactNode {\n const registrations = operations\n .map(({ tool, mcp, zod }) => {\n // Group params into the same `{ path, query, headers, body }` shape the contract `<op>`\n // expects, so the MCP tool input mirrors every other client consumer.\n const entries: Array<{ key: string; value: string }> = []\n\n if (zod.pathParams.length) {\n entries.push({ key: 'path', value: zodObject(zod.pathParams) })\n }\n\n if (zod.queryParams) {\n entries.push({ key: 'query', value: zodObject(zod.queryParams) })\n }\n\n if (zod.headerParams) {\n entries.push({ key: 'headers', value: zodObject(zod.headerParams) })\n }\n\n if (zod.requestName) {\n entries.push({ key: 'body', value: zod.requestName })\n }\n\n const destructured = `{ ${entries.map((e) => e.key).join(', ')} }`\n const inputSchema = entries.length ? `z.object({ ${entries.map((e) => `${e.key}: ${e.value}`).join(', ')} })` : null\n const outputSchema = zod.responseName\n\n const config = [\n tool.title ? `title: ${JSON.stringify(tool.title)}` : null,\n `description: ${JSON.stringify(tool.description)}`,\n outputSchema ? `outputSchema: z.object({ data: ${outputSchema} })` : null,\n ]\n .filter(Boolean)\n .join(',\\n ')\n\n if (inputSchema) {\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n inputSchema: ${inputSchema},\n}, async (${destructured}, ctx) => {\n return ${mcp.name}(${destructured}, ctx)\n})\n `\n }\n\n return `\nserver.registerTool(${JSON.stringify(tool.name)}, {\n ${config},\n}, async (ctx) => {\n return ${mcp.name}(ctx)\n})\n `\n })\n .filter(Boolean)\n .join('\\n')\n\n return (\n <>\n <File.Source name=\"getServer\" isExportable isIndexable>\n <Function name=\"getServer\" export>\n {`const server = new McpServer({\n name: '${serverName}',\n version: '${serverVersion}',\n})\n${registrations}\nreturn server`}\n </Function>\n </File.Source>\n\n <File.Source name=\"server\" isExportable isIndexable>\n <Const name={'server'} export>\n {'getServer()'}\n </Const>\n </File.Source>\n\n <File.Source name=\"startServer\" isExportable isIndexable>\n <Function name=\"startServer\" async export>\n {`return serveStdio(getServer, {\n onerror: (error) => console.error('MCP server error:', error),\n })`}\n </Function>\n </File.Source>\n </>\n )\n}\n","import { type ast, Diagnostics, type Generator, type Group, type Output } from '@kubb/kit'\nimport { pluginTsName, type ResolverTs } from '@kubb/plugin-ts'\nimport { pluginZodName, type ResolverZod } from '@kubb/plugin-zod'\nimport type { ContractClientFactory } from './types.ts'\n\ntype GeneratorDriver = Parameters<NonNullable<Generator<ContractClientFactory>['operations']>>[1]['driver']\n\n/**\n * The two per-operation type names a generated client references: the grouped input and the\n * per-status responses record its `RequestResult` is keyed on.\n */\nexport type OperationTypeNames = {\n response: {\n /**\n * Resolves the name of the operation's grouped `{ body, path, query, headers }` input type.\n */\n options(node: ast.OperationNode): string\n /**\n * Resolves the name of the operation's per-status responses record type.\n */\n responses(node: ast.OperationNode): string\n }\n}\n\n/**\n * Where a generated client sources its operation types, plus the resolver and output the file\n * declaring them is resolved with.\n */\nexport type OperationTypeSource = OperationTypeNames & {\n /**\n * `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.\n */\n resolver: ResolverTs\n /**\n * The supplying plugin's own `output`, when it configured one.\n */\n output: Output | undefined\n /**\n * The supplying plugin's own `group`, when it configured one.\n */\n group: Group | undefined\n}\n\n/**\n * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`\n * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.\n */\nfunction toZodTypeResolver(resolver: ResolverZod): ResolverTs {\n const type = (name: string) => resolver.schema.type(name)\n\n return {\n ...resolver,\n // Class methods, so a spread drops them. `file` reads private fields, and `memo` gets its own key\n // space so these type names never share an entry with the zod names.\n file: resolver.file.bind(resolver),\n memo: (key: string, compute: () => unknown) => resolver.memo(`zodTypes:${key}`, compute),\n param: {\n name: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.name(node, p)),\n path: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.path(node, p)),\n query: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.query(node, p)),\n headers: (node: ast.OperationNode, p: ast.ParameterNode) => type(resolver.param.headers(node, p)),\n },\n response: {\n body: (node: ast.OperationNode) => type(resolver.response.body(node)),\n status: (node: ast.OperationNode, statusCode: ast.StatusCode) => type(resolver.response.status(node, statusCode)),\n response: (node: ast.OperationNode) => type(resolver.response.response(node)),\n responses: (node: ast.OperationNode) => type(resolver.response.responses(node)),\n options: (node: ast.OperationNode) => resolver.response.options(node),\n },\n } as unknown as ResolverTs\n}\n\n/**\n * Picks the plugin generated clients, query hooks, and MCP handlers take their operation types from.\n *\n * `pluginZod({ inferred: 'codec' })` wins, so a codec param takes its domain value. Otherwise `plugin-ts`\n * wins when it is in the pipeline, and without it any `pluginZod({ inferred })`. Throws\n * `KUBB_MISSING_DEPENDENCY` for `pluginName` when neither is available.\n *\n * @example\n * ```ts\n * const types = resolveOperationTypes(ctx.driver, ctx.plugin.name)\n * types.response.options(node) // 'GetPetByIdOptions', or 'GetPetByIdOptionsSchemaType' from zod\n * ```\n */\nexport function resolveOperationTypes(driver: GeneratorDriver, pluginName: string): OperationTypeSource {\n return driver.memo(`operationTypes:${pluginName}`, () => {\n const pluginTs = driver.getPlugin(pluginTsName)\n const pluginZod = driver.getPlugin(pluginZodName)\n\n if (pluginTs && pluginZod?.options?.inferred !== 'codec') {\n const resolver = driver.getResolver(pluginTsName)\n return { response: resolver.response, resolver, output: pluginTs.options?.output, group: pluginTs.options?.group ?? undefined }\n }\n\n if (!pluginZod?.options?.inferred) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.missingDependency,\n severity: 'error',\n message: `Plugin \"${pluginName}\" has no source for operation types.`,\n help: `Add \\`pluginTs()\\` before \"${pluginName}\", or add \\`pluginZod({ inferred: true })\\`.`,\n location: { kind: 'config' },\n plugin: pluginName,\n })\n }\n\n const resolver = toZodTypeResolver(driver.getResolver(pluginZodName))\n return { response: resolver.response, resolver, output: pluginZod.options.output, group: pluginZod.options.group ?? undefined }\n })\n}\n\ndeclare global {\n namespace Kubb {\n interface MemoRegistry {\n operationTypes: OperationTypeSource\n /**\n * Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.\n */\n zodTypes: unknown\n }\n }\n}\n","/**\n * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an\n * operation, shared so the selection rules and diagnostics stay in one place.\n *\n * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered\n * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own\n * inline client:\n *\n * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer\n * imports and calls them.\n * - `error` — no client plugin is registered, several are registered without a selector, the\n * requested one is missing, or `client` is not a known selector.\n *\n * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a\n * lone registered contract client plugin is picked up automatically.\n */\n\nimport { Diagnostics } from '@kubb/kit'\n\n// Canonical plugin names. They mirror the `pluginFetchName` / `pluginAxiosName` / `pluginClientName`\n// consts the plugins export, kept as literals so this internal needs no plugin install deps.\nconst pluginFetchName = 'plugin-fetch'\nconst pluginAxiosName = 'plugin-axios'\nconst pluginClientName = 'plugin-client'\n\n/**\n * The client selector accepted by a consumer's `client` option. Each calls a registered contract\n * client plugin.\n */\nexport type ClientSelector = 'fetch' | 'axios' | 'client'\n\n/**\n * The resolved client strategy stored in a consumer plugin's options: the generated code always\n * imports and calls a registered contract client plugin's `<op>`. The client runtime lives in\n * plugin-axios / plugin-fetch, so nothing is bundled by the consumer.\n */\nexport type ResolvedContractClient = { kind: 'contract'; pluginName: string }\n\n/**\n * The outcome of {@link resolveClient}.\n *\n * - `contract` names the contract client plugin whose `<op>` functions the consumer imports.\n * - `error` carries a setup diagnostic: its code, what is wrong, and how to fix it.\n */\nexport type ResolveClientResult =\n | ResolvedContractClient\n | { kind: 'error'; code: typeof Diagnostics.code.missingDependency | typeof Diagnostics.code.invalidPluginOptions; message: string; help: string }\n\nconst selectorToPlugin: Record<ClientSelector, string> = {\n fetch: pluginFetchName,\n axios: pluginAxiosName,\n client: pluginClientName,\n}\n\n// Every contract client plugin, in auto-detect priority order.\nconst contractPlugins = [pluginFetchName, pluginAxiosName, pluginClientName] as const\n\n/**\n * Applies the `client` resolution rules. See the module comment for the strategy shape.\n *\n * @example\n * ```ts\n * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })\n * // { kind: 'contract', pluginName: 'plugin-fetch' }\n * ```\n *\n * @example\n * ```ts\n * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })\n * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }\n * ```\n */\nexport function resolveClient(options: { client: ClientSelector | undefined; pluginNames: ReadonlyArray<string> }): ResolveClientResult {\n const { client, pluginNames } = options\n const has = (name: string) => pluginNames.includes(name)\n\n if (client === 'fetch' || client === 'axios' || client === 'client') {\n const pluginName = selectorToPlugin[client]\n if (!has(pluginName)) {\n return {\n kind: 'error',\n code: Diagnostics.code.missingDependency,\n message: `\\`client: '${client}'\\` is set but \\`@kubb/plugin-${client}\\` is not registered in \\`plugins\\`.`,\n help: `Add \\`@kubb/plugin-${client}\\` to \\`plugins\\`, or drop \\`client\\` to use a different client plugin.`,\n }\n }\n return { kind: 'contract', pluginName }\n }\n\n // A JS config bypasses the `ClientSelector` type, so reject unknown selectors instead of auto-detecting.\n if (client !== undefined) {\n return {\n kind: 'error',\n code: Diagnostics.code.invalidPluginOptions,\n message: `Option \\`client\\` is ${typeof client === 'string' ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,\n help: 'Set `client` to one of those values, or drop it to use the registered client plugin.',\n }\n }\n\n // `client` unset: auto-detect a lone registered contract client plugin.\n const registered = contractPlugins.filter(has)\n if (registered.length === 1) {\n return { kind: 'contract', pluginName: registered[0]! }\n }\n if (registered.length > 1) {\n return {\n kind: 'error',\n code: Diagnostics.code.invalidPluginOptions,\n message: `Multiple client plugins are registered (${registered.map((name) => `\\`@kubb/${name}\\``).join(', ')}) and \\`client\\` is not set.`,\n help: \"Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin.\",\n }\n }\n\n return {\n kind: 'error',\n code: Diagnostics.code.missingDependency,\n message: 'No client plugin is registered.',\n help: 'Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call.',\n }\n}\n\n/**\n * Resolves the contract client during a consumer plugin's setup hook.\n * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.\n * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer\n * fails fast with the same message.\n */\nexport function resolveContractClient(options: {\n plugin: string\n client: ClientSelector | undefined\n plugins?: ReadonlyArray<unknown>\n}): ResolvedContractClient {\n const { plugin, client, plugins = [] } = options\n const pluginNames = plugins.map((plugin) => (plugin as { name?: string }).name).filter((name): name is string => Boolean(name))\n const resolved = resolveClient({ client, pluginNames })\n if (resolved.kind === 'error') {\n const { code, message, help } = resolved\n throw new Diagnostics.Error({ code, severity: 'error', message, help, location: { kind: 'config' }, plugin })\n }\n return resolved\n}\n","import path from 'node:path'\nimport { operationFileEntry, operationKey } from '@internals/shared'\nimport type { ast, Exclude, Group, Include, Memo, Output, Override, Resolver } from '@kubb/kit'\nimport type { ReturnTypeOption } from './types.ts'\n\n/**\n * The resolved contract `<op>` for one operation: the generated function name, the file it lives in,\n * the client module path (where `RequestConfig` / `ResponseErrorConfig` come from), and the\n * registered client plugin's `returnType`.\n *\n * `clientPath` is the absolute `.kubb/client.ts` path for plugin-fetch / plugin-axios, or\n * plugin-client's `importPath`: a relative one is resolved against the `<op>` file to an absolute\n * path, a package name or alias is kept verbatim. `clientPathIsFile` tells a consumer whether to\n * make it relative to the importing file.\n */\nexport type ClientOperation = { name: string; path: string; clientPath: string; clientPathIsFile: boolean; returnType: ReturnTypeOption }\n\n/**\n * The client plugin options a dependent reads, including the filters that scope them per operation.\n */\ntype ClientPluginOptions = {\n output?: Output\n group?: Group | null\n returnType?: ReturnTypeOption\n importPath?: string\n exclude?: Array<Exclude>\n include?: Array<Include>\n override?: Array<Override<Omit<ClientPluginOptions, 'override'>>>\n}\n\nfunction isRelativeImport(importPath: string): boolean {\n return importPath.startsWith('.')\n}\n\n// plugin-client resolves a relative `importPath` from its `<op>` file, so do the same here.\nfunction resolveImportPath(options: { importPath: string; operationFile: string }): string {\n const { importPath, operationFile } = options\n return isRelativeImport(importPath) ? path.resolve(path.dirname(operationFile), importPath) : importPath\n}\n\n/**\n * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up\n * the registered contract client plugin's resolver and output. Works for any contract client plugin\n * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline\n * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then\n * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global\n * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.\n * With plugin-client they come from the user's `importPath` module instead.\n *\n * The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,\n * so several dependents reading the same client plugin for one operation in a single pass\n * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share\n * one computed result instead of each re-deriving the name and path.\n *\n * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its\n * `override` entries, the same resolution its own generator sees. A dependent's generated call body\n * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.\n */\nexport function resolveClientOperation(options: {\n clientPlugin: { pluginName: string } | null\n driver: {\n getPlugin: (name: string) => { options?: ClientPluginOptions } | undefined\n getResolver: (name: string) => Resolver\n }\n node: ast.OperationNode\n root: string\n output: Output\n memo: Memo\n}): ClientOperation | null {\n const { clientPlugin, driver, node, root, output, memo } = options\n if (!clientPlugin) return null\n\n return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {\n const resolver = driver.getResolver(clientPlugin.pluginName)\n const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {}\n const { exclude, include, override } = pluginOptions\n const hasOperationOptions = Boolean(exclude?.length || include?.length || override?.length)\n // Kubb's resolver always has `default`; the fallback keeps partial or custom resolvers working.\n const operationOptions =\n hasOperationOptions && resolver.default ? resolver.default.options(node, { options: pluginOptions, exclude, include, override }) : pluginOptions\n if (!operationOptions) return null\n\n const file = resolver.file({\n ...operationFileEntry(node, node.operationId),\n root,\n output: operationOptions.output ?? output,\n group: operationOptions.group ?? undefined,\n })\n\n const { importPath } = operationOptions\n const name = resolver.name(node.operationId)\n\n return {\n name: resolver.resolveName({ key: operationKey(node), name }),\n path: file.path,\n clientPath: importPath === undefined ? path.resolve(root, '.kubb/client.ts') : resolveImportPath({ importPath, operationFile: file.path }),\n clientPathIsFile: importPath === undefined || isRelativeImport(importPath),\n returnType: operationOptions.returnType ?? 'full',\n }\n })\n}\n","import { resolveClientOperation, resolveOperationTypes } from '@internals/client'\nimport { operationFileEntry, resolveDependencyOperationFile } from '@internals/shared'\nimport { ast, defineGenerator } from '@kubb/kit'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { McpHandler } from '../components/McpHandler.tsx'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Built-in operation generator for `@kubb/plugin-mcp`. Emits one MCP tool\n * handler per OpenAPI operation. The handler takes the grouped `{ path, query,\n * headers, body }` config and forwards it to the registered client plugin's\n * (`@kubb/plugin-axios` / `@kubb/plugin-fetch`) `<op>` function.\n */\nexport const mcpGenerator = defineGenerator<PluginMcp>({\n name: 'mcp',\n renderer: jsxRenderer,\n operation(node, ctx) {\n if (!ast.isHttpOperationNode(node)) return null\n const { resolver, driver, root, config } = ctx\n const { output, client, group } = ctx.options\n\n const types = resolveOperationTypes(driver, resolver.pluginName)\n const tsResolver = types.resolver\n\n // The registered contract client plugin owns the `<op>` the handler imports and calls.\n const contractOp = resolveClientOperation({ clientPlugin: { pluginName: client.pluginName }, driver, node, root, output, memo: ctx.memo })\n if (!contractOp) {\n return null\n }\n\n // The handler signature references the grouped `<Name>Options`.\n const optionsName = tsResolver.response.options(node)\n\n const meta = {\n name: resolver.handler.name(node),\n file: resolver.file({ ...operationFileEntry(node, node.operationId), root, output, group: group ?? undefined }),\n fileTs: resolveDependencyOperationFile({\n memo: ctx.memo,\n node,\n resolver: tsResolver,\n root,\n output: types.output ?? output,\n group: types.group,\n }),\n } as const\n\n return (\n <File\n baseName={meta.file.baseName}\n path={meta.file.path}\n meta={meta.file.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}\n >\n {meta.fileTs && optionsName && <File.Import name={[optionsName]} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />}\n <File.Import name={['CallToolResult', 'ServerContext']} path={'@modelcontextprotocol/server'} isTypeOnly />\n\n <File.Import name={[contractOp.name]} root={meta.file.path} path={contractOp.path} />\n\n <McpHandler name={meta.name} clientName={contractOp.name} node={node} resolver={tsResolver} returnType={contractOp.returnType} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { getOperationParameters, getPrimarySuccessResponse, operationFileEntry } from '@internals/shared'\nimport { getRelativePath } from '@internals/utils'\nimport { ast, defineGenerator } from '@kubb/kit'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { Server } from '../components/Server.tsx'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Default v5 server generator for `@kubb/plugin-mcp`.\n *\n * Uses individual zod schemas for each param (e.g. `createPetsPathUuidSchema`, `createPetsQueryOffsetSchema`)\n * and `resolveResponseStatusName` for per-status response schemas.\n * Query and header params are composed into `z.object({ ... })` from individual schemas.\n */\nexport const serverGenerator = defineGenerator<PluginMcp>({\n name: 'operations',\n renderer: jsxRenderer,\n operations(nodes, ctx) {\n const { config, resolver, plugin, driver, root } = ctx\n const { output, group } = ctx.options\n\n const pluginZod = ctx.requirePlugin(pluginZodName)\n\n const zodResolver = driver.getResolver(pluginZodName)\n\n const fileAt = <TName extends `${string}.${string}`>(baseName: TName) => ({\n baseName,\n path: path.resolve(root, output.path, baseName),\n meta: { pluginName: plugin.name },\n })\n const serverFile = fileAt('server.ts')\n const startFile = fileAt('start.ts')\n const jsonFile = fileAt('.mcp.json')\n\n // MCP clients spawn the command from their own working directory, usually the project root,\n // so `args` points at `start.ts` relative to `config.root` instead of the `.mcp.json` folder.\n const mcpConfig = {\n mcpServers: {\n [ctx.meta.title || 'server']: {\n type: 'stdio',\n command: 'npx',\n args: ['tsx', getRelativePath(path.resolve(config.root), startFile.path)],\n },\n },\n }\n\n const operationsMapped = nodes.filter(ast.isHttpOperationNode).map((node) => {\n const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node)\n\n const fileEntry = operationFileEntry(node, node.operationId)\n const mcpFile = resolver.file({ ...fileEntry, root, output, group: group ?? undefined })\n const zodFile = zodResolver.file({\n ...fileEntry,\n root,\n output: pluginZod.options?.output ?? output,\n group: pluginZod.options?.group ?? undefined,\n })\n\n const requestName = node.requestBody?.content?.[0]?.schema ? zodResolver.response.body(node) : null\n const successStatus = getPrimarySuccessResponse(node)?.statusCode\n const responseName = successStatus ? zodResolver.response.status(node, successStatus) : null\n\n const resolveParams = (params: typeof pathParams) => params.map((p) => ({ name: p.name, schemaName: zodResolver.param.name(node, p) }))\n\n return {\n tool: {\n name: node.operationId,\n title: node.summary || undefined,\n description: node.description || `Make a ${node.method.toUpperCase()} request to ${node.path}`,\n },\n mcp: {\n name: resolver.handler.name(node),\n file: mcpFile,\n },\n zod: {\n pathParams: resolveParams(pathParams),\n queryParams: queryParams.length ? resolveParams(queryParams) : null,\n headerParams: headerParams.length ? resolveParams(headerParams) : null,\n requestName,\n responseName,\n file: zodFile,\n },\n }\n })\n\n const imports = operationsMapped.flatMap(({ mcp, zod }) => {\n const zodNames = [\n ...zod.pathParams.map((p) => p.schemaName),\n ...(zod.queryParams ?? []).map((p) => p.schemaName),\n ...(zod.headerParams ?? []).map((p) => p.schemaName),\n zod.requestName,\n zod.responseName,\n ].filter((name): name is string => Boolean(name))\n\n const uniqueNames = [...new Set(zodNames)].sort()\n\n return [\n <File.Import key={mcp.name} name={[mcp.name]} root={serverFile.path} path={mcp.file.path} />,\n uniqueNames.length > 0 && <File.Import key={`zod-${mcp.name}`} name={uniqueNames} root={serverFile.path} path={zod.file.path} />,\n ].filter(Boolean)\n })\n\n return (\n <>\n <File\n baseName={serverFile.baseName}\n path={serverFile.path}\n meta={serverFile.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: serverFile.path, baseName: serverFile.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: serverFile.path, baseName: serverFile.baseName } })}\n >\n <File.Import name={['McpServer']} path={'@modelcontextprotocol/server'} />\n <File.Import name={['serveStdio']} path={'@modelcontextprotocol/server/stdio'} />\n <File.Import name={['z']} path={'zod'} />\n\n {imports}\n <Server serverName={ctx.meta.title ?? 'server'} serverVersion={ctx.meta.version ?? '0.0.0'} operations={operationsMapped} />\n </File>\n\n <File\n baseName={startFile.baseName}\n path={startFile.path}\n meta={startFile.meta}\n banner={resolver.default.banner(ctx.meta, { output, config, file: { path: startFile.path, baseName: startFile.baseName } })}\n footer={resolver.default.footer(ctx.meta, { output, config, file: { path: startFile.path, baseName: startFile.baseName } })}\n >\n <File.Import name={['startServer']} root={startFile.path} path={serverFile.path} />\n {/* Not indexable: barrels must not re-export this entry, importing it starts the server. */}\n <File.Source name=\"start\">{'void startServer()'}</File.Source>\n </File>\n\n <File baseName={jsonFile.baseName} path={jsonFile.path} meta={jsonFile.meta}>\n <File.Source name=\"server\">{`${JSON.stringify(mcpConfig, null, 2)}\\n`}</File.Source>\n </File>\n </>\n )\n },\n})\n","","","import { operationKey } from '@internals/shared'\nimport { camelCase, createResolver } from '@kubb/kit'\nimport type { PluginMcp } from '../types.ts'\n\n/**\n * Default resolver used by `@kubb/plugin-mcp`. Decides the names and file\n * paths for every generated MCP tool handler. Function names get a `Handler`\n * suffix so an operation `addPet` becomes `addPetHandler`.\n *\n * @example Resolve a handler name\n * ```ts\n * import { resolverMcp } from '@kubb/plugin-mcp'\n *\n * resolverMcp.name('addPet') // 'addPetHandler'\n * ```\n */\nexport const resolverMcp = createResolver<PluginMcp>({\n pluginName: 'plugin-mcp',\n name(name) {\n return this.memo(`name:${name}`, () => camelCase(name, { suffix: 'handler' }))\n },\n handler: {\n name(node) {\n const name = this.name(node.operationId)\n return this.resolveName({ key: operationKey(node, 'handler', 'name'), name })\n },\n },\n})\n","import { createGroupConfig } from '@internals/shared'\n\nimport { resolveContractClient } from '@internals/client'\nimport { addGenerator, defineExtension, Resolver, setMacros, setResolver, useConfig } from '@kubb/kit'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator } from './generators/mcpGenerator.tsx'\nimport { serverGenerator } from './generators/serverGenerator.tsx'\nimport { resolverMcp } from './resolvers/resolverMcp.ts'\nimport type { PluginMcp, ResolverMcp } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-mcp`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\n/**\n * Generates a Model Context Protocol (MCP) server from an OpenAPI spec. Every\n * operation becomes a typed MCP tool that AI assistants (Claude Desktop, Claude\n * Code, MCP-compatible clients) can call directly. Each handler calls a contract\n * client `<op>` from a registered `@kubb/plugin-axios` or `@kubb/plugin-fetch`.\n * Next to the handlers it writes `server.ts`, a `start.ts` entry that serves the\n * tools over stdio, and a `.mcp.json` that runs `start.ts` with `tsx`.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb/config'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginZod } from '@kubb/plugin-zod'\n * import { pluginFetch } from '@kubb/plugin-fetch'\n * import { pluginMcp } from '@kubb/plugin-mcp'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginZod(),\n * pluginFetch({ baseURL: 'https://petstore.swagger.io/v2' }),\n * pluginMcp({ output: { path: 'mcp' } }),\n * ],\n * })\n * ```\n */\nexport const pluginMcp = defineExtension<PluginMcp>({\n kind: 'plugin',\n meta: { name: pluginMcpName, version, compatibility },\n dependencies: { [pluginTsName]: { optional: true }, [pluginZodName]: {} },\n setup(options) {\n const {\n output = { path: 'mcp', barrel: { type: 'named' } },\n group,\n exclude = [],\n include,\n override = [],\n client,\n resolver: userResolver,\n macros: userMacros,\n } = options\n\n const resolver = userResolver ? Resolver.merge<ResolverMcp>(resolverMcp, userResolver) : resolverMcp\n\n setResolver(resolver)\n if (userMacros?.length) {\n setMacros(userMacros)\n }\n addGenerator(mcpGenerator, serverGenerator)\n\n return {\n output,\n exclude,\n include,\n override,\n group: createGroupConfig(group),\n client: resolveContractClient({ plugin: pluginMcpName, client, plugins: useConfig().plugins }),\n resolver,\n }\n },\n})\n\nexport default pluginMcp\n"],"mappings":";;;;;;;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,MAAyB,MAAc,UAAyC,OAA2B;CAC5I,OAAO;EACL;EACA;EACA,KAAK,KAAK,KAAK,MAAM;EACrB,MAAM,KAAK;CACb;AACF;;;;;;;;;;;;AAaA,SAAgB,+BAA+B,SAO9B;CACf,MAAM,EAAE,MAAM,MAAM,UAAU,MAAM,QAAQ,UAAU;CAEtD,OAAO,KAAK,GAAG,SAAS,WAAW,iBAAiB,KAAK,qBACvD,SAAS,KAAK;EAAE,GAAG,mBAAmB,MAAM,KAAK,WAAW;EAAG;EAAM;EAAQ,OAAO,SAAS,KAAA;CAAU,CAAC,CAC1G;AACF;AA8DA,SAAS,iBAAiB,MAAyB,MAA2C;CAC5F,IAAI,CAAC,MACH,OAAO;CAGT,IAAI,OAAO,SAAS,YAClB,OAAO,KAAK,IAAI,KAAK;CAGvB,OAAO,KAAK,OAAO,UAAU,IAAI,OAAO,KAAK,IAAI,EAAE,KAAK;AAC1D;;;;;AAMA,SAAS,qBAAqB,cAAyC;CACrE,MAAM,yBAAyB,aAAa,SAAS;C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;EAAE,GAClD,OACA,UAAU,CAAC,GACX,SACA,WAAW,CAAC,GACZ,QACA,UAAU,cACV,QAAQ,eACN;EAEJ,MAAM,WAAW,eAAe,SAAS,MAAmB,aAAa,YAAY,IAAI;EAEzF,YAAY,QAAQ;EACpB,IAAI,YAAY,QACd,UAAU,UAAU;EAEtB,aAAa,cAAc,eAAe;EAE1C,OAAO;GACL;GACA;GACA;GACA;GACA,OAAO,kBAAkB,KAAK;GAC9B,QAAQ,sBAAsB;IAAE,QAAQ;IAAe;IAAQ,SAAS,UAAU,CAAC,CAAC;GAAQ,CAAC;GAC7F;EACF;CACF;AACF,CAAC"}
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "dependencies": ["plugin-ts", "plugin-zod"],
22
22
  "compatibility": {
23
- "kubb": ">=5.14.6",
23
+ "kubb": ">=5.16.0",
24
24
  "node": ">=22.22"
25
25
  },
26
26
  "role": "consumer",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-mcp",
3
- "version": "5.4.0",
3
+ "version": "5.4.2",
4
4
  "description": "Generate Model Context Protocol (MCP) tool definitions with Kubb. Expose your REST APIs as AI-callable tools for LLMs, Claude, ChatGPT, and other AI assistants.",
5
5
  "keywords": [
6
6
  "ai",
@@ -68,10 +68,10 @@
68
68
  "registry": "https://registry.npmjs.org/"
69
69
  },
70
70
  "dependencies": {
71
- "@kubb/kit": "^5.15.2",
72
- "@kubb/plugin-ts": "^5.4.0",
73
- "@kubb/plugin-zod": "^5.8.0",
74
- "@kubb/renderer-jsx": "^5.15.2"
71
+ "@kubb/kit": "^5.16.0",
72
+ "@kubb/plugin-ts": "^5.4.2",
73
+ "@kubb/plugin-zod": "^5.8.3",
74
+ "@kubb/renderer-jsx": "^5.16.0"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@internals/client": "0.0.0",