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