@kizunajs/mcp 2.0.0-beta.3 → 2.0.0-beta.31
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 +204 -189
- package/dist/index.d.cts +70 -101
- package/dist/index.d.mts +70 -101
- package/dist/index.mjs +201 -192
- package/package.json +11 -11
package/dist/index.d.cts
CHANGED
|
@@ -1,122 +1,89 @@
|
|
|
1
|
+
import * as _$kizunajs_plugin0 from "kizunajs/plugin";
|
|
2
|
+
import { PluginRoutes } from "kizunajs/plugin";
|
|
1
3
|
import * as _$kizunajs from "kizunajs";
|
|
2
|
-
import { ApiDefinition, RouteDefinition
|
|
4
|
+
import { ApiDefinition, RouteDefinition } from "kizunajs";
|
|
3
5
|
import { z } from "zod";
|
|
4
|
-
import { RoutePath, WithSlug } from "kizunajs/plugin";
|
|
5
6
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
6
|
-
import { ApiWithRouter } from "kizunajs/adapter";
|
|
7
|
+
import { ApiWithRouter, ToolInputSchema } from "kizunajs/adapter";
|
|
7
8
|
|
|
8
|
-
//#region src/oauth.d.ts
|
|
9
|
-
interface McpOAuthProps {
|
|
10
|
-
/**
|
|
11
|
-
* Canonical URI of the MCP endpoint as clients reach it: absolute, no
|
|
12
|
-
* fragment, ending in the endpoint's `path`. The RFC 9728 `resource`
|
|
13
|
-
* value and the RFC 8707 audience your guard checks tokens against.
|
|
14
|
-
*/
|
|
15
|
-
resource: string;
|
|
16
|
-
/**
|
|
17
|
-
* Name of the identity whose guard verifies the token on every request.
|
|
18
|
-
* Its `issuer` and flow scopes become the metadata document.
|
|
19
|
-
*/
|
|
20
|
-
scheme: string;
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
9
|
//#region src/plugin.d.ts
|
|
24
10
|
/**
|
|
25
11
|
* What the MCP endpoint is, and where. Which routes it publishes is each
|
|
26
12
|
* route's own business: declare `tool` on the ones a model may call.
|
|
27
13
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* Human-readable name shown to AI assistants.
|
|
43
|
-
*
|
|
44
|
-
* @default 'MCP Server'
|
|
45
|
-
*/
|
|
46
|
-
name?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Semantic version string (e.g. "1.0.0").
|
|
49
|
-
*
|
|
50
|
-
* @default '1.0.0'
|
|
51
|
-
*/
|
|
52
|
-
version?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Guidance for the model, appended to the overview built from the
|
|
55
|
-
* contract's tags.
|
|
56
|
-
*/
|
|
57
|
-
instructions?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Serve the endpoint as an OAuth 2.1 resource server, per the MCP
|
|
60
|
-
* authorization specification: RFC 9728 metadata on a well-known route,
|
|
61
|
-
* and HTTP `401`/`403` challenges built from the named identity.
|
|
62
|
-
*/
|
|
63
|
-
oauth?: McpOAuthProps;
|
|
64
|
-
}
|
|
65
|
-
declare const declare: (slug: string, props: McpPluginProps<string>) => _$kizunajs.PluginDeclaration<{
|
|
66
|
-
readonly protectedResourceMetadata?: {
|
|
67
|
-
readonly method: "GET";
|
|
68
|
-
readonly path: `/${string}`;
|
|
69
|
-
readonly summary: "OAuth protected resource metadata";
|
|
70
|
-
readonly responses: {
|
|
71
|
-
readonly 200: z.ZodObject<{
|
|
72
|
-
resource: z.ZodString;
|
|
73
|
-
authorization_servers: z.ZodArray<z.ZodString>;
|
|
74
|
-
scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
75
|
-
bearer_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
76
|
-
}, z.core.$strip>;
|
|
77
|
-
};
|
|
78
|
-
} | undefined;
|
|
79
|
-
readonly endpoint: {
|
|
80
|
-
readonly method: "POST";
|
|
81
|
-
readonly path: `/${string}`;
|
|
82
|
-
readonly summary: "MCP (Model Context Protocol) endpoint";
|
|
83
|
-
readonly body: z.ZodUnknown;
|
|
84
|
-
readonly responses: {
|
|
85
|
-
readonly 200: z.ZodUnknown;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
}, McpPluginProps<string>, undefined, string, {
|
|
89
|
-
[key: string]: unknown;
|
|
90
|
-
body: unknown;
|
|
91
|
-
headers: Record<string, string | string[] | undefined>;
|
|
92
|
-
requestContext?: Record<string, unknown>;
|
|
93
|
-
}>;
|
|
14
|
+
declare const McpPluginOptionsSchema: z.ZodObject<{
|
|
15
|
+
path: z.ZodOptional<z.ZodCustom<`/${string}`, `/${string}`>>;
|
|
16
|
+
name: z.ZodOptional<z.ZodString>;
|
|
17
|
+
version: z.ZodOptional<z.ZodString>;
|
|
18
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
19
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
resource: z.ZodString;
|
|
21
|
+
scheme: z.ZodString;
|
|
22
|
+
}, z.core.$strip>>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
/**
|
|
25
|
+
* What the MCP endpoint is, and where.
|
|
26
|
+
*/
|
|
27
|
+
type McpPluginProps = z.output<typeof McpPluginOptionsSchema>;
|
|
94
28
|
/**
|
|
95
29
|
* Let AI assistants use the API. Serves an MCP (Model Context Protocol)
|
|
96
30
|
* endpoint where every route declaring `tool` is one an assistant can discover
|
|
97
31
|
* and call, behind the same guards as the HTTP endpoints.
|
|
98
32
|
*
|
|
99
33
|
* The endpoint is an ordinary kizuna route, so `api.mount` serves it on any
|
|
100
|
-
* adapter
|
|
101
|
-
* not see it.
|
|
34
|
+
* adapter.
|
|
102
35
|
*
|
|
103
36
|
* @example
|
|
104
37
|
* ```ts
|
|
105
38
|
* export default defineConfig({
|
|
106
39
|
* routes,
|
|
107
|
-
* plugins: [
|
|
40
|
+
* plugins: [
|
|
41
|
+
* mcpPlugin({
|
|
42
|
+
* name: 'My API',
|
|
43
|
+
* }),
|
|
44
|
+
* ],
|
|
108
45
|
* });
|
|
109
46
|
* ```
|
|
110
47
|
*/
|
|
111
|
-
declare
|
|
48
|
+
declare const mcpPlugin: {
|
|
49
|
+
<const Slug extends string>(options: {
|
|
50
|
+
path?: `/${string}` | undefined;
|
|
51
|
+
name?: string | undefined;
|
|
52
|
+
version?: string | undefined;
|
|
53
|
+
instructions?: string | undefined;
|
|
54
|
+
oauth?: {
|
|
55
|
+
resource: string;
|
|
56
|
+
scheme: string;
|
|
57
|
+
} | undefined;
|
|
58
|
+
} & {
|
|
59
|
+
basePath?: never;
|
|
60
|
+
} & _$kizunajs_plugin0.SlugOption<Slug>): _$kizunajs.PluginDeclaration<Slug, {
|
|
61
|
+
routes: PluginRoutes;
|
|
62
|
+
validate: () => void;
|
|
63
|
+
}>;
|
|
64
|
+
(options?: ({
|
|
65
|
+
path?: `/${string}` | undefined;
|
|
66
|
+
name?: string | undefined;
|
|
67
|
+
version?: string | undefined;
|
|
68
|
+
instructions?: string | undefined;
|
|
69
|
+
oauth?: {
|
|
70
|
+
resource: string;
|
|
71
|
+
scheme: string;
|
|
72
|
+
} | undefined;
|
|
73
|
+
} & {
|
|
74
|
+
basePath?: never;
|
|
75
|
+
}) | undefined): _$kizunajs.PluginDeclaration<"mcp", {
|
|
76
|
+
routes: PluginRoutes;
|
|
77
|
+
validate: () => void;
|
|
78
|
+
}>;
|
|
79
|
+
};
|
|
112
80
|
//#endregion
|
|
113
|
-
//#region src/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
81
|
+
//#region src/oauth.d.ts
|
|
82
|
+
declare const McpOAuthSchema: z.ZodObject<{
|
|
83
|
+
resource: z.ZodString;
|
|
84
|
+
scheme: z.ZodString;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
type McpOAuthProps = z.output<typeof McpOAuthSchema>;
|
|
120
87
|
//#endregion
|
|
121
88
|
//#region src/mcp-server.d.ts
|
|
122
89
|
interface McpServerOptions {
|
|
@@ -141,7 +108,7 @@ interface McpServerOptions {
|
|
|
141
108
|
onlyReadOnly?: boolean;
|
|
142
109
|
/**
|
|
143
110
|
* Guidance for the model, appended to the overview built from the
|
|
144
|
-
*
|
|
111
|
+
* API's groups. Use it for what belongs to no single route: the order
|
|
145
112
|
* operations happen in, the conventions every route shares.
|
|
146
113
|
*/
|
|
147
114
|
instructions?: string;
|
|
@@ -170,7 +137,7 @@ interface McpServerOptions {
|
|
|
170
137
|
context?: Record<string, unknown>;
|
|
171
138
|
};
|
|
172
139
|
}
|
|
173
|
-
interface
|
|
140
|
+
interface McpTool {
|
|
174
141
|
name: string;
|
|
175
142
|
title: string | undefined;
|
|
176
143
|
description: string;
|
|
@@ -178,13 +145,15 @@ interface ToolDefinition {
|
|
|
178
145
|
outputSchema: z.ZodType;
|
|
179
146
|
route: RouteDefinition;
|
|
180
147
|
routeKey: string;
|
|
181
|
-
|
|
148
|
+
/**
|
|
149
|
+
* The route's groups, as dotted paths.
|
|
150
|
+
*/
|
|
151
|
+
groups: string[];
|
|
182
152
|
}
|
|
183
|
-
declare const buildToolDefinitions: (routes: Routes) => ToolDefinition[];
|
|
184
153
|
/**
|
|
185
154
|
* What a client puts in front of the model before it picks a tool.
|
|
186
155
|
*/
|
|
187
|
-
declare const buildInstructions: (contract: ApiDefinition | undefined, definitions: readonly
|
|
156
|
+
declare const buildInstructions: (contract: ApiDefinition | undefined, definitions: readonly McpTool[], authored: string | undefined) => string;
|
|
188
157
|
/**
|
|
189
158
|
* Create an MCP server from a kizuna API.
|
|
190
159
|
*
|
|
@@ -200,4 +169,4 @@ declare const buildInstructions: (contract: ApiDefinition | undefined, definitio
|
|
|
200
169
|
*/
|
|
201
170
|
declare const createMcpServer: (api: ApiWithRouter, options?: McpServerOptions) => McpServer;
|
|
202
171
|
//#endregion
|
|
203
|
-
export { type McpOAuthProps, type McpPluginProps, type McpServerOptions,
|
|
172
|
+
export { type McpOAuthProps, type McpPluginProps, type McpServerOptions, buildInstructions, createMcpServer, mcpPlugin };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,122 +1,89 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import
|
|
2
|
+
import * as _$kizunajs_plugin0 from "kizunajs/plugin";
|
|
3
|
+
import { PluginRoutes } from "kizunajs/plugin";
|
|
3
4
|
import * as _$kizunajs from "kizunajs";
|
|
4
|
-
import { ApiDefinition, RouteDefinition
|
|
5
|
+
import { ApiDefinition, RouteDefinition } from "kizunajs";
|
|
5
6
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
6
|
-
import { ApiWithRouter } from "kizunajs/adapter";
|
|
7
|
+
import { ApiWithRouter, ToolInputSchema } from "kizunajs/adapter";
|
|
7
8
|
|
|
8
|
-
//#region src/oauth.d.ts
|
|
9
|
-
interface McpOAuthProps {
|
|
10
|
-
/**
|
|
11
|
-
* Canonical URI of the MCP endpoint as clients reach it: absolute, no
|
|
12
|
-
* fragment, ending in the endpoint's `path`. The RFC 9728 `resource`
|
|
13
|
-
* value and the RFC 8707 audience your guard checks tokens against.
|
|
14
|
-
*/
|
|
15
|
-
resource: string;
|
|
16
|
-
/**
|
|
17
|
-
* Name of the identity whose guard verifies the token on every request.
|
|
18
|
-
* Its `issuer` and flow scopes become the metadata document.
|
|
19
|
-
*/
|
|
20
|
-
scheme: string;
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
9
|
//#region src/plugin.d.ts
|
|
24
10
|
/**
|
|
25
11
|
* What the MCP endpoint is, and where. Which routes it publishes is each
|
|
26
12
|
* route's own business: declare `tool` on the ones a model may call.
|
|
27
13
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* Human-readable name shown to AI assistants.
|
|
43
|
-
*
|
|
44
|
-
* @default 'MCP Server'
|
|
45
|
-
*/
|
|
46
|
-
name?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Semantic version string (e.g. "1.0.0").
|
|
49
|
-
*
|
|
50
|
-
* @default '1.0.0'
|
|
51
|
-
*/
|
|
52
|
-
version?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Guidance for the model, appended to the overview built from the
|
|
55
|
-
* contract's tags.
|
|
56
|
-
*/
|
|
57
|
-
instructions?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Serve the endpoint as an OAuth 2.1 resource server, per the MCP
|
|
60
|
-
* authorization specification: RFC 9728 metadata on a well-known route,
|
|
61
|
-
* and HTTP `401`/`403` challenges built from the named identity.
|
|
62
|
-
*/
|
|
63
|
-
oauth?: McpOAuthProps;
|
|
64
|
-
}
|
|
65
|
-
declare const declare: (slug: string, props: McpPluginProps<string>) => _$kizunajs.PluginDeclaration<{
|
|
66
|
-
readonly protectedResourceMetadata?: {
|
|
67
|
-
readonly method: "GET";
|
|
68
|
-
readonly path: `/${string}`;
|
|
69
|
-
readonly summary: "OAuth protected resource metadata";
|
|
70
|
-
readonly responses: {
|
|
71
|
-
readonly 200: z.ZodObject<{
|
|
72
|
-
resource: z.ZodString;
|
|
73
|
-
authorization_servers: z.ZodArray<z.ZodString>;
|
|
74
|
-
scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
75
|
-
bearer_methods_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
76
|
-
}, z.core.$strip>;
|
|
77
|
-
};
|
|
78
|
-
} | undefined;
|
|
79
|
-
readonly endpoint: {
|
|
80
|
-
readonly method: "POST";
|
|
81
|
-
readonly path: `/${string}`;
|
|
82
|
-
readonly summary: "MCP (Model Context Protocol) endpoint";
|
|
83
|
-
readonly body: z.ZodUnknown;
|
|
84
|
-
readonly responses: {
|
|
85
|
-
readonly 200: z.ZodUnknown;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
}, McpPluginProps<string>, undefined, string, {
|
|
89
|
-
[key: string]: unknown;
|
|
90
|
-
body: unknown;
|
|
91
|
-
headers: Record<string, string | string[] | undefined>;
|
|
92
|
-
requestContext?: Record<string, unknown>;
|
|
93
|
-
}>;
|
|
14
|
+
declare const McpPluginOptionsSchema: z.ZodObject<{
|
|
15
|
+
path: z.ZodOptional<z.ZodCustom<`/${string}`, `/${string}`>>;
|
|
16
|
+
name: z.ZodOptional<z.ZodString>;
|
|
17
|
+
version: z.ZodOptional<z.ZodString>;
|
|
18
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
19
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
resource: z.ZodString;
|
|
21
|
+
scheme: z.ZodString;
|
|
22
|
+
}, z.core.$strip>>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
/**
|
|
25
|
+
* What the MCP endpoint is, and where.
|
|
26
|
+
*/
|
|
27
|
+
type McpPluginProps = z.output<typeof McpPluginOptionsSchema>;
|
|
94
28
|
/**
|
|
95
29
|
* Let AI assistants use the API. Serves an MCP (Model Context Protocol)
|
|
96
30
|
* endpoint where every route declaring `tool` is one an assistant can discover
|
|
97
31
|
* and call, behind the same guards as the HTTP endpoints.
|
|
98
32
|
*
|
|
99
33
|
* The endpoint is an ordinary kizuna route, so `api.mount` serves it on any
|
|
100
|
-
* adapter
|
|
101
|
-
* not see it.
|
|
34
|
+
* adapter.
|
|
102
35
|
*
|
|
103
36
|
* @example
|
|
104
37
|
* ```ts
|
|
105
38
|
* export default defineConfig({
|
|
106
39
|
* routes,
|
|
107
|
-
* plugins: [
|
|
40
|
+
* plugins: [
|
|
41
|
+
* mcpPlugin({
|
|
42
|
+
* name: 'My API',
|
|
43
|
+
* }),
|
|
44
|
+
* ],
|
|
108
45
|
* });
|
|
109
46
|
* ```
|
|
110
47
|
*/
|
|
111
|
-
declare
|
|
48
|
+
declare const mcpPlugin: {
|
|
49
|
+
<const Slug extends string>(options: {
|
|
50
|
+
path?: `/${string}` | undefined;
|
|
51
|
+
name?: string | undefined;
|
|
52
|
+
version?: string | undefined;
|
|
53
|
+
instructions?: string | undefined;
|
|
54
|
+
oauth?: {
|
|
55
|
+
resource: string;
|
|
56
|
+
scheme: string;
|
|
57
|
+
} | undefined;
|
|
58
|
+
} & {
|
|
59
|
+
basePath?: never;
|
|
60
|
+
} & _$kizunajs_plugin0.SlugOption<Slug>): _$kizunajs.PluginDeclaration<Slug, {
|
|
61
|
+
routes: PluginRoutes;
|
|
62
|
+
validate: () => void;
|
|
63
|
+
}>;
|
|
64
|
+
(options?: ({
|
|
65
|
+
path?: `/${string}` | undefined;
|
|
66
|
+
name?: string | undefined;
|
|
67
|
+
version?: string | undefined;
|
|
68
|
+
instructions?: string | undefined;
|
|
69
|
+
oauth?: {
|
|
70
|
+
resource: string;
|
|
71
|
+
scheme: string;
|
|
72
|
+
} | undefined;
|
|
73
|
+
} & {
|
|
74
|
+
basePath?: never;
|
|
75
|
+
}) | undefined): _$kizunajs.PluginDeclaration<"mcp", {
|
|
76
|
+
routes: PluginRoutes;
|
|
77
|
+
validate: () => void;
|
|
78
|
+
}>;
|
|
79
|
+
};
|
|
112
80
|
//#endregion
|
|
113
|
-
//#region src/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
81
|
+
//#region src/oauth.d.ts
|
|
82
|
+
declare const McpOAuthSchema: z.ZodObject<{
|
|
83
|
+
resource: z.ZodString;
|
|
84
|
+
scheme: z.ZodString;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
type McpOAuthProps = z.output<typeof McpOAuthSchema>;
|
|
120
87
|
//#endregion
|
|
121
88
|
//#region src/mcp-server.d.ts
|
|
122
89
|
interface McpServerOptions {
|
|
@@ -141,7 +108,7 @@ interface McpServerOptions {
|
|
|
141
108
|
onlyReadOnly?: boolean;
|
|
142
109
|
/**
|
|
143
110
|
* Guidance for the model, appended to the overview built from the
|
|
144
|
-
*
|
|
111
|
+
* API's groups. Use it for what belongs to no single route: the order
|
|
145
112
|
* operations happen in, the conventions every route shares.
|
|
146
113
|
*/
|
|
147
114
|
instructions?: string;
|
|
@@ -170,7 +137,7 @@ interface McpServerOptions {
|
|
|
170
137
|
context?: Record<string, unknown>;
|
|
171
138
|
};
|
|
172
139
|
}
|
|
173
|
-
interface
|
|
140
|
+
interface McpTool {
|
|
174
141
|
name: string;
|
|
175
142
|
title: string | undefined;
|
|
176
143
|
description: string;
|
|
@@ -178,13 +145,15 @@ interface ToolDefinition {
|
|
|
178
145
|
outputSchema: z.ZodType;
|
|
179
146
|
route: RouteDefinition;
|
|
180
147
|
routeKey: string;
|
|
181
|
-
|
|
148
|
+
/**
|
|
149
|
+
* The route's groups, as dotted paths.
|
|
150
|
+
*/
|
|
151
|
+
groups: string[];
|
|
182
152
|
}
|
|
183
|
-
declare const buildToolDefinitions: (routes: Routes) => ToolDefinition[];
|
|
184
153
|
/**
|
|
185
154
|
* What a client puts in front of the model before it picks a tool.
|
|
186
155
|
*/
|
|
187
|
-
declare const buildInstructions: (contract: ApiDefinition | undefined, definitions: readonly
|
|
156
|
+
declare const buildInstructions: (contract: ApiDefinition | undefined, definitions: readonly McpTool[], authored: string | undefined) => string;
|
|
188
157
|
/**
|
|
189
158
|
* Create an MCP server from a kizuna API.
|
|
190
159
|
*
|
|
@@ -200,4 +169,4 @@ declare const buildInstructions: (contract: ApiDefinition | undefined, definitio
|
|
|
200
169
|
*/
|
|
201
170
|
declare const createMcpServer: (api: ApiWithRouter, options?: McpServerOptions) => McpServer;
|
|
202
171
|
//#endregion
|
|
203
|
-
export { type McpOAuthProps, type McpPluginProps, type McpServerOptions,
|
|
172
|
+
export { type McpOAuthProps, type McpPluginProps, type McpServerOptions, buildInstructions, createMcpServer, mcpPlugin };
|