@kubb/plugin-mcp 5.0.0-beta.10 → 5.0.0-beta.100
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/README.md +22 -25
- package/dist/index.cjs +520 -679
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +171 -134
- package/dist/index.js +498 -656
- package/dist/index.js.map +1 -1
- package/package.json +11 -24
- package/extension.yaml +0 -463
- package/src/components/McpHandler.tsx +0 -167
- package/src/components/Server.tsx +0 -154
- package/src/generators/mcpGenerator.tsx +0 -79
- package/src/generators/serverGenerator.tsx +0 -146
- package/src/index.ts +0 -11
- package/src/plugin.ts +0 -122
- package/src/resolvers/resolverMcp.ts +0 -31
- package/src/types.ts +0 -88
- package/src/utils.ts +0 -64
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,99 +1,18 @@
|
|
|
1
|
-
import { t as __name } from "./
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
3
|
+
import { KubbReactNode } from "kubb/jsx";
|
|
4
4
|
import { ResolverTs } from "@kubb/plugin-ts";
|
|
5
|
-
import
|
|
6
|
-
import { KubbReactNode } from "@kubb/renderer-jsx/types";
|
|
7
|
-
|
|
8
|
-
//#region src/types.d.ts
|
|
9
|
-
/**
|
|
10
|
-
* Resolver for MCP that provides naming methods for handler functions.
|
|
11
|
-
*/
|
|
12
|
-
type ResolverMcp = Resolver & {
|
|
13
|
-
/**
|
|
14
|
-
* Resolves the base handler function name for an operation.
|
|
15
|
-
*
|
|
16
|
-
* @example Resolving handler function names
|
|
17
|
-
* `resolver.resolveName('show pet by id') // -> 'showPetByIdHandler'`
|
|
18
|
-
*/
|
|
19
|
-
resolveName(this: ResolverMcp, name: string): string;
|
|
20
|
-
/**
|
|
21
|
-
* Resolves the output file name for an MCP module.
|
|
22
|
-
*/
|
|
23
|
-
resolvePathName(this: ResolverMcp, name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
24
|
-
/**
|
|
25
|
-
* Resolves the handler function name for an operation.
|
|
26
|
-
*/
|
|
27
|
-
resolveHandlerName(this: ResolverMcp, node: ast.OperationNode): string;
|
|
28
|
-
};
|
|
29
|
-
type Options = {
|
|
30
|
-
/**
|
|
31
|
-
* Specify the export location for the files and define the behavior of the output.
|
|
32
|
-
* @default { path: 'mcp', barrelType: 'named' }
|
|
33
|
-
*/
|
|
34
|
-
output?: Output;
|
|
35
|
-
/**
|
|
36
|
-
* Client configuration for HTTP request generation.
|
|
37
|
-
*/
|
|
38
|
-
client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>;
|
|
39
|
-
/**
|
|
40
|
-
* Apply casing to parameter names to match your configuration.
|
|
41
|
-
*/
|
|
42
|
-
paramsCasing?: 'camelcase';
|
|
43
|
-
/**
|
|
44
|
-
* Group the MCP requests based on the provided name.
|
|
45
|
-
*/
|
|
46
|
-
group?: Group;
|
|
47
|
-
/**
|
|
48
|
-
* Tags, operations, or paths to exclude from generation.
|
|
49
|
-
*/
|
|
50
|
-
exclude?: Array<Exclude>;
|
|
51
|
-
/**
|
|
52
|
-
* Tags, operations, or paths to include in generation.
|
|
53
|
-
*/
|
|
54
|
-
include?: Array<Include>;
|
|
55
|
-
/**
|
|
56
|
-
* Override options for specific tags, operations, or paths.
|
|
57
|
-
*/
|
|
58
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
59
|
-
/**
|
|
60
|
-
* Override naming conventions for function names and types.
|
|
61
|
-
*/
|
|
62
|
-
resolver?: Partial<ResolverMcp> & ThisType<ResolverMcp>;
|
|
63
|
-
/**
|
|
64
|
-
* AST visitor to transform generated nodes.
|
|
65
|
-
*/
|
|
66
|
-
transformer?: ast.Visitor;
|
|
67
|
-
/**
|
|
68
|
-
* Additional generators alongside the default generators.
|
|
69
|
-
*/
|
|
70
|
-
generators?: Array<Generator<PluginMcp>>;
|
|
71
|
-
};
|
|
72
|
-
type ResolvedOptions = {
|
|
73
|
-
output: Output;
|
|
74
|
-
exclude: Array<Exclude>;
|
|
75
|
-
include: Array<Include> | undefined;
|
|
76
|
-
override: Array<Override<ResolvedOptions>>;
|
|
77
|
-
group: Group | undefined;
|
|
78
|
-
client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>;
|
|
79
|
-
paramsCasing: Options['paramsCasing'];
|
|
80
|
-
resolver: ResolverMcp;
|
|
81
|
-
};
|
|
82
|
-
type PluginMcp = PluginFactoryOptions<'plugin-mcp', Options, ResolvedOptions, ResolverMcp>;
|
|
83
|
-
declare global {
|
|
84
|
-
namespace Kubb {
|
|
85
|
-
interface PluginRegistry {
|
|
86
|
-
'plugin-mcp': PluginMcp;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
//#endregion
|
|
5
|
+
import "@kubb/plugin-zod";
|
|
91
6
|
//#region src/components/McpHandler.d.ts
|
|
92
7
|
type Props$1 = {
|
|
93
8
|
/**
|
|
94
9
|
* Name of the handler function.
|
|
95
10
|
*/
|
|
96
11
|
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* Name of the contract client `<op>` the handler calls.
|
|
14
|
+
*/
|
|
15
|
+
clientName: string;
|
|
97
16
|
/**
|
|
98
17
|
* AST operation node.
|
|
99
18
|
*/
|
|
@@ -102,30 +21,8 @@ type Props$1 = {
|
|
|
102
21
|
* TypeScript resolver for resolving param/data/response type names.
|
|
103
22
|
*/
|
|
104
23
|
resolver: ResolverTs;
|
|
105
|
-
/**
|
|
106
|
-
* Base URL prepended to every generated request URL.
|
|
107
|
-
*/
|
|
108
|
-
baseURL: string | undefined;
|
|
109
|
-
/**
|
|
110
|
-
* Return type when calling fetch.
|
|
111
|
-
* - 'data' returns response data only.
|
|
112
|
-
* - 'full' returns the full response object.
|
|
113
|
-
* @default 'data'
|
|
114
|
-
*/
|
|
115
|
-
dataReturnType: PluginMcp['resolvedOptions']['client']['dataReturnType'];
|
|
116
|
-
/**
|
|
117
|
-
* How to style your params.
|
|
118
|
-
*/
|
|
119
|
-
paramsCasing?: PluginMcp['resolvedOptions']['paramsCasing'];
|
|
120
24
|
};
|
|
121
|
-
declare function McpHandler({
|
|
122
|
-
name,
|
|
123
|
-
node,
|
|
124
|
-
resolver,
|
|
125
|
-
baseURL,
|
|
126
|
-
dataReturnType,
|
|
127
|
-
paramsCasing
|
|
128
|
-
}: Props$1): KubbReactNode;
|
|
25
|
+
declare function McpHandler({ name, clientName, node, resolver }: Props$1): KubbReactNode;
|
|
129
26
|
//#endregion
|
|
130
27
|
//#region src/utils.d.ts
|
|
131
28
|
type ZodParam = {
|
|
@@ -147,10 +44,6 @@ type Props = {
|
|
|
147
44
|
* Semantic version string passed to `new McpServer({ version })`.
|
|
148
45
|
*/
|
|
149
46
|
serverVersion: string;
|
|
150
|
-
/**
|
|
151
|
-
* How to style your params.
|
|
152
|
-
*/
|
|
153
|
-
paramsCasing?: PluginMcp['resolvedOptions']['paramsCasing'];
|
|
154
47
|
/**
|
|
155
48
|
* Operations to register as MCP tools, each carrying its handler,
|
|
156
49
|
* zod schema, and AST node metadata.
|
|
@@ -170,27 +63,136 @@ type Props = {
|
|
|
170
63
|
/**
|
|
171
64
|
* Query params — individual schemas to compose into `z.object({ ... })`.
|
|
172
65
|
*/
|
|
173
|
-
queryParams?: string | Array<ZodParam
|
|
66
|
+
queryParams?: string | Array<ZodParam> | null;
|
|
174
67
|
/**
|
|
175
68
|
* Header params — individual schemas to compose into `z.object({ ... })`.
|
|
176
69
|
*/
|
|
177
|
-
headerParams?: string | Array<ZodParam
|
|
178
|
-
requestName?: string;
|
|
179
|
-
responseName?: string;
|
|
70
|
+
headerParams?: string | Array<ZodParam> | null;
|
|
71
|
+
requestName?: string | null;
|
|
72
|
+
responseName?: string | null;
|
|
180
73
|
};
|
|
181
74
|
node: ast.OperationNode;
|
|
182
75
|
}>;
|
|
183
76
|
};
|
|
184
|
-
declare function Server({
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
77
|
+
declare function Server({ name, serverName, serverVersion, operations }: Props): KubbReactNode;
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region ../../internals/client/src/resolveClient.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
82
|
+
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
83
|
+
*
|
|
84
|
+
* Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
|
|
85
|
+
* contract client plugin (plugin-fetch or plugin-axios) and never emits its own inline client:
|
|
86
|
+
*
|
|
87
|
+
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
88
|
+
* imports and calls them.
|
|
89
|
+
* - `error` — no client plugin is registered, several are registered without a selector, or the
|
|
90
|
+
* requested one is missing.
|
|
91
|
+
*
|
|
92
|
+
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
93
|
+
* contract client plugin is picked up automatically.
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* The client selector accepted by a consumer's `client` option. Both call a registered contract
|
|
97
|
+
* client plugin.
|
|
98
|
+
*/
|
|
99
|
+
type ClientSelector = 'fetch' | 'axios';
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/types.d.ts
|
|
102
|
+
/**
|
|
103
|
+
* Resolver for MCP that provides naming methods for handler functions.
|
|
104
|
+
*/
|
|
105
|
+
type ResolverMcp = Resolver & {
|
|
106
|
+
/**
|
|
107
|
+
* Naming for the generated MCP tool handler functions.
|
|
108
|
+
*/
|
|
109
|
+
handler: {
|
|
110
|
+
/**
|
|
111
|
+
* Resolves the handler function name for an operation.
|
|
112
|
+
*
|
|
113
|
+
* @example Resolving handler function names
|
|
114
|
+
* `resolver.handler.name(operationNode) // -> 'showPetByIdHandler'`
|
|
115
|
+
*/
|
|
116
|
+
name(node: ast.OperationNode): string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Where the generated MCP tool handlers are written and how they are exported, plus the optional
|
|
121
|
+
* `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
|
|
122
|
+
*
|
|
123
|
+
* @default { path: 'mcp', barrel: { type: 'named' } }
|
|
124
|
+
*/
|
|
125
|
+
type Options = OutputOptions & {
|
|
126
|
+
/**
|
|
127
|
+
* Selects the HTTP client each MCP handler calls. Every client plugin speaks the `RequestResult`
|
|
128
|
+
* contract, so each handler calls a contract `<op>` that takes one grouped `{ path, query, headers,
|
|
129
|
+
* body }` object.
|
|
130
|
+
*
|
|
131
|
+
* `'fetch'` / `'axios'` calls the `@kubb/plugin-fetch` / `@kubb/plugin-axios` functions. When a
|
|
132
|
+
* single client plugin (plugin-fetch or plugin-axios) is registered it is auto-detected, so the
|
|
133
|
+
* string is only needed to disambiguate several client plugins. Register one of those plugins.
|
|
134
|
+
* Options such as `baseURL` live there.
|
|
135
|
+
*/
|
|
136
|
+
client?: ClientSelector;
|
|
137
|
+
/**
|
|
138
|
+
* Skip operations matching at least one entry in the list.
|
|
139
|
+
*/
|
|
140
|
+
exclude?: Array<Exclude>;
|
|
141
|
+
/**
|
|
142
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
143
|
+
*/
|
|
144
|
+
include?: Array<Include>;
|
|
145
|
+
/**
|
|
146
|
+
* Apply a different options object to operations matching a pattern.
|
|
147
|
+
*/
|
|
148
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
149
|
+
/**
|
|
150
|
+
* Override how handler names and file paths are built. Methods you omit fall
|
|
151
|
+
* back to the default `resolverMcp`.
|
|
152
|
+
*/
|
|
153
|
+
resolver?: ResolverPatch<ResolverMcp>;
|
|
154
|
+
/**
|
|
155
|
+
* Macros applied to each operation node before printing.
|
|
156
|
+
*/
|
|
157
|
+
macros?: Array<ast.Macro>;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* The resolved client strategy for the generated handlers, computed once during setup. The handlers
|
|
161
|
+
* always import and call a registered contract client plugin's `<op>`.
|
|
162
|
+
*/
|
|
163
|
+
type ResolvedClient = {
|
|
164
|
+
kind: 'contract';
|
|
165
|
+
pluginName: string;
|
|
166
|
+
};
|
|
167
|
+
type ResolvedOptions = {
|
|
168
|
+
output: Output;
|
|
169
|
+
exclude: Array<Exclude>;
|
|
170
|
+
include: Array<Include> | undefined;
|
|
171
|
+
override: Array<Override<ResolvedOptions>>;
|
|
172
|
+
group: Group | null;
|
|
173
|
+
/**
|
|
174
|
+
* The resolved client strategy the generators branch on.
|
|
175
|
+
*/
|
|
176
|
+
client: ResolvedClient;
|
|
177
|
+
resolver: ResolverMcp;
|
|
178
|
+
};
|
|
179
|
+
type PluginMcp = PluginFactoryOptions<'plugin-mcp', Options, ResolvedOptions, ResolverMcp>;
|
|
180
|
+
declare global {
|
|
181
|
+
namespace Kubb {
|
|
182
|
+
interface PluginRegistry {
|
|
183
|
+
'plugin-mcp': PluginMcp;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
191
187
|
//#endregion
|
|
192
188
|
//#region src/generators/mcpGenerator.d.ts
|
|
193
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Built-in operation generator for `@kubb/plugin-mcp`. Emits one MCP tool
|
|
191
|
+
* handler per OpenAPI operation. The handler takes the grouped `{ path, query,
|
|
192
|
+
* headers, body }` config and forwards it to the registered client plugin's
|
|
193
|
+
* (`@kubb/plugin-axios` / `@kubb/plugin-fetch`) `<op>` function.
|
|
194
|
+
*/
|
|
195
|
+
declare const mcpGenerator: import("kubb/kit").Generator<PluginMcp, unknown>;
|
|
194
196
|
//#endregion
|
|
195
197
|
//#region src/generators/serverGenerator.d.ts
|
|
196
198
|
/**
|
|
@@ -200,20 +202,55 @@ declare const mcpGenerator: _$_kubb_core0.Generator<PluginMcp, unknown>;
|
|
|
200
202
|
* and `resolveResponseStatusName` for per-status response schemas.
|
|
201
203
|
* Query and header params are composed into `z.object({ ... })` from individual schemas.
|
|
202
204
|
*/
|
|
203
|
-
declare const serverGenerator:
|
|
205
|
+
declare const serverGenerator: import("kubb/kit").Generator<PluginMcp, unknown>;
|
|
204
206
|
//#endregion
|
|
205
207
|
//#region src/plugin.d.ts
|
|
208
|
+
/**
|
|
209
|
+
* Canonical plugin name for `@kubb/plugin-mcp`. Used for driver lookups and
|
|
210
|
+
* cross-plugin dependency references.
|
|
211
|
+
*/
|
|
206
212
|
declare const pluginMcpName = "plugin-mcp";
|
|
207
|
-
|
|
213
|
+
/**
|
|
214
|
+
* Generates a Model Context Protocol (MCP) server from an OpenAPI spec. Every
|
|
215
|
+
* operation becomes a typed MCP tool that AI assistants (Claude Desktop, Claude
|
|
216
|
+
* Code, MCP-compatible clients) can call directly. Each handler calls a contract
|
|
217
|
+
* client `<op>` from a registered `@kubb/plugin-axios` or `@kubb/plugin-fetch`.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* import { defineConfig } from 'kubb/config'
|
|
222
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
223
|
+
* import { pluginZod } from '@kubb/plugin-zod'
|
|
224
|
+
* import { pluginMcp } from '@kubb/plugin-mcp'
|
|
225
|
+
*
|
|
226
|
+
* export default defineConfig({
|
|
227
|
+
* input: './petStore.yaml',
|
|
228
|
+
* output: { path: './src/gen' },
|
|
229
|
+
* plugins: [
|
|
230
|
+
* pluginTs(),
|
|
231
|
+
* pluginZod(),
|
|
232
|
+
* pluginMcp({
|
|
233
|
+
* output: { path: './mcp' },
|
|
234
|
+
* baseURL: 'https://petstore.swagger.io/v2',
|
|
235
|
+
* }),
|
|
236
|
+
* ],
|
|
237
|
+
* })
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
declare const pluginMcp: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginMcp>;
|
|
208
241
|
//#endregion
|
|
209
242
|
//#region src/resolvers/resolverMcp.d.ts
|
|
210
243
|
/**
|
|
211
|
-
*
|
|
244
|
+
* Default resolver used by `@kubb/plugin-mcp`. Decides the names and file
|
|
245
|
+
* paths for every generated MCP tool handler. Function names get a `Handler`
|
|
246
|
+
* suffix so an operation `addPet` becomes `addPetHandler`.
|
|
212
247
|
*
|
|
213
|
-
*
|
|
248
|
+
* @example Resolve a handler name
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { resolverMcp } from '@kubb/plugin-mcp'
|
|
214
251
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
252
|
+
* resolverMcp.name('addPet') // 'addPetHandler'
|
|
253
|
+
* ```
|
|
217
254
|
*/
|
|
218
255
|
declare const resolverMcp: ResolverMcp;
|
|
219
256
|
//#endregion
|