@kubb/plugin-mcp 4.4.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- import { h as File, r as OperationSchemas } from "./SchemaGenerator-wXj7HtlS.js";
1
+ import { a as OperationSchemas } from "./index-BlpJVG8h.js";
2
+ import { KubbFile } from "@kubb/fabric-core/types";
2
3
  import { KubbNode } from "@kubb/react-fabric/types";
3
4
 
4
5
  //#region src/components/Server.d.ts
@@ -13,11 +14,11 @@ type Props = {
13
14
  };
14
15
  mcp: {
15
16
  name: string;
16
- file: File;
17
+ file: KubbFile.File;
17
18
  };
18
19
  zod: {
19
20
  name: string;
20
- file: File;
21
+ file: KubbFile.File;
21
22
  schemas: OperationSchemas;
22
23
  };
23
24
  type: {
@@ -1,14 +1,14 @@
1
1
  const require_Server = require('./Server-vKCXRjmg.cjs');
2
- let __kubb_plugin_oas = require("@kubb/plugin-oas");
3
- __kubb_plugin_oas = require_Server.__toESM(__kubb_plugin_oas);
2
+ let node_path = require("node:path");
3
+ node_path = require_Server.__toESM(node_path);
4
4
  let __kubb_plugin_ts = require("@kubb/plugin-ts");
5
5
  __kubb_plugin_ts = require_Server.__toESM(__kubb_plugin_ts);
6
6
  let __kubb_plugin_zod = require("@kubb/plugin-zod");
7
7
  __kubb_plugin_zod = require_Server.__toESM(__kubb_plugin_zod);
8
- let __kubb_core_hooks = require("@kubb/core/hooks");
9
- __kubb_core_hooks = require_Server.__toESM(__kubb_core_hooks);
10
8
  let __kubb_plugin_client_components = require("@kubb/plugin-client/components");
11
9
  __kubb_plugin_client_components = require_Server.__toESM(__kubb_plugin_client_components);
10
+ let __kubb_plugin_oas_generators = require("@kubb/plugin-oas/generators");
11
+ __kubb_plugin_oas_generators = require_Server.__toESM(__kubb_plugin_oas_generators);
12
12
  let __kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
13
13
  __kubb_plugin_oas_hooks = require_Server.__toESM(__kubb_plugin_oas_hooks);
14
14
  let __kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
@@ -17,14 +17,16 @@ let __kubb_react_fabric = require("@kubb/react-fabric");
17
17
  __kubb_react_fabric = require_Server.__toESM(__kubb_react_fabric);
18
18
  let __kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
19
19
  __kubb_react_fabric_jsx_runtime = require_Server.__toESM(__kubb_react_fabric_jsx_runtime);
20
+ let __kubb_core_hooks = require("@kubb/core/hooks");
21
+ __kubb_core_hooks = require_Server.__toESM(__kubb_core_hooks);
20
22
 
21
23
  //#region src/generators/mcpGenerator.tsx
22
- const mcpGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
24
+ const mcpGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
23
25
  name: "mcp",
24
- Operation({ operation }) {
25
- const { options } = (0, __kubb_core_hooks.usePlugin)();
26
+ Operation({ config, operation, generator, plugin }) {
27
+ const { options } = plugin;
26
28
  const oas = (0, __kubb_plugin_oas_hooks.useOas)();
27
- const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
29
+ const { getSchemas, getName, getFile } = (0, __kubb_plugin_oas_hooks.useOperationManager)(generator);
28
30
  const mcp = {
29
31
  name: getName(operation, {
30
32
  type: "function",
@@ -52,20 +54,45 @@ const mcpGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
52
54
  output: options.output
53
55
  }),
54
56
  children: [
57
+ options.client.importPath ? /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric_jsx_runtime.Fragment, { children: [
58
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
59
+ name: "fetch",
60
+ path: options.client.importPath
61
+ }),
62
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
63
+ name: ["RequestConfig", "ResponseErrorConfig"],
64
+ path: options.client.importPath,
65
+ isTypeOnly: true
66
+ }),
67
+ options.client.dataReturnType === "full" && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
68
+ name: ["ResponseConfig"],
69
+ path: options.client.importPath,
70
+ isTypeOnly: true
71
+ })
72
+ ] }) : /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric_jsx_runtime.Fragment, { children: [
73
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
74
+ name: "fetch",
75
+ root: mcp.file.path,
76
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetcher.ts")
77
+ }),
78
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
79
+ name: ["RequestConfig", "ResponseErrorConfig"],
80
+ root: mcp.file.path,
81
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetcher.ts"),
82
+ isTypeOnly: true
83
+ }),
84
+ options.client.dataReturnType === "full" && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
85
+ name: ["ResponseConfig"],
86
+ root: mcp.file.path,
87
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetcher.ts"),
88
+ isTypeOnly: true
89
+ })
90
+ ] }),
55
91
  /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
56
92
  name: ["CallToolResult"],
57
93
  path: "@modelcontextprotocol/sdk/types",
58
94
  isTypeOnly: true
59
95
  }),
60
- /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
61
- name: "fetch",
62
- path: options.client.importPath
63
- }),
64
- /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
65
- name: ["RequestConfig", "ResponseErrorConfig"],
66
- path: options.client.importPath,
67
- isTypeOnly: true
68
- }),
69
96
  /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
70
97
  name: [
71
98
  type.schemas.request?.name,
@@ -87,7 +114,7 @@ const mcpGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
87
114
  operation,
88
115
  typeSchemas: type.schemas,
89
116
  zodSchemas: void 0,
90
- dataReturnType: options.client.dataReturnType,
117
+ dataReturnType: options.client.dataReturnType || "data",
91
118
  paramsType: "object",
92
119
  paramsCasing: "camelcase",
93
120
  pathParamsType: "object",
@@ -115,13 +142,13 @@ const mcpGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
115
142
 
116
143
  //#endregion
117
144
  //#region src/generators/serverGenerator.tsx
118
- const serverGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
145
+ const serverGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
119
146
  name: "operations",
120
- Operations({ operations, options }) {
121
- const plugin = (0, __kubb_core_hooks.usePlugin)();
147
+ Operations({ operations, generator, plugin }) {
122
148
  const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
149
+ const { options } = plugin;
123
150
  const oas = (0, __kubb_plugin_oas_hooks.useOas)();
124
- const { getFile, getName, getSchemas } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
151
+ const { getFile, getName, getSchemas } = (0, __kubb_plugin_oas_hooks.useOperationManager)(generator);
125
152
  const name = "server";
126
153
  const file = pluginManager.getFile({
127
154
  name,
@@ -244,4 +271,4 @@ Object.defineProperty(exports, 'serverGenerator', {
244
271
  return serverGenerator;
245
272
  }
246
273
  });
247
- //# sourceMappingURL=generators-8HowWmDg.cjs.map
274
+ //# sourceMappingURL=generators-CSDgJv8G.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-CSDgJv8G.cjs","names":["pluginTsName","File","path","Client","pluginZodName","pluginTsName","File","Server"],"sources":["../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx"],"sourcesContent":["import path from 'node:path'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport type { PluginMcp } from '../types'\n\nexport const mcpGenerator = createReactGenerator<PluginMcp>({\n name: 'mcp',\n Operation({ config, operation, generator, plugin }) {\n const { options } = plugin\n const oas = useOas()\n\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mcp = {\n name: getName(operation, { type: 'function', suffix: 'handler' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File\n baseName={mcp.file.baseName}\n path={mcp.file.path}\n meta={mcp.file.meta}\n banner={getBanner({ oas, output: options.output })}\n footer={getFooter({ oas, output: options.output })}\n >\n {options.client.importPath ? (\n <>\n <File.Import name={'fetch'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n </>\n ) : (\n <>\n <File.Import name={'fetch'} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')} />\n <File.Import\n name={['RequestConfig', 'ResponseErrorConfig']}\n root={mcp.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')}\n isTypeOnly\n />\n {options.client.dataReturnType === 'full' && (\n <File.Import name={['ResponseConfig']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')} isTypeOnly />\n )}\n </>\n )}\n <File.Import name={['CallToolResult']} path={'@modelcontextprotocol/sdk/types'} isTypeOnly />\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={mcp.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <Client\n name={mcp.name}\n isConfigurable={false}\n returnType={'Promise<CallToolResult>'}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={undefined}\n dataReturnType={options.client.dataReturnType || 'data'}\n paramsType={'object'}\n paramsCasing={'camelcase'}\n pathParamsType={'object'}\n parser={'client'}\n >\n {options.client.dataReturnType === 'data' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res.data)\n }\n ]\n }`}\n {options.client.dataReturnType === 'full' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res)\n }\n ]\n }`}\n </Client>\n </File>\n )\n },\n})\n","import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File } from '@kubb/react-fabric'\nimport { Server } from '../components/Server'\nimport type { PluginMcp } from '../types'\n\nexport const serverGenerator = createReactGenerator<PluginMcp>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const pluginManager = usePluginManager()\n const { options } = plugin\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager(generator)\n\n const name = 'server'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: plugin.key })\n\n const jsonFile = pluginManager.getFile({ name: '.mcp', extname: '.json', pluginKey: plugin.key })\n\n const operationsMapped = operations.map((operation) => {\n return {\n tool: {\n name: operation.getOperationId() || operation.getSummary() || `${operation.method.toUpperCase()} ${operation.path}`,\n description: operation.getDescription() || `Make a ${operation.method.toUpperCase()} request to ${operation.path}`,\n },\n mcp: {\n name: getName(operation, {\n type: 'function',\n suffix: 'handler',\n }),\n file: getFile(operation),\n },\n zod: {\n name: getName(operation, {\n type: 'function',\n pluginKey: [pluginZodName],\n }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n },\n type: {\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n },\n }\n })\n\n const imports = operationsMapped.flatMap(({ mcp, zod }) => {\n return [\n <File.Import key={mcp.name} name={[mcp.name]} root={file.path} path={mcp.file.path} />,\n <File.Import\n key={zod.name}\n name={[zod.schemas.request?.name, zod.schemas.pathParams?.name, zod.schemas.queryParams?.name, zod.schemas.headerParams?.name].filter(Boolean)}\n root={file.path}\n path={zod.file.path}\n />,\n ]\n })\n\n return (\n <>\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: options.output })}\n >\n <File.Import name={['McpServer']} path={'@modelcontextprotocol/sdk/server/mcp'} />\n <File.Import name={['StdioServerTransport']} path={'@modelcontextprotocol/sdk/server/stdio'} />\n\n {imports}\n <Server name={name} serverName={oas.api.info?.title} serverVersion={oas.getVersion()} operations={operationsMapped} />\n </File>\n\n <File baseName={jsonFile.baseName} path={jsonFile.path} meta={jsonFile.meta}>\n <File.Source name={name}>\n {`\n {\n \"mcpServers\": {\n \"${oas.api.info?.title || 'server'}\": {\n \"type\": \"stdio\",\n \"command\": \"npx\",\n \"args\": [\"tsx\", \"${file.path}\"]\n }\n }\n }\n `}\n </File.Source>\n </File>\n </>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,sEAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EAAE,YAAY;EACpB,MAAM,2CAAc;EAEpB,MAAM,E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AK;KAAO,MAAM,CAAC,uBAAuB;KAAE,MAAM;MAA4C;IAE9F;IACD,yDAACC;KAAa;KAAM,YAAY,IAAI,IAAI,MAAM;KAAO,eAAe,IAAI,YAAY;KAAE,YAAY;MAAoB;;IACjH,EAEP,yDAACD;GAAK,UAAU,SAAS;GAAU,MAAM,SAAS;GAAM,MAAM,SAAS;aACrE,yDAACA,yBAAK;IAAa;cAChB;;;iBAGI,IAAI,IAAI,MAAM,SAAS,SAAS;;;mCAGd,KAAK,KAAK;;;;;KAKrB;IACT,IACN;;CAGR,CAAC"}
@@ -1,21 +1,22 @@
1
1
  import { t as Server } from "./Server-DMDo69md.js";
2
- import { createReactGenerator } from "@kubb/plugin-oas";
2
+ import path from "node:path";
3
3
  import { pluginTsName } from "@kubb/plugin-ts";
4
4
  import { pluginZodName } from "@kubb/plugin-zod";
5
- import { usePlugin, usePluginManager } from "@kubb/core/hooks";
6
5
  import { Client } from "@kubb/plugin-client/components";
6
+ import { createReactGenerator } from "@kubb/plugin-oas/generators";
7
7
  import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
8
8
  import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
9
9
  import { File } from "@kubb/react-fabric";
10
10
  import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
11
+ import { usePluginManager } from "@kubb/core/hooks";
11
12
 
12
13
  //#region src/generators/mcpGenerator.tsx
13
14
  const mcpGenerator = createReactGenerator({
14
15
  name: "mcp",
15
- Operation({ operation }) {
16
- const { options } = usePlugin();
16
+ Operation({ config, operation, generator, plugin }) {
17
+ const { options } = plugin;
17
18
  const oas = useOas();
18
- const { getSchemas, getName, getFile } = useOperationManager();
19
+ const { getSchemas, getName, getFile } = useOperationManager(generator);
19
20
  const mcp = {
20
21
  name: getName(operation, {
21
22
  type: "function",
@@ -43,20 +44,45 @@ const mcpGenerator = createReactGenerator({
43
44
  output: options.output
44
45
  }),
45
46
  children: [
47
+ options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
48
+ /* @__PURE__ */ jsx(File.Import, {
49
+ name: "fetch",
50
+ path: options.client.importPath
51
+ }),
52
+ /* @__PURE__ */ jsx(File.Import, {
53
+ name: ["RequestConfig", "ResponseErrorConfig"],
54
+ path: options.client.importPath,
55
+ isTypeOnly: true
56
+ }),
57
+ options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
58
+ name: ["ResponseConfig"],
59
+ path: options.client.importPath,
60
+ isTypeOnly: true
61
+ })
62
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
63
+ /* @__PURE__ */ jsx(File.Import, {
64
+ name: "fetch",
65
+ root: mcp.file.path,
66
+ path: path.resolve(config.root, config.output.path, ".kubb/fetcher.ts")
67
+ }),
68
+ /* @__PURE__ */ jsx(File.Import, {
69
+ name: ["RequestConfig", "ResponseErrorConfig"],
70
+ root: mcp.file.path,
71
+ path: path.resolve(config.root, config.output.path, ".kubb/fetcher.ts"),
72
+ isTypeOnly: true
73
+ }),
74
+ options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
75
+ name: ["ResponseConfig"],
76
+ root: mcp.file.path,
77
+ path: path.resolve(config.root, config.output.path, ".kubb/fetcher.ts"),
78
+ isTypeOnly: true
79
+ })
80
+ ] }),
46
81
  /* @__PURE__ */ jsx(File.Import, {
47
82
  name: ["CallToolResult"],
48
83
  path: "@modelcontextprotocol/sdk/types",
49
84
  isTypeOnly: true
50
85
  }),
51
- /* @__PURE__ */ jsx(File.Import, {
52
- name: "fetch",
53
- path: options.client.importPath
54
- }),
55
- /* @__PURE__ */ jsx(File.Import, {
56
- name: ["RequestConfig", "ResponseErrorConfig"],
57
- path: options.client.importPath,
58
- isTypeOnly: true
59
- }),
60
86
  /* @__PURE__ */ jsx(File.Import, {
61
87
  name: [
62
88
  type.schemas.request?.name,
@@ -78,7 +104,7 @@ const mcpGenerator = createReactGenerator({
78
104
  operation,
79
105
  typeSchemas: type.schemas,
80
106
  zodSchemas: void 0,
81
- dataReturnType: options.client.dataReturnType,
107
+ dataReturnType: options.client.dataReturnType || "data",
82
108
  paramsType: "object",
83
109
  paramsCasing: "camelcase",
84
110
  pathParamsType: "object",
@@ -108,11 +134,11 @@ const mcpGenerator = createReactGenerator({
108
134
  //#region src/generators/serverGenerator.tsx
109
135
  const serverGenerator = createReactGenerator({
110
136
  name: "operations",
111
- Operations({ operations, options }) {
112
- const plugin = usePlugin();
137
+ Operations({ operations, generator, plugin }) {
113
138
  const pluginManager = usePluginManager();
139
+ const { options } = plugin;
114
140
  const oas = useOas();
115
- const { getFile, getName, getSchemas } = useOperationManager();
141
+ const { getFile, getName, getSchemas } = useOperationManager(generator);
116
142
  const name = "server";
117
143
  const file = pluginManager.getFile({
118
144
  name,
@@ -224,4 +250,4 @@ const serverGenerator = createReactGenerator({
224
250
 
225
251
  //#endregion
226
252
  export { mcpGenerator as n, serverGenerator as t };
227
- //# sourceMappingURL=generators-Bp0d1HbP.js.map
253
+ //# sourceMappingURL=generators-DP6UAisL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-DP6UAisL.js","names":[],"sources":["../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx"],"sourcesContent":["import path from 'node:path'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport type { PluginMcp } from '../types'\n\nexport const mcpGenerator = createReactGenerator<PluginMcp>({\n name: 'mcp',\n Operation({ config, operation, generator, plugin }) {\n const { options } = plugin\n const oas = useOas()\n\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mcp = {\n name: getName(operation, { type: 'function', suffix: 'handler' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File\n baseName={mcp.file.baseName}\n path={mcp.file.path}\n meta={mcp.file.meta}\n banner={getBanner({ oas, output: options.output })}\n footer={getFooter({ oas, output: options.output })}\n >\n {options.client.importPath ? (\n <>\n <File.Import name={'fetch'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n </>\n ) : (\n <>\n <File.Import name={'fetch'} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')} />\n <File.Import\n name={['RequestConfig', 'ResponseErrorConfig']}\n root={mcp.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')}\n isTypeOnly\n />\n {options.client.dataReturnType === 'full' && (\n <File.Import name={['ResponseConfig']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')} isTypeOnly />\n )}\n </>\n )}\n <File.Import name={['CallToolResult']} path={'@modelcontextprotocol/sdk/types'} isTypeOnly />\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={mcp.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <Client\n name={mcp.name}\n isConfigurable={false}\n returnType={'Promise<CallToolResult>'}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={undefined}\n dataReturnType={options.client.dataReturnType || 'data'}\n paramsType={'object'}\n paramsCasing={'camelcase'}\n pathParamsType={'object'}\n parser={'client'}\n >\n {options.client.dataReturnType === 'data' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res.data)\n }\n ]\n }`}\n {options.client.dataReturnType === 'full' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res)\n }\n ]\n }`}\n </Client>\n </File>\n )\n },\n})\n","import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File } from '@kubb/react-fabric'\nimport { Server } from '../components/Server'\nimport type { PluginMcp } from '../types'\n\nexport const serverGenerator = createReactGenerator<PluginMcp>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const pluginManager = usePluginManager()\n const { options } = plugin\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager(generator)\n\n const name = 'server'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: plugin.key })\n\n const jsonFile = pluginManager.getFile({ name: '.mcp', extname: '.json', pluginKey: plugin.key })\n\n const operationsMapped = operations.map((operation) => {\n return {\n tool: {\n name: operation.getOperationId() || operation.getSummary() || `${operation.method.toUpperCase()} ${operation.path}`,\n description: operation.getDescription() || `Make a ${operation.method.toUpperCase()} request to ${operation.path}`,\n },\n mcp: {\n name: getName(operation, {\n type: 'function',\n suffix: 'handler',\n }),\n file: getFile(operation),\n },\n zod: {\n name: getName(operation, {\n type: 'function',\n pluginKey: [pluginZodName],\n }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n },\n type: {\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n },\n }\n })\n\n const imports = operationsMapped.flatMap(({ mcp, zod }) => {\n return [\n <File.Import key={mcp.name} name={[mcp.name]} root={file.path} path={mcp.file.path} />,\n <File.Import\n key={zod.name}\n name={[zod.schemas.request?.name, zod.schemas.pathParams?.name, zod.schemas.queryParams?.name, zod.schemas.headerParams?.name].filter(Boolean)}\n root={file.path}\n path={zod.file.path}\n />,\n ]\n })\n\n return (\n <>\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: options.output })}\n >\n <File.Import name={['McpServer']} path={'@modelcontextprotocol/sdk/server/mcp'} />\n <File.Import name={['StdioServerTransport']} path={'@modelcontextprotocol/sdk/server/stdio'} />\n\n {imports}\n <Server name={name} serverName={oas.api.info?.title} serverVersion={oas.getVersion()} operations={operationsMapped} />\n </File>\n\n <File baseName={jsonFile.baseName} path={jsonFile.path} meta={jsonFile.meta}>\n <File.Source name={name}>\n {`\n {\n \"mcpServers\": {\n \"${oas.api.info?.title || 'server'}\": {\n \"type\": \"stdio\",\n \"command\": \"npx\",\n \"args\": [\"tsx\", \"${file.path}\"]\n }\n }\n }\n `}\n </File.Source>\n </File>\n </>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AASA,MAAa,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EAAE,YAAY;EACpB,MAAM,MAAM,QAAQ;EAEpB,MAAM,EAAE,YAAY,SAAS,YAAY,oBAAoB,UAAU;EAEvE,MAAM,MAAM;GACV,MAAM,QAAQ,WAAW;IAAE,MAAM;IAAY,QAAQ;IAAW,CAAC;GACjE,MAAM,QAAQ,UAAU;GACzB;EAED,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,WAAW,CAAC,aAAa,EAAE,CAAC;GACvD,SAAS,WAAW,WAAW;IAAE,WAAW,CAAC,aAAa;IAAE,MAAM;IAAQ,CAAC;GAC5E;AAED,SACE,qBAAC;GACC,UAAU,IAAI,KAAK;GACnB,MAAM,IAAI,KAAK;GACf,MAAM,IAAI,KAAK;GACf,QAAQ,UAAU;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;GAClD,QAAQ,UAAU;IAAE;IAAK,QAAQ,QAAQ;IAAQ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
4
4
  exports.mcpGenerator = require_generators.mcpGenerator;
5
5
  exports.serverGenerator = require_generators.serverGenerator;
@@ -1,5 +1,5 @@
1
- import { s as ReactGenerator } from "./SchemaGenerator-C1vgcKII.cjs";
2
- import { n as PluginMcp } from "./types-3zb5y21F.cjs";
1
+ import { n as ReactGenerator } from "./OperationGenerator-Beq8iOZY.cjs";
2
+ import { n as PluginMcp } from "./types-B4xu5uHh.cjs";
3
3
 
4
4
  //#region src/generators/mcpGenerator.d.ts
5
5
  declare const mcpGenerator: ReactGenerator<PluginMcp>;
@@ -1,5 +1,5 @@
1
- import { s as ReactGenerator } from "./SchemaGenerator-wXj7HtlS.js";
2
- import { n as PluginMcp } from "./types-b6nPxXzv.js";
1
+ import { n as ReactGenerator } from "./index-BlpJVG8h.js";
2
+ import { n as PluginMcp } from "./types-Cy3TnfH5.js";
3
3
 
4
4
  //#region src/generators/mcpGenerator.d.ts
5
5
  declare const mcpGenerator: ReactGenerator<PluginMcp>;
@@ -1,4 +1,4 @@
1
- import { n as mcpGenerator, t as serverGenerator } from "./generators-Bp0d1HbP.js";
1
+ import { n as mcpGenerator, t as serverGenerator } from "./generators-DP6UAisL.js";
2
2
  import "./Server-DMDo69md.js";
3
3
 
4
4
  export { mcpGenerator, serverGenerator };