@kya-os/mcp-i-cloudflare 1.5.10-canary.8 → 1.6.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.
Files changed (102) hide show
  1. package/README.md +130 -0
  2. package/dist/__tests__/e2e/test-config.d.ts +37 -0
  3. package/dist/__tests__/e2e/test-config.d.ts.map +1 -0
  4. package/dist/__tests__/e2e/test-config.js +62 -0
  5. package/dist/__tests__/e2e/test-config.js.map +1 -0
  6. package/dist/adapter.d.ts +44 -1
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/adapter.js +712 -112
  9. package/dist/adapter.js.map +1 -1
  10. package/dist/agent.d.ts +103 -25
  11. package/dist/agent.d.ts.map +1 -1
  12. package/dist/agent.js +617 -40
  13. package/dist/agent.js.map +1 -1
  14. package/dist/app.d.ts +0 -8
  15. package/dist/app.d.ts.map +1 -1
  16. package/dist/app.js +277 -119
  17. package/dist/app.js.map +1 -1
  18. package/dist/cache/kv-oauth-config-cache.d.ts +47 -0
  19. package/dist/cache/kv-oauth-config-cache.d.ts.map +1 -0
  20. package/dist/cache/kv-oauth-config-cache.js +82 -0
  21. package/dist/cache/kv-oauth-config-cache.js.map +1 -0
  22. package/dist/cache/kv-tool-protection-cache.d.ts +26 -1
  23. package/dist/cache/kv-tool-protection-cache.d.ts.map +1 -1
  24. package/dist/cache/kv-tool-protection-cache.js +19 -11
  25. package/dist/cache/kv-tool-protection-cache.js.map +1 -1
  26. package/dist/config.d.ts.map +1 -1
  27. package/dist/config.js +39 -14
  28. package/dist/config.js.map +1 -1
  29. package/dist/helpers/env-mapper.d.ts +60 -1
  30. package/dist/helpers/env-mapper.d.ts.map +1 -1
  31. package/dist/helpers/env-mapper.js +136 -6
  32. package/dist/helpers/env-mapper.js.map +1 -1
  33. package/dist/index.d.ts +4 -2
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +16 -3
  36. package/dist/index.js.map +1 -1
  37. package/dist/runtime/audit-logger.d.ts +96 -0
  38. package/dist/runtime/audit-logger.d.ts.map +1 -0
  39. package/dist/runtime/audit-logger.js +276 -0
  40. package/dist/runtime/audit-logger.js.map +1 -0
  41. package/dist/runtime/oauth-handler.d.ts +5 -0
  42. package/dist/runtime/oauth-handler.d.ts.map +1 -1
  43. package/dist/runtime/oauth-handler.js +287 -35
  44. package/dist/runtime/oauth-handler.js.map +1 -1
  45. package/dist/runtime.d.ts +12 -1
  46. package/dist/runtime.d.ts.map +1 -1
  47. package/dist/runtime.js +34 -4
  48. package/dist/runtime.js.map +1 -1
  49. package/dist/server.d.ts +7 -0
  50. package/dist/server.d.ts.map +1 -1
  51. package/dist/server.js +133 -18
  52. package/dist/server.js.map +1 -1
  53. package/dist/services/admin.service.d.ts +1 -3
  54. package/dist/services/admin.service.d.ts.map +1 -1
  55. package/dist/services/admin.service.js +175 -146
  56. package/dist/services/admin.service.js.map +1 -1
  57. package/dist/services/consent-audit.service.d.ts +91 -0
  58. package/dist/services/consent-audit.service.d.ts.map +1 -0
  59. package/dist/services/consent-audit.service.js +243 -0
  60. package/dist/services/consent-audit.service.js.map +1 -0
  61. package/dist/services/consent-config.service.d.ts +2 -2
  62. package/dist/services/consent-config.service.d.ts.map +1 -1
  63. package/dist/services/consent-config.service.js +55 -28
  64. package/dist/services/consent-config.service.js.map +1 -1
  65. package/dist/services/consent-page-renderer.d.ts +14 -0
  66. package/dist/services/consent-page-renderer.d.ts.map +1 -1
  67. package/dist/services/consent-page-renderer.js +54 -27
  68. package/dist/services/consent-page-renderer.js.map +1 -1
  69. package/dist/services/consent.service.d.ts +93 -8
  70. package/dist/services/consent.service.d.ts.map +1 -1
  71. package/dist/services/consent.service.js +1817 -553
  72. package/dist/services/consent.service.js.map +1 -1
  73. package/dist/services/delegation.service.d.ts.map +1 -1
  74. package/dist/services/delegation.service.js +67 -29
  75. package/dist/services/delegation.service.js.map +1 -1
  76. package/dist/services/idp-token-storage.d.ts +68 -0
  77. package/dist/services/idp-token-storage.d.ts.map +1 -0
  78. package/dist/services/idp-token-storage.js +157 -0
  79. package/dist/services/idp-token-storage.js.map +1 -0
  80. package/dist/services/oauth-service.d.ts +66 -0
  81. package/dist/services/oauth-service.d.ts.map +1 -0
  82. package/dist/services/oauth-service.js +223 -0
  83. package/dist/services/oauth-service.js.map +1 -0
  84. package/dist/services/proof.service.d.ts +8 -6
  85. package/dist/services/proof.service.d.ts.map +1 -1
  86. package/dist/services/proof.service.js +131 -75
  87. package/dist/services/proof.service.js.map +1 -1
  88. package/dist/services/tool-context-builder.d.ts +55 -0
  89. package/dist/services/tool-context-builder.d.ts.map +1 -0
  90. package/dist/services/tool-context-builder.js +124 -0
  91. package/dist/services/tool-context-builder.js.map +1 -0
  92. package/dist/types/tool-context.d.ts +35 -0
  93. package/dist/types/tool-context.d.ts.map +1 -0
  94. package/dist/types/tool-context.js +13 -0
  95. package/dist/types/tool-context.js.map +1 -0
  96. package/dist/types.d.ts +31 -2
  97. package/dist/types.d.ts.map +1 -1
  98. package/dist/utils/oauth-service-registry.d.ts +65 -0
  99. package/dist/utils/oauth-service-registry.d.ts.map +1 -0
  100. package/dist/utils/oauth-service-registry.js +125 -0
  101. package/dist/utils/oauth-service-registry.js.map +1 -0
  102. package/package.json +27 -60
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-context-builder.js","sourceRoot":"","sources":["../../src/services/tool-context-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAsBH;;;;;;GAMG;AACH,MAAM,OAAO,kBAAkB;IACrB,MAAM,CAEZ;IAEF,YAAY,MAAgC;QAC1C,IAAI,CAAC,MAAM,GAAG;YACZ,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;SACpC,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;I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AAE,IAAI,CAAC,MAAM,CAAC,SAAS;aACjC,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Tool Execution Context
3
+ *
4
+ * Execution context passed to tool handlers, enabling tools to access
5
+ * IDP tokens for external API calls (GitHub, Google, etc.).
6
+ *
7
+ * All fields are optional for backward compatibility - tools that don't
8
+ * require OAuth will receive undefined context.
9
+ *
10
+ * @package @kya-os/mcp-i-cloudflare
11
+ */
12
+ /**
13
+ * Execution context passed to tool handlers
14
+ *
15
+ * Enables tools to access IDP tokens for external API calls.
16
+ * Context is only provided when:
17
+ * - Tool requires OAuth (has requiredScopes)
18
+ * - User DID is available
19
+ * - IDP token is successfully resolved
20
+ */
21
+ export interface ToolExecutionContext {
22
+ /** IDP access token for external API calls (e.g., GitHub, Google) */
23
+ idpToken?: string;
24
+ /** OAuth provider name (e.g., "github", "google") */
25
+ provider?: string;
26
+ /** Scopes granted for this token */
27
+ scopes?: string[];
28
+ /** User DID associated with this token */
29
+ userDid?: string;
30
+ /** Session ID */
31
+ sessionId?: string;
32
+ /** Delegation token (MCP-I internal authorization) */
33
+ delegationToken?: string;
34
+ }
35
+ //# sourceMappingURL=tool-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-context.d.ts","sourceRoot":"","sources":["../../src/types/tool-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB;IACnC,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Tool Execution Context
3
+ *
4
+ * Execution context passed to tool handlers, enabling tools to access
5
+ * IDP tokens for external API calls (GitHub, Google, etc.).
6
+ *
7
+ * All fields are optional for backward compatibility - tools that don't
8
+ * require OAuth will receive undefined context.
9
+ *
10
+ * @package @kya-os/mcp-i-cloudflare
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=tool-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-context.js","sourceRoot":"","sources":["../../src/types/tool-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
package/dist/types.d.ts CHANGED
@@ -3,15 +3,42 @@
3
3
  *
4
4
  * These types are separated to avoid circular dependencies.
5
5
  */
6
- import type { KVNamespace, DurableObjectState } from "@cloudflare/workers-types";
6
+ import type { KVNamespace, DurableObjectState } from '@cloudflare/workers-types';
7
7
  /**
8
8
  * Cloudflare environment bindings for MCP-I
9
+ *
10
+ * This is the normalized format after prefix mapping. All components expect
11
+ * this format with standard KV binding names (e.g., `NONCE_CACHE`, not `_17429_NONCE_CACHE`).
12
+ *
13
+ * To handle prefixed KV bindings (required for multi-agent deployments in the same account),
14
+ * use `normalizeCloudflareEnv()` from `@kya-os/mcp-i-cloudflare/helpers/env-mapper` before
15
+ * passing the environment to components.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { normalizeCloudflareEnv } from '@kya-os/mcp-i-cloudflare/helpers/env-mapper';
20
+ *
21
+ * // With prefixed bindings
22
+ * const env = { _17429_NONCE_CACHE: kvNamespace };
23
+ * const normalized = normalizeCloudflareEnv(env, '_17429');
24
+ * // normalized.NONCE_CACHE is now available
25
+ *
26
+ * // Without prefix (direct access)
27
+ * const env2 = { NONCE_CACHE: kvNamespace };
28
+ * const normalized2 = normalizeCloudflareEnv(env2);
29
+ * // normalized2.NONCE_CACHE is available
30
+ * ```
9
31
  */
10
32
  export interface CloudflareEnv {
33
+ /** KV namespace for nonce cache (required for replay attack prevention) */
11
34
  NONCE_CACHE: KVNamespace;
35
+ /** KV namespace for proof archive (optional, for auditability) */
12
36
  PROOF_ARCHIVE?: KVNamespace;
37
+ /** KV namespace for identity storage (optional, for persistent agent identity) */
13
38
  IDENTITY_STORAGE?: KVNamespace;
39
+ /** KV namespace for tool protection config cache (optional, for dashboard-controlled delegation) */
14
40
  TOOL_PROTECTION_KV?: KVNamespace;
41
+ /** KV namespace for delegation storage (required for OAuth/delegation flows) */
15
42
  DELEGATION_STORAGE?: KVNamespace;
16
43
  MCP_IDENTITY_PRIVATE_KEY?: string;
17
44
  MCP_IDENTITY_PUBLIC_KEY?: string;
@@ -20,10 +47,12 @@ export interface CloudflareEnv {
20
47
  AGENTSHIELD_API_URL?: string;
21
48
  AGENTSHIELD_API_KEY?: string;
22
49
  AGENTSHIELD_PROJECT_ID?: string;
50
+ /** Optional encryption secret for OAuth token encryption (CSRF protection) */
51
+ OAUTH_ENCRYPTION_SECRET?: string;
23
52
  MCPI_ENV?: string;
24
53
  ENVIRONMENT?: string;
25
54
  ADMIN_API_KEY?: string;
55
+ /** Optional Durable Object state for identity persistence */
26
56
  _durableObjectState?: DurableObjectState;
27
57
  }
28
- export type { MCPICloudflareAdapterConfig } from "./adapter";
29
58
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,WAAW,CAAC;IACzB,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,gBAAgB,CAAC,EAAE,WAAW,CAAC;IAC/B,kBAAkB,CAAC,EAAE,WAAW,CAAC;IACjC,kBAAkB,CAAC,EAAE,WAAW,CAAC;IACjC,wBA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AC9E,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,mBAAmB,CAAC,EAAE,kBAAkB,CAAC;CAC1C"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * OAuth Service Registry - Centralized tree-shaking prevention
3
+ *
4
+ * This module solves a critical bundling issue with Cloudflare Workers:
5
+ * Wrangler uses esbuild which aggressively tree-shakes imports that are
6
+ * only used inside async functions with conditional execution.
7
+ *
8
+ * Solution: Register OAuth services on globalThis at module load time,
9
+ * creating an observable side effect that esbuild cannot eliminate.
10
+ *
11
+ * @module oauth-service-registry
12
+ * @see https://esbuild.github.io/api/#tree-shaking
13
+ */
14
+ import { OAuthConfigService, OAuthProviderRegistry, ProviderResolver } from "@kya-os/mcp-i-core";
15
+ /**
16
+ * Type definition for the OAuth services registry
17
+ */
18
+ export interface OAuthServicesRegistry {
19
+ OAuthConfigService: typeof OAuthConfigService;
20
+ OAuthProviderRegistry: typeof OAuthProviderRegistry;
21
+ ProviderResolver: typeof ProviderResolver;
22
+ }
23
+ /**
24
+ * Error thrown when OAuth services are not available
25
+ */
26
+ export declare class OAuthServicesUnavailableError extends Error {
27
+ constructor(serviceName: string);
28
+ }
29
+ /**
30
+ * Get OAuth services from the global registry
31
+ *
32
+ * This is the primary API for retrieving OAuth services.
33
+ * It retrieves services that were registered on globalThis at module load,
34
+ * ensuring they survive esbuild's tree-shaking.
35
+ *
36
+ * @returns The OAuth services registry containing all constructors
37
+ * @throws {OAuthServicesUnavailableError} If services are not registered
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const { OAuthConfigService, OAuthProviderRegistry } = getOAuthServices();
42
+ * const configService = new OAuthConfigService({ ... });
43
+ * ```
44
+ */
45
+ export declare function getOAuthServices(): OAuthServicesRegistry;
46
+ /**
47
+ * Check if OAuth services are available without throwing
48
+ *
49
+ * Useful for conditional initialization where missing services
50
+ * should be handled gracefully rather than throwing.
51
+ *
52
+ * @returns true if all OAuth services are registered and valid
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * if (isOAuthServicesAvailable()) {
57
+ * const services = getOAuthServices();
58
+ * // Initialize OAuth functionality
59
+ * } else {
60
+ * console.warn("OAuth services not available");
61
+ * }
62
+ * ```
63
+ */
64
+ export declare function isOAuthServicesAvailable(): boolean;
65
+ //# sourceMappingURL=oauth-service-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-service-registry.d.ts","sourceRoot":"","sources":["../../src/utils/oauth-service-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAQ5B;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IAC9C,qBAAqB,EAAE,OAAO,qBAAqB,CAAC;IACpD,gBAAgB,EAAE,OAAO,gBAAgB,CAAC;CAC3C;AA6CD;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;gBAC1C,WAAW,EAAE,MAAM;CAQhC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,IAAI,qBAAqB,CAqBxD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAelD"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * OAuth Service Registry - Centralized tree-shaking prevention
3
+ *
4
+ * This module solves a critical bundling issue with Cloudflare Workers:
5
+ * Wrangler uses esbuild which aggressively tree-shakes imports that are
6
+ * only used inside async functions with conditional execution.
7
+ *
8
+ * Solution: Register OAuth services on globalThis at module load time,
9
+ * creating an observable side effect that esbuild cannot eliminate.
10
+ *
11
+ * @module oauth-service-registry
12
+ * @see https://esbuild.github.io/api/#tree-shaking
13
+ */
14
+ import { OAuthConfigService, OAuthProviderRegistry, ProviderResolver, } from "@kya-os/mcp-i-core";
15
+ /**
16
+ * Global registry key for OAuth services
17
+ * Using a unique symbol-like string to avoid collisions
18
+ */
19
+ const REGISTRY_KEY = "__MCPI_OAUTH_SERVICES__";
20
+ /**
21
+ * The services object containing all OAuth-related constructors
22
+ * This is created at module load time to ensure bundler inclusion
23
+ */
24
+ const _oauthServices = {
25
+ OAuthConfigService,
26
+ OAuthProviderRegistry,
27
+ ProviderResolver,
28
+ };
29
+ /**
30
+ * CRITICAL: Register on globalThis at module load
31
+ *
32
+ * This creates an observable side effect that esbuild cannot optimize away.
33
+ * The write to globalThis MUST happen for the program to work correctly,
34
+ * so esbuild will include all the OAuth service classes in the bundle.
35
+ */
36
+ globalThis[REGISTRY_KEY] = _oauthServices;
37
+ /**
38
+ * Validate registration succeeded
39
+ * Logs errors at module load if services are missing (indicates bundler issue)
40
+ */
41
+ const _registeredServices = globalThis[REGISTRY_KEY];
42
+ if (!_registeredServices?.OAuthConfigService) {
43
+ console.error("[OAuthServiceRegistry] CRITICAL: OAuthConfigService not registered - bundler issue");
44
+ }
45
+ if (!_registeredServices?.OAuthProviderRegistry) {
46
+ console.error("[OAuthServiceRegistry] CRITICAL: OAuthProviderRegistry not registered - bundler issue");
47
+ }
48
+ if (!_registeredServices?.ProviderResolver) {
49
+ console.error("[OAuthServiceRegistry] CRITICAL: ProviderResolver not registered - bundler issue");
50
+ }
51
+ /**
52
+ * Error thrown when OAuth services are not available
53
+ */
54
+ export class OAuthServicesUnavailableError extends Error {
55
+ constructor(serviceName) {
56
+ super(`${serviceName} not available from OAuth service registry. ` +
57
+ `This indicates a bundler tree-shaking issue. ` +
58
+ `The globalThis registration should have happened at module load.`);
59
+ this.name = "OAuthServicesUnavailableError";
60
+ }
61
+ }
62
+ /**
63
+ * Get OAuth services from the global registry
64
+ *
65
+ * This is the primary API for retrieving OAuth services.
66
+ * It retrieves services that were registered on globalThis at module load,
67
+ * ensuring they survive esbuild's tree-shaking.
68
+ *
69
+ * @returns The OAuth services registry containing all constructors
70
+ * @throws {OAuthServicesUnavailableError} If services are not registered
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const { OAuthConfigService, OAuthProviderRegistry } = getOAuthServices();
75
+ * const configService = new OAuthConfigService({ ... });
76
+ * ```
77
+ */
78
+ export function getOAuthServices() {
79
+ const services = globalThis[REGISTRY_KEY];
80
+ if (!services) {
81
+ throw new OAuthServicesUnavailableError("OAuth services registry");
82
+ }
83
+ // Validate each service is a constructor
84
+ if (typeof services.OAuthConfigService !== "function") {
85
+ throw new OAuthServicesUnavailableError("OAuthConfigService");
86
+ }
87
+ if (typeof services.OAuthProviderRegistry !== "function") {
88
+ throw new OAuthServicesUnavailableError("OAuthProviderRegistry");
89
+ }
90
+ if (typeof services.ProviderResolver !== "function") {
91
+ throw new OAuthServicesUnavailableError("ProviderResolver");
92
+ }
93
+ return services;
94
+ }
95
+ /**
96
+ * Check if OAuth services are available without throwing
97
+ *
98
+ * Useful for conditional initialization where missing services
99
+ * should be handled gracefully rather than throwing.
100
+ *
101
+ * @returns true if all OAuth services are registered and valid
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * if (isOAuthServicesAvailable()) {
106
+ * const services = getOAuthServices();
107
+ * // Initialize OAuth functionality
108
+ * } else {
109
+ * console.warn("OAuth services not available");
110
+ * }
111
+ * ```
112
+ */
113
+ export function isOAuthServicesAvailable() {
114
+ try {
115
+ const services = globalThis[REGISTRY_KEY];
116
+ return (!!services &&
117
+ typeof services.OAuthConfigService === "function" &&
118
+ typeof services.OAuthProviderRegistry === "function" &&
119
+ typeof services.ProviderResolver === "function");
120
+ }
121
+ catch {
122
+ return false;
123
+ }
124
+ }
125
+ //# sourceMappingURL=oauth-service-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-service-registry.js","sourceRoot":"","sources":["../../src/utils/oauth-service-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GA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AI,6BAA6B,CAAC,oBAAoB,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,OAAO,QAAQ,CAAC,qBAAqB,KAAK,UAAU,EAAE,CAAC;QACzD,MAAM,IAAI,6BAA6B,CAAC,uBAAuB,CAAC,CAAC;IACnE,CAAC;IACD,IAAI,OAAO,QAAQ,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;QACpD,MAAM,IAAI,6BAA6B,CAAC,kBAAkB,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,wBAAwB;IACtC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAI,UAAsC,CAAC,YAAY,CAExD,CAAC;QAEd,OAAO,CACL,CAAC,CAAC,QAAQ;YACV,OAAO,QAAQ,CAAC,kBAAkB,KAAK,UAAU;YACjD,OAAO,QAAQ,CAAC,qBAAqB,KAAK,UAAU;YACpD,OAAO,QAAQ,CAAC,gBAAgB,KAAK,UAAU,CAChD,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,74 +1,41 @@
1
1
  {
2
2
  "name": "@kya-os/mcp-i-cloudflare",
3
- "version": "1.5.10-canary.8",
4
- "description": "Cloudflare Workers implementation of MCP-I framework",
3
+ "version": "1.6.0",
4
+ "description": "Cloudflare Workers adapter for MCP-I framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "type": "module",
8
- "exports": {
9
- ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
- },
13
- "./config": {
14
- "import": "./dist/config.js",
15
- "types": "./dist/config.d.ts"
16
- }
17
- },
18
7
  "files": [
19
- "dist/**/*",
20
- "README.md"
8
+ "dist"
21
9
  ],
22
10
  "scripts": {
23
11
  "build": "tsc",
24
- "dev": "tsc --watch",
25
- "test": "vitest --run",
26
- "test:coverage": "vitest --run --coverage",
27
- "lint": "eslint src/**/*.ts",
28
- "type-check": "tsc --noEmit",
29
- "prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-dependencies.js"
12
+ "test": "vitest run",
13
+ "test:coverage": "vitest run --coverage",
14
+ "test:watch": "vitest",
15
+ "lint": "eslint .",
16
+ "clean": "rm -rf dist .turbo node_modules",
17
+ "prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-no-workspace.js"
30
18
  },
31
- "keywords": [
32
- "mcp-i",
33
- "mcp",
34
- "identity",
35
- "did",
36
- "cloudflare",
37
- "workers",
38
- "edge"
39
- ],
40
19
  "dependencies": {
41
- "@kya-os/contracts": "^1.5.4-canary.2",
42
- "@kya-os/mcp-i-core": "^1.2.3-canary.6",
43
- "@modelcontextprotocol/sdk": "^1.11.4",
44
- "base-x": "^5.0.1"
45
- },
46
- "peerDependencies": {
47
- "hono": "^4.0.0",
48
- "agents": "^0.2.21"
20
+ "@kya-os/contracts": "^1.6.0",
21
+ "@kya-os/mcp-i-core": "^1.3.0",
22
+ "@modelcontextprotocol/sdk": "^1.22.0",
23
+ "agents": "^0.2.21",
24
+ "base-x": "^5.0.0",
25
+ "hono": "^4.6.3",
26
+ "jose": "^5.6.3",
27
+ "zod": "^3.23.8"
49
28
  },
50
29
  "devDependencies": {
51
- "@cloudflare/workers-types": "^4.20251109.0",
52
- "@types/node": "^20.0.0",
53
- "@typescript-eslint/eslint-plugin": "^6.0.0",
54
- "@typescript-eslint/parser": "^6.0.0",
30
+ "@cloudflare/workers-types": "^4.20240701.0",
31
+ "@types/node": "^20.14.9",
55
32
  "@vitest/coverage-v8": "^4.0.5",
56
- "eslint": "^8.0.0",
57
- "typescript": "^5.3.0",
58
- "vitest": "^4.0.5",
59
- "wrangler": "^3.0.0"
60
- },
61
- "engines": {
62
- "node": ">=20.0.0"
63
- },
64
- "author": "MCP-I Team",
65
- "license": "MIT",
66
- "repository": {
67
- "type": "git",
68
- "url": "git+https://github.com/modelcontextprotocol-identity/mcp-i.git"
69
- },
70
- "bugs": {
71
- "url": "https://github.com/modelcontextprotocol-identity/mcp-i/issues"
72
- },
73
- "homepage": "https://github.com/modelcontextprotocol-identity/mcp-i#readme"
33
+ "dotenv": "^16.3.1",
34
+ "eslint": "^8.57.0",
35
+ "typescript": "^5.5.3",
36
+ "vitest": "^4.0.5"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ }
74
41
  }