@astrasyncai/verification-gateway 2.4.4 → 2.4.5
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 +82 -0
- package/dist/adapter-interface/interface.d.mts +2 -2
- package/dist/adapter-interface/interface.d.ts +2 -2
- package/dist/adapters/express.d.mts +2 -2
- package/dist/adapters/express.d.ts +2 -2
- package/dist/adapters/express.js +4 -0
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/express.mjs +4 -0
- package/dist/adapters/express.mjs.map +1 -1
- package/dist/adapters/mcp.d.mts +54 -18
- package/dist/adapters/mcp.d.ts +54 -18
- package/dist/adapters/mcp.js +76 -23
- package/dist/adapters/mcp.js.map +1 -1
- package/dist/adapters/mcp.mjs +76 -23
- package/dist/adapters/mcp.mjs.map +1 -1
- package/dist/adapters/nextjs.d.mts +2 -2
- package/dist/adapters/nextjs.d.ts +2 -2
- package/dist/adapters/nextjs.js +4 -0
- package/dist/adapters/nextjs.js.map +1 -1
- package/dist/adapters/nextjs.mjs +4 -0
- package/dist/adapters/nextjs.mjs.map +1 -1
- package/dist/adapters/sdk.d.mts +2 -2
- package/dist/adapters/sdk.d.ts +2 -2
- package/dist/adapters/sdk.js +4 -0
- package/dist/adapters/sdk.js.map +1 -1
- package/dist/adapters/sdk.mjs +4 -0
- package/dist/adapters/sdk.mjs.map +1 -1
- package/dist/agent/index.d.mts +2 -2
- package/dist/agent/index.d.ts +2 -2
- package/dist/browser/background.js +4 -0
- package/dist/browser/background.js.map +1 -1
- package/dist/browser/background.mjs +4 -0
- package/dist/browser/background.mjs.map +1 -1
- package/dist/browser/browser-adapter.d.mts +2 -2
- package/dist/browser/browser-adapter.d.ts +2 -2
- package/dist/cli/index.d.mts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cursor/cursor-adapter.d.mts +2 -2
- package/dist/cursor/cursor-adapter.d.ts +2 -2
- package/dist/cursor/extension.d.mts +2 -2
- package/dist/cursor/extension.d.ts +2 -2
- package/dist/cursor/extension.js +4 -0
- package/dist/cursor/extension.js.map +1 -1
- package/dist/cursor/extension.mjs +4 -0
- package/dist/cursor/extension.mjs.map +1 -1
- package/dist/{express-Ck2RHZLT.d.mts → express-D5hAJ2Gv.d.mts} +1 -1
- package/dist/{express-DZmEzCgo.d.ts → express-XCkk7BsJ.d.ts} +1 -1
- package/dist/gateway/gateway.d.mts +2 -2
- package/dist/gateway/gateway.d.ts +2 -2
- package/dist/gateway/gateway.js +4 -0
- package/dist/gateway/gateway.js.map +1 -1
- package/dist/gateway/gateway.mjs +4 -0
- package/dist/gateway/gateway.mjs.map +1 -1
- package/dist/git-trigger/git-hooks.d.mts +2 -2
- package/dist/git-trigger/git-hooks.d.ts +2 -2
- package/dist/{index-6Jus6yWU.d.ts → index-Bstl43HI.d.ts} +1 -1
- package/dist/{index-BgKghi19.d.ts → index-CH4TfcbL.d.ts} +1 -1
- package/dist/{index-D698fDOk.d.mts → index-TS4SGvf4.d.mts} +1 -1
- package/dist/{index-BZZTOfrI.d.mts → index-u08qcXq9.d.mts} +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -1
- package/dist/local-evaluator/evaluator.d.mts +2 -2
- package/dist/local-evaluator/evaluator.d.ts +2 -2
- package/dist/{nextjs-93PHcE-i.d.mts → nextjs-CFA0J_4x.d.mts} +1 -1
- package/dist/{nextjs-t_ix2zQZ.d.ts → nextjs-DP2EpI-4.d.ts} +1 -1
- package/dist/{sdk-BFwzjYjl.d.mts → sdk-C8W54WZS.d.mts} +1 -1
- package/dist/{sdk-Chq02d82.d.ts → sdk-CwwCGDzK.d.ts} +1 -1
- package/dist/transport/index.d.mts +2 -2
- package/dist/transport/index.d.ts +2 -2
- package/dist/{types-CVT-sorC.d.mts → types-CbZOkIr-.d.mts} +21 -15
- package/dist/{types-CVT-sorC.d.ts → types-CbZOkIr-.d.ts} +21 -15
- package/dist/{types-CLP_TDu5.d.ts → types-DXNkr61h.d.ts} +1 -1
- package/dist/{types-y13mmzbA.d.mts → types-tBNFSbw_.d.mts} +1 -1
- package/dist/ui/index.d.mts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/adapters/mcp.mjs
CHANGED
|
@@ -17,6 +17,9 @@ function hasMinimumAccess(actual, required) {
|
|
|
17
17
|
return ACCESS_LEVEL_HIERARCHY[actual] >= ACCESS_LEVEL_HIERARCHY[required];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// src/version.ts
|
|
21
|
+
var SDK_VERSION = "2.4.5";
|
|
22
|
+
|
|
20
23
|
// src/verify.ts
|
|
21
24
|
var DEFAULT_CONFIG = {
|
|
22
25
|
apiBaseUrl: "https://astrasync.ai/api",
|
|
@@ -175,6 +178,7 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
175
178
|
if (requestData.runtimeChallengeOptions)
|
|
176
179
|
body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
|
|
177
180
|
if (requestData.invocationProtocol) body.invocationProtocol = requestData.invocationProtocol;
|
|
181
|
+
body.sdkVersion = SDK_VERSION;
|
|
178
182
|
if (requestData.callerMetadata || requestData.clientIp || requestData.userAgent) {
|
|
179
183
|
const meta = {
|
|
180
184
|
...requestData.clientIp && { sourceIp: requestData.clientIp },
|
|
@@ -458,16 +462,17 @@ function parseMcpJsonRpc(body) {
|
|
|
458
462
|
if (method === "initialize" && params && typeof params.protocolVersion === "string") {
|
|
459
463
|
protocolVersion = params.protocolVersion;
|
|
460
464
|
}
|
|
461
|
-
let agentIdFromBody;
|
|
462
465
|
const meta = params?._meta;
|
|
463
466
|
const astrasyncMeta = meta?.astrasync;
|
|
467
|
+
const args = params?.arguments;
|
|
468
|
+
let agentIdFromBody;
|
|
464
469
|
if (astrasyncMeta && typeof astrasyncMeta.agentId === "string") {
|
|
465
470
|
agentIdFromBody = astrasyncMeta.agentId;
|
|
466
|
-
} else {
|
|
467
|
-
|
|
468
|
-
if (args && typeof args.agent_id === "string") agentIdFromBody = args.agent_id;
|
|
471
|
+
} else if (args && typeof args.agent_id === "string") {
|
|
472
|
+
agentIdFromBody = args.agent_id;
|
|
469
473
|
}
|
|
470
|
-
const
|
|
474
|
+
const purposeBodyResult = extractFromMcpBody(astrasyncMeta, args, "purpose");
|
|
475
|
+
const actionBodyResult = extractFromMcpBody(astrasyncMeta, args, "action");
|
|
471
476
|
const isInitialize = method === "initialize";
|
|
472
477
|
const isToolCall = method === "tools/call";
|
|
473
478
|
const isIntrospection = method === "tools/list" || method === "prompts/list" || method === "resources/list" || method === "ping" || method === "notifications/initialized";
|
|
@@ -476,22 +481,51 @@ function parseMcpJsonRpc(body) {
|
|
|
476
481
|
...toolName ? { toolName } : {},
|
|
477
482
|
...protocolVersion ? { protocolVersion } : {},
|
|
478
483
|
...agentIdFromBody ? { agentIdFromBody } : {},
|
|
479
|
-
...
|
|
484
|
+
...purposeBodyResult.value ? { purposeFromBody: purposeBodyResult.value } : {},
|
|
485
|
+
...purposeBodyResult.source ? { purposeSourceFromBody: purposeBodyResult.source } : {},
|
|
486
|
+
...actionBodyResult.value ? { actionFromBody: actionBodyResult.value } : {},
|
|
487
|
+
...actionBodyResult.source ? { actionSourceFromBody: actionBodyResult.source } : {},
|
|
480
488
|
isInitialize,
|
|
481
489
|
isToolCall,
|
|
482
490
|
isIntrospection
|
|
483
491
|
};
|
|
484
492
|
}
|
|
485
|
-
function
|
|
486
|
-
|
|
493
|
+
function extractFromMcpBody(astrasyncMeta, args, key) {
|
|
494
|
+
if (astrasyncMeta && typeof astrasyncMeta[key] === "string") {
|
|
495
|
+
return { value: astrasyncMeta[key], source: "meta" };
|
|
496
|
+
}
|
|
497
|
+
if (args && typeof args[key] === "string") {
|
|
498
|
+
return { value: args[key], source: "tool_argument" };
|
|
499
|
+
}
|
|
500
|
+
return { value: void 0, source: void 0 };
|
|
501
|
+
}
|
|
502
|
+
function mcpToPdlss(parsed, headerPurpose, headerAction) {
|
|
487
503
|
const resource = parsed.toolName ? `mcp:tool/${parsed.toolName}` : `mcp:method/${parsed.method}`;
|
|
504
|
+
let purpose;
|
|
505
|
+
let purposeSource;
|
|
488
506
|
if (headerPurpose) {
|
|
489
|
-
|
|
507
|
+
purpose = headerPurpose;
|
|
508
|
+
purposeSource = "header";
|
|
509
|
+
} else if (parsed.purposeFromBody && parsed.purposeSourceFromBody) {
|
|
510
|
+
purpose = parsed.purposeFromBody;
|
|
511
|
+
purposeSource = parsed.purposeSourceFromBody;
|
|
512
|
+
} else {
|
|
513
|
+
purpose = "mcp_invoke";
|
|
514
|
+
purposeSource = "default_mcp_invoke";
|
|
490
515
|
}
|
|
491
|
-
|
|
492
|
-
|
|
516
|
+
let action;
|
|
517
|
+
let actionSource;
|
|
518
|
+
if (headerAction) {
|
|
519
|
+
action = headerAction;
|
|
520
|
+
actionSource = "header";
|
|
521
|
+
} else if (parsed.actionFromBody && parsed.actionSourceFromBody) {
|
|
522
|
+
action = parsed.actionFromBody;
|
|
523
|
+
actionSource = parsed.actionSourceFromBody;
|
|
524
|
+
} else {
|
|
525
|
+
action = parsed.toolName ? `${parsed.method}:${parsed.toolName}` : parsed.method;
|
|
526
|
+
actionSource = "transport_layer";
|
|
493
527
|
}
|
|
494
|
-
return { purpose
|
|
528
|
+
return { purpose, action, resource, purposeSource, actionSource };
|
|
495
529
|
}
|
|
496
530
|
function mcpRiskTier(parsed) {
|
|
497
531
|
if (parsed.isInitialize || parsed.method === "notifications/initialized") return "none";
|
|
@@ -502,6 +536,11 @@ function mcpRiskTier(parsed) {
|
|
|
502
536
|
}
|
|
503
537
|
|
|
504
538
|
// src/adapters/mcp.ts
|
|
539
|
+
function readSingleHeader(value) {
|
|
540
|
+
if (typeof value === "string") return value;
|
|
541
|
+
if (Array.isArray(value)) return value[0];
|
|
542
|
+
return void 0;
|
|
543
|
+
}
|
|
505
544
|
function defaultMcpDenied(result, req, res) {
|
|
506
545
|
const id = req.body?.id ?? null;
|
|
507
546
|
const status = result.verified ? 403 : 401;
|
|
@@ -596,25 +635,28 @@ function createMcpMiddleware(options) {
|
|
|
596
635
|
toolGates,
|
|
597
636
|
methodGates
|
|
598
637
|
});
|
|
599
|
-
|
|
638
|
+
const credentials = extractCredentials(
|
|
639
|
+
req.headers,
|
|
640
|
+
req.query
|
|
641
|
+
);
|
|
642
|
+
if (effectiveAstraId) credentials.astraId = effectiveAstraId;
|
|
643
|
+
const shouldEnforce = minAccessLevel !== "none";
|
|
644
|
+
if (minAccessLevel === "none" && (!config.evaluateAlwaysIfCredentialed || !credentials.astraId)) {
|
|
600
645
|
if (config.setPassThroughHeader) {
|
|
601
646
|
res.setHeader("X-Astra-Gateway-Mode", "unenforced");
|
|
602
647
|
res.setHeader("X-Astra-Gateway-Reason", "mcp-tier-none");
|
|
603
648
|
}
|
|
604
649
|
return next();
|
|
605
650
|
}
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
);
|
|
610
|
-
if (effectiveAstraId) credentials.astraId = effectiveAstraId;
|
|
611
|
-
const headerPurposeRaw = req.headers["x-astra-purpose"];
|
|
612
|
-
const headerPurpose = typeof headerPurposeRaw === "string" ? headerPurposeRaw : Array.isArray(headerPurposeRaw) ? headerPurposeRaw[0] : void 0;
|
|
613
|
-
const pdlss = mcpToPdlss(parsed, headerPurpose, parsed.purposeFromBody);
|
|
651
|
+
const headerPurpose = readSingleHeader(req.headers["x-astra-purpose"]);
|
|
652
|
+
const headerAction = readSingleHeader(req.headers["x-astra-action"]);
|
|
653
|
+
const pdlss = mcpToPdlss(parsed, headerPurpose, headerAction);
|
|
614
654
|
if (config.debug) {
|
|
615
|
-
console.debug("[mcp-middleware]
|
|
655
|
+
console.debug("[mcp-middleware] pdlss resolved", {
|
|
616
656
|
purpose_source: pdlss.purposeSource,
|
|
617
|
-
resolved_purpose: pdlss.purpose
|
|
657
|
+
resolved_purpose: pdlss.purpose,
|
|
658
|
+
action_source: pdlss.actionSource,
|
|
659
|
+
resolved_action: pdlss.action
|
|
618
660
|
});
|
|
619
661
|
}
|
|
620
662
|
const counterpartyUrl = config.counterpartyUrl || `${req.protocol}://${req.get("host")}${req.path}`;
|
|
@@ -649,6 +691,17 @@ function createMcpMiddleware(options) {
|
|
|
649
691
|
onDenied(result, req, res);
|
|
650
692
|
return;
|
|
651
693
|
}
|
|
694
|
+
if (!shouldEnforce) {
|
|
695
|
+
if (config.setPassThroughHeader) {
|
|
696
|
+
res.setHeader("X-Astra-Gateway-Mode", "enforced");
|
|
697
|
+
res.setHeader("X-Astra-Gateway-Reason", "evaluated-not-enforced");
|
|
698
|
+
}
|
|
699
|
+
if (shouldRecordDecisions && sessionId) {
|
|
700
|
+
recordDecision(config, sessionId, "granted").catch(() => {
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
return next();
|
|
704
|
+
}
|
|
652
705
|
if (!hasMinimumAccess(result.accessLevel, minAccessLevel)) {
|
|
653
706
|
const insufficientFailure = {
|
|
654
707
|
dimension: "access_level.insufficient",
|