@kya-os/mcp-i-core 1.7.0 → 1.8.1

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.
Files changed (121) hide show
  1. package/README.md +1 -1
  2. package/dist/conformance/capability-verifier-adapter.d.ts +66 -0
  3. package/dist/conformance/capability-verifier-adapter.js +61 -0
  4. package/dist/conformance/index.d.ts +10 -0
  5. package/dist/conformance/index.js +19 -0
  6. package/dist/conformance/validate-level2.d.ts +203 -0
  7. package/dist/conformance/validate-level2.js +294 -0
  8. package/dist/conformance/vc-jwt-verifier.d.ts +55 -0
  9. package/dist/conformance/vc-jwt-verifier.js +147 -0
  10. package/dist/delegation/did-web-resolver.d.ts +60 -0
  11. package/dist/delegation/did-web-resolver.js +129 -0
  12. package/dist/delegation/outbound-proof.d.ts +3 -2
  13. package/dist/delegation/outbound-proof.js +3 -2
  14. package/dist/delegation/utils.d.ts +3 -1
  15. package/dist/index.d.ts +9 -63
  16. package/dist/index.js +22 -161
  17. package/dist/utils/base58.d.ts +4 -28
  18. package/dist/utils/base58.js +18 -98
  19. package/dist/utils/base64.d.ts +4 -29
  20. package/dist/utils/base64.js +18 -167
  21. package/dist/utils/did-helpers.d.ts +4 -165
  22. package/dist/utils/did-helpers.js +18 -217
  23. package/package.json +5 -7
  24. package/dist/auth/handshake.d.ts +0 -119
  25. package/dist/auth/handshake.js +0 -250
  26. package/dist/auth/index.d.ts +0 -6
  27. package/dist/auth/index.js +0 -11
  28. package/dist/auth/types.d.ts +0 -46
  29. package/dist/auth/types.js +0 -10
  30. package/dist/cache/oauth-config-cache.d.ts +0 -69
  31. package/dist/cache/oauth-config-cache.js +0 -76
  32. package/dist/cache/tool-protection-cache.d.ts +0 -89
  33. package/dist/cache/tool-protection-cache.js +0 -118
  34. package/dist/compliance/index.d.ts +0 -8
  35. package/dist/compliance/index.js +0 -24
  36. package/dist/compliance/schema-registry.d.ts +0 -50
  37. package/dist/compliance/schema-registry.js +0 -438
  38. package/dist/compliance/schema-verifier.d.ts +0 -110
  39. package/dist/compliance/schema-verifier.js +0 -518
  40. package/dist/config/remote-config.d.ts +0 -173
  41. package/dist/config/remote-config.js +0 -253
  42. package/dist/config.d.ts +0 -182
  43. package/dist/config.js +0 -148
  44. package/dist/identity/idp-token-resolver.d.ts +0 -69
  45. package/dist/identity/idp-token-resolver.js +0 -136
  46. package/dist/identity/idp-token-storage.interface.d.ts +0 -80
  47. package/dist/identity/idp-token-storage.interface.js +0 -14
  48. package/dist/identity/user-did-manager.d.ts +0 -228
  49. package/dist/identity/user-did-manager.js +0 -356
  50. package/dist/logging/index.d.ts +0 -5
  51. package/dist/logging/index.js +0 -10
  52. package/dist/logging/logger.d.ts +0 -33
  53. package/dist/logging/logger.js +0 -104
  54. package/dist/proof/generator.d.ts +0 -109
  55. package/dist/proof/generator.js +0 -236
  56. package/dist/proof/index.d.ts +0 -5
  57. package/dist/proof/index.js +0 -11
  58. package/dist/providers/base.d.ts +0 -95
  59. package/dist/providers/base.js +0 -47
  60. package/dist/providers/memory.d.ts +0 -42
  61. package/dist/providers/memory.js +0 -121
  62. package/dist/runtime/audit-logger.d.ts +0 -37
  63. package/dist/runtime/audit-logger.js +0 -9
  64. package/dist/runtime/base.d.ts +0 -375
  65. package/dist/runtime/base.js +0 -1491
  66. package/dist/runtime/ext-apps-constants.d.ts +0 -14
  67. package/dist/runtime/ext-apps-constants.js +0 -17
  68. package/dist/services/access-control.service.d.ts +0 -138
  69. package/dist/services/access-control.service.js +0 -721
  70. package/dist/services/authorization/authorization-registry.d.ts +0 -29
  71. package/dist/services/authorization/authorization-registry.js +0 -58
  72. package/dist/services/authorization/types.d.ts +0 -53
  73. package/dist/services/authorization/types.js +0 -10
  74. package/dist/services/batch-delegation.service.d.ts +0 -53
  75. package/dist/services/batch-delegation.service.js +0 -95
  76. package/dist/services/crypto.service.d.ts +0 -69
  77. package/dist/services/crypto.service.js +0 -225
  78. package/dist/services/delegation-error-formatter.d.ts +0 -124
  79. package/dist/services/delegation-error-formatter.js +0 -214
  80. package/dist/services/errors.d.ts +0 -49
  81. package/dist/services/errors.js +0 -66
  82. package/dist/services/index.d.ts +0 -9
  83. package/dist/services/index.js +0 -15
  84. package/dist/services/oauth-config.service.d.ts +0 -53
  85. package/dist/services/oauth-config.service.js +0 -141
  86. package/dist/services/oauth-provider-registry.d.ts +0 -88
  87. package/dist/services/oauth-provider-registry.js +0 -128
  88. package/dist/services/oauth-service.d.ts +0 -122
  89. package/dist/services/oauth-service.js +0 -442
  90. package/dist/services/oauth-token-retrieval.service.d.ts +0 -49
  91. package/dist/services/oauth-token-retrieval.service.js +0 -150
  92. package/dist/services/policy.service.d.ts +0 -130
  93. package/dist/services/policy.service.js +0 -399
  94. package/dist/services/proof-verifier.d.ts +0 -98
  95. package/dist/services/proof-verifier.js +0 -319
  96. package/dist/services/provider-resolver.d.ts +0 -89
  97. package/dist/services/provider-resolver.js +0 -196
  98. package/dist/services/provider-validator.d.ts +0 -55
  99. package/dist/services/provider-validator.js +0 -135
  100. package/dist/services/session-registration.service.d.ts +0 -80
  101. package/dist/services/session-registration.service.js +0 -174
  102. package/dist/services/storage.service.d.ts +0 -116
  103. package/dist/services/storage.service.js +0 -411
  104. package/dist/services/tool-context-builder.d.ts +0 -74
  105. package/dist/services/tool-context-builder.js +0 -215
  106. package/dist/services/tool-protection.service.d.ts +0 -193
  107. package/dist/services/tool-protection.service.js +0 -736
  108. package/dist/session/index.d.ts +0 -5
  109. package/dist/session/index.js +0 -11
  110. package/dist/session/manager.d.ts +0 -113
  111. package/dist/session/manager.js +0 -273
  112. package/dist/types/oauth-required-error.d.ts +0 -46
  113. package/dist/types/oauth-required-error.js +0 -42
  114. package/dist/types/tool-protection.d.ts +0 -144
  115. package/dist/types/tool-protection.js +0 -48
  116. package/dist/utils/cors.d.ts +0 -44
  117. package/dist/utils/cors.js +0 -71
  118. package/dist/utils/index.d.ts +0 -8
  119. package/dist/utils/index.js +0 -24
  120. package/dist/utils/storage-keys.d.ts +0 -120
  121. package/dist/utils/storage-keys.js +0 -217
@@ -1,250 +0,0 @@
1
- "use strict";
2
- /**
3
- * Authorization Handshake — Platform-agnostic Protocol Reference
4
- *
5
- * Orchestrates the authorization flow for MCP-I bouncer:
6
- * 1. Check agent reputation (optional)
7
- * 2. Verify delegation exists
8
- * 3. Return needs_authorization error if missing
9
- *
10
- * This module uses only the global fetch API — no Node-specific imports.
11
- * It is safe to run on Node.js, Cloudflare Workers, and any fetch-capable runtime.
12
- *
13
- * Flow:
14
- * - If delegation exists + valid → allow (fast path)
15
- * - If delegation missing → return needs_authorization with hints
16
- * - If reputation too low (optional) → require authorization
17
- */
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.MemoryResumeTokenStore = void 0;
20
- exports.verifyOrHints = verifyOrHints;
21
- exports.hasSensitiveScopes = hasSensitiveScopes;
22
- const runtime_1 = require("@kya-os/contracts/runtime");
23
- const logging_1 = require("../logging");
24
- /**
25
- * Simple in-memory resume token store (for testing/development).
26
- * Not suitable for multi-instance deployments.
27
- */
28
- class MemoryResumeTokenStore {
29
- tokens = new Map();
30
- ttl;
31
- constructor(ttlMs = 600_000) {
32
- this.ttl = ttlMs;
33
- }
34
- async create(agentDid, scopes, metadata) {
35
- const token = `rt_${Date.now()}_${Math.random().toString(36).substring(2, 18)}`;
36
- const now = Date.now();
37
- this.tokens.set(token, {
38
- agentDid,
39
- scopes,
40
- createdAt: now,
41
- expiresAt: now + this.ttl,
42
- metadata,
43
- fulfilled: false,
44
- });
45
- return token;
46
- }
47
- async get(token) {
48
- const data = this.tokens.get(token);
49
- if (!data)
50
- return null;
51
- if (Date.now() > data.expiresAt) {
52
- this.tokens.delete(token);
53
- return null;
54
- }
55
- if (data.fulfilled)
56
- return null;
57
- return {
58
- agentDid: data.agentDid,
59
- scopes: data.scopes,
60
- createdAt: data.createdAt,
61
- expiresAt: data.expiresAt,
62
- metadata: data.metadata,
63
- };
64
- }
65
- async fulfill(token) {
66
- const data = this.tokens.get(token);
67
- if (data) {
68
- data.fulfilled = true;
69
- }
70
- }
71
- clear() {
72
- this.tokens.clear();
73
- }
74
- }
75
- exports.MemoryResumeTokenStore = MemoryResumeTokenStore;
76
- /**
77
- * Main auth handshake function.
78
- *
79
- * Verifies agent authorization or returns authorization hints.
80
- */
81
- async function verifyOrHints(agentDid, scopes, config, _resumeToken) {
82
- const startTime = Date.now();
83
- if (config.debug) {
84
- logging_1.logger.debug(`[AuthHandshake] Verifying ${agentDid} for scopes: ${scopes.join(", ")}`);
85
- }
86
- let reputation;
87
- if (config.kta && config.bouncer.minReputationScore !== undefined) {
88
- try {
89
- reputation = await fetchAgentReputation(agentDid, config.kta);
90
- if (config.debug) {
91
- logging_1.logger.debug(`[AuthHandshake] Reputation score: ${reputation.score}`);
92
- }
93
- if (reputation.score < config.bouncer.minReputationScore) {
94
- if (config.debug) {
95
- logging_1.logger.debug(`[AuthHandshake] Reputation ${reputation.score} < ${config.bouncer.minReputationScore}, requiring authorization`);
96
- }
97
- const authError = await buildNeedsAuthorizationError(agentDid, scopes, config, "Agent reputation score below threshold");
98
- return {
99
- authorized: false,
100
- authError,
101
- reputation,
102
- reason: "Low reputation score",
103
- };
104
- }
105
- }
106
- catch (error) {
107
- logging_1.logger.warn("[AuthHandshake] Failed to check reputation:", error);
108
- }
109
- }
110
- let delegationResult;
111
- try {
112
- delegationResult = await config.delegationVerifier.verify(agentDid, scopes);
113
- }
114
- catch (error) {
115
- logging_1.logger.error("[AuthHandshake] Delegation verification failed:", error);
116
- const errorMessage = `Delegation verification error: ${error instanceof Error ? error.message : "Unknown error"}`;
117
- const authError = await buildNeedsAuthorizationError(agentDid, scopes, config, errorMessage);
118
- return {
119
- authorized: false,
120
- authError,
121
- reason: errorMessage,
122
- };
123
- }
124
- if (delegationResult.valid && delegationResult.delegation) {
125
- if (config.debug) {
126
- logging_1.logger.debug(`[AuthHandshake] Delegation valid, authorized (${Date.now() - startTime}ms)`);
127
- }
128
- return {
129
- authorized: true,
130
- delegation: delegationResult.delegation,
131
- credential: delegationResult.credential,
132
- reputation,
133
- reason: "Valid delegation found",
134
- };
135
- }
136
- if (config.debug) {
137
- logging_1.logger.debug(`[AuthHandshake] No delegation found, returning needs_authorization (${Date.now() - startTime}ms)`);
138
- }
139
- const authError = await buildNeedsAuthorizationError(agentDid, scopes, config, delegationResult.reason ?? "No valid delegation found");
140
- return {
141
- authorized: false,
142
- authError,
143
- reputation,
144
- reason: delegationResult.reason ?? "No delegation",
145
- };
146
- }
147
- /**
148
- * Fetch agent reputation from KTA.
149
- */
150
- async function fetchAgentReputation(agentDid, ktaConfig) {
151
- const apiUrl = ktaConfig.apiUrl.replace(/\/$/, "");
152
- const headers = {
153
- "Content-Type": "application/json",
154
- };
155
- if (ktaConfig.apiKey) {
156
- headers["X-API-Key"] = ktaConfig.apiKey;
157
- }
158
- const isArgusFormat = ktaConfig.apiFormat === "argus";
159
- let response;
160
- if (isArgusFormat) {
161
- response = await fetch(`${apiUrl}/v1/reputation/${encodeURIComponent(agentDid)}`, {
162
- method: "POST",
163
- headers,
164
- body: JSON.stringify({ include_details: false }),
165
- });
166
- }
167
- else {
168
- response = await fetch(`${apiUrl}/api/v1/reputation/${encodeURIComponent(agentDid)}`, {
169
- method: "GET",
170
- headers,
171
- });
172
- }
173
- if (!response.ok) {
174
- if (response.status === 404) {
175
- return {
176
- agentDid,
177
- score: 50,
178
- totalInteractions: 0,
179
- successRate: 0,
180
- riskLevel: "unknown",
181
- updatedAt: Date.now(),
182
- };
183
- }
184
- throw new Error(`KTA API error: ${response.status} ${response.statusText}`);
185
- }
186
- const data = (await response.json());
187
- const score = data.score ?? 50;
188
- const levelRaw = (data.level ??
189
- data.riskLevel ??
190
- "unknown").toLowerCase();
191
- const riskLevel = levelRaw === "low" || levelRaw === "medium" || levelRaw === "high"
192
- ? levelRaw
193
- : "unknown";
194
- return {
195
- agentDid: data.agent_did ??
196
- data.agentDid ??
197
- agentDid,
198
- score,
199
- totalInteractions: data.totalInteractions ?? 0,
200
- successRate: data.successRate ?? 0,
201
- riskLevel,
202
- updatedAt: data.calculatedAt
203
- ? new Date(data.calculatedAt).getTime()
204
- : (data.updatedAt ?? Date.now()),
205
- };
206
- }
207
- /**
208
- * Build needs_authorization error with hints.
209
- */
210
- async function buildNeedsAuthorizationError(agentDid, scopes, config, message) {
211
- const resumeToken = await config.resumeTokenStore.create(agentDid, scopes, {
212
- requestedAt: Date.now(),
213
- });
214
- const expiresAt = Date.now() + (config.bouncer.resumeTokenTtl ?? 600_000);
215
- const authUrl = new URL(config.bouncer.authorizationUrl);
216
- authUrl.searchParams.set("agent_did", agentDid);
217
- authUrl.searchParams.set("scopes", scopes.join(","));
218
- authUrl.searchParams.set("resume_token", resumeToken);
219
- const authCode = resumeToken.substring(0, 8).toUpperCase();
220
- const display = {
221
- title: "Authorization Required",
222
- hint: ["link", "qr"],
223
- authorizationCode: authCode,
224
- qrUrl: `https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=${encodeURIComponent(authUrl.toString())}`,
225
- };
226
- return (0, runtime_1.createNeedsAuthorizationError)({
227
- message,
228
- authorizationUrl: authUrl.toString(),
229
- resumeToken,
230
- expiresAt,
231
- scopes,
232
- display,
233
- });
234
- }
235
- /**
236
- * Helper: Check if scopes are sensitive and require authorization.
237
- */
238
- function hasSensitiveScopes(scopes) {
239
- const sensitivePatterns = [
240
- "write",
241
- "delete",
242
- "admin",
243
- "payment",
244
- "transfer",
245
- "execute",
246
- "modify",
247
- ];
248
- return scopes.some((scope) => sensitivePatterns.some((pattern) => scope.toLowerCase().includes(pattern)));
249
- }
250
- //# sourceMappingURL=handshake.js.map
@@ -1,6 +0,0 @@
1
- /**
2
- * Auth module — platform-agnostic authorization handshake reference implementation.
3
- */
4
- export { verifyOrHints, hasSensitiveScopes, MemoryResumeTokenStore, type AuthHandshakeConfig, type VerifyOrHintsResult, type AgentReputation, type ResumeTokenStore, } from "./handshake";
5
- export type { DelegationVerifier, VerifyDelegationResult } from "./types";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryResumeTokenStore = exports.hasSensitiveScopes = exports.verifyOrHints = void 0;
4
- /**
5
- * Auth module — platform-agnostic authorization handshake reference implementation.
6
- */
7
- var handshake_1 = require("./handshake");
8
- Object.defineProperty(exports, "verifyOrHints", { enumerable: true, get: function () { return handshake_1.verifyOrHints; } });
9
- Object.defineProperty(exports, "hasSensitiveScopes", { enumerable: true, get: function () { return handshake_1.hasSensitiveScopes; } });
10
- Object.defineProperty(exports, "MemoryResumeTokenStore", { enumerable: true, get: function () { return handshake_1.MemoryResumeTokenStore; } });
11
- //# sourceMappingURL=index.js.map
@@ -1,46 +0,0 @@
1
- /**
2
- * Authorization types for mcp-i-core auth module.
3
- *
4
- * These are the minimal interfaces required by the auth handshake.
5
- * Platform adapters (packages/mcp-i, packages/mcp-i-cloudflare) may extend
6
- * these types with additional fields.
7
- */
8
- import { DelegationRecord } from "@kya-os/contracts/delegation";
9
- /**
10
- * Result of a delegation verification check.
11
- * Structurally compatible with the full VerifyDelegationResult in packages/mcp-i.
12
- */
13
- export interface VerifyDelegationResult {
14
- /** Whether a valid delegation was found */
15
- valid: boolean;
16
- /** The delegation record (if found) */
17
- delegation?: DelegationRecord;
18
- /** Credential from AgentShield API (includes authorization method) */
19
- credential?: {
20
- agent_did: string;
21
- user_did: string;
22
- scopes: string[];
23
- authorization: {
24
- type: "oauth" | "oauth2" | "password" | "credential" | "webauthn" | "siwe" | "none";
25
- provider?: string;
26
- credentialType?: string;
27
- rpId?: string;
28
- userVerification?: "required" | "preferred" | "discouraged";
29
- chainId?: number;
30
- domain?: string;
31
- };
32
- [key: string]: unknown;
33
- };
34
- /** Reason for invalid result */
35
- reason?: string;
36
- /** Whether result came from cache */
37
- cached?: boolean;
38
- }
39
- /**
40
- * Minimal delegation verifier interface required by verifyOrHints().
41
- * Concrete implementations live in packages/mcp-i (AgentShieldAPIDelegationVerifier, etc.).
42
- */
43
- export interface DelegationVerifier {
44
- verify(agentDid: string, scopes: string[]): Promise<VerifyDelegationResult>;
45
- }
46
- //# sourceMappingURL=types.d.ts.map
@@ -1,10 +0,0 @@
1
- "use strict";
2
- /**
3
- * Authorization types for mcp-i-core auth module.
4
- *
5
- * These are the minimal interfaces required by the auth handshake.
6
- * Platform adapters (packages/mcp-i, packages/mcp-i-cloudflare) may extend
7
- * these types with additional fields.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- //# sourceMappingURL=types.js.map
@@ -1,69 +0,0 @@
1
- /**
2
- * Platform-agnostic cache interface for OAuth provider configurations
3
- *
4
- * This interface allows different runtime adapters to provide their own
5
- * caching implementations (e.g., in-memory for Node.js, KV for Cloudflare)
6
- *
7
- * @package @kya-os/mcp-i-core
8
- */
9
- import type { OAuthConfig } from "@kya-os/contracts/config";
10
- /**
11
- * Cache interface for storing and retrieving OAuth provider configurations
12
- */
13
- export interface OAuthConfigCache {
14
- /**
15
- * Retrieve a cached OAuth configuration
16
- * @param key Cache key (typically projectId)
17
- * @returns Cached config or null if not found/expired
18
- */
19
- get(key: string): Promise<OAuthConfig | null>;
20
- /**
21
- * Store an OAuth configuration in cache
22
- * @param key Cache key (typically projectId)
23
- * @param value OAuth configuration to cache
24
- * @param ttl Time-to-live in milliseconds
25
- */
26
- set(key: string, value: OAuthConfig, ttl: number): Promise<void>;
27
- /**
28
- * Clear all cached entries
29
- */
30
- clear(): Promise<void>;
31
- /**
32
- * Remove a specific cache entry
33
- * @param key Cache key to remove
34
- */
35
- delete(key: string): Promise<void>;
36
- }
37
- /**
38
- * In-memory cache implementation
39
- *
40
- * Suitable for:
41
- * - Node.js runtimes
42
- * - Development/testing
43
- * - Single-instance deployments
44
- *
45
- * NOT suitable for:
46
- * - Multi-instance deployments (cache not shared)
47
- * - Serverless environments (state not persisted)
48
- */
49
- export declare class InMemoryOAuthConfigCache implements OAuthConfigCache {
50
- private cache;
51
- get(key: string): Promise<OAuthConfig | null>;
52
- set(key: string, value: OAuthConfig, ttl: number): Promise<void>;
53
- clear(): Promise<void>;
54
- delete(key: string): Promise<void>;
55
- }
56
- /**
57
- * No-op cache implementation (disables caching)
58
- *
59
- * Use when:
60
- * - You want to disable caching entirely
61
- * - Testing scenarios that require fresh data
62
- */
63
- export declare class NoOpOAuthConfigCache implements OAuthConfigCache {
64
- get(_key: string): Promise<OAuthConfig | null>;
65
- set(_key: string, _value: OAuthConfig, _ttl: number): Promise<void>;
66
- clear(): Promise<void>;
67
- delete(_key: string): Promise<void>;
68
- }
69
- //# sourceMappingURL=oauth-config-cache.d.ts.map
@@ -1,76 +0,0 @@
1
- "use strict";
2
- /**
3
- * Platform-agnostic cache interface for OAuth provider configurations
4
- *
5
- * This interface allows different runtime adapters to provide their own
6
- * caching implementations (e.g., in-memory for Node.js, KV for Cloudflare)
7
- *
8
- * @package @kya-os/mcp-i-core
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.NoOpOAuthConfigCache = exports.InMemoryOAuthConfigCache = void 0;
12
- /**
13
- * In-memory cache implementation
14
- *
15
- * Suitable for:
16
- * - Node.js runtimes
17
- * - Development/testing
18
- * - Single-instance deployments
19
- *
20
- * NOT suitable for:
21
- * - Multi-instance deployments (cache not shared)
22
- * - Serverless environments (state not persisted)
23
- */
24
- class InMemoryOAuthConfigCache {
25
- cache = new Map();
26
- async get(key) {
27
- const entry = this.cache.get(key);
28
- if (!entry) {
29
- return null;
30
- }
31
- // Check if expired
32
- if (Date.now() > entry.expiresAt) {
33
- this.cache.delete(key);
34
- return null;
35
- }
36
- return entry.value;
37
- }
38
- async set(key, value, ttl) {
39
- // If TTL is <= 0, don't store (entry would be immediately expired)
40
- if (ttl <= 0) {
41
- return;
42
- }
43
- const expiresAt = Date.now() + ttl;
44
- this.cache.set(key, { value, expiresAt });
45
- }
46
- async clear() {
47
- this.cache.clear();
48
- }
49
- async delete(key) {
50
- this.cache.delete(key);
51
- }
52
- }
53
- exports.InMemoryOAuthConfigCache = InMemoryOAuthConfigCache;
54
- /**
55
- * No-op cache implementation (disables caching)
56
- *
57
- * Use when:
58
- * - You want to disable caching entirely
59
- * - Testing scenarios that require fresh data
60
- */
61
- class NoOpOAuthConfigCache {
62
- async get(_key) {
63
- return null;
64
- }
65
- async set(_key, _value, _ttl) {
66
- // No-op
67
- }
68
- async clear() {
69
- // No-op
70
- }
71
- async delete(_key) {
72
- // No-op
73
- }
74
- }
75
- exports.NoOpOAuthConfigCache = NoOpOAuthConfigCache;
76
- //# sourceMappingURL=oauth-config-cache.js.map
@@ -1,89 +0,0 @@
1
- /**
2
- * Platform-agnostic cache interface for tool protection configurations
3
- *
4
- * This interface allows different runtime adapters to provide their own
5
- * caching implementations (e.g., in-memory for Node.js, KV for CloudFlare)
6
- *
7
- * @package @kya-os/mcp-i-core
8
- */
9
- import type { ToolProtectionConfig } from '../types/tool-protection.js';
10
- /**
11
- * Cache interface for storing and retrieving tool protection configurations
12
- */
13
- export interface ToolProtectionCache {
14
- /**
15
- * Retrieve a cached tool protection configuration
16
- * @param key Cache key (typically projectId)
17
- * @returns Cached config or null if not found/expired
18
- */
19
- get(key: string): Promise<ToolProtectionConfig | null>;
20
- /**
21
- * Store a tool protection configuration in cache
22
- * @param key Cache key (typically projectId)
23
- * @param value Tool protection configuration to cache
24
- * @param ttl Time-to-live in milliseconds
25
- */
26
- set(key: string, value: ToolProtectionConfig, ttl: number): Promise<void>;
27
- /**
28
- * Clear all cached entries
29
- */
30
- clear(): Promise<void>;
31
- /**
32
- * Remove a specific cache entry
33
- * @param key Cache key to remove
34
- */
35
- delete(key: string): Promise<void>;
36
- }
37
- /**
38
- * In-memory cache implementation
39
- *
40
- * Suitable for:
41
- * - Node.js runtimes
42
- * - Development/testing
43
- * - Single-instance deployments
44
- *
45
- * NOT suitable for:
46
- * - Multi-instance deployments (cache not shared)
47
- * - Serverless environments (state not persisted)
48
- */
49
- export declare class InMemoryToolProtectionCache implements ToolProtectionCache {
50
- private cache;
51
- get(key: string): Promise<ToolProtectionConfig | null>;
52
- set(key: string, value: ToolProtectionConfig, ttl: number): Promise<void>;
53
- clear(): Promise<void>;
54
- delete(key: string): Promise<void>;
55
- /**
56
- * Clean up expired entries (call periodically)
57
- */
58
- cleanup(): void;
59
- /**
60
- * Get stale cache entry (including expired entries)
61
- * Used for fail-safe behavior when API is unavailable
62
- * This method accesses the internal cache map directly to avoid
63
- * deletion of expired entries that would occur with get()
64
- * @param key Cache key
65
- * @returns Cached config or null if not found
66
- */
67
- getStale(key: string): ToolProtectionConfig | null;
68
- /**
69
- * Get expiration timestamp for a cache entry
70
- * Used to check if stale cache is within maxStaleCacheAge
71
- * @param key Cache key
72
- * @returns Expiration timestamp in milliseconds, or null if not found
73
- */
74
- getExpiresAt(key: string): number | null;
75
- }
76
- /**
77
- * No-op cache implementation (disables caching)
78
- *
79
- * Use when:
80
- * - You want to disable caching entirely
81
- * - Testing scenarios that require fresh data
82
- */
83
- export declare class NoOpToolProtectionCache implements ToolProtectionCache {
84
- get(_key: string): Promise<ToolProtectionConfig | null>;
85
- set(_key: string, _value: ToolProtectionConfig, _ttl: number): Promise<void>;
86
- clear(): Promise<void>;
87
- delete(_key: string): Promise<void>;
88
- }
89
- //# sourceMappingURL=tool-protection-cache.d.ts.map
@@ -1,118 +0,0 @@
1
- "use strict";
2
- /**
3
- * Platform-agnostic cache interface for tool protection configurations
4
- *
5
- * This interface allows different runtime adapters to provide their own
6
- * caching implementations (e.g., in-memory for Node.js, KV for CloudFlare)
7
- *
8
- * @package @kya-os/mcp-i-core
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.NoOpToolProtectionCache = exports.InMemoryToolProtectionCache = void 0;
12
- /**
13
- * In-memory cache implementation
14
- *
15
- * Suitable for:
16
- * - Node.js runtimes
17
- * - Development/testing
18
- * - Single-instance deployments
19
- *
20
- * NOT suitable for:
21
- * - Multi-instance deployments (cache not shared)
22
- * - Serverless environments (state not persisted)
23
- */
24
- class InMemoryToolProtectionCache {
25
- cache = new Map();
26
- async get(key) {
27
- const entry = this.cache.get(key);
28
- if (!entry) {
29
- return null;
30
- }
31
- // Check if expired
32
- if (Date.now() > entry.expiresAt) {
33
- this.cache.delete(key);
34
- return null;
35
- }
36
- return entry.value;
37
- }
38
- async set(key, value, ttl) {
39
- // If TTL is <= 0, don't store (entry would be immediately expired)
40
- if (ttl <= 0) {
41
- return;
42
- }
43
- const expiresAt = Date.now() + ttl;
44
- this.cache.set(key, { value, expiresAt });
45
- }
46
- async clear() {
47
- this.cache.clear();
48
- }
49
- async delete(key) {
50
- this.cache.delete(key);
51
- }
52
- /**
53
- * Clean up expired entries (call periodically)
54
- */
55
- cleanup() {
56
- const now = Date.now();
57
- for (const [key, entry] of this.cache.entries()) {
58
- if (now > entry.expiresAt) {
59
- this.cache.delete(key);
60
- }
61
- }
62
- }
63
- /**
64
- * Get stale cache entry (including expired entries)
65
- * Used for fail-safe behavior when API is unavailable
66
- * This method accesses the internal cache map directly to avoid
67
- * deletion of expired entries that would occur with get()
68
- * @param key Cache key
69
- * @returns Cached config or null if not found
70
- */
71
- getStale(key) {
72
- // Access internal cache map directly (not through async get() which deletes expired entries)
73
- const entry = this.cache.get(key);
74
- if (!entry) {
75
- return null;
76
- }
77
- // Return value even if expired (getStale is meant for fail-safe behavior)
78
- return entry.value;
79
- }
80
- /**
81
- * Get expiration timestamp for a cache entry
82
- * Used to check if stale cache is within maxStaleCacheAge
83
- * @param key Cache key
84
- * @returns Expiration timestamp in milliseconds, or null if not found
85
- */
86
- getExpiresAt(key) {
87
- // Access internal cache map directly (not through async get() which deletes expired entries)
88
- const entry = this.cache.get(key);
89
- if (!entry) {
90
- return null;
91
- }
92
- return entry.expiresAt;
93
- }
94
- }
95
- exports.InMemoryToolProtectionCache = InMemoryToolProtectionCache;
96
- /**
97
- * No-op cache implementation (disables caching)
98
- *
99
- * Use when:
100
- * - You want to disable caching entirely
101
- * - Testing scenarios that require fresh data
102
- */
103
- class NoOpToolProtectionCache {
104
- async get(_key) {
105
- return null;
106
- }
107
- async set(_key, _value, _ttl) {
108
- // No-op
109
- }
110
- async clear() {
111
- // No-op
112
- }
113
- async delete(_key) {
114
- // No-op
115
- }
116
- }
117
- exports.NoOpToolProtectionCache = NoOpToolProtectionCache;
118
- //# sourceMappingURL=tool-protection-cache.js.map
@@ -1,8 +0,0 @@
1
- /**
2
- * Schema Compliance Module
3
- *
4
- * Automated verification against canonical schemas from schemas.kya-os.ai
5
- */
6
- export * from './schema-verifier';
7
- export * from './schema-registry';
8
- //# sourceMappingURL=index.d.ts.map