@kubb/plugin-mcp 4.4.1 → 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,6 +1,7 @@
1
- import { a as ResolvePathOptions, c as Oas, d as Output, f as PluginFactoryOptions, i as Override, l as contentType, n as Include, o as Generator, p as ResolveNameParams, t as Exclude, u as Group } from "./SchemaGenerator-geilI4rJ.js";
1
+ import { c as Oas, d as Output, f as PluginFactoryOptions, i as Include, l as contentType, o as Override, p as ResolveNameParams, r as Exclude, s as ResolvePathOptions, t as Generator, u as Group } from "./OperationGenerator-Beq8iOZY.cjs";
2
2
 
3
3
  //#region ../plugin-client/src/types.d.ts
4
+
4
5
  type Options$1 = {
5
6
  /**
6
7
  * Specify the export location for the files and define the behavior of the output
@@ -44,7 +45,6 @@ type Options$1 = {
44
45
  * Path to the client import path that will be used to do the API calls.
45
46
  * It will be used as `import client from '${client.importPath}'`.
46
47
  * It allows both relative and absolute path but be aware that we will not change the path.
47
- * @default '@kubb/plugin-client/clients/axios'
48
48
  */
49
49
  importPath?: string;
50
50
  /**
@@ -85,8 +85,8 @@ type Options$1 = {
85
85
  parser?: 'client' | 'zod';
86
86
  /**
87
87
  * Which client should be used to do the HTTP calls
88
- * - 'axios' will use `@kubb/plugin-client/clients/axios` to fetch data.
89
- * - 'fetch' will use `@kubb/plugin-client/clients/fetch` to fetch data.
88
+ * - 'axios' will use `@kubb/plugin-client/templates/axios` to fetch data.
89
+ * - 'fetch' will use `@kubb/plugin-client/templates/fetch` to fetch data.
90
90
  * @default 'axios'
91
91
  */
92
92
  client?: 'axios' | 'fetch';
@@ -105,9 +105,10 @@ type ResolvedOptions$1 = {
105
105
  output: Output<Oas>;
106
106
  group?: Options$1['group'];
107
107
  baseURL: string | undefined;
108
+ client: Options$1['client'];
108
109
  parser: NonNullable<Options$1['parser']>;
109
110
  urlType: NonNullable<Options$1['urlType']>;
110
- importPath: NonNullable<Options$1['importPath']>;
111
+ importPath: Options$1['importPath'];
111
112
  dataReturnType: NonNullable<Options$1['dataReturnType']>;
112
113
  pathParamsType: NonNullable<Options$1['pathParamsType']>;
113
114
  paramsType: NonNullable<Options$1['paramsType']>;
@@ -127,7 +128,7 @@ type Options = {
127
128
  * By default, the first JSON valid mediaType will be used
128
129
  */
129
130
  contentType?: contentType;
130
- client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
131
+ client?: Pick<PluginClient['options'], 'client' | 'dataReturnType' | 'importPath' | 'baseURL'>;
131
132
  /**
132
133
  * Group the mcp requests based on the provided name.
133
134
  */
@@ -158,11 +159,9 @@ type Options = {
158
159
  type ResolvedOptions = {
159
160
  output: Output<Oas>;
160
161
  group: Options['group'];
161
- client: Required<Omit<NonNullable<PluginMcp['options']['client']>, 'baseURL'>> & {
162
- baseURL?: string;
163
- };
162
+ client: NonNullable<PluginMcp['options']['client']>;
164
163
  };
165
164
  type PluginMcp = PluginFactoryOptions<'plugin-mcp', Options, ResolvedOptions, never, ResolvePathOptions>;
166
165
  //#endregion
167
166
  export { PluginMcp as n, Options as t };
168
- //# sourceMappingURL=types-DXH0aZQO.d.ts.map
167
+ //# sourceMappingURL=types-B4xu5uHh.d.cts.map
@@ -1,6 +1,7 @@
1
- import { a as ResolvePathOptions, c as Oas, d as Output, f as PluginFactoryOptions, i as Override, l as contentType, n as Include, o as Generator, p as ResolveNameParams, t as Exclude, u as Group } from "./SchemaGenerator-Bu2D8QtI.cjs";
1
+ import { c as Oas, d as Output, f as PluginFactoryOptions, i as Include, l as contentType, o as Override, p as ResolveNameParams, r as Exclude, s as ResolvePathOptions, t as Generator, u as Group } from "./index-BlpJVG8h.js";
2
2
 
3
3
  //#region ../plugin-client/src/types.d.ts
4
+
4
5
  type Options$1 = {
5
6
  /**
6
7
  * Specify the export location for the files and define the behavior of the output
@@ -44,7 +45,6 @@ type Options$1 = {
44
45
  * Path to the client import path that will be used to do the API calls.
45
46
  * It will be used as `import client from '${client.importPath}'`.
46
47
  * It allows both relative and absolute path but be aware that we will not change the path.
47
- * @default '@kubb/plugin-client/clients/axios'
48
48
  */
49
49
  importPath?: string;
50
50
  /**
@@ -85,8 +85,8 @@ type Options$1 = {
85
85
  parser?: 'client' | 'zod';
86
86
  /**
87
87
  * Which client should be used to do the HTTP calls
88
- * - 'axios' will use `@kubb/plugin-client/clients/axios` to fetch data.
89
- * - 'fetch' will use `@kubb/plugin-client/clients/fetch` to fetch data.
88
+ * - 'axios' will use `@kubb/plugin-client/templates/axios` to fetch data.
89
+ * - 'fetch' will use `@kubb/plugin-client/templates/fetch` to fetch data.
90
90
  * @default 'axios'
91
91
  */
92
92
  client?: 'axios' | 'fetch';
@@ -105,9 +105,10 @@ type ResolvedOptions$1 = {
105
105
  output: Output<Oas>;
106
106
  group?: Options$1['group'];
107
107
  baseURL: string | undefined;
108
+ client: Options$1['client'];
108
109
  parser: NonNullable<Options$1['parser']>;
109
110
  urlType: NonNullable<Options$1['urlType']>;
110
- importPath: NonNullable<Options$1['importPath']>;
111
+ importPath: Options$1['importPath'];
111
112
  dataReturnType: NonNullable<Options$1['dataReturnType']>;
112
113
  pathParamsType: NonNullable<Options$1['pathParamsType']>;
113
114
  paramsType: NonNullable<Options$1['paramsType']>;
@@ -127,7 +128,7 @@ type Options = {
127
128
  * By default, the first JSON valid mediaType will be used
128
129
  */
129
130
  contentType?: contentType;
130
- client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
131
+ client?: Pick<PluginClient['options'], 'client' | 'dataReturnType' | 'importPath' | 'baseURL'>;
131
132
  /**
132
133
  * Group the mcp requests based on the provided name.
133
134
  */
@@ -158,11 +159,9 @@ type Options = {
158
159
  type ResolvedOptions = {
159
160
  output: Output<Oas>;
160
161
  group: Options['group'];
161
- client: Required<Omit<NonNullable<PluginMcp['options']['client']>, 'baseURL'>> & {
162
- baseURL?: string;
163
- };
162
+ client: NonNullable<PluginMcp['options']['client']>;
164
163
  };
165
164
  type PluginMcp = PluginFactoryOptions<'plugin-mcp', Options, ResolvedOptions, never, ResolvePathOptions>;
166
165
  //#endregion
167
166
  export { PluginMcp as n, Options as t };
168
- //# sourceMappingURL=types-BPcoHHAu.d.cts.map
167
+ //# sourceMappingURL=types-Cy3TnfH5.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-mcp",
3
- "version": "4.4.1",
3
+ "version": "4.5.0",
4
4
  "description": "Generator mcp",
5
5
  "keywords": [
6
6
  "typescript",
@@ -69,17 +69,17 @@
69
69
  }
70
70
  ],
71
71
  "dependencies": {
72
- "@kubb/react-fabric": "0.2.10",
73
- "@kubb/core": "4.4.1",
74
- "@kubb/oas": "4.4.1",
75
- "@kubb/plugin-client": "4.4.1",
76
- "@kubb/plugin-oas": "4.4.1",
77
- "@kubb/plugin-ts": "4.4.1",
78
- "@kubb/plugin-zod": "4.4.1"
72
+ "@kubb/react-fabric": "0.2.14",
73
+ "@kubb/core": "4.5.0",
74
+ "@kubb/oas": "4.5.0",
75
+ "@kubb/plugin-client": "4.5.0",
76
+ "@kubb/plugin-oas": "4.5.0",
77
+ "@kubb/plugin-ts": "4.5.0",
78
+ "@kubb/plugin-zod": "4.5.0"
79
79
  },
80
80
  "devDependencies": {},
81
81
  "peerDependencies": {
82
- "@kubb/react-fabric": "0.2.10"
82
+ "@kubb/react-fabric": "0.2.14"
83
83
  },
84
84
  "engines": {
85
85
  "node": ">=20"
@@ -1,6 +1,6 @@
1
- import { usePlugin } from '@kubb/core/hooks'
1
+ import path from 'node:path'
2
2
  import { Client } from '@kubb/plugin-client/components'
3
- import { createReactGenerator } from '@kubb/plugin-oas'
3
+ import { createReactGenerator } from '@kubb/plugin-oas/generators'
4
4
  import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
5
5
  import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
6
6
  import { pluginTsName } from '@kubb/plugin-ts'
@@ -9,10 +9,11 @@ import type { PluginMcp } from '../types'
9
9
 
10
10
  export const mcpGenerator = createReactGenerator<PluginMcp>({
11
11
  name: 'mcp',
12
- Operation({ operation }) {
13
- const { options } = usePlugin<PluginMcp>()
12
+ Operation({ config, operation, generator, plugin }) {
13
+ const { options } = plugin
14
14
  const oas = useOas()
15
- const { getSchemas, getName, getFile } = useOperationManager()
15
+
16
+ const { getSchemas, getName, getFile } = useOperationManager(generator)
16
17
 
17
18
  const mcp = {
18
19
  name: getName(operation, { type: 'function', suffix: 'handler' }),
@@ -32,9 +33,27 @@ export const mcpGenerator = createReactGenerator<PluginMcp>({
32
33
  banner={getBanner({ oas, output: options.output })}
33
34
  footer={getFooter({ oas, output: options.output })}
34
35
  >
36
+ {options.client.importPath ? (
37
+ <>
38
+ <File.Import name={'fetch'} path={options.client.importPath} />
39
+ <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />
40
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
41
+ </>
42
+ ) : (
43
+ <>
44
+ <File.Import name={'fetch'} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')} />
45
+ <File.Import
46
+ name={['RequestConfig', 'ResponseErrorConfig']}
47
+ root={mcp.file.path}
48
+ path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')}
49
+ isTypeOnly
50
+ />
51
+ {options.client.dataReturnType === 'full' && (
52
+ <File.Import name={['ResponseConfig']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')} isTypeOnly />
53
+ )}
54
+ </>
55
+ )}
35
56
  <File.Import name={['CallToolResult']} path={'@modelcontextprotocol/sdk/types'} isTypeOnly />
36
- <File.Import name={'fetch'} path={options.client.importPath} />
37
- <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />
38
57
  <File.Import
39
58
  name={[
40
59
  type.schemas.request?.name,
@@ -57,7 +76,7 @@ export const mcpGenerator = createReactGenerator<PluginMcp>({
57
76
  operation={operation}
58
77
  typeSchemas={type.schemas}
59
78
  zodSchemas={undefined}
60
- dataReturnType={options.client.dataReturnType}
79
+ dataReturnType={options.client.dataReturnType || 'data'}
61
80
  paramsType={'object'}
62
81
  paramsCasing={'camelcase'}
63
82
  pathParamsType={'object'}
@@ -1,5 +1,5 @@
1
- import { usePlugin, usePluginManager } from '@kubb/core/hooks'
2
- import { createReactGenerator } from '@kubb/plugin-oas'
1
+ import { usePluginManager } from '@kubb/core/hooks'
2
+ import { createReactGenerator } from '@kubb/plugin-oas/generators'
3
3
  import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
4
4
  import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
5
5
  import { pluginTsName } from '@kubb/plugin-ts'
@@ -10,12 +10,12 @@ import type { PluginMcp } from '../types'
10
10
 
11
11
  export const serverGenerator = createReactGenerator<PluginMcp>({
12
12
  name: 'operations',
13
- Operations({ operations, options }) {
14
- const plugin = usePlugin<PluginMcp>()
13
+ Operations({ operations, generator, plugin }) {
15
14
  const pluginManager = usePluginManager()
15
+ const { options } = plugin
16
16
 
17
17
  const oas = useOas()
18
- const { getFile, getName, getSchemas } = useOperationManager()
18
+ const { getFile, getName, getSchemas } = useOperationManager(generator)
19
19
 
20
20
  const name = 'server'
21
21
  const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: plugin.key })
package/src/plugin.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import path from 'node:path'
2
2
  import { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'
3
3
  import { camelCase } from '@kubb/core/transformers'
4
+ import { resolveModuleSource } from '@kubb/core/utils'
4
5
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
5
6
  import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
6
7
  import { pluginTsName } from '@kubb/plugin-ts'
@@ -28,7 +29,7 @@ export const pluginMcp = createPlugin<PluginMcp>((options) => {
28
29
  output,
29
30
  group,
30
31
  client: {
31
- importPath: '@kubb/plugin-client/clients/axios',
32
+ client: 'axios',
32
33
  dataReturnType: 'data',
33
34
  ...options.client,
34
35
  },
@@ -85,6 +86,29 @@ export const pluginMcp = createPlugin<PluginMcp>((options) => {
85
86
  const oas = await swaggerPlugin.context.getOas()
86
87
  const root = path.resolve(this.config.root, this.config.output.path)
87
88
  const mode = getMode(path.resolve(root, output.path))
89
+ const baseURL = await swaggerPlugin.context.getBaseURL()
90
+
91
+ if (baseURL) {
92
+ this.plugin.options.client.baseURL = baseURL
93
+ }
94
+
95
+ const containsFetcher = this.fileManager.files.some((file) => file.baseName === 'fetcher.ts')
96
+
97
+ if (!this.plugin.options.client.importPath && !containsFetcher) {
98
+ // pre add bundled fetcher
99
+ await this.addFile({
100
+ baseName: 'fetcher.ts',
101
+ path: path.resolve(root, '.kubb/fetcher.ts'),
102
+ sources: [
103
+ {
104
+ name: 'fetcher',
105
+ value: resolveModuleSource(
106
+ this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',
107
+ ).source,
108
+ },
109
+ ],
110
+ })
111
+ }
88
112
 
89
113
  const operationGenerator = new OperationGenerator(this.plugin.options, {
90
114
  fabric: this.fabric,
package/src/types.ts CHANGED
@@ -2,7 +2,8 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@ku
2
2
 
3
3
  import type { contentType, Oas } from '@kubb/oas'
4
4
  import type { PluginClient } from '@kubb/plugin-client'
5
- import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
5
+ import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
6
+ import type { Generator } from '@kubb/plugin-oas/generators'
6
7
 
7
8
  export type Options = {
8
9
  /**
@@ -15,7 +16,7 @@ export type Options = {
15
16
  * By default, the first JSON valid mediaType will be used
16
17
  */
17
18
  contentType?: contentType
18
- client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>
19
+ client?: Pick<PluginClient['options'], 'client' | 'dataReturnType' | 'importPath' | 'baseURL'>
19
20
 
20
21
  /**
21
22
  * Group the mcp requests based on the provided name.
@@ -48,7 +49,7 @@ export type Options = {
48
49
  type ResolvedOptions = {
49
50
  output: Output<Oas>
50
51
  group: Options['group']
51
- client: Required<Omit<NonNullable<PluginMcp['options']['client']>, 'baseURL'>> & { baseURL?: string }
52
+ client: NonNullable<PluginMcp['options']['client']>
52
53
  }
53
54
 
54
55
  export type PluginMcp = PluginFactoryOptions<'plugin-mcp', Options, ResolvedOptions, never, ResolvePathOptions>
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-8HowWmDg.cjs","names":["pluginTsName","File","Client","pluginZodName","pluginTsName","File","Server"],"sources":["../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx"],"sourcesContent":["import { usePlugin } from '@kubb/core/hooks'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\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({ operation }) {\n const { options } = usePlugin<PluginMcp>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\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 <File.Import name={['CallToolResult']} path={'@modelcontextprotocol/sdk/types'} isTypeOnly />\n <File.Import name={'fetch'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} 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}\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 { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas'\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, options }) {\n const plugin = usePlugin<PluginMcp>()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager()\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,2DAA+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MAAM,UAAU,iBAAiB,SAAS,EAAE,KAAK,UAAU;AACzD,UAAO,CACL,yDAACC,yBAAK;IAAsB,MAAM,CAAC,IAAI,KAAK;IAAE,MAAM,KAAK;IAAM,MAAM,IAAI,KAAK;MAA5D,IAAI,KAAgE,EACtF,yDAACA,yBAAK;IAEJ,MAAM;KAAC,IAAI,QAAQ,SAAS;KAAM,IAAI,QAAQ,YAAY;KAAM,IAAI,QAAQ,aAAa;KAAM,IAAI,QAAQ,cAAc;KAAK,CAAC,OAAO,QAAQ;IAC9I,MAAM,KAAK;IACX,MAAM,IAAI,KAAK;MAHV,IAAI,KAIT,CACH;IACD;AAEF,SACE,iHACE,0DAACA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChF,+CAAkB;IAAE;IAAK,QAAQ,QAAQ;IAAQ,CAAC;;IAElD,yDAACA,yBAAK;KAAO,MAAM,CAAC,YAAY;KAAE,MAAM;MAA0C;IAClF,yDAACA,yBAAK;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 +0,0 @@
1
- {"version":3,"file":"generators-Bp0d1HbP.js","names":[],"sources":["../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx"],"sourcesContent":["import { usePlugin } from '@kubb/core/hooks'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\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({ operation }) {\n const { options } = usePlugin<PluginMcp>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\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 <File.Import name={['CallToolResult']} path={'@modelcontextprotocol/sdk/types'} isTypeOnly />\n <File.Import name={'fetch'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} 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}\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 { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas'\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, options }) {\n const plugin = usePlugin<PluginMcp>()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager()\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,aAAa;EACvB,MAAM,EAAE,YAAY,WAAsB;EAC1C,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,YAAY,qBAAqB;EAE9D,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,CAAC;;IAElD,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