@kizunajs/mcp 2.0.0-beta.27 → 2.0.0-beta.29
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 +13 -9
- package/dist/index.mjs +14 -10
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -307,11 +307,10 @@ const runGuards = async (requirements, roles, requires, label, params, guards, s
|
|
|
307
307
|
};
|
|
308
308
|
const schemeDefinition = schemes?.[scheme];
|
|
309
309
|
const credential = schemeDefinition ? (0, kizunajs_adapter.extractCredential)(schemeDefinition, credentialRequest) : {};
|
|
310
|
-
const guardResult = await guard
|
|
310
|
+
const guardResult = await (0, kizunajs_adapter.callGuard)(guard, schemeDefinition, {
|
|
311
311
|
...handlerContext ?? {},
|
|
312
312
|
...credential,
|
|
313
313
|
params,
|
|
314
|
-
deny: (0, kizunajs_adapter.guardDenyFor)(schemeDefinition),
|
|
315
314
|
...Object.keys(requestContext).length > 0 ? { requestContext } : {}
|
|
316
315
|
});
|
|
317
316
|
if ((0, kizunajs_adapter.isGuardDenial)(guardResult)) return {
|
|
@@ -448,11 +447,10 @@ const enforceOAuth = async (args) => {
|
|
|
448
447
|
};
|
|
449
448
|
const credential = (0, kizunajs_adapter.extractCredential)(args.schemeDefinition, credentialRequest);
|
|
450
449
|
const presented = Object.values(credential).some((value) => value !== null);
|
|
451
|
-
const guardResult = await args.guard
|
|
450
|
+
const guardResult = await (0, kizunajs_adapter.callGuard)(args.guard, args.schemeDefinition, {
|
|
452
451
|
...args.handlerContext,
|
|
453
452
|
...credential,
|
|
454
453
|
params: args.params,
|
|
455
|
-
deny: (0, kizunajs_adapter.guardDenyFor)(args.schemeDefinition),
|
|
456
454
|
...args.requestContext && Object.keys(args.requestContext).length > 0 ? { requestContext: args.requestContext } : {}
|
|
457
455
|
});
|
|
458
456
|
if ((0, kizunajs_adapter.isGuardDenial)(guardResult)) {
|
|
@@ -541,16 +539,17 @@ const prepareOAuth = (oauth, endpointPath, api) => {
|
|
|
541
539
|
tools: new Map(buildMcpTools(api.routes).map((definition) => [definition.name, definition]))
|
|
542
540
|
};
|
|
543
541
|
};
|
|
542
|
+
const isToolCall = (message) => message !== null && typeof message === "object" && message.method === "tools/call";
|
|
544
543
|
/**
|
|
545
|
-
* The oauth scheme's requirement for the tool a `tools/call`
|
|
544
|
+
* The oauth scheme's requirement for the tool a `tools/call` message names, so
|
|
546
545
|
* the challenge speaks about the operation the client is attempting. The
|
|
547
546
|
* route's `roles` and `requires` ride along when the oauth identity is the only one on
|
|
548
547
|
* the route whose roles can satisfy it; otherwise the tool call checks it,
|
|
549
548
|
* with every guard's role in hand.
|
|
550
549
|
*/
|
|
551
|
-
const toolCallTarget = (
|
|
552
|
-
if (
|
|
553
|
-
const callParams =
|
|
550
|
+
const toolCallTarget = (message, enforcement) => {
|
|
551
|
+
if (isToolCall(message)) {
|
|
552
|
+
const callParams = message.params;
|
|
554
553
|
const definition = typeof callParams?.name === "string" ? enforcement.tools.get(callParams.name) : void 0;
|
|
555
554
|
if (definition !== void 0) {
|
|
556
555
|
const requirements = (0, kizunajs_adapter.resolveSecurityRequirements)(definition.route);
|
|
@@ -594,7 +593,12 @@ const mcpEndpoint = (props, api) => {
|
|
|
594
593
|
const enforcement = enforcementOf();
|
|
595
594
|
let transportAuth;
|
|
596
595
|
if (enforcement !== void 0) {
|
|
597
|
-
const
|
|
596
|
+
const calls = (Array.isArray(args.body) ? args.body : [args.body]).filter(isToolCall);
|
|
597
|
+
if (calls.length > 1) return denialResponse({
|
|
598
|
+
status: 400,
|
|
599
|
+
body: { detail: "Send one tools/call per request." }
|
|
600
|
+
});
|
|
601
|
+
const target = toolCallTarget(calls[0], enforcement);
|
|
598
602
|
const outcome = await enforceOAuth({
|
|
599
603
|
scheme: enforcement.oauth.scheme,
|
|
600
604
|
guard: enforcement.guard,
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ 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, formatValidationError,
|
|
6
|
+
import { GUARDS_META, GUARD_SCHEMA_META, REQUEST_CONTEXT_META, ROUTER_META, ResponseError, SCHEMES_META, adapterContextOf, bearerChallenge, buildToolInputSchema, callGuard, contractOf, describeTool, extractCredential, flattenRoutes, formatValidationError, insufficientScope, isGuardDenial, rawResponse, requiresDenial, resolveSecurityRequirements, selectToolRoutes, toolInputJsonSchema, toolJsonSchema, toolOptionsOf, validateRequest, withPermissions } from "kizunajs/adapter";
|
|
7
7
|
import { deriveToolNames, isJsonMediaType, isStreamResponse, isSuccessStatus, isVoidSchema, resolveResponseBody, resolveResponseContentType } from "kizunajs/generator";
|
|
8
8
|
//#region src/oauth.ts
|
|
9
9
|
const McpOAuthSchema = z.object({
|
|
@@ -306,11 +306,10 @@ const runGuards = async (requirements, roles, requires, label, params, guards, s
|
|
|
306
306
|
};
|
|
307
307
|
const schemeDefinition = schemes?.[scheme];
|
|
308
308
|
const credential = schemeDefinition ? extractCredential(schemeDefinition, credentialRequest) : {};
|
|
309
|
-
const guardResult = await guard
|
|
309
|
+
const guardResult = await callGuard(guard, schemeDefinition, {
|
|
310
310
|
...handlerContext ?? {},
|
|
311
311
|
...credential,
|
|
312
312
|
params,
|
|
313
|
-
deny: guardDenyFor(schemeDefinition),
|
|
314
313
|
...Object.keys(requestContext).length > 0 ? { requestContext } : {}
|
|
315
314
|
});
|
|
316
315
|
if (isGuardDenial(guardResult)) return {
|
|
@@ -447,11 +446,10 @@ const enforceOAuth = async (args) => {
|
|
|
447
446
|
};
|
|
448
447
|
const credential = extractCredential(args.schemeDefinition, credentialRequest);
|
|
449
448
|
const presented = Object.values(credential).some((value) => value !== null);
|
|
450
|
-
const guardResult = await args.guard
|
|
449
|
+
const guardResult = await callGuard(args.guard, args.schemeDefinition, {
|
|
451
450
|
...args.handlerContext,
|
|
452
451
|
...credential,
|
|
453
452
|
params: args.params,
|
|
454
|
-
deny: guardDenyFor(args.schemeDefinition),
|
|
455
453
|
...args.requestContext && Object.keys(args.requestContext).length > 0 ? { requestContext: args.requestContext } : {}
|
|
456
454
|
});
|
|
457
455
|
if (isGuardDenial(guardResult)) {
|
|
@@ -540,16 +538,17 @@ const prepareOAuth = (oauth, endpointPath, api) => {
|
|
|
540
538
|
tools: new Map(buildMcpTools(api.routes).map((definition) => [definition.name, definition]))
|
|
541
539
|
};
|
|
542
540
|
};
|
|
541
|
+
const isToolCall = (message) => message !== null && typeof message === "object" && message.method === "tools/call";
|
|
543
542
|
/**
|
|
544
|
-
* The oauth scheme's requirement for the tool a `tools/call`
|
|
543
|
+
* The oauth scheme's requirement for the tool a `tools/call` message names, so
|
|
545
544
|
* the challenge speaks about the operation the client is attempting. The
|
|
546
545
|
* route's `roles` and `requires` ride along when the oauth identity is the only one on
|
|
547
546
|
* the route whose roles can satisfy it; otherwise the tool call checks it,
|
|
548
547
|
* with every guard's role in hand.
|
|
549
548
|
*/
|
|
550
|
-
const toolCallTarget = (
|
|
551
|
-
if (
|
|
552
|
-
const callParams =
|
|
549
|
+
const toolCallTarget = (message, enforcement) => {
|
|
550
|
+
if (isToolCall(message)) {
|
|
551
|
+
const callParams = message.params;
|
|
553
552
|
const definition = typeof callParams?.name === "string" ? enforcement.tools.get(callParams.name) : void 0;
|
|
554
553
|
if (definition !== void 0) {
|
|
555
554
|
const requirements = resolveSecurityRequirements(definition.route);
|
|
@@ -593,7 +592,12 @@ const mcpEndpoint = (props, api) => {
|
|
|
593
592
|
const enforcement = enforcementOf();
|
|
594
593
|
let transportAuth;
|
|
595
594
|
if (enforcement !== void 0) {
|
|
596
|
-
const
|
|
595
|
+
const calls = (Array.isArray(args.body) ? args.body : [args.body]).filter(isToolCall);
|
|
596
|
+
if (calls.length > 1) return denialResponse({
|
|
597
|
+
status: 400,
|
|
598
|
+
body: { detail: "Send one tools/call per request." }
|
|
599
|
+
});
|
|
600
|
+
const target = toolCallTarget(calls[0], enforcement);
|
|
597
601
|
const outcome = await enforceOAuth({
|
|
598
602
|
scheme: enforcement.oauth.scheme,
|
|
599
603
|
guard: enforcement.guard,
|
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.29",
|
|
4
4
|
"description": "MCP endpoint for Kizuna.js, so AI assistants can call your routes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -57,21 +57,21 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@modelcontextprotocol/server": "^2.
|
|
60
|
+
"@modelcontextprotocol/server": "^2.4.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"kizunajs": "2.0.0-beta.
|
|
63
|
+
"kizunajs": "2.0.0-beta.29",
|
|
64
64
|
"zod": "^4.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@
|
|
68
|
-
"
|
|
69
|
-
"@
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"tsdown": "^0.21.
|
|
67
|
+
"@kizunajs/express": "2.0.0-beta.29",
|
|
68
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
69
|
+
"@types/express": "^5.0.6",
|
|
70
|
+
"express": "^5.3.0",
|
|
71
|
+
"kizunajs": "2.0.0-beta.29",
|
|
72
|
+
"tsdown": "^0.21.10",
|
|
73
73
|
"typescript": "^6.0.3",
|
|
74
|
-
"zod": "^4.
|
|
74
|
+
"zod": "^4.6.7"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"build": "tsdown src/index.ts --format esm,cjs --dts --clean --external kizunajs --external zod --external @modelcontextprotocol/sdk",
|