@kya-os/mcp-i-runtime 1.0.0
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/.turbo/turbo-build.log +4 -0
- package/dist/auth/handshake.d.ts +136 -0
- package/dist/auth/handshake.d.ts.map +1 -0
- package/dist/auth/handshake.js +276 -0
- package/dist/auth/handshake.js.map +1 -0
- package/dist/auth/index.d.ts +6 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +12 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.ts +52 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +10 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/cache/oauth-config-cache.d.ts +69 -0
- package/dist/cache/oauth-config-cache.d.ts.map +1 -0
- package/dist/cache/oauth-config-cache.js +76 -0
- package/dist/cache/oauth-config-cache.js.map +1 -0
- package/dist/cache/tool-protection-cache.d.ts +102 -0
- package/dist/cache/tool-protection-cache.d.ts.map +1 -0
- package/dist/cache/tool-protection-cache.js +131 -0
- package/dist/cache/tool-protection-cache.js.map +1 -0
- package/dist/compliance/index.d.ts +8 -0
- package/dist/compliance/index.d.ts.map +1 -0
- package/dist/compliance/index.js +24 -0
- package/dist/compliance/index.js.map +1 -0
- package/dist/compliance/schema-registry.d.ts +50 -0
- package/dist/compliance/schema-registry.d.ts.map +1 -0
- package/dist/compliance/schema-registry.js +438 -0
- package/dist/compliance/schema-registry.js.map +1 -0
- package/dist/compliance/schema-verifier.d.ts +110 -0
- package/dist/compliance/schema-verifier.d.ts.map +1 -0
- package/dist/compliance/schema-verifier.js +518 -0
- package/dist/compliance/schema-verifier.js.map +1 -0
- package/dist/config/remote-config.d.ts +188 -0
- package/dist/config/remote-config.d.ts.map +1 -0
- package/dist/config/remote-config.js +268 -0
- package/dist/config/remote-config.js.map +1 -0
- package/dist/config.d.ts +182 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +148 -0
- package/dist/config.js.map +1 -0
- package/dist/identity/idp-token-resolver.d.ts +69 -0
- package/dist/identity/idp-token-resolver.d.ts.map +1 -0
- package/dist/identity/idp-token-resolver.js +136 -0
- package/dist/identity/idp-token-resolver.js.map +1 -0
- package/dist/identity/idp-token-storage.interface.d.ts +80 -0
- package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
- package/dist/identity/idp-token-storage.interface.js +14 -0
- package/dist/identity/idp-token-storage.interface.js.map +1 -0
- package/dist/identity/user-did-manager.d.ts +228 -0
- package/dist/identity/user-did-manager.d.ts.map +1 -0
- package/dist/identity/user-did-manager.js +356 -0
- package/dist/identity/user-did-manager.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +193 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/index.d.ts +5 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +10 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +33 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +104 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/proof/generator.d.ts +109 -0
- package/dist/proof/generator.d.ts.map +1 -0
- package/dist/proof/generator.js +236 -0
- package/dist/proof/generator.js.map +1 -0
- package/dist/proof/index.d.ts +5 -0
- package/dist/proof/index.d.ts.map +1 -0
- package/dist/proof/index.js +11 -0
- package/dist/proof/index.js.map +1 -0
- package/dist/providers/base.d.ts +95 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +47 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/memory.d.ts +42 -0
- package/dist/providers/memory.d.ts.map +1 -0
- package/dist/providers/memory.js +121 -0
- package/dist/providers/memory.js.map +1 -0
- package/dist/runtime/audit-logger.d.ts +37 -0
- package/dist/runtime/audit-logger.d.ts.map +1 -0
- package/dist/runtime/audit-logger.js +9 -0
- package/dist/runtime/audit-logger.js.map +1 -0
- package/dist/runtime/base.d.ts +392 -0
- package/dist/runtime/base.d.ts.map +1 -0
- package/dist/runtime/base.js +1527 -0
- package/dist/runtime/base.js.map +1 -0
- package/dist/runtime/dif-core.d.ts +33 -0
- package/dist/runtime/dif-core.d.ts.map +1 -0
- package/dist/runtime/dif-core.js +14 -0
- package/dist/runtime/dif-core.js.map +1 -0
- package/dist/runtime/ext-apps-constants.d.ts +20 -0
- package/dist/runtime/ext-apps-constants.d.ts.map +1 -0
- package/dist/runtime/ext-apps-constants.js +23 -0
- package/dist/runtime/ext-apps-constants.js.map +1 -0
- package/dist/services/access-control.service.d.ts +138 -0
- package/dist/services/access-control.service.d.ts.map +1 -0
- package/dist/services/access-control.service.js +721 -0
- package/dist/services/access-control.service.js.map +1 -0
- package/dist/services/authorization/authorization-registry.d.ts +29 -0
- package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
- package/dist/services/authorization/authorization-registry.js +58 -0
- package/dist/services/authorization/authorization-registry.js.map +1 -0
- package/dist/services/authorization/types.d.ts +53 -0
- package/dist/services/authorization/types.d.ts.map +1 -0
- package/dist/services/authorization/types.js +10 -0
- package/dist/services/authorization/types.js.map +1 -0
- package/dist/services/batch-delegation.service.d.ts +53 -0
- package/dist/services/batch-delegation.service.d.ts.map +1 -0
- package/dist/services/batch-delegation.service.js +95 -0
- package/dist/services/batch-delegation.service.js.map +1 -0
- package/dist/services/crypto.service.d.ts +69 -0
- package/dist/services/crypto.service.d.ts.map +1 -0
- package/dist/services/crypto.service.js +225 -0
- package/dist/services/crypto.service.js.map +1 -0
- package/dist/services/delegation-error-formatter.d.ts +124 -0
- package/dist/services/delegation-error-formatter.d.ts.map +1 -0
- package/dist/services/delegation-error-formatter.js +214 -0
- package/dist/services/delegation-error-formatter.js.map +1 -0
- package/dist/services/errors.d.ts +49 -0
- package/dist/services/errors.d.ts.map +1 -0
- package/dist/services/errors.js +66 -0
- package/dist/services/errors.js.map +1 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +15 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/oauth-config.service.d.ts +53 -0
- package/dist/services/oauth-config.service.d.ts.map +1 -0
- package/dist/services/oauth-config.service.js +141 -0
- package/dist/services/oauth-config.service.js.map +1 -0
- package/dist/services/oauth-provider-registry.d.ts +88 -0
- package/dist/services/oauth-provider-registry.d.ts.map +1 -0
- package/dist/services/oauth-provider-registry.js +128 -0
- package/dist/services/oauth-provider-registry.js.map +1 -0
- package/dist/services/oauth-service.d.ts +122 -0
- package/dist/services/oauth-service.d.ts.map +1 -0
- package/dist/services/oauth-service.js +442 -0
- package/dist/services/oauth-service.js.map +1 -0
- package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
- package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
- package/dist/services/oauth-token-retrieval.service.js +150 -0
- package/dist/services/oauth-token-retrieval.service.js.map +1 -0
- package/dist/services/policy.service.d.ts +130 -0
- package/dist/services/policy.service.d.ts.map +1 -0
- package/dist/services/policy.service.js +399 -0
- package/dist/services/policy.service.js.map +1 -0
- package/dist/services/proof-verifier.d.ts +103 -0
- package/dist/services/proof-verifier.d.ts.map +1 -0
- package/dist/services/proof-verifier.js +190 -0
- package/dist/services/proof-verifier.js.map +1 -0
- package/dist/services/provider-resolver.d.ts +89 -0
- package/dist/services/provider-resolver.d.ts.map +1 -0
- package/dist/services/provider-resolver.js +196 -0
- package/dist/services/provider-resolver.js.map +1 -0
- package/dist/services/provider-validator.d.ts +55 -0
- package/dist/services/provider-validator.d.ts.map +1 -0
- package/dist/services/provider-validator.js +135 -0
- package/dist/services/provider-validator.js.map +1 -0
- package/dist/services/session-registration.service.d.ts +80 -0
- package/dist/services/session-registration.service.d.ts.map +1 -0
- package/dist/services/session-registration.service.js +174 -0
- package/dist/services/session-registration.service.js.map +1 -0
- package/dist/services/storage.service.d.ts +116 -0
- package/dist/services/storage.service.d.ts.map +1 -0
- package/dist/services/storage.service.js +411 -0
- package/dist/services/storage.service.js.map +1 -0
- package/dist/services/tool-context-builder.d.ts +74 -0
- package/dist/services/tool-context-builder.d.ts.map +1 -0
- package/dist/services/tool-context-builder.js +215 -0
- package/dist/services/tool-context-builder.js.map +1 -0
- package/dist/services/tool-protection.service.d.ts +209 -0
- package/dist/services/tool-protection.service.d.ts.map +1 -0
- package/dist/services/tool-protection.service.js +752 -0
- package/dist/services/tool-protection.service.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +11 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +118 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +285 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/types/oauth-required-error.d.ts +46 -0
- package/dist/types/oauth-required-error.d.ts.map +1 -0
- package/dist/types/oauth-required-error.js +42 -0
- package/dist/types/oauth-required-error.js.map +1 -0
- package/dist/types/tool-protection.d.ts +144 -0
- package/dist/types/tool-protection.d.ts.map +1 -0
- package/dist/types/tool-protection.js +48 -0
- package/dist/types/tool-protection.js.map +1 -0
- package/dist/utils/base58.d.ts +31 -0
- package/dist/utils/base58.d.ts.map +1 -0
- package/dist/utils/base58.js +103 -0
- package/dist/utils/base58.js.map +1 -0
- package/dist/utils/base64.d.ts +32 -0
- package/dist/utils/base64.d.ts.map +1 -0
- package/dist/utils/base64.js +172 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/cors.d.ts +52 -0
- package/dist/utils/cors.d.ts.map +1 -0
- package/dist/utils/cors.js +79 -0
- package/dist/utils/cors.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +168 -0
- package/dist/utils/did-helpers.d.ts.map +1 -0
- package/dist/utils/did-helpers.js +222 -0
- package/dist/utils/did-helpers.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +24 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/storage-keys.d.ts +120 -0
- package/dist/utils/storage-keys.d.ts.map +1 -0
- package/dist/utils/storage-keys.js +217 -0
- package/dist/utils/storage-keys.js.map +1 -0
- package/dist/wire-format.d.ts +62 -0
- package/dist/wire-format.d.ts.map +1 -0
- package/dist/wire-format.js +89 -0
- package/dist/wire-format.js.map +1 -0
- package/package.json +83 -0
- package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
- package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
- package/src/__tests__/config.test.ts +307 -0
- package/src/__tests__/identity/user-did-manager.test.ts +232 -0
- package/src/__tests__/index.test.ts +56 -0
- package/src/__tests__/integration/full-flow.test.ts +779 -0
- package/src/__tests__/integration.test.ts +281 -0
- package/src/__tests__/providers/base.test.ts +173 -0
- package/src/__tests__/providers/memory.test.ts +319 -0
- package/src/__tests__/regression/phase2-regression.test.ts +406 -0
- package/src/__tests__/runtime/audit-logger.test.ts +154 -0
- package/src/__tests__/runtime/base-extensions.test.ts +595 -0
- package/src/__tests__/runtime/base.test.ts +1328 -0
- package/src/__tests__/runtime/delegation-flow.test.ts +159 -0
- package/src/__tests__/runtime/process-tool-call-security.test.ts +1024 -0
- package/src/__tests__/runtime/proof-client-did.test.ts +376 -0
- package/src/__tests__/runtime/provider-selection.test.ts +292 -0
- package/src/__tests__/runtime/route-interception.test.ts +670 -0
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +989 -0
- package/src/__tests__/services/access-control-retry.test.ts +595 -0
- package/src/__tests__/services/agentshield-integration.test.ts +709 -0
- package/src/__tests__/services/cache-busting.test.ts +125 -0
- package/src/__tests__/services/oauth-service-errors.test.ts +704 -0
- package/src/__tests__/services/oauth-service-pkce.test.ts +556 -0
- package/src/__tests__/services/oauth-service-secret-resolution.test.ts +349 -0
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +591 -0
- package/src/__tests__/services/tool-protection-failsafe.test.ts +683 -0
- package/src/__tests__/services/tool-protection-merged-config.test.ts +664 -0
- package/src/__tests__/services/tool-protection-oauth-provider.test.ts +300 -0
- package/src/__tests__/services/tool-protection.service.test.ts +1201 -0
- package/src/__tests__/utils/mock-providers.ts +340 -0
- package/src/__tests__/wire-format.test.ts +123 -0
- package/src/auth/__tests__/resume-token.test.ts +42 -0
- package/src/auth/handshake.ts +476 -0
- package/src/auth/index.ts +15 -0
- package/src/auth/types.ts +68 -0
- package/src/cache/__tests__/oauth-config-cache.test.ts +215 -0
- package/src/cache/oauth-config-cache.d.ts +69 -0
- package/src/cache/oauth-config-cache.d.ts.map +1 -0
- package/src/cache/oauth-config-cache.js.map +1 -0
- package/src/cache/oauth-config-cache.ts +123 -0
- package/src/cache/tool-protection-cache.ts +184 -0
- package/src/compliance/EXAMPLE.md +412 -0
- package/src/compliance/__tests__/schema-verifier.test.ts +791 -0
- package/src/compliance/index.ts +8 -0
- package/src/compliance/schema-registry.ts +460 -0
- package/src/compliance/schema-verifier.ts +708 -0
- package/src/config/__tests__/merged-config.spec.ts +445 -0
- package/src/config/__tests__/remote-config-edge-cases.test.ts +424 -0
- package/src/config/__tests__/remote-config-helpers.test.ts +280 -0
- package/src/config/__tests__/remote-config.spec.ts +265 -0
- package/src/config/remote-config.ts +368 -0
- package/src/config.ts +312 -0
- package/src/identity/__tests__/idp-token-resolver.test.ts +340 -0
- package/src/identity/__tests__/user-did-manager.test.ts +487 -0
- package/src/identity/idp-token-resolver.ts +181 -0
- package/src/identity/idp-token-storage.interface.ts +102 -0
- package/src/identity/user-did-manager.ts +592 -0
- package/src/index.ts +331 -0
- package/src/logging/__tests__/logger.test.ts +366 -0
- package/src/logging/index.ts +10 -0
- package/src/logging/logger.ts +112 -0
- package/src/proof/__tests__/crypto-parity.test.ts +202 -0
- package/src/proof/__tests__/proof-generator.test.ts +484 -0
- package/src/proof/generator.ts +347 -0
- package/src/proof/index.ts +12 -0
- package/src/providers/base.d.ts +91 -0
- package/src/providers/base.d.ts.map +1 -0
- package/src/providers/base.js.map +1 -0
- package/src/providers/base.ts +100 -0
- package/src/providers/memory.ts +142 -0
- package/src/runtime/__tests__/dif-esm-bridge.test.ts +33 -0
- package/src/runtime/__tests__/ext-apps-consent.test.ts +334 -0
- package/src/runtime/audit-logger.ts +39 -0
- package/src/runtime/base.ts +2100 -0
- package/src/runtime/dif-core.ts +39 -0
- package/src/runtime/ext-apps-constants.ts +20 -0
- package/src/services/__tests__/access-control.integration.test.ts +441 -0
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
- package/src/services/__tests__/access-control.service.test.ts +1132 -0
- package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
- package/src/services/__tests__/crypto.service.test.ts +531 -0
- package/src/services/__tests__/delegation-error-formatter.test.ts +643 -0
- package/src/services/__tests__/oauth-config.service.test.ts +359 -0
- package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
- package/src/services/__tests__/oauth-token-retrieval.service.test.ts +365 -0
- package/src/services/__tests__/proof-verifier.integration.test.ts +494 -0
- package/src/services/__tests__/proof-verifier.test.ts +489 -0
- package/src/services/__tests__/provider-resolution.integration.test.ts +202 -0
- package/src/services/__tests__/provider-resolver.test.ts +213 -0
- package/src/services/__tests__/provider-validator.test.ts +370 -0
- package/src/services/__tests__/session-registration.service.test.ts +312 -0
- package/src/services/__tests__/storage.service.test.ts +358 -0
- package/src/services/__tests__/tool-context-builder.test.ts +438 -0
- package/src/services/access-control.service.ts +1048 -0
- package/src/services/authorization/authorization-registry.ts +67 -0
- package/src/services/authorization/types.ts +71 -0
- package/src/services/batch-delegation.service.ts +136 -0
- package/src/services/crypto.service.ts +296 -0
- package/src/services/delegation-error-formatter.ts +299 -0
- package/src/services/errors.ts +76 -0
- package/src/services/index.ts +34 -0
- package/src/services/oauth-config.service.d.ts +53 -0
- package/src/services/oauth-config.service.d.ts.map +1 -0
- package/src/services/oauth-config.service.js.map +1 -0
- package/src/services/oauth-config.service.ts +192 -0
- package/src/services/oauth-provider-registry.d.ts +57 -0
- package/src/services/oauth-provider-registry.d.ts.map +1 -0
- package/src/services/oauth-provider-registry.js.map +1 -0
- package/src/services/oauth-provider-registry.ts +141 -0
- package/src/services/oauth-service.ts +652 -0
- package/src/services/oauth-token-retrieval.service.ts +245 -0
- package/src/services/policy.service.ts +527 -0
- package/src/services/proof-verifier.ts +295 -0
- package/src/services/provider-resolver.d.ts +48 -0
- package/src/services/provider-resolver.d.ts.map +1 -0
- package/src/services/provider-resolver.js.map +1 -0
- package/src/services/provider-resolver.ts +236 -0
- package/src/services/provider-validator.ts +170 -0
- package/src/services/session-registration.service.ts +259 -0
- package/src/services/storage.service.ts +566 -0
- package/src/services/tool-context-builder.ts +285 -0
- package/src/services/tool-protection.service.ts +971 -0
- package/src/session/__tests__/session-manager.test.ts +327 -0
- package/src/session/index.ts +10 -0
- package/src/session/manager.ts +380 -0
- package/src/types/__tests__/oauth-required-error.test.ts +79 -0
- package/src/types/__tests__/tool-protection.test.ts +121 -0
- package/src/types/oauth-required-error.ts +71 -0
- package/src/types/tool-protection.ts +179 -0
- package/src/utils/__tests__/base58.test.ts +281 -0
- package/src/utils/__tests__/base64.test.ts +239 -0
- package/src/utils/__tests__/cors.test.ts +184 -0
- package/src/utils/__tests__/did-helpers.test.ts +156 -0
- package/src/utils/__tests__/storage-keys.test.ts +372 -0
- package/src/utils/base58.ts +109 -0
- package/src/utils/base64.ts +185 -0
- package/src/utils/cors.ts +93 -0
- package/src/utils/did-helpers.ts +229 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/storage-keys.ts +285 -0
- package/src/wire-format.ts +114 -0
- package/tsconfig.json +21 -0
- package/vitest.config.mts +57 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DIF ESM-bridge gate — C2 (#2916), PR-0
|
|
3
|
+
*
|
|
4
|
+
* `@kya-os/mcp` (DIF, "KYA-OS for MCP") is ESM-only (`"type": "module"`); this
|
|
5
|
+
* package (`@kya-os/mcp-i-core`) is CommonJS (`module: Node16`). A static
|
|
6
|
+
* runtime `import ... from "@kya-os/mcp"` in source compiles to a `require()` of
|
|
7
|
+
* an ESM-only module → TS1479. The node-side product layer therefore reaches
|
|
8
|
+
* DIF through the async dynamic-import seam in `src/runtime/dif-core.ts`.
|
|
9
|
+
*
|
|
10
|
+
* This gate asserts the seam resolves the DIF primitives the C2 re-home
|
|
11
|
+
* composes against. If it fails, the node-side C2 PRs (the runtime-base
|
|
12
|
+
* keystone — proof/session, etc.) are blocked at the module-interop boundary.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, it, expect } from "vitest";
|
|
16
|
+
import { loadDifCore } from "../dif-core.js";
|
|
17
|
+
|
|
18
|
+
describe("DIF ESM-bridge seam (C2 PR-0)", () => {
|
|
19
|
+
it("dynamically resolves @kya-os/mcp from the CJS package", async () => {
|
|
20
|
+
const dif = await loadDifCore();
|
|
21
|
+
// Primitives the C2 re-home composes against (proof/session keystone, PR-3):
|
|
22
|
+
expect(typeof dif.createKyaOsMiddleware).toBe("function");
|
|
23
|
+
expect(typeof dif.SessionManager).toBe("function");
|
|
24
|
+
expect(typeof dif.ProofGenerator).toBe("function");
|
|
25
|
+
expect(typeof dif.ProofVerifier).toBe("function");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("caches the dynamic import across calls", async () => {
|
|
29
|
+
const first = await loadDifCore();
|
|
30
|
+
const second = await loadDifCore();
|
|
31
|
+
expect(first).toBe(second);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for MCP Apps Consent UI Integration
|
|
3
|
+
*
|
|
4
|
+
* Covers hasUICapability(), buildConsentUIResult(), and the
|
|
5
|
+
* processToolCall() UI path that tries inline consent before
|
|
6
|
+
* falling back to DelegationRequiredError.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
10
|
+
import { MCPIRuntimeBase } from "../base.js";
|
|
11
|
+
import type { ProviderRuntimeConfig } from "../../config.js";
|
|
12
|
+
import { CONSENT_UI_RESOURCE_URI } from "../ext-apps-constants.js";
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Minimal mock providers so we can instantiate MCPIRuntimeBase
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
function stubProvider<T>(overrides: Partial<T> = {}): T {
|
|
19
|
+
return new Proxy(overrides as T, {
|
|
20
|
+
get(target, prop) {
|
|
21
|
+
if (prop in target)
|
|
22
|
+
return (target as Record<string, unknown>)[prop as string];
|
|
23
|
+
return vi.fn();
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createTestConfig(
|
|
29
|
+
overrides: Partial<ProviderRuntimeConfig> = {}
|
|
30
|
+
): ProviderRuntimeConfig {
|
|
31
|
+
return {
|
|
32
|
+
environment: "development",
|
|
33
|
+
cryptoProvider: stubProvider(),
|
|
34
|
+
clockProvider: stubProvider({
|
|
35
|
+
now: () => Date.now(),
|
|
36
|
+
calculateExpiry: (ttl: number) => Date.now() + ttl * 1000,
|
|
37
|
+
isWithinSkew: () => true,
|
|
38
|
+
hasExpired: () => false,
|
|
39
|
+
format: (ts: number) => new Date(ts).toISOString(),
|
|
40
|
+
}),
|
|
41
|
+
fetchProvider: stubProvider(),
|
|
42
|
+
storageProvider: stubProvider({
|
|
43
|
+
get: async () => null,
|
|
44
|
+
set: async () => {},
|
|
45
|
+
delete: async () => {},
|
|
46
|
+
exists: async () => false,
|
|
47
|
+
list: async () => [],
|
|
48
|
+
}),
|
|
49
|
+
nonceCacheProvider: stubProvider({
|
|
50
|
+
has: async () => false,
|
|
51
|
+
add: async () => {},
|
|
52
|
+
cleanup: async () => {},
|
|
53
|
+
destroy: async () => {},
|
|
54
|
+
}),
|
|
55
|
+
identityProvider: stubProvider({
|
|
56
|
+
getIdentity: async () => ({
|
|
57
|
+
did: "did:key:test123",
|
|
58
|
+
publicKey: "test-pub",
|
|
59
|
+
privateKey: "test-priv",
|
|
60
|
+
}),
|
|
61
|
+
}),
|
|
62
|
+
...overrides,
|
|
63
|
+
} as ProviderRuntimeConfig;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// Helper: Build MCP client capabilities in the format getUiCapability expects
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
function buildUICapabilities(): Record<string, unknown> {
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
72
|
+
const {
|
|
73
|
+
RESOURCE_MIME_TYPE,
|
|
74
|
+
} = require("@modelcontextprotocol/ext-apps/server");
|
|
75
|
+
return {
|
|
76
|
+
extensions: {
|
|
77
|
+
"io.modelcontextprotocol/ui": {
|
|
78
|
+
mimeTypes: [RESOURCE_MIME_TYPE],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Expose protected methods for testing via a thin subclass
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
class TestableRuntime extends MCPIRuntimeBase {
|
|
89
|
+
public testHasUICapability(
|
|
90
|
+
clientCapabilities?: Record<string, unknown>
|
|
91
|
+
): boolean {
|
|
92
|
+
return this.hasUICapability(clientCapabilities);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public testBuildConsentUIResult(
|
|
96
|
+
toolName: string,
|
|
97
|
+
scopes: string[],
|
|
98
|
+
session?: Record<string, unknown>,
|
|
99
|
+
resumeToken?: string,
|
|
100
|
+
projectId?: string,
|
|
101
|
+
serverUrl?: string,
|
|
102
|
+
clientCapabilities?: Record<string, unknown>
|
|
103
|
+
): Record<string, unknown> | null {
|
|
104
|
+
return this.buildConsentUIResult(
|
|
105
|
+
toolName,
|
|
106
|
+
scopes,
|
|
107
|
+
session,
|
|
108
|
+
resumeToken,
|
|
109
|
+
projectId,
|
|
110
|
+
serverUrl,
|
|
111
|
+
clientCapabilities
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// Tests
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
describe("ext-apps-constants", () => {
|
|
121
|
+
it("exports CONSENT_UI_RESOURCE_URI with correct value", () => {
|
|
122
|
+
expect(CONSENT_UI_RESOURCE_URI).toBe("ui://kya-os-consent/authorize");
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("MCPIRuntimeBase - MCP Apps consent UI", () => {
|
|
127
|
+
let runtime: TestableRuntime;
|
|
128
|
+
|
|
129
|
+
beforeEach(() => {
|
|
130
|
+
runtime = new TestableRuntime(createTestConfig({ inlineConsent: true }));
|
|
131
|
+
// Explicitly enable ext-apps — mirrors what agent.ts does after
|
|
132
|
+
// successfully importing @modelcontextprotocol/ext-apps
|
|
133
|
+
runtime.setExtAppsAvailable(true);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// -----------------------------------------------------------------------
|
|
137
|
+
// hasUICapability
|
|
138
|
+
// -----------------------------------------------------------------------
|
|
139
|
+
|
|
140
|
+
describe("hasUICapability", () => {
|
|
141
|
+
it("returns false when no clientCapabilities provided", () => {
|
|
142
|
+
expect(runtime.testHasUICapability()).toBe(false);
|
|
143
|
+
expect(runtime.testHasUICapability(undefined)).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("returns false when clientCapabilities is empty", () => {
|
|
147
|
+
expect(runtime.testHasUICapability({})).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("returns true when ext-apps SDK detects UI capability", () => {
|
|
151
|
+
const caps = buildUICapabilities();
|
|
152
|
+
expect(runtime.testHasUICapability(caps)).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("returns false when client has UI capability but wrong MIME types", () => {
|
|
156
|
+
const caps = {
|
|
157
|
+
extensions: {
|
|
158
|
+
"io.modelcontextprotocol/ui": {
|
|
159
|
+
mimeTypes: ["text/html"],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
expect(runtime.testHasUICapability(caps)).toBe(false);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("returns false when UI capability has no mimeTypes", () => {
|
|
168
|
+
const caps = {
|
|
169
|
+
extensions: {
|
|
170
|
+
"io.modelcontextprotocol/ui": {},
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
expect(runtime.testHasUICapability(caps)).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("returns false when extensions key is missing", () => {
|
|
178
|
+
const caps = {
|
|
179
|
+
"io.modelcontextprotocol/ui": {
|
|
180
|
+
mimeTypes: ["text/html;profile=mcp-app"],
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
expect(runtime.testHasUICapability(caps)).toBe(false);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// -----------------------------------------------------------------------
|
|
189
|
+
// buildConsentUIResult
|
|
190
|
+
// -----------------------------------------------------------------------
|
|
191
|
+
|
|
192
|
+
describe("buildConsentUIResult", () => {
|
|
193
|
+
it("returns result even when client capabilities are empty (capability check is not gating)", () => {
|
|
194
|
+
const result = runtime.testBuildConsentUIResult(
|
|
195
|
+
"checkout",
|
|
196
|
+
["cart:write"],
|
|
197
|
+
{ id: "sess-1", agentDid: "did:key:abc" },
|
|
198
|
+
"resume-tok",
|
|
199
|
+
"proj-1",
|
|
200
|
+
"https://example.com",
|
|
201
|
+
{} // empty capabilities - UI still returned per spec
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
expect(result).not.toBeNull();
|
|
205
|
+
const sc = result!.structuredContent as Record<string, unknown>;
|
|
206
|
+
expect(sc.tool).toBe("checkout");
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("returns null when ext-apps is not available", () => {
|
|
210
|
+
runtime.setExtAppsAvailable(false);
|
|
211
|
+
const result = runtime.testBuildConsentUIResult(
|
|
212
|
+
"checkout",
|
|
213
|
+
["cart:write"],
|
|
214
|
+
undefined,
|
|
215
|
+
undefined,
|
|
216
|
+
undefined,
|
|
217
|
+
undefined,
|
|
218
|
+
undefined
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
expect(result).toBeNull();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("returns null when inlineConsent config is false", () => {
|
|
225
|
+
const noInlineRuntime = new TestableRuntime(
|
|
226
|
+
createTestConfig({ inlineConsent: false })
|
|
227
|
+
);
|
|
228
|
+
noInlineRuntime.setExtAppsAvailable(true);
|
|
229
|
+
const result = noInlineRuntime.testBuildConsentUIResult(
|
|
230
|
+
"checkout",
|
|
231
|
+
["cart:write"],
|
|
232
|
+
undefined,
|
|
233
|
+
undefined,
|
|
234
|
+
undefined,
|
|
235
|
+
undefined,
|
|
236
|
+
undefined
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
expect(result).toBeNull();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("returns structured result with all fields when UI is available", () => {
|
|
243
|
+
const caps = buildUICapabilities();
|
|
244
|
+
|
|
245
|
+
const session = {
|
|
246
|
+
id: "sess-123",
|
|
247
|
+
agentDid: "did:key:agent456",
|
|
248
|
+
agentName: "TestAgent",
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const result = runtime.testBuildConsentUIResult(
|
|
252
|
+
"sensitive-tool",
|
|
253
|
+
["data:read", "data:write"],
|
|
254
|
+
session,
|
|
255
|
+
"resume-abc",
|
|
256
|
+
"proj-xyz",
|
|
257
|
+
"https://mcp.example.com",
|
|
258
|
+
caps
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
expect(result).not.toBeNull();
|
|
262
|
+
|
|
263
|
+
// Verify content text
|
|
264
|
+
const content = result!.content as Array<{ type: string; text: string }>;
|
|
265
|
+
expect(content).toHaveLength(1);
|
|
266
|
+
expect(content[0].type).toBe("text");
|
|
267
|
+
expect(content[0].text).toContain("sensitive-tool");
|
|
268
|
+
expect(content[0].text).toContain("Authorization required");
|
|
269
|
+
|
|
270
|
+
// Verify structuredContent
|
|
271
|
+
const sc = result!.structuredContent as Record<string, unknown>;
|
|
272
|
+
expect(sc.type).toBe("consent_required");
|
|
273
|
+
expect(sc.tool).toBe("sensitive-tool");
|
|
274
|
+
expect(sc.scopes).toEqual(["data:read", "data:write"]);
|
|
275
|
+
expect(sc.agentDid).toBe("did:key:agent456");
|
|
276
|
+
expect(sc.agentName).toBe("TestAgent");
|
|
277
|
+
expect(sc.sessionId).toBe("sess-123");
|
|
278
|
+
expect(sc.projectId).toBe("proj-xyz");
|
|
279
|
+
expect(sc.resumeToken).toBe("resume-abc");
|
|
280
|
+
expect(sc.serverUrl).toBe("https://mcp.example.com");
|
|
281
|
+
expect(sc.consentUrl).toBeDefined();
|
|
282
|
+
expect(typeof sc.consentUrl).toBe("string");
|
|
283
|
+
|
|
284
|
+
// Verify _meta with resourceUri
|
|
285
|
+
const meta = result!._meta as Record<string, unknown>;
|
|
286
|
+
const ui = meta.ui as Record<string, unknown>;
|
|
287
|
+
expect(ui.resourceUri).toBe(CONSENT_UI_RESOURCE_URI);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("handles missing session fields gracefully", () => {
|
|
291
|
+
const caps = buildUICapabilities();
|
|
292
|
+
|
|
293
|
+
const result = runtime.testBuildConsentUIResult(
|
|
294
|
+
"some-tool",
|
|
295
|
+
["scope:a"],
|
|
296
|
+
undefined, // no session
|
|
297
|
+
undefined, // no resume token
|
|
298
|
+
undefined, // no project id
|
|
299
|
+
undefined, // no server url
|
|
300
|
+
caps
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
expect(result).not.toBeNull();
|
|
304
|
+
|
|
305
|
+
const sc = result!.structuredContent as Record<string, unknown>;
|
|
306
|
+
expect(sc.agentDid).toBe("");
|
|
307
|
+
expect(sc.agentName).toBe("");
|
|
308
|
+
expect(sc.sessionId).toBe("");
|
|
309
|
+
expect(sc.projectId).toBe("");
|
|
310
|
+
expect(sc.resumeToken).toBe("");
|
|
311
|
+
expect(sc.serverUrl).toBe("");
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("resourceUri matches the exported constant", () => {
|
|
315
|
+
const caps = buildUICapabilities();
|
|
316
|
+
|
|
317
|
+
const result = runtime.testBuildConsentUIResult(
|
|
318
|
+
"tool",
|
|
319
|
+
["scope"],
|
|
320
|
+
{},
|
|
321
|
+
undefined,
|
|
322
|
+
undefined,
|
|
323
|
+
undefined,
|
|
324
|
+
caps
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
expect(result).not.toBeNull();
|
|
328
|
+
|
|
329
|
+
const meta = result!._meta as Record<string, unknown>;
|
|
330
|
+
const ui = meta.ui as Record<string, unknown>;
|
|
331
|
+
expect(ui.resourceUri).toBe("ui://kya-os-consent/authorize");
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Logger Interface
|
|
3
|
+
*
|
|
4
|
+
* Platform-agnostic interface for audit logging in the MCP-I framework.
|
|
5
|
+
* Implementations should be provided by platform-specific packages.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { AuditContext, AuditEventContext } from "@kya-os/contracts/audit";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Interface for audit logging implementations
|
|
12
|
+
*
|
|
13
|
+
* This interface is platform-agnostic and can be implemented by:
|
|
14
|
+
* - Node.js implementations (using Node.js crypto)
|
|
15
|
+
* - Cloudflare Workers implementations (using Web Crypto API)
|
|
16
|
+
* - Other platform-specific implementations
|
|
17
|
+
*/
|
|
18
|
+
export interface IAuditLogger {
|
|
19
|
+
/**
|
|
20
|
+
* Log an audit record (with session deduplication)
|
|
21
|
+
*
|
|
22
|
+
* This method logs audit records using the frozen audit.v1 format.
|
|
23
|
+
* Only the first call per session is logged (deduplication).
|
|
24
|
+
*
|
|
25
|
+
* @param context - Audit context with identity, session, hashes, and verification status
|
|
26
|
+
*/
|
|
27
|
+
logAuditRecord(context: AuditContext): Promise<void>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Log an event (without session deduplication)
|
|
31
|
+
*
|
|
32
|
+
* This method logs events using the frozen audit.v1 format.
|
|
33
|
+
* Unlike logAuditRecord(), this always logs the event, allowing
|
|
34
|
+
* multiple events per session (e.g., consent events).
|
|
35
|
+
*
|
|
36
|
+
* @param context - Event context with eventType, identity, session, and optional eventData
|
|
37
|
+
*/
|
|
38
|
+
logEvent(context: AuditEventContext): Promise<void>;
|
|
39
|
+
}
|