@kizunajs/mcp 2.0.0-beta.22 → 2.0.0-beta.24
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 +44 -26
- package/dist/index.mjs +46 -28
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -130,6 +130,37 @@ const approval = (route, context) => {
|
|
|
130
130
|
};
|
|
131
131
|
};
|
|
132
132
|
/**
|
|
133
|
+
* A schema as JSON Schema, with a `z.date()` as the ISO string the wire
|
|
134
|
+
* carries. Zod alone throws on a date, which would empty the whole tool list.
|
|
135
|
+
*/
|
|
136
|
+
const toJsonSchema = (schema, io) => zod.z.toJSONSchema(schema, {
|
|
137
|
+
target: "draft-2020-12",
|
|
138
|
+
io,
|
|
139
|
+
unrepresentable: "any",
|
|
140
|
+
override: kizunajs_generator.encodeForWire
|
|
141
|
+
});
|
|
142
|
+
/**
|
|
143
|
+
* What the SDK publishes for a tool. Input passes through unchecked, so the
|
|
144
|
+
* call is validated once, by `validateRequest`, as an HTTP request is. Output
|
|
145
|
+
* keeps the route's own check.
|
|
146
|
+
*/
|
|
147
|
+
const publishedSchema = (jsonSchema, check) => ({ "~standard": {
|
|
148
|
+
version: 1,
|
|
149
|
+
vendor: "kizuna",
|
|
150
|
+
validate: check === void 0 ? (value) => ({ value }) : check["~standard"].validate,
|
|
151
|
+
jsonSchema: {
|
|
152
|
+
input: () => jsonSchema,
|
|
153
|
+
output: () => jsonSchema
|
|
154
|
+
}
|
|
155
|
+
} });
|
|
156
|
+
/**
|
|
157
|
+
* MCP's recommended schema for a tool that takes nothing.
|
|
158
|
+
*/
|
|
159
|
+
const NO_INPUT = {
|
|
160
|
+
type: "object",
|
|
161
|
+
additionalProperties: false
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
133
164
|
* What the route says about itself, over what its method already implies.
|
|
134
165
|
*/
|
|
135
166
|
const buildToolAnnotations = (route) => {
|
|
@@ -304,21 +335,16 @@ const executeToolCall = async (route, routeKey, args, router, handlerContext, gu
|
|
|
304
335
|
params,
|
|
305
336
|
query,
|
|
306
337
|
body,
|
|
307
|
-
headers: {}
|
|
338
|
+
headers: credentialHeaders ?? {}
|
|
308
339
|
});
|
|
309
|
-
if (!validation.ok)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
}, null, 2)
|
|
319
|
-
}],
|
|
320
|
-
isError: true
|
|
321
|
-
};
|
|
340
|
+
if (!validation.ok) {
|
|
341
|
+
const formatted = (0, kizunajs_adapter.formatValidationError)(validation.error);
|
|
342
|
+
return toolEnvelope(400, (0, kizunajs.problemDetails)(400, formatted.detail, { errors: formatted.issues.map((issue) => ({
|
|
343
|
+
code: issue.code ?? "custom",
|
|
344
|
+
path: issue.path,
|
|
345
|
+
message: issue.message
|
|
346
|
+
})) }));
|
|
347
|
+
}
|
|
322
348
|
const handler = resolveHandler(router, routeKey);
|
|
323
349
|
if (typeof handler !== "function") return {
|
|
324
350
|
content: [{
|
|
@@ -350,16 +376,8 @@ const executeToolCall = async (route, routeKey, args, router, handlerContext, gu
|
|
|
350
376
|
return toolEnvelope(result.status, result.body);
|
|
351
377
|
} catch (error) {
|
|
352
378
|
if (error instanceof kizunajs_adapter.ResponseError) return toolEnvelope(error.status, error.body);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
type: "text",
|
|
356
|
-
text: JSON.stringify({
|
|
357
|
-
status: 500,
|
|
358
|
-
body: { detail: error instanceof Error ? error.message : "Internal Server Error" }
|
|
359
|
-
}, null, 2)
|
|
360
|
-
}],
|
|
361
|
-
isError: true
|
|
362
|
-
};
|
|
379
|
+
console.error(`[kizuna] tool "${routeKey}" threw:`, error);
|
|
380
|
+
return toolEnvelope(500, (0, kizunajs.problemDetails)(500, "Internal Server Error"));
|
|
363
381
|
}
|
|
364
382
|
};
|
|
365
383
|
/**
|
|
@@ -390,8 +408,8 @@ const createMcpServer = (api, options) => {
|
|
|
390
408
|
for (const definition of definitions) server.registerTool(definition.name, {
|
|
391
409
|
...definition.title === void 0 ? {} : { title: definition.title },
|
|
392
410
|
description: definition.description,
|
|
393
|
-
inputSchema: definition.inputSchema.shape === void 0 ?
|
|
394
|
-
outputSchema: definition.outputSchema,
|
|
411
|
+
inputSchema: publishedSchema(definition.inputSchema.shape === void 0 ? NO_INPUT : toJsonSchema(zod.z.object(definition.inputSchema.shape), "input")),
|
|
412
|
+
outputSchema: publishedSchema(toJsonSchema(definition.outputSchema, "output"), definition.outputSchema),
|
|
395
413
|
annotations: buildToolAnnotations(definition.route)
|
|
396
414
|
}, async (args, context) => {
|
|
397
415
|
const refusal = approval(definition.route, context);
|
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { RoutePathSchema, definePlugin, route } from "kizunajs/plugin";
|
|
|
3
3
|
import { ProtectedResourceMetadataSchema } from "kizunajs/schemas";
|
|
4
4
|
import { assertCanonicalResourceUri, buildProtectedResourceMetadata, declaredScopes, problemDetails, problemFromBody } from "kizunajs";
|
|
5
5
|
import { McpServer, acceptedContent, createMcpHandler, inputRequired } from "@modelcontextprotocol/server";
|
|
6
|
-
import { GUARDS_META, GUARD_SCHEMA_META, REQUEST_CONTEXT_META, ROUTER_META, ResponseError, SCHEMES_META, adapterContextOf, bearerChallenge, buildToolInputSchema, contractOf, describeTool, extractCredential, flattenRoutes, guardDenyFor, insufficientScope, isGuardDenial, rawResponse, requiresDenial, resolveSecurityRequirements, selectToolRoutes, toolOptionsOf, validateRequest, withPermissions } from "kizunajs/adapter";
|
|
7
|
-
import { deriveToolNames, isJsonMediaType, isStreamResponse, isSuccessStatus, isVoidSchema, resolveResponseBody, resolveResponseContentType } from "kizunajs/generator";
|
|
6
|
+
import { GUARDS_META, GUARD_SCHEMA_META, REQUEST_CONTEXT_META, ROUTER_META, ResponseError, SCHEMES_META, adapterContextOf, bearerChallenge, buildToolInputSchema, contractOf, describeTool, extractCredential, flattenRoutes, formatValidationError, guardDenyFor, insufficientScope, isGuardDenial, rawResponse, requiresDenial, resolveSecurityRequirements, selectToolRoutes, toolOptionsOf, validateRequest, withPermissions } from "kizunajs/adapter";
|
|
7
|
+
import { deriveToolNames, encodeForWire, isJsonMediaType, isStreamResponse, isSuccessStatus, isVoidSchema, resolveResponseBody, resolveResponseContentType } from "kizunajs/generator";
|
|
8
8
|
//#region src/oauth.ts
|
|
9
9
|
const McpOAuthSchema = z.object({
|
|
10
10
|
/**
|
|
@@ -129,6 +129,37 @@ const approval = (route, context) => {
|
|
|
129
129
|
};
|
|
130
130
|
};
|
|
131
131
|
/**
|
|
132
|
+
* A schema as JSON Schema, with a `z.date()` as the ISO string the wire
|
|
133
|
+
* carries. Zod alone throws on a date, which would empty the whole tool list.
|
|
134
|
+
*/
|
|
135
|
+
const toJsonSchema = (schema, io) => z.toJSONSchema(schema, {
|
|
136
|
+
target: "draft-2020-12",
|
|
137
|
+
io,
|
|
138
|
+
unrepresentable: "any",
|
|
139
|
+
override: encodeForWire
|
|
140
|
+
});
|
|
141
|
+
/**
|
|
142
|
+
* What the SDK publishes for a tool. Input passes through unchecked, so the
|
|
143
|
+
* call is validated once, by `validateRequest`, as an HTTP request is. Output
|
|
144
|
+
* keeps the route's own check.
|
|
145
|
+
*/
|
|
146
|
+
const publishedSchema = (jsonSchema, check) => ({ "~standard": {
|
|
147
|
+
version: 1,
|
|
148
|
+
vendor: "kizuna",
|
|
149
|
+
validate: check === void 0 ? (value) => ({ value }) : check["~standard"].validate,
|
|
150
|
+
jsonSchema: {
|
|
151
|
+
input: () => jsonSchema,
|
|
152
|
+
output: () => jsonSchema
|
|
153
|
+
}
|
|
154
|
+
} });
|
|
155
|
+
/**
|
|
156
|
+
* MCP's recommended schema for a tool that takes nothing.
|
|
157
|
+
*/
|
|
158
|
+
const NO_INPUT = {
|
|
159
|
+
type: "object",
|
|
160
|
+
additionalProperties: false
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
132
163
|
* What the route says about itself, over what its method already implies.
|
|
133
164
|
*/
|
|
134
165
|
const buildToolAnnotations = (route) => {
|
|
@@ -303,21 +334,16 @@ const executeToolCall = async (route, routeKey, args, router, handlerContext, gu
|
|
|
303
334
|
params,
|
|
304
335
|
query,
|
|
305
336
|
body,
|
|
306
|
-
headers: {}
|
|
337
|
+
headers: credentialHeaders ?? {}
|
|
307
338
|
});
|
|
308
|
-
if (!validation.ok)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
}, null, 2)
|
|
318
|
-
}],
|
|
319
|
-
isError: true
|
|
320
|
-
};
|
|
339
|
+
if (!validation.ok) {
|
|
340
|
+
const formatted = formatValidationError(validation.error);
|
|
341
|
+
return toolEnvelope(400, problemDetails(400, formatted.detail, { errors: formatted.issues.map((issue) => ({
|
|
342
|
+
code: issue.code ?? "custom",
|
|
343
|
+
path: issue.path,
|
|
344
|
+
message: issue.message
|
|
345
|
+
})) }));
|
|
346
|
+
}
|
|
321
347
|
const handler = resolveHandler(router, routeKey);
|
|
322
348
|
if (typeof handler !== "function") return {
|
|
323
349
|
content: [{
|
|
@@ -349,16 +375,8 @@ const executeToolCall = async (route, routeKey, args, router, handlerContext, gu
|
|
|
349
375
|
return toolEnvelope(result.status, result.body);
|
|
350
376
|
} catch (error) {
|
|
351
377
|
if (error instanceof ResponseError) return toolEnvelope(error.status, error.body);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
type: "text",
|
|
355
|
-
text: JSON.stringify({
|
|
356
|
-
status: 500,
|
|
357
|
-
body: { detail: error instanceof Error ? error.message : "Internal Server Error" }
|
|
358
|
-
}, null, 2)
|
|
359
|
-
}],
|
|
360
|
-
isError: true
|
|
361
|
-
};
|
|
378
|
+
console.error(`[kizuna] tool "${routeKey}" threw:`, error);
|
|
379
|
+
return toolEnvelope(500, problemDetails(500, "Internal Server Error"));
|
|
362
380
|
}
|
|
363
381
|
};
|
|
364
382
|
/**
|
|
@@ -389,8 +407,8 @@ const createMcpServer = (api, options) => {
|
|
|
389
407
|
for (const definition of definitions) server.registerTool(definition.name, {
|
|
390
408
|
...definition.title === void 0 ? {} : { title: definition.title },
|
|
391
409
|
description: definition.description,
|
|
392
|
-
inputSchema: definition.inputSchema.shape === void 0 ?
|
|
393
|
-
outputSchema: definition.outputSchema,
|
|
410
|
+
inputSchema: publishedSchema(definition.inputSchema.shape === void 0 ? NO_INPUT : toJsonSchema(z.object(definition.inputSchema.shape), "input")),
|
|
411
|
+
outputSchema: publishedSchema(toJsonSchema(definition.outputSchema, "output"), definition.outputSchema),
|
|
394
412
|
annotations: buildToolAnnotations(definition.route)
|
|
395
413
|
}, async (args, context) => {
|
|
396
414
|
const refusal = approval(definition.route, context);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/mcp",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.24",
|
|
4
4
|
"description": "MCP endpoint for Kizuna.js, so AI assistants can call your routes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
"@modelcontextprotocol/server": "^2.0.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"kizunajs": "2.0.0-beta.
|
|
63
|
+
"kizunajs": "2.0.0-beta.24",
|
|
64
64
|
"zod": "^4.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@modelcontextprotocol/client": "^2.0.0",
|
|
68
|
-
"kizunajs": "2.0.0-beta.
|
|
69
|
-
"@kizunajs/express": "2.0.0-beta.
|
|
68
|
+
"kizunajs": "2.0.0-beta.24",
|
|
69
|
+
"@kizunajs/express": "2.0.0-beta.24",
|
|
70
70
|
"@types/express": "^5.0.0",
|
|
71
71
|
"express": "^5.0.0",
|
|
72
72
|
"tsdown": "^0.21.0",
|