@kya-os/mcp-i 0.1.0-alpha.3.9 → 1.2.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 (328) hide show
  1. package/README.md +350 -213
  2. package/dist/149.js +1 -0
  3. package/dist/189.js +1 -0
  4. package/dist/261.js +1 -0
  5. package/dist/28.js +1 -0
  6. package/dist/295.js +1 -0
  7. package/dist/460.js +1 -0
  8. package/dist/570.js +1 -0
  9. package/dist/634.js +1 -0
  10. package/dist/647.js +1 -0
  11. package/dist/67.js +1 -0
  12. package/dist/739.js +1 -0
  13. package/dist/742.js +1 -0
  14. package/dist/904.js +1 -0
  15. package/dist/938.js +1 -0
  16. package/dist/auth/api-key.d.ts +16 -0
  17. package/dist/auth/api-key.js +82 -0
  18. package/dist/auth/jwt.d.ts +43 -0
  19. package/dist/auth/jwt.js +51 -0
  20. package/dist/auth/oauth/factory.d.ts +12 -0
  21. package/dist/auth/oauth/factory.js +36 -0
  22. package/dist/auth/oauth/index.d.ts +5 -0
  23. package/dist/auth/oauth/index.js +27 -0
  24. package/dist/auth/oauth/providers/proxy-provider.d.ts +13 -0
  25. package/dist/auth/oauth/providers/proxy-provider.js +159 -0
  26. package/dist/auth/oauth/router.d.ts +4 -0
  27. package/dist/auth/oauth/router.js +294 -0
  28. package/dist/auth/oauth/storage/memory-storage.d.ts +12 -0
  29. package/dist/auth/oauth/storage/memory-storage.js +40 -0
  30. package/dist/auth/oauth/types.d.ts +112 -0
  31. package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.d.ts +4 -0
  32. package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.js +176 -0
  33. package/dist/cache/__tests__/concurrency.test.d.ts +5 -0
  34. package/dist/cache/__tests__/concurrency.test.js +300 -0
  35. package/dist/cache/__tests__/dynamodb-nonce-cache.test.d.ts +4 -0
  36. package/dist/cache/__tests__/dynamodb-nonce-cache.test.js +176 -0
  37. package/dist/cache/__tests__/memory-nonce-cache.test.d.ts +4 -0
  38. package/dist/cache/__tests__/memory-nonce-cache.test.js +132 -0
  39. package/dist/cache/__tests__/nonce-cache-factory-simple.test.d.ts +4 -0
  40. package/dist/cache/__tests__/nonce-cache-factory-simple.test.js +133 -0
  41. package/dist/cache/__tests__/nonce-cache-factory.test.d.ts +4 -0
  42. package/dist/cache/__tests__/nonce-cache-factory.test.js +252 -0
  43. package/dist/cache/__tests__/redis-nonce-cache.test.d.ts +4 -0
  44. package/dist/cache/__tests__/redis-nonce-cache.test.js +95 -0
  45. package/dist/cache/cloudflare-kv-nonce-cache.d.ts +14 -0
  46. package/dist/cache/cloudflare-kv-nonce-cache.js +93 -0
  47. package/dist/cache/dynamodb-nonce-cache.d.ts +15 -0
  48. package/dist/cache/dynamodb-nonce-cache.js +92 -0
  49. package/dist/cache/index.d.ts +16 -0
  50. package/dist/cache/index.js +32 -0
  51. package/dist/cache/memory-nonce-cache.d.ts +44 -0
  52. package/dist/cache/memory-nonce-cache.js +105 -0
  53. package/dist/cache/nonce-cache-factory.d.ts +20 -0
  54. package/dist/cache/nonce-cache-factory.js +208 -0
  55. package/dist/cache/redis-nonce-cache.d.ts +14 -0
  56. package/dist/cache/redis-nonce-cache.js +53 -0
  57. package/dist/compiler/compiler-context.d.ts +23 -0
  58. package/dist/compiler/compiler-context.js +24 -0
  59. package/dist/compiler/config/constants.d.ts +41 -0
  60. package/dist/compiler/config/constants.js +45 -0
  61. package/dist/compiler/config/index.d.ts +252 -0
  62. package/dist/compiler/config/index.js +15 -0
  63. package/dist/compiler/config/injection.d.ts +26 -0
  64. package/dist/compiler/config/injection.js +58 -0
  65. package/dist/compiler/config/schemas/experimental/index.d.ts +91 -0
  66. package/dist/compiler/config/schemas/experimental/index.js +16 -0
  67. package/dist/compiler/config/schemas/experimental/oauth.d.ts +74 -0
  68. package/dist/compiler/config/schemas/experimental/oauth.js +25 -0
  69. package/dist/compiler/config/schemas/index.d.ts +6 -0
  70. package/dist/compiler/config/schemas/index.js +17 -0
  71. package/dist/compiler/config/schemas/paths.d.ts +9 -0
  72. package/dist/compiler/config/schemas/paths.js +12 -0
  73. package/dist/compiler/config/schemas/transport/http.d.ts +82 -0
  74. package/dist/compiler/config/schemas/transport/http.js +33 -0
  75. package/dist/compiler/config/schemas/transport/stdio.d.ts +9 -0
  76. package/dist/compiler/config/schemas/transport/stdio.js +15 -0
  77. package/dist/compiler/config/schemas/webpack.d.ts +3 -0
  78. package/dist/compiler/config/schemas/webpack.js +15 -0
  79. package/dist/compiler/config/types.d.ts +1 -0
  80. package/dist/compiler/config/types.js +2 -0
  81. package/dist/compiler/config/utils.d.ts +20 -0
  82. package/dist/compiler/config/utils.js +36 -0
  83. package/dist/compiler/generate-env-code.d.ts +1 -0
  84. package/dist/compiler/generate-env-code.js +8 -0
  85. package/dist/compiler/generate-import-code.d.ts +1 -0
  86. package/dist/compiler/generate-import-code.js +24 -0
  87. package/dist/compiler/get-webpack-config/get-entries.d.ts +3 -0
  88. package/dist/compiler/get-webpack-config/get-entries.js +29 -0
  89. package/dist/compiler/get-webpack-config/get-externals.d.ts +7 -0
  90. package/dist/compiler/get-webpack-config/get-externals.js +88 -0
  91. package/dist/compiler/get-webpack-config/get-injected-variables.d.ts +8 -0
  92. package/dist/compiler/get-webpack-config/get-injected-variables.js +25 -0
  93. package/dist/compiler/get-webpack-config/index.d.ts +4 -0
  94. package/dist/compiler/get-webpack-config/index.js +101 -0
  95. package/dist/compiler/get-webpack-config/plugins.d.ts +8 -0
  96. package/dist/compiler/get-webpack-config/plugins.js +132 -0
  97. package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.d.ts +9 -0
  98. package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.js +40 -0
  99. package/dist/compiler/index.d.ts +6 -0
  100. package/dist/compiler/index.js +194 -0
  101. package/dist/compiler/on-first-build.d.ts +3 -0
  102. package/dist/compiler/on-first-build.js +58 -0
  103. package/dist/compiler/parse-xmcp-config.d.ts +9 -0
  104. package/dist/compiler/parse-xmcp-config.js +155 -0
  105. package/dist/compiler/start-http-server.d.ts +1 -0
  106. package/dist/compiler/start-http-server.js +34 -0
  107. package/dist/index.d.ts +12 -0
  108. package/dist/index.js +38 -0
  109. package/dist/index.js.LICENSE.txt +49 -0
  110. package/dist/runtime/__tests__/audit.test.d.ts +4 -0
  111. package/dist/runtime/__tests__/audit.test.js +328 -0
  112. package/dist/runtime/__tests__/identity.test.d.ts +4 -0
  113. package/dist/runtime/__tests__/identity.test.js +164 -0
  114. package/dist/runtime/__tests__/mcpi-runtime.test.d.ts +4 -0
  115. package/dist/runtime/__tests__/mcpi-runtime.test.js +372 -0
  116. package/dist/runtime/__tests__/proof.test.d.ts +4 -0
  117. package/dist/runtime/__tests__/proof.test.js +302 -0
  118. package/dist/runtime/__tests__/session.test.d.ts +4 -0
  119. package/dist/runtime/__tests__/session.test.js +254 -0
  120. package/dist/runtime/__tests__/well-known.test.d.ts +4 -0
  121. package/dist/runtime/__tests__/well-known.test.js +312 -0
  122. package/dist/runtime/adapter-express.js +2 -0
  123. package/dist/runtime/adapter-express.js.LICENSE.txt +252 -0
  124. package/dist/runtime/adapter-nextjs.js +2 -0
  125. package/dist/runtime/adapter-nextjs.js.LICENSE.txt +53 -0
  126. package/dist/runtime/adapters/express/index.d.ts +2 -0
  127. package/dist/runtime/adapters/express/index.js +48 -0
  128. package/dist/runtime/adapters/nextjs/index.d.ts +8 -0
  129. package/dist/runtime/adapters/nextjs/index.js +18 -0
  130. package/dist/runtime/audit.d.ts +93 -0
  131. package/dist/runtime/audit.js +212 -0
  132. package/dist/runtime/debug.d.ts +118 -0
  133. package/dist/runtime/debug.js +612 -0
  134. package/dist/runtime/delegation-hooks.d.ts +85 -0
  135. package/dist/runtime/delegation-hooks.js +116 -0
  136. package/dist/runtime/demo.d.ts +71 -0
  137. package/dist/runtime/demo.js +135 -0
  138. package/dist/runtime/headers.d.ts +1 -0
  139. package/dist/runtime/headers.js +9 -0
  140. package/dist/runtime/http.js +2 -0
  141. package/dist/runtime/http.js.LICENSE.txt +252 -0
  142. package/dist/runtime/identity.d.ts +105 -0
  143. package/dist/runtime/identity.js +232 -0
  144. package/dist/runtime/index.d.ts +16 -0
  145. package/dist/runtime/index.js +56 -0
  146. package/dist/runtime/mcpi-runtime.d.ts +164 -0
  147. package/dist/runtime/mcpi-runtime.js +352 -0
  148. package/dist/runtime/proof.d.ts +87 -0
  149. package/dist/runtime/proof.js +223 -0
  150. package/dist/runtime/session.d.ts +88 -0
  151. package/dist/runtime/session.js +216 -0
  152. package/dist/runtime/stdio.js +2 -0
  153. package/dist/runtime/stdio.js.LICENSE.txt +1 -0
  154. package/dist/runtime/templates/home.d.ts +2 -0
  155. package/dist/runtime/templates/home.js +50 -0
  156. package/dist/runtime/transports/http/base-streamable-http.d.ts +25 -0
  157. package/dist/runtime/transports/http/base-streamable-http.js +16 -0
  158. package/dist/runtime/transports/http/http-context.d.ts +9 -0
  159. package/dist/runtime/transports/http/http-context.js +8 -0
  160. package/dist/runtime/transports/http/index.js +55 -0
  161. package/dist/runtime/transports/http/setup-cors.d.ts +4 -0
  162. package/dist/runtime/transports/http/setup-cors.js +24 -0
  163. package/dist/runtime/transports/http/stateless-streamable-http.d.ts +39 -0
  164. package/dist/runtime/transports/http/stateless-streamable-http.js +331 -0
  165. package/dist/runtime/transports/stdio/index.d.ts +1 -0
  166. package/dist/runtime/transports/stdio/index.js +51 -0
  167. package/dist/runtime/utils/server.d.ts +42 -0
  168. package/dist/runtime/utils/server.js +39 -0
  169. package/dist/runtime/utils/tools.d.ts +8 -0
  170. package/dist/runtime/utils/tools.js +115 -0
  171. package/dist/runtime/verifier-middleware.d.ts +76 -0
  172. package/dist/runtime/verifier-middleware.js +322 -0
  173. package/dist/runtime/well-known.d.ts +151 -0
  174. package/dist/runtime/well-known.js +258 -0
  175. package/dist/storage/config.d.ts +28 -0
  176. package/dist/storage/config.js +79 -0
  177. package/dist/storage/delegation.d.ts +59 -0
  178. package/dist/storage/delegation.js +130 -0
  179. package/dist/storage/merkle-verifier.d.ts +84 -0
  180. package/dist/storage/merkle-verifier.js +261 -0
  181. package/dist/test/__tests__/nonce-cache-integration.test.d.ts +1 -0
  182. package/dist/test/__tests__/nonce-cache-integration.test.js +116 -0
  183. package/dist/test/__tests__/nonce-cache.test.d.ts +1 -0
  184. package/dist/test/__tests__/nonce-cache.test.js +122 -0
  185. package/dist/test/__tests__/runtime-integration.test.d.ts +4 -0
  186. package/dist/test/__tests__/runtime-integration.test.js +192 -0
  187. package/dist/test/__tests__/test-infrastructure.test.d.ts +4 -0
  188. package/dist/test/__tests__/test-infrastructure.test.js +178 -0
  189. package/dist/test/deterministic-keys.d.ts +31 -0
  190. package/dist/test/deterministic-keys.js +108 -0
  191. package/dist/test/examples/test-usage-example.d.ts +140 -0
  192. package/dist/test/examples/test-usage-example.js +175 -0
  193. package/dist/test/index.d.ts +11 -0
  194. package/dist/test/index.js +27 -0
  195. package/dist/test/local-verification.d.ts +28 -0
  196. package/dist/test/local-verification.js +342 -0
  197. package/dist/test/mock-identity-provider.d.ts +96 -0
  198. package/dist/test/mock-identity-provider.js +243 -0
  199. package/dist/test/runtime-integration.d.ts +63 -0
  200. package/dist/test/runtime-integration.js +140 -0
  201. package/dist/test/test-environment.d.ts +26 -0
  202. package/dist/test/test-environment.js +50 -0
  203. package/dist/types/declarations.d.ts +1 -0
  204. package/dist/types/declarations.js +6 -0
  205. package/dist/types/middleware.d.ts +2 -0
  206. package/dist/types/middleware.js +2 -0
  207. package/dist/types/tool.d.ts +80 -0
  208. package/dist/types/tool.js +2 -0
  209. package/dist/utils/cli-icons.d.ts +3 -0
  210. package/dist/utils/cli-icons.js +7 -0
  211. package/dist/utils/constants.d.ts +6 -0
  212. package/dist/utils/constants.js +13 -0
  213. package/dist/utils/context.d.ts +33 -0
  214. package/dist/utils/context.js +58 -0
  215. package/dist/utils/file-watcher.d.ts +19 -0
  216. package/dist/utils/file-watcher.js +49 -0
  217. package/dist/utils/fs-utils.d.ts +2 -0
  218. package/dist/utils/fs-utils.js +22 -0
  219. package/dist/utils/path-validation.d.ts +3 -0
  220. package/dist/utils/path-validation.js +56 -0
  221. package/dist/utils/spawn-process.d.ts +9 -0
  222. package/dist/utils/spawn-process.js +50 -0
  223. package/dist/utils/subscribable.d.ts +12 -0
  224. package/dist/utils/subscribable.js +44 -0
  225. package/package.json +91 -77
  226. package/dist/cjs/auto.js +0 -16
  227. package/dist/cjs/cli-mode.d.ts +0 -16
  228. package/dist/cjs/cli-mode.js +0 -32
  229. package/dist/cjs/crypto.d.ts +0 -16
  230. package/dist/cjs/crypto.js +0 -212
  231. package/dist/cjs/dev-helper.d.ts +0 -3
  232. package/dist/cjs/dev-helper.js +0 -46
  233. package/dist/cjs/encrypted-storage.d.ts +0 -11
  234. package/dist/cjs/encrypted-storage.js +0 -73
  235. package/dist/cjs/index.d.ts +0 -56
  236. package/dist/cjs/index.js +0 -727
  237. package/dist/cjs/logger.d.ts +0 -32
  238. package/dist/cjs/logger.js +0 -85
  239. package/dist/cjs/nextjs.d.ts +0 -10
  240. package/dist/cjs/nextjs.js +0 -83
  241. package/dist/cjs/platform-info.d.ts +0 -36
  242. package/dist/cjs/platform-info.js +0 -274
  243. package/dist/cjs/polling.d.ts +0 -13
  244. package/dist/cjs/polling.js +0 -52
  245. package/dist/cjs/registry/index.d.ts +0 -12
  246. package/dist/cjs/registry/index.js +0 -56
  247. package/dist/cjs/registry/knowthat.d.ts +0 -17
  248. package/dist/cjs/registry/knowthat.js +0 -173
  249. package/dist/cjs/rotation.d.ts +0 -35
  250. package/dist/cjs/rotation.js +0 -102
  251. package/dist/cjs/storage.d.ts +0 -41
  252. package/dist/cjs/storage.js +0 -163
  253. package/dist/cjs/transport.d.ts +0 -35
  254. package/dist/cjs/transport.js +0 -300
  255. package/dist/cjs/types.d.ts +0 -206
  256. package/dist/cjs/vercel-adapter.d.ts +0 -8
  257. package/dist/cjs/vercel-adapter.js +0 -67
  258. package/dist/esm/auto.d.ts +0 -13
  259. package/dist/esm/auto.d.ts.map +0 -1
  260. package/dist/esm/auto.js +0 -30
  261. package/dist/esm/auto.js.map +0 -1
  262. package/dist/esm/cli-mode.d.ts +0 -52
  263. package/dist/esm/cli-mode.d.ts.map +0 -1
  264. package/dist/esm/cli-mode.js +0 -59
  265. package/dist/esm/cli-mode.js.map +0 -1
  266. package/dist/esm/crypto.d.ts +0 -51
  267. package/dist/esm/crypto.d.ts.map +0 -1
  268. package/dist/esm/crypto.js +0 -230
  269. package/dist/esm/crypto.js.map +0 -1
  270. package/dist/esm/dev-helper.d.ts +0 -15
  271. package/dist/esm/dev-helper.d.ts.map +0 -1
  272. package/dist/esm/dev-helper.js +0 -63
  273. package/dist/esm/dev-helper.js.map +0 -1
  274. package/dist/esm/encrypted-storage.d.ts +0 -19
  275. package/dist/esm/encrypted-storage.d.ts.map +0 -1
  276. package/dist/esm/encrypted-storage.js +0 -48
  277. package/dist/esm/encrypted-storage.js.map +0 -1
  278. package/dist/esm/index.d.ts +0 -129
  279. package/dist/esm/index.d.ts.map +0 -1
  280. package/dist/esm/index.js +0 -853
  281. package/dist/esm/index.js.map +0 -1
  282. package/dist/esm/logger.d.ts +0 -46
  283. package/dist/esm/logger.d.ts.map +0 -1
  284. package/dist/esm/logger.js +0 -100
  285. package/dist/esm/logger.js.map +0 -1
  286. package/dist/esm/nextjs.d.ts +0 -22
  287. package/dist/esm/nextjs.d.ts.map +0 -1
  288. package/dist/esm/nextjs.js +0 -83
  289. package/dist/esm/nextjs.js.map +0 -1
  290. package/dist/esm/package.json +0 -1
  291. package/dist/esm/platform-info.d.ts +0 -74
  292. package/dist/esm/platform-info.d.ts.map +0 -1
  293. package/dist/esm/platform-info.js +0 -293
  294. package/dist/esm/platform-info.js.map +0 -1
  295. package/dist/esm/polling.d.ts +0 -29
  296. package/dist/esm/polling.d.ts.map +0 -1
  297. package/dist/esm/polling.js +0 -76
  298. package/dist/esm/polling.js.map +0 -1
  299. package/dist/esm/registry/index.d.ts +0 -43
  300. package/dist/esm/registry/index.d.ts.map +0 -1
  301. package/dist/esm/registry/index.js +0 -89
  302. package/dist/esm/registry/index.js.map +0 -1
  303. package/dist/esm/registry/knowthat.d.ts +0 -44
  304. package/dist/esm/registry/knowthat.d.ts.map +0 -1
  305. package/dist/esm/registry/knowthat.js +0 -220
  306. package/dist/esm/registry/knowthat.js.map +0 -1
  307. package/dist/esm/rotation.d.ts +0 -57
  308. package/dist/esm/rotation.d.ts.map +0 -1
  309. package/dist/esm/rotation.js +0 -133
  310. package/dist/esm/rotation.js.map +0 -1
  311. package/dist/esm/storage.d.ts +0 -65
  312. package/dist/esm/storage.d.ts.map +0 -1
  313. package/dist/esm/storage.js +0 -160
  314. package/dist/esm/storage.js.map +0 -1
  315. package/dist/esm/transport.d.ts +0 -52
  316. package/dist/esm/transport.d.ts.map +0 -1
  317. package/dist/esm/transport.js +0 -340
  318. package/dist/esm/transport.js.map +0 -1
  319. package/dist/esm/types.d.ts +0 -293
  320. package/dist/esm/types.d.ts.map +0 -1
  321. package/dist/esm/types.js +0 -5
  322. package/dist/esm/types.js.map +0 -1
  323. package/dist/esm/vercel-adapter.d.ts +0 -26
  324. package/dist/esm/vercel-adapter.d.ts.map +0 -1
  325. package/dist/esm/vercel-adapter.js +0 -80
  326. package/dist/esm/vercel-adapter.js.map +0 -1
  327. /package/dist/{cjs → auth/oauth}/types.js +0 -0
  328. /package/dist/{cjs/auto.d.ts → runtime/transports/http/index.d.ts} +0 -0
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Runtime integration for test infrastructure
3
+ *
4
+ * This module provides integration points between the test infrastructure
5
+ * and the XMCP-I runtime to ensure test mode works seamlessly.
6
+ */
7
+ /**
8
+ * Test mode runtime configuration
9
+ */
10
+ export interface TestRuntimeConfig {
11
+ skipKTACalls: boolean;
12
+ useMockIdentities: boolean;
13
+ deterministicKeys: boolean;
14
+ mockKTAResponses: boolean;
15
+ }
16
+ /**
17
+ * Get test runtime configuration
18
+ */
19
+ export declare function getTestRuntimeConfig(): TestRuntimeConfig | null;
20
+ /**
21
+ * Intercept KTA calls in test mode
22
+ */
23
+ export declare function interceptKTACall<T>(operation: string, originalCall: () => Promise<T>, mockResponse?: () => Promise<T>): Promise<T>;
24
+ /**
25
+ * Get test identity for runtime use
26
+ */
27
+ export declare function getTestIdentityForRuntime(identityKey?: string): {
28
+ did: string;
29
+ keyId: string;
30
+ privateKey: string;
31
+ publicKey: string;
32
+ createdAt: string;
33
+ lastRotated: string;
34
+ };
35
+ /**
36
+ * Create test session context
37
+ */
38
+ export declare function createTestSessionContext(options?: {
39
+ sessionId?: string;
40
+ audience?: string;
41
+ nonce?: string;
42
+ timestamp?: number;
43
+ }): {
44
+ sessionId: string;
45
+ audience: string;
46
+ nonce: string;
47
+ timestamp: number;
48
+ createdAt: number;
49
+ lastActivity: number;
50
+ ttlMinutes: number;
51
+ };
52
+ /**
53
+ * Validate test environment setup
54
+ */
55
+ export declare function validateTestEnvironment(): {
56
+ valid: boolean;
57
+ errors: string[];
58
+ warnings: string[];
59
+ };
60
+ /**
61
+ * Test mode guard decorator
62
+ */
63
+ export declare function testModeOnly<T extends (...args: any[]) => any>(fn: T): T;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ /**
3
+ * Runtime integration for test infrastructure
4
+ *
5
+ * This module provides integration points between the test infrastructure
6
+ * and the XMCP-I runtime to ensure test mode works seamlessly.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getTestRuntimeConfig = getTestRuntimeConfig;
10
+ exports.interceptKTACall = interceptKTACall;
11
+ exports.getTestIdentityForRuntime = getTestIdentityForRuntime;
12
+ exports.createTestSessionContext = createTestSessionContext;
13
+ exports.validateTestEnvironment = validateTestEnvironment;
14
+ exports.testModeOnly = testModeOnly;
15
+ const test_environment_1 = require("./test-environment");
16
+ const mock_identity_provider_1 = require("./mock-identity-provider");
17
+ const test_1 = require("@kya-os/contracts/test");
18
+ /**
19
+ * Get test runtime configuration
20
+ */
21
+ function getTestRuntimeConfig() {
22
+ if (!(0, test_environment_1.isTestMode)()) {
23
+ return null;
24
+ }
25
+ return {
26
+ skipKTACalls: (0, test_environment_1.shouldSkipKTACalls)(),
27
+ useMockIdentities: true,
28
+ deterministicKeys: true,
29
+ mockKTAResponses: true,
30
+ };
31
+ }
32
+ /**
33
+ * Intercept KTA calls in test mode
34
+ */
35
+ async function interceptKTACall(operation, originalCall, mockResponse) {
36
+ const testConfig = getTestRuntimeConfig();
37
+ if (!testConfig || !testConfig.skipKTACalls) {
38
+ return originalCall();
39
+ }
40
+ if (mockResponse) {
41
+ return mockResponse();
42
+ }
43
+ // Default mock responses based on operation
44
+ switch (operation) {
45
+ case "register":
46
+ return {
47
+ success: true,
48
+ agentURL: "https://test-kta.example.com/agents/test-agent",
49
+ agentId: "test-agent",
50
+ agentSlug: "test-agent",
51
+ verificationEndpoint: "https://test-kta.example.com/verify/test-agent",
52
+ conformanceCapabilities: ["handshake", "signing", "verification"],
53
+ mirrorStatus: "success",
54
+ };
55
+ case "checkDelegation":
56
+ return {
57
+ status: "active",
58
+ valid: true,
59
+ };
60
+ case "claim":
61
+ return {
62
+ success: true,
63
+ claimed: true,
64
+ agentURL: "https://test-kta.example.com/agents/test-agent",
65
+ };
66
+ default:
67
+ throw new Error(`${test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION}: Unknown KTA operation: ${operation}`);
68
+ }
69
+ }
70
+ /**
71
+ * Get test identity for runtime use
72
+ */
73
+ function getTestIdentityForRuntime(identityKey = "agent1") {
74
+ if (!(0, test_environment_1.isTestMode)()) {
75
+ throw new Error(`${test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION}: Test identity can only be used in test mode`);
76
+ }
77
+ const mockProvider = (0, mock_identity_provider_1.getMockIdentityProvider)();
78
+ const identity = mockProvider.getIdentity(identityKey);
79
+ if (!identity) {
80
+ throw new Error(`${test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION}: Test identity '${identityKey}' not found`);
81
+ }
82
+ return identity;
83
+ }
84
+ /**
85
+ * Create test session context
86
+ */
87
+ function createTestSessionContext(options = {}) {
88
+ if (!(0, test_environment_1.isTestMode)()) {
89
+ throw new Error(`${test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION}: Test session context can only be created in test mode`);
90
+ }
91
+ const now = Math.floor(Date.now() / 1000);
92
+ return {
93
+ sessionId: options.sessionId || "sess_test_default",
94
+ audience: options.audience || "test.example.com",
95
+ nonce: options.nonce || "test_nonce_123",
96
+ timestamp: options.timestamp || now,
97
+ createdAt: now,
98
+ lastActivity: now,
99
+ ttlMinutes: 30,
100
+ };
101
+ }
102
+ /**
103
+ * Validate test environment setup
104
+ */
105
+ function validateTestEnvironment() {
106
+ const errors = [];
107
+ const warnings = [];
108
+ if (!(0, test_environment_1.isTestMode)()) {
109
+ errors.push("XMCP_ENV is not set to 'test'");
110
+ }
111
+ if (!(0, test_environment_1.shouldSkipKTACalls)()) {
112
+ warnings.push("KTA calls are not being skipped in test mode");
113
+ }
114
+ try {
115
+ const mockProvider = (0, mock_identity_provider_1.getMockIdentityProvider)();
116
+ const identities = mockProvider.getAllIdentities();
117
+ if (Object.keys(identities).length === 0) {
118
+ warnings.push("No test identities are configured");
119
+ }
120
+ }
121
+ catch (error) {
122
+ errors.push(`Failed to access mock identity provider: ${error instanceof Error ? error.message : "Unknown error"}`);
123
+ }
124
+ return {
125
+ valid: errors.length === 0,
126
+ errors,
127
+ warnings,
128
+ };
129
+ }
130
+ /**
131
+ * Test mode guard decorator
132
+ */
133
+ function testModeOnly(fn) {
134
+ return ((...args) => {
135
+ if (!(0, test_environment_1.isTestMode)()) {
136
+ throw new Error(`${test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION}: Function can only be called in test mode`);
137
+ }
138
+ return fn(...args);
139
+ });
140
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Test environment detection and configuration
3
+ */
4
+ /**
5
+ * Check if we're running in test mode
6
+ */
7
+ export declare function isTestMode(): boolean;
8
+ /**
9
+ * Get the current test seed for deterministic key generation
10
+ */
11
+ export declare function getCurrentTestSeed(testName?: string): string;
12
+ /**
13
+ * Ensure we're in test mode, throw if not
14
+ */
15
+ export declare function ensureTestMode(): void;
16
+ /**
17
+ * Configure test environment
18
+ */
19
+ export declare function configureTestEnvironment(options?: {
20
+ seed?: string;
21
+ skipKTACalls?: boolean;
22
+ }): void;
23
+ /**
24
+ * Check if KTA calls should be skipped
25
+ */
26
+ export declare function shouldSkipKTACalls(): boolean;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ /**
3
+ * Test environment detection and configuration
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isTestMode = isTestMode;
7
+ exports.getCurrentTestSeed = getCurrentTestSeed;
8
+ exports.ensureTestMode = ensureTestMode;
9
+ exports.configureTestEnvironment = configureTestEnvironment;
10
+ exports.shouldSkipKTACalls = shouldSkipKTACalls;
11
+ const test_1 = require("@kya-os/contracts/test");
12
+ /**
13
+ * Check if we're running in test mode
14
+ */
15
+ function isTestMode() {
16
+ return (0, test_1.isTestEnvironment)();
17
+ }
18
+ /**
19
+ * Get the current test seed for deterministic key generation
20
+ */
21
+ function getCurrentTestSeed(testName) {
22
+ return (0, test_1.getTestSeed)(testName);
23
+ }
24
+ /**
25
+ * Ensure we're in test mode, throw if not
26
+ */
27
+ function ensureTestMode() {
28
+ if (!isTestMode()) {
29
+ throw new Error(`${test_1.TEST_ERROR_CODES.INVALID_TEST_CONFIGURATION}: Test utilities can only be used when XMCP_ENV=test`);
30
+ }
31
+ }
32
+ /**
33
+ * Configure test environment
34
+ */
35
+ function configureTestEnvironment(options = {}) {
36
+ if (options.seed) {
37
+ process.env.XMCP_TEST_SEED = options.seed;
38
+ }
39
+ if (options.skipKTACalls !== false) {
40
+ process.env.XMCP_SKIP_KTA_CALLS = "true";
41
+ }
42
+ // Ensure we're in test mode
43
+ process.env.XMCP_ENV = "test";
44
+ }
45
+ /**
46
+ * Check if KTA calls should be skipped
47
+ */
48
+ function shouldSkipKTACalls() {
49
+ return isTestMode() || process.env.XMCP_SKIP_KTA_CALLS === "true";
50
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // TODO: Fix module declaration
4
+ // declare module "xmcp/headers" {
5
+ // export const headers: typeof import("../runtime/headers").headers;
6
+ // }
@@ -0,0 +1,2 @@
1
+ import { type RequestHandler } from "express";
2
+ export type Middleware = RequestHandler | RequestHandler[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,80 @@
1
+ import { z } from "zod";
2
+ export interface ToolAnnotations {
3
+ /** Human-readable title for the tool */
4
+ title?: string;
5
+ /** If true, the tool does not modify its environment */
6
+ readOnlyHint?: boolean;
7
+ /** If true, the tool may perform destructive updates */
8
+ destructiveHint?: boolean;
9
+ /** If true, repeated calls with same args have no additional effect */
10
+ idempotentHint?: boolean;
11
+ /** If true, tool interacts with external entities */
12
+ openWorldHint?: boolean;
13
+ [key: string]: any;
14
+ }
15
+ export interface ToolMetadata {
16
+ /** Unique identifier for the tool */
17
+ name: string;
18
+ /** Human-readable description */
19
+ description: string;
20
+ /** Optional hints about tool behavior */
21
+ annotations?: ToolAnnotations;
22
+ }
23
+ export type ToolSchema = Record<string, z.ZodType<unknown, z.ZodTypeDef, unknown>>;
24
+ /**
25
+ * Extra arguments passed to MCP tool functions.
26
+ */
27
+ export interface ToolExtraArguments {
28
+ /** An abort signal used to communicate if the request was cancelled from the sender's side */
29
+ signal: AbortSignal;
30
+ /** Information about a validated access token, provided to request handlers */
31
+ authInfo?: {
32
+ /** The access token */
33
+ token: string;
34
+ /** The client ID associated with this token */
35
+ clientId: string;
36
+ /** Scopes associated with this token */
37
+ scopes: string[];
38
+ /** When the token expires (in seconds since epoch) */
39
+ expiresAt?: number;
40
+ /** The RFC 8707 resource server identifier for which this token is valid */
41
+ resource?: URL;
42
+ /** Additional data associated with the token */
43
+ extra?: Record<string, unknown>;
44
+ };
45
+ /** The session ID from the transport, if available */
46
+ sessionId?: string;
47
+ /** Metadata from the original request */
48
+ _meta?: {
49
+ /** Progress token for tracking long-running operations */
50
+ progressToken?: string | number;
51
+ };
52
+ /** The JSON-RPC ID of the request being handled */
53
+ requestId: string | number;
54
+ /** The original HTTP request information */
55
+ requestInfo?: {
56
+ /** The headers of the request */
57
+ headers: Record<string, string | string[] | undefined>;
58
+ };
59
+ /** Sends a notification that relates to the current request being handled */
60
+ sendNotification: (notification: any) => Promise<void>;
61
+ /** Sends a request that relates to the current request being handled */
62
+ sendRequest: <U extends z.ZodType<object>>(request: any, resultSchema: U, options?: {
63
+ /** Progress notification callback */
64
+ onprogress?: (progress: any) => void;
65
+ /** Abort signal for cancelling the request */
66
+ signal?: AbortSignal;
67
+ /** Request timeout in milliseconds */
68
+ timeout?: number;
69
+ /** Whether receiving progress notifications resets the timeout */
70
+ resetTimeoutOnProgress?: boolean;
71
+ /** Maximum total time to wait for a response */
72
+ maxTotalTimeout?: number;
73
+ /** Additional transport-specific options */
74
+ [key: string]: unknown;
75
+ }) => Promise<z.infer<U>>;
76
+ }
77
+ export type InferSchema<T extends ToolSchema> = {
78
+ [K in keyof T]: z.infer<T[K]>;
79
+ };
80
+ export type ToolHandler = (args: Record<string, unknown>, extra?: ToolExtraArguments) => Promise<unknown> | unknown;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export declare const greenCheck = "\u2714";
2
+ export declare const xmcpLogo = " XMCP ";
3
+ export declare const yellowArrow = "\u2192";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.yellowArrow = exports.xmcpLogo = exports.greenCheck = void 0;
4
+ // Simplified - remove chalk styling for now
5
+ exports.greenCheck = "✔";
6
+ exports.xmcpLogo = " XMCP ";
7
+ exports.yellowArrow = "→";
@@ -0,0 +1,6 @@
1
+ export declare const runtimeFolder = ".xmcp";
2
+ export declare const runtimeFolderPath: string;
3
+ export declare const rootFolder: string;
4
+ export declare const processFolder: string;
5
+ export declare const distOutputPath: string;
6
+ export declare const adapterOutputPath: string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.adapterOutputPath = exports.distOutputPath = exports.processFolder = exports.rootFolder = exports.runtimeFolderPath = exports.runtimeFolder = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ exports.runtimeFolder = ".xmcp";
9
+ exports.runtimeFolderPath = path_1.default.join(process.cwd(), exports.runtimeFolder);
10
+ exports.rootFolder = path_1.default.join(process.cwd());
11
+ exports.processFolder = process.cwd();
12
+ exports.distOutputPath = path_1.default.join(exports.processFolder, "dist");
13
+ exports.adapterOutputPath = path_1.default.join(exports.runtimeFolderPath, "adapter");
@@ -0,0 +1,33 @@
1
+ type DefaultContext = Object;
2
+ type GetContext<T extends DefaultContext> = () => T;
3
+ type SetContext<T extends DefaultContext> = (data: Partial<T>) => void;
4
+ export interface Context<T extends DefaultContext> {
5
+ /** Run a callback with a specific context. */
6
+ provider: (initialValue: T, callback: () => void) => void;
7
+ /** Get the context. */
8
+ getContext: GetContext<T>;
9
+ /** Partially update the context. */
10
+ setContext: SetContext<T>;
11
+ }
12
+ interface CreateContextOptions {
13
+ name: string;
14
+ }
15
+ /**
16
+ * Create context allows you to create scoped variables for fucntions.
17
+ * Similar to React's context API.
18
+ * Usage:
19
+ * ```ts
20
+ * interface MyContext {
21
+ * value: string;
22
+ * }
23
+ *
24
+ * const context = createContext({ name: "my-context" });
25
+ *
26
+ * context.provider({
27
+ * value: "hello",
28
+ * }, () => {
29
+ * // Do something with the context
30
+ * })```
31
+ */
32
+ export declare function createContext<T extends Object>({ name, }: CreateContextOptions): Context<T>;
33
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createContext = createContext;
4
+ const async_hooks_1 = require("async_hooks");
5
+ const setGlobalContext = (key, context) => {
6
+ globalThis[key] = context;
7
+ };
8
+ const getGlobalContext = (key) => {
9
+ return globalThis[key];
10
+ };
11
+ /**
12
+ * Create context allows you to create scoped variables for fucntions.
13
+ * Similar to React's context API.
14
+ * Usage:
15
+ * ```ts
16
+ * interface MyContext {
17
+ * value: string;
18
+ * }
19
+ *
20
+ * const context = createContext({ name: "my-context" });
21
+ *
22
+ * context.provider({
23
+ * value: "hello",
24
+ * }, () => {
25
+ * // Do something with the context
26
+ * })```
27
+ */
28
+ function createContext({ name, }) {
29
+ const storageKey = Symbol.for(`xmcp-context-${name}`);
30
+ if (getGlobalContext(storageKey)) {
31
+ return getGlobalContext(storageKey);
32
+ }
33
+ const context = new async_hooks_1.AsyncLocalStorage();
34
+ const getContext = () => {
35
+ const store = context.getStore();
36
+ if (!store) {
37
+ throw new Error(`getContext() can only be used within the ${name} context.`);
38
+ }
39
+ return store;
40
+ };
41
+ const setContext = (data) => {
42
+ const store = context.getStore();
43
+ if (!store) {
44
+ throw new Error(`setContext() can only be used within the ${name} context.`);
45
+ }
46
+ Object.assign(store, data);
47
+ };
48
+ const provider = (initialValue, callback) => {
49
+ return context.run(initialValue, callback);
50
+ };
51
+ const result = {
52
+ provider,
53
+ getContext,
54
+ setContext,
55
+ };
56
+ setGlobalContext(storageKey, result);
57
+ return result;
58
+ }
@@ -0,0 +1,19 @@
1
+ import chokidar from "chokidar";
2
+ import { Subscribable } from "./subscribable";
3
+ interface WatcherOptions {
4
+ onAdd?: (path: string) => void;
5
+ onUnlink?: (path: string) => void;
6
+ onChange?: (path: string) => void;
7
+ }
8
+ export declare class Watcher {
9
+ private watchers;
10
+ isReady: boolean;
11
+ globalOptions: chokidar.WatchOptions;
12
+ onReadySubscribable: Subscribable;
13
+ constructor(options?: chokidar.WatchOptions);
14
+ watch(path: string, options: WatcherOptions, chokidarOptions?: chokidar.WatchOptions): void;
15
+ onReady(callback: () => void): void;
16
+ private checkReady;
17
+ close(): Promise<void>;
18
+ }
19
+ export {};
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Watcher = void 0;
7
+ const chokidar_1 = __importDefault(require("chokidar"));
8
+ const subscribable_1 = require("./subscribable");
9
+ class Watcher {
10
+ watchers = [];
11
+ isReady = false;
12
+ globalOptions = {};
13
+ onReadySubscribable = (0, subscribable_1.subscribable)();
14
+ constructor(options = {}) {
15
+ this.globalOptions = options;
16
+ }
17
+ watch(path, options, chokidarOptions = {}) {
18
+ const instance = chokidar_1.default.watch(path, {
19
+ ...this.globalOptions,
20
+ ...chokidarOptions,
21
+ });
22
+ options.onAdd && instance.on("add", options.onAdd);
23
+ options.onUnlink && instance.on("unlink", options.onUnlink);
24
+ options.onChange && instance.on("change", options.onChange);
25
+ const watcherInstance = {
26
+ isReady: false,
27
+ watcher: instance,
28
+ };
29
+ this.watchers.push(watcherInstance);
30
+ instance.on("ready", () => {
31
+ watcherInstance.isReady = true;
32
+ this.checkReady();
33
+ });
34
+ }
35
+ onReady(callback) {
36
+ this.onReadySubscribable.addCallback(callback);
37
+ }
38
+ checkReady() {
39
+ if (this.watchers.every((watcher) => watcher.isReady)) {
40
+ this.onReadySubscribable.runCallbacks();
41
+ this.onReadySubscribable.clearCallbacks();
42
+ }
43
+ }
44
+ async close() {
45
+ await Promise.all(this.watchers.map((watcherInstance) => watcherInstance.watcher.close()));
46
+ this.watchers = [];
47
+ }
48
+ }
49
+ exports.Watcher = Watcher;
@@ -0,0 +1,2 @@
1
+ export declare function createFolder(folderPath: string): void;
2
+ export declare function parseJson<T = any>(json: string): readonly [T, null] | readonly [null, Error];
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createFolder = createFolder;
7
+ exports.parseJson = parseJson;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const json5_1 = __importDefault(require("json5"));
10
+ function createFolder(folderPath) {
11
+ if (!fs_1.default.existsSync(folderPath)) {
12
+ fs_1.default.mkdirSync(folderPath, { recursive: true });
13
+ }
14
+ }
15
+ function parseJson(json) {
16
+ try {
17
+ return [json5_1.default.parse(json), null];
18
+ }
19
+ catch (e) {
20
+ return [null, e];
21
+ }
22
+ }
@@ -0,0 +1,3 @@
1
+ type PathType = "tools";
2
+ export declare function isValidPath(pathStr: string | undefined, type: PathType): string | undefined;
3
+ export {};
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isValidPath = isValidPath;
7
+ const constants_1 = require("./constants");
8
+ // Simplified - remove chalk styling for now
9
+ const chalk = {
10
+ red: {
11
+ bold: (text) => text,
12
+ },
13
+ yellow: (text) => text,
14
+ };
15
+ const fs_1 = __importDefault(require("fs"));
16
+ const path_1 = __importDefault(require("path"));
17
+ function isValidPath(pathStr, type) {
18
+ function isNonEmptyString(str) {
19
+ return typeof str === "string" && str.length > 0;
20
+ }
21
+ function isGlob(str) {
22
+ return /[*?\[\]{}]/.test(str);
23
+ }
24
+ function normalizePath(p) {
25
+ // normalize to posix (forward slashes)
26
+ return p.split(/\\|\//).join("/");
27
+ }
28
+ function resolveAndCheckExists(p) {
29
+ const normalized = normalizePath(p);
30
+ const absPath = path_1.default.resolve(constants_1.rootFolder, normalized);
31
+ if (!fs_1.default.existsSync(absPath)) {
32
+ exitError(`The path set in xmcp config for ${type} does not exist: ${absPath}`);
33
+ }
34
+ return normalized; // still return the normalized path cause we're formatting to glob later
35
+ }
36
+ if (pathStr === undefined) {
37
+ return undefined;
38
+ }
39
+ // reject empty string
40
+ if (pathStr === "") {
41
+ exitError(`${type} path cannot be an empty string`);
42
+ }
43
+ if (isNonEmptyString(pathStr)) {
44
+ if (isGlob(pathStr)) {
45
+ exitError(`If you are using a glob pattern, please use a string for the ${type} path`);
46
+ }
47
+ return resolveAndCheckExists(pathStr);
48
+ }
49
+ exitError(`${type} path must be a non-empty string`);
50
+ }
51
+ function exitError(message) {
52
+ console.log("");
53
+ console.log(chalk.red.bold(message));
54
+ console.log("");
55
+ process.exit(1);
56
+ }