@kya-os/mcp-i-cloudflare 1.5.1-canary.6 → 1.5.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 (40) hide show
  1. package/dist/adapter.d.ts +8 -0
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/adapter.js +102 -87
  4. package/dist/adapter.js.map +1 -1
  5. package/dist/constants/storage-keys.d.ts +89 -0
  6. package/dist/constants/storage-keys.d.ts.map +1 -0
  7. package/dist/constants/storage-keys.js +142 -0
  8. package/dist/constants/storage-keys.js.map +1 -0
  9. package/dist/index.d.ts +7 -3
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +9 -3
  12. package/dist/index.js.map +1 -1
  13. package/dist/runtime/oauth-handler.d.ts +6 -0
  14. package/dist/runtime/oauth-handler.d.ts.map +1 -1
  15. package/dist/runtime/oauth-handler.js +96 -21
  16. package/dist/runtime/oauth-handler.js.map +1 -1
  17. package/dist/services/consent-page-renderer.d.ts +5 -2
  18. package/dist/services/consent-page-renderer.d.ts.map +1 -1
  19. package/dist/services/consent-page-renderer.js +29 -8
  20. package/dist/services/consent-page-renderer.js.map +1 -1
  21. package/dist/services/consent.service.d.ts +52 -0
  22. package/dist/services/consent.service.d.ts.map +1 -1
  23. package/dist/services/consent.service.js +451 -99
  24. package/dist/services/consent.service.js.map +1 -1
  25. package/dist/services/delegation.service.d.ts.map +1 -1
  26. package/dist/services/delegation.service.js +54 -19
  27. package/dist/services/delegation.service.js.map +1 -1
  28. package/dist/services/oauth-security.service.d.ts +92 -0
  29. package/dist/services/oauth-security.service.d.ts.map +1 -0
  30. package/dist/services/oauth-security.service.js +260 -0
  31. package/dist/services/oauth-security.service.js.map +1 -0
  32. package/dist/services/rate-limit.service.d.ts +59 -0
  33. package/dist/services/rate-limit.service.d.ts.map +1 -0
  34. package/dist/services/rate-limit.service.js +146 -0
  35. package/dist/services/rate-limit.service.js.map +1 -0
  36. package/dist/utils/day0-config.d.ts +51 -0
  37. package/dist/utils/day0-config.d.ts.map +1 -0
  38. package/dist/utils/day0-config.js +72 -0
  39. package/dist/utils/day0-config.js.map +1 -0
  40. package/package.json +3 -3
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Rate Limiting Service
3
+ *
4
+ * Provides rate limiting functionality for OAuth operations, delegation creation,
5
+ * and identity verification to prevent abuse and ensure fair usage.
6
+ *
7
+ * Uses KV storage for distributed rate limiting across Cloudflare Workers.
8
+ */
9
+ import type { KVNamespace } from "@cloudflare/workers-types";
10
+ interface RateLimitConfig {
11
+ maxRequests: number;
12
+ windowMs: number;
13
+ keyPrefix: string;
14
+ }
15
+ export interface RateLimitResult {
16
+ allowed: boolean;
17
+ remaining: number;
18
+ resetAt: number;
19
+ }
20
+ /**
21
+ * Rate limiting service for Cloudflare Workers
22
+ */
23
+ export declare class RateLimitService {
24
+ private storage;
25
+ private readonly limits;
26
+ constructor(storage: KVNamespace);
27
+ /**
28
+ * Check if operation is allowed under rate limit
29
+ *
30
+ * @param operation - Operation name (e.g., "oauth-linking", "delegation-creation")
31
+ * @param identifier - Unique identifier (e.g., user ID, IP address, OAuth subject)
32
+ * @returns Rate limit check result
33
+ */
34
+ checkLimit(operation: string, identifier: string): Promise<RateLimitResult>;
35
+ /**
36
+ * Reset rate limit for an operation and identifier
37
+ *
38
+ * @param operation - Operation name
39
+ * @param identifier - Unique identifier
40
+ */
41
+ resetLimit(operation: string, identifier: string): Promise<void>;
42
+ /**
43
+ * Get current rate limit status without incrementing counter
44
+ *
45
+ * @param operation - Operation name
46
+ * @param identifier - Unique identifier
47
+ * @returns Current rate limit status
48
+ */
49
+ getStatus(operation: string, identifier: string): Promise<RateLimitResult>;
50
+ /**
51
+ * Register a custom rate limit configuration
52
+ *
53
+ * @param operation - Operation name
54
+ * @param config - Rate limit configuration
55
+ */
56
+ registerLimit(operation: string, config: RateLimitConfig): void;
57
+ }
58
+ export {};
59
+ //# sourceMappingURL=rate-limit.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit.service.d.ts","sourceRoot":"","sources":["../../src/services/rate-limit.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAG7D,UAAU,eAAe;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IA4Bf,OAAO,CAAC,OAAO;IA3B3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAyBpB;gBAEiB,OAAO,EAAE,WAAW;IAExC;;;;;;OAMG;IACG,UAAU,CACd,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,CAAC;IA0D3B;;;;;OAKG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtE;;;;;;OAMG;IACG,SAAS,CACb,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,CAAC;IA+B3B;;;;;OAKG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI;CAGhE"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Rate Limiting Service
3
+ *
4
+ * Provides rate limiting functionality for OAuth operations, delegation creation,
5
+ * and identity verification to prevent abuse and ensure fair usage.
6
+ *
7
+ * Uses KV storage for distributed rate limiting across Cloudflare Workers.
8
+ */
9
+ import { STORAGE_KEYS } from "../constants/storage-keys";
10
+ /**
11
+ * Rate limiting service for Cloudflare Workers
12
+ */
13
+ export class RateLimitService {
14
+ storage;
15
+ limits = new Map([
16
+ [
17
+ "oauth-linking",
18
+ { maxRequests: 10, windowMs: 3600000, keyPrefix: "rl:oauth" },
19
+ ],
20
+ [
21
+ "delegation-creation",
22
+ { maxRequests: 100, windowMs: 3600000, keyPrefix: "rl:delegation" },
23
+ ],
24
+ [
25
+ "identity-verification",
26
+ { maxRequests: 50, windowMs: 3600000, keyPrefix: "rl:verify" },
27
+ ],
28
+ [
29
+ "oauth-login",
30
+ { maxRequests: 5, windowMs: 300000, keyPrefix: "rl:oauth:login" },
31
+ ],
32
+ [
33
+ "oauth-callback",
34
+ { maxRequests: 10, windowMs: 300000, keyPrefix: "rl:oauth:callback" },
35
+ ],
36
+ [
37
+ "oauth-refresh",
38
+ { maxRequests: 20, windowMs: 3600000, keyPrefix: "rl:oauth:refresh" },
39
+ ],
40
+ ]);
41
+ constructor(storage) {
42
+ this.storage = storage;
43
+ }
44
+ /**
45
+ * Check if operation is allowed under rate limit
46
+ *
47
+ * @param operation - Operation name (e.g., "oauth-linking", "delegation-creation")
48
+ * @param identifier - Unique identifier (e.g., user ID, IP address, OAuth subject)
49
+ * @returns Rate limit check result
50
+ */
51
+ async checkLimit(operation, identifier) {
52
+ const config = this.limits.get(operation);
53
+ if (!config) {
54
+ // No limit configured - allow all requests
55
+ return { allowed: true, remaining: 999, resetAt: 0 };
56
+ }
57
+ const key = STORAGE_KEYS.rateLimit(operation, identifier);
58
+ const now = Date.now();
59
+ const windowStart = now - config.windowMs;
60
+ try {
61
+ // Get current count from KV
62
+ const countData = (await this.storage.get(key, "json"));
63
+ const requests = countData?.requests || [];
64
+ // Filter requests within window
65
+ const recentRequests = requests.filter((t) => t > windowStart);
66
+ if (recentRequests.length >= config.maxRequests) {
67
+ // Rate limit exceeded
68
+ const oldestRequest = Math.min(...recentRequests);
69
+ const resetAt = oldestRequest + config.windowMs;
70
+ return {
71
+ allowed: false,
72
+ remaining: 0,
73
+ resetAt,
74
+ };
75
+ }
76
+ // Add current request
77
+ recentRequests.push(now);
78
+ // Store updated count with TTL matching window
79
+ await this.storage.put(key, JSON.stringify({ requests: recentRequests }), {
80
+ expirationTtl: Math.ceil(config.windowMs / 1000),
81
+ });
82
+ return {
83
+ allowed: true,
84
+ remaining: config.maxRequests - recentRequests.length,
85
+ resetAt: now + config.windowMs,
86
+ };
87
+ }
88
+ catch (error) {
89
+ // On error, allow request but log warning
90
+ console.error("[RateLimitService] Error checking limit:", error);
91
+ return { allowed: true, remaining: 999, resetAt: 0 };
92
+ }
93
+ }
94
+ /**
95
+ * Reset rate limit for an operation and identifier
96
+ *
97
+ * @param operation - Operation name
98
+ * @param identifier - Unique identifier
99
+ */
100
+ async resetLimit(operation, identifier) {
101
+ const key = STORAGE_KEYS.rateLimit(operation, identifier);
102
+ await this.storage.delete(key);
103
+ }
104
+ /**
105
+ * Get current rate limit status without incrementing counter
106
+ *
107
+ * @param operation - Operation name
108
+ * @param identifier - Unique identifier
109
+ * @returns Current rate limit status
110
+ */
111
+ async getStatus(operation, identifier) {
112
+ const config = this.limits.get(operation);
113
+ if (!config) {
114
+ return { allowed: true, remaining: 999, resetAt: 0 };
115
+ }
116
+ const key = STORAGE_KEYS.rateLimit(operation, identifier);
117
+ const now = Date.now();
118
+ const windowStart = now - config.windowMs;
119
+ try {
120
+ const countData = (await this.storage.get(key, "json"));
121
+ const requests = countData?.requests || [];
122
+ const recentRequests = requests.filter((t) => t > windowStart);
123
+ return {
124
+ allowed: recentRequests.length < config.maxRequests,
125
+ remaining: Math.max(0, config.maxRequests - recentRequests.length),
126
+ resetAt: recentRequests.length > 0
127
+ ? Math.min(...recentRequests) + config.windowMs
128
+ : now + config.windowMs,
129
+ };
130
+ }
131
+ catch (error) {
132
+ console.error("[RateLimitService] Error getting status:", error);
133
+ return { allowed: true, remaining: 999, resetAt: 0 };
134
+ }
135
+ }
136
+ /**
137
+ * Register a custom rate limit configuration
138
+ *
139
+ * @param operation - Operation name
140
+ * @param config - Rate limit configuration
141
+ */
142
+ registerLimit(operation, config) {
143
+ this.limits.set(operation, config);
144
+ }
145
+ }
146
+ //# sourceMappingURL=rate-limit.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit.service.js","sourceRoot":"","sources":["../../src/services/rate-limit.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAczD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IA4BP;IA3BH,MAAM,GAAiC,IAAI,GAAG,CAAC;QAC9D;YACE,eAAe;YACf,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE;SAC9D;QACD;YACE,qBAAqB;YACrB,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE;SACpE;QACD;YACE,uBAAuB;YACvB,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE;SAC/D;QACD;YACE,aAAa;YACb,EAAE,WAAW,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE;SAClE;QACD;YACE,gBAAgB;YAChB,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,mBAAmB,EAAE;SACtE;QACD;YACE,eAAe;YACf,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE;SACtE;KACF,CAAC,CAAC;IAEH,YAAoB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAE5C;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CACd,SAAiB,EACjB,UAAkB;QAElB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,MA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,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAE9C,CAAC;YAET,MAAM,QAAQ,GAAG,SAAS,EAAE,QAAQ,IAAI,EAAE,CAAC;YAC3C,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC;YAEvE,OAAO;gBACL,OAAO,EAAE,cAAc,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW;gBACnD,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC;gBAClE,OAAO,EAAE,cAAc,CAAC,MAAM,GAAG,CAAC;oBAChC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,MAAM,CAAC,QAAQ;oBAC/C,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,QAAQ;aAC1B,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAC;YACjE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QACvD,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,aAAa,CAAC,SAAiB,EAAE,MAAuB;QACtD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Day0 API Configuration Loader
3
+ *
4
+ * Loads Day0 API verification results for use in services.
5
+ * Day0 verification tests actual AgentShield API behavior to determine
6
+ * correct field names, response formats, and capabilities.
7
+ */
8
+ import type { KVNamespace } from "@cloudflare/workers-types";
9
+ export interface Day0Config {
10
+ apiFormat: {
11
+ hasWrapper: boolean;
12
+ supportsFullFormat: boolean;
13
+ actualResponseStructure: string[];
14
+ };
15
+ fieldName: "metadata" | "custom_fields" | "neither";
16
+ timestamp: number;
17
+ }
18
+ /**
19
+ * Load Day0 configuration from KV storage or fallback to defaults
20
+ *
21
+ * In Cloudflare Workers, this should load from KV.
22
+ * In Node.js, this loads from day0-api-config.json file.
23
+ *
24
+ * @param storage - Optional KV namespace for Cloudflare Workers
25
+ * @returns Day0 configuration or null if not available
26
+ */
27
+ export declare function loadDay0Config(storage?: KVNamespace): Promise<Day0Config | null>;
28
+ /**
29
+ * Get the field name to use for delegation requests
30
+ *
31
+ * Returns the field name determined by Day0 verification, or defaults to "metadata"
32
+ *
33
+ * @param storage - Optional KV namespace for Cloudflare Workers
34
+ * @returns Field name: "metadata" or "custom_fields"
35
+ */
36
+ export declare function getDelegationFieldName(storage?: KVNamespace): Promise<"metadata" | "custom_fields">;
37
+ /**
38
+ * Check if API supports full DelegationRecord format
39
+ *
40
+ * @param storage - Optional KV namespace for Cloudflare Workers
41
+ * @returns True if full format is supported
42
+ */
43
+ export declare function supportsFullDelegationFormat(storage?: KVNamespace): Promise<boolean>;
44
+ /**
45
+ * Check if API responses use success/error wrapper
46
+ *
47
+ * @param storage - Optional KV namespace for Cloudflare Workers
48
+ * @returns True if responses are wrapped
49
+ */
50
+ export declare function hasResponseWrapper(storage?: KVNamespace): Promise<boolean>;
51
+ //# sourceMappingURL=day0-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"day0-config.d.ts","sourceRoot":"","sources":["../../src/utils/day0-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE;QACT,UAAU,EAAE,OAAO,CAAC;QACpB,kBAAkB,EAAE,OAAO,CAAC;QAC5B,uBAAuB,EAAE,MAAM,EAAE,CAAC;KACnC,CAAC;IACF,SAAS,EAAE,UAAU,GAAG,eAAe,GAAG,SAAS,CAAC;IACpD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAClC,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAmB5B;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,GAAG,eAAe,CAAC,CAOvC;AAED;;;;;GAKG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,OAAO,CAAC,CAGlB"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Day0 API Configuration Loader
3
+ *
4
+ * Loads Day0 API verification results for use in services.
5
+ * Day0 verification tests actual AgentShield API behavior to determine
6
+ * correct field names, response formats, and capabilities.
7
+ */
8
+ /**
9
+ * Load Day0 configuration from KV storage or fallback to defaults
10
+ *
11
+ * In Cloudflare Workers, this should load from KV.
12
+ * In Node.js, this loads from day0-api-config.json file.
13
+ *
14
+ * @param storage - Optional KV namespace for Cloudflare Workers
15
+ * @returns Day0 configuration or null if not available
16
+ */
17
+ export async function loadDay0Config(storage) {
18
+ // Try KV storage first (Cloudflare Workers)
19
+ if (storage) {
20
+ try {
21
+ const cached = await storage.get("day0:api:config", "json");
22
+ if (cached && typeof cached === "object") {
23
+ return cached;
24
+ }
25
+ }
26
+ catch (error) {
27
+ console.warn("[Day0Config] Failed to load from KV:", error);
28
+ }
29
+ }
30
+ // Fallback: File system loading is not available in Cloudflare Workers
31
+ // Day0 config should be loaded from KV storage in Workers environment
32
+ // For Node.js environments, use KV storage or set DAY0_CONFIG_PATH environment variable
33
+ // and load the config manually before calling this function
34
+ return null;
35
+ }
36
+ /**
37
+ * Get the field name to use for delegation requests
38
+ *
39
+ * Returns the field name determined by Day0 verification, or defaults to "metadata"
40
+ *
41
+ * @param storage - Optional KV namespace for Cloudflare Workers
42
+ * @returns Field name: "metadata" or "custom_fields"
43
+ */
44
+ export async function getDelegationFieldName(storage) {
45
+ const config = await loadDay0Config(storage);
46
+ if (config?.fieldName && config.fieldName !== "neither") {
47
+ return config.fieldName;
48
+ }
49
+ // Default to metadata if not configured
50
+ return "metadata";
51
+ }
52
+ /**
53
+ * Check if API supports full DelegationRecord format
54
+ *
55
+ * @param storage - Optional KV namespace for Cloudflare Workers
56
+ * @returns True if full format is supported
57
+ */
58
+ export async function supportsFullDelegationFormat(storage) {
59
+ const config = await loadDay0Config(storage);
60
+ return config?.apiFormat?.supportsFullFormat ?? false;
61
+ }
62
+ /**
63
+ * Check if API responses use success/error wrapper
64
+ *
65
+ * @param storage - Optional KV namespace for Cloudflare Workers
66
+ * @returns True if responses are wrapped
67
+ */
68
+ export async function hasResponseWrapper(storage) {
69
+ const config = await loadDay0Config(storage);
70
+ return config?.apiFormat?.hasWrapper ?? true; // Default to true (safer)
71
+ }
72
+ //# sourceMappingURL=day0-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"day0-config.js","sourceRoot":"","sources":["../../src/utils/day0-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAqB;IAErB,4CAA4C;IAC5C,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;YAC5D,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACzC,OAAO,MAAoB,CAAC;YAC9B,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAED,uEAAuE;IACvE,sEAAsE;IACtE,wFAAwF;IACxF,4DAA4D;IAE5D,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAqB;IAErB,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,MAAM,EAAE,SAAS,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACxD,OAAO,MAAM,CAAC,SAAS,CAAC;IAC1B,CAAC;IACD,wCAAwC;IACxC,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,OAAqB;IAErB,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,MAAM,EAAE,SAAS,EAAE,kBAAkB,IAAI,KAAK,CAAC;AACxD,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAqB;IAErB,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,MAAM,EAAE,SAAS,EAAE,UAAU,IAAI,IAAI,CAAC,CAAC,0BAA0B;AAC1E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-os/mcp-i-cloudflare",
3
- "version": "1.5.1-canary.6",
3
+ "version": "1.5.1",
4
4
  "description": "Cloudflare Workers implementation of MCP-I framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -38,8 +38,8 @@
38
38
  "edge"
39
39
  ],
40
40
  "dependencies": {
41
- "@kya-os/contracts": "^1.5.2-canary.5",
42
- "@kya-os/mcp-i-core": "^1.2.1-canary.0",
41
+ "@kya-os/contracts": "^1.5.2",
42
+ "@kya-os/mcp-i-core": "^1.2.1",
43
43
  "@modelcontextprotocol/sdk": "^1.11.4",
44
44
  "base-x": "^5.0.1"
45
45
  },