@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 @@
1
+ /** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
@@ -0,0 +1,2 @@
1
+ declare const homeTemplate: (endpoint: string) => string;
2
+ export default homeTemplate;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const homeTemplate = (endpoint) => `
4
+ <!DOCTYPE html>
5
+ <html>
6
+ <head>
7
+ <title>xmcp_ MCP Server</title>
8
+ <link href="https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;700&display=swap" rel="stylesheet">
9
+ <style>
10
+ body {
11
+ background: #000;
12
+ font-family: 'Geist Mono', monospace;
13
+ color: #fff;
14
+ margin: 0;
15
+ padding: 0;
16
+ min-height: 100vh;
17
+ display: flex;
18
+ flex-direction: column;
19
+ justify-content: center;
20
+ align-items: center;
21
+ }
22
+ h1 {
23
+ color: #fff;
24
+ margin-bottom: 16px;
25
+ font-size: 2.5rem;
26
+ font-weight: 400;
27
+ letter-spacing: 1px;
28
+ }
29
+ .endpoint-btn {
30
+ display: inline-block;
31
+ background: #FF4800;
32
+ color: #fff;
33
+ font-family: 'Geist Mono', monospace;
34
+ font-size: 1.1rem;
35
+ font-weight: 400;
36
+ border: none;
37
+ padding: 6px 12px;
38
+ margin-top: 32px;
39
+ text-decoration: none;
40
+ cursor: pointer;
41
+ }
42
+ </style>
43
+ </head>
44
+ <body>
45
+ <h1>xmcp_</h1>
46
+ <a class="endpoint-btn" href="${endpoint}">ENDPOINT -&gt;</a>
47
+ </body>
48
+ </html>
49
+ `;
50
+ exports.default = homeTemplate;
@@ -0,0 +1,25 @@
1
+ import { IncomingMessage, ServerResponse } from "http";
2
+ export interface HttpTransportOptions {
3
+ port?: number;
4
+ host?: string;
5
+ endpoint?: string;
6
+ bodySizeLimit?: string;
7
+ debug?: boolean;
8
+ }
9
+ export interface JsonRpcMessage {
10
+ jsonrpc: string;
11
+ method?: string;
12
+ params?: any;
13
+ id?: string | number | null;
14
+ result?: any;
15
+ error?: any;
16
+ }
17
+ export declare abstract class BaseHttpServerTransport {
18
+ onmessage?: (message: JsonRpcMessage) => void;
19
+ onerror?: (error: Error) => void;
20
+ onclose?: () => void;
21
+ abstract start(): Promise<void>;
22
+ abstract close(): Promise<void>;
23
+ abstract send(message: JsonRpcMessage): Promise<void>;
24
+ abstract handleRequest(req: IncomingMessage, res: ServerResponse, parsedBody?: unknown): Promise<void>;
25
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseHttpServerTransport = void 0;
4
+ // shared between stateless and stateful transports
5
+ // just to paint the same interface
6
+ class BaseHttpServerTransport {
7
+ // If we ever want to have more control over the transport, we can add onclose, onerror, onmessage here
8
+ // or interceptors for requests and responses
9
+ // e.g. to add a custom header to the response or a middleware layer!
10
+ // to do add the logging methods like log and error
11
+ // MCP SDK transport interface
12
+ onmessage;
13
+ onerror;
14
+ onclose;
15
+ }
16
+ exports.BaseHttpServerTransport = BaseHttpServerTransport;
@@ -0,0 +1,9 @@
1
+ import { IncomingHttpHeaders } from "http";
2
+ export interface HttpContext {
3
+ id: string;
4
+ headers: IncomingHttpHeaders;
5
+ }
6
+ export declare const httpContext: import("../../../utils/context").Context<HttpContext>;
7
+ export declare const setHttpContext: (data: Partial<HttpContext>) => void;
8
+ export declare const getHttpContext: () => HttpContext;
9
+ export declare const httpContextProvider: (initialValue: HttpContext, callback: () => void) => void;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.httpContextProvider = exports.getHttpContext = exports.setHttpContext = exports.httpContext = void 0;
4
+ const context_1 = require("../../../utils/context");
5
+ exports.httpContext = (0, context_1.createContext)({ name: "http-context" });
6
+ exports.setHttpContext = exports.httpContext.setContext;
7
+ exports.getHttpContext = exports.httpContext.getContext;
8
+ exports.httpContextProvider = exports.httpContext.provider;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const server_1 = require("../../utils/server");
4
+ const stateless_streamable_http_1 = require("./stateless-streamable-http");
5
+ // @ts-expect-error: injected by compiler
6
+ const httpConfig = HTTP_CONFIG;
7
+ // @ts-expect-error: injected by compiler
8
+ const corsConfig = HTTP_CORS_CONFIG;
9
+ // middleware
10
+ // @ts-expect-error: injected by compiler
11
+ const middleware = INJECTED_MIDDLEWARE;
12
+ // oauth config
13
+ // @ts-expect-error: injected by compiler
14
+ const oauthConfig = OAUTH_CONFIG;
15
+ async function main() {
16
+ const options = {
17
+ port: httpConfig?.port,
18
+ host: httpConfig?.host,
19
+ debug: httpConfig?.debug,
20
+ bodySizeLimit: httpConfig?.bodySizeLimit?.toString(),
21
+ endpoint: httpConfig?.endpoint,
22
+ };
23
+ const corsOptions = {
24
+ origin: corsConfig.origin,
25
+ methods: corsConfig.methods,
26
+ allowedHeaders: corsConfig.allowedHeaders,
27
+ exposedHeaders: corsConfig.exposedHeaders,
28
+ credentials: corsConfig.credentials,
29
+ maxAge: corsConfig.maxAge,
30
+ };
31
+ let middlewareFn = undefined;
32
+ if (middleware) {
33
+ const middlewareModule = await middleware();
34
+ if (middlewareModule && middlewareModule.default) {
35
+ const defaultExport = middlewareModule.default;
36
+ if (Array.isArray(defaultExport)) {
37
+ // Handle array of middlewares
38
+ middlewareFn = defaultExport.filter((mw) => typeof mw === "function");
39
+ }
40
+ else if (typeof defaultExport === "function") {
41
+ // Handle single middleware
42
+ middlewareFn = [defaultExport];
43
+ }
44
+ else {
45
+ throw new Error("Middleware module does not export a valid RequestHandler or array of RequestHandlers");
46
+ }
47
+ }
48
+ else {
49
+ throw new Error("Middleware module does not export a default middleware");
50
+ }
51
+ }
52
+ const transport = new stateless_streamable_http_1.StatelessStreamableHTTPTransport(server_1.createServer, options, corsOptions, oauthConfig, middlewareFn);
53
+ transport.start();
54
+ }
55
+ main();
@@ -0,0 +1,4 @@
1
+ import { Response } from "express";
2
+ import { CorsConfig } from "../../../compiler/config/schemas";
3
+ export type { CorsConfig } from "../../../compiler/config/schemas";
4
+ export declare function setResponseCorsHeaders(cors: CorsConfig, res: Response): void;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setResponseCorsHeaders = setResponseCorsHeaders;
4
+ function setResponseCorsHeaders(cors, res) {
5
+ // set cors headers dynamically
6
+ if (cors.origin !== undefined)
7
+ res.setHeader("Access-Control-Allow-Origin", Array.isArray(cors.origin) ? cors.origin.join(",") : String(cors.origin));
8
+ if (cors.methods !== undefined)
9
+ res.setHeader("Access-Control-Allow-Methods", Array.isArray(cors.methods)
10
+ ? cors.methods.join(",")
11
+ : String(cors.methods));
12
+ if (cors.allowedHeaders !== undefined)
13
+ res.setHeader("Access-Control-Allow-Headers", Array.isArray(cors.allowedHeaders)
14
+ ? cors.allowedHeaders.join(",")
15
+ : String(cors.allowedHeaders));
16
+ if (cors.exposedHeaders !== undefined)
17
+ res.setHeader("Access-Control-Expose-Headers", Array.isArray(cors.exposedHeaders)
18
+ ? cors.exposedHeaders.join(",")
19
+ : String(cors.exposedHeaders));
20
+ if (typeof cors.credentials === "boolean")
21
+ res.setHeader("Access-Control-Allow-Credentials", String(cors.credentials));
22
+ if (typeof cors.maxAge === "number")
23
+ res.setHeader("Access-Control-Max-Age", String(cors.maxAge));
24
+ }
@@ -0,0 +1,39 @@
1
+ import { Server as McpServer } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { RequestHandler } from "express";
3
+ import { IncomingMessage, ServerResponse } from "http";
4
+ import { BaseHttpServerTransport, JsonRpcMessage, HttpTransportOptions } from "./base-streamable-http";
5
+ import { type OAuthProxyConfig } from "../../../auth/oauth";
6
+ import { CorsConfig } from "../../../compiler/config/schemas";
7
+ export declare class StatelessHttpServerTransport extends BaseHttpServerTransport {
8
+ debug: boolean;
9
+ bodySizeLimit: string;
10
+ private _started;
11
+ private _singleResponseCollectors;
12
+ private _requestToCollectorMapping;
13
+ constructor(debug: boolean, bodySizeLimit: string);
14
+ start(): Promise<void>;
15
+ close(): Promise<void>;
16
+ send(message: JsonRpcMessage): Promise<void>;
17
+ handleRequest(req: IncomingMessage, res: ServerResponse, parsedBody?: unknown): Promise<void>;
18
+ private handlePOST;
19
+ }
20
+ export declare class StatelessStreamableHTTPTransport {
21
+ private app;
22
+ private server;
23
+ private port;
24
+ private endpoint;
25
+ private debug;
26
+ private options;
27
+ private createServerFn;
28
+ private corsConfig;
29
+ private oauthProxy;
30
+ private middlewares;
31
+ constructor(createServerFn: () => Promise<McpServer>, options?: HttpTransportOptions, corsConfig?: CorsConfig, oauthConfig?: OAuthProxyConfig | null, middlewares?: RequestHandler[]);
32
+ private log;
33
+ private setupMiddleware;
34
+ private setupRoutes;
35
+ private handleStatelessRequest;
36
+ start(): void;
37
+ private setupShutdownHandlers;
38
+ shutdown(): void;
39
+ }
@@ -0,0 +1,331 @@
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.StatelessStreamableHTTPTransport = exports.StatelessHttpServerTransport = void 0;
7
+ const express_1 = __importDefault(require("express"));
8
+ const http_1 = __importDefault(require("http"));
9
+ const node_crypto_1 = require("node:crypto");
10
+ const raw_body_1 = __importDefault(require("raw-body"));
11
+ const content_type_1 = __importDefault(require("content-type"));
12
+ const base_streamable_http_1 = require("./base-streamable-http");
13
+ const home_1 = __importDefault(require("../../templates/home"));
14
+ const http_context_1 = require("./http-context");
15
+ const oauth_1 = require("../../../auth/oauth");
16
+ const cli_icons_1 = require("../../../utils/cli-icons");
17
+ const setup_cors_1 = require("./setup-cors");
18
+ // no session management, POST only
19
+ class StatelessHttpServerTransport extends base_streamable_http_1.BaseHttpServerTransport {
20
+ debug;
21
+ bodySizeLimit;
22
+ _started = false;
23
+ _singleResponseCollectors = new Map();
24
+ _requestToCollectorMapping = new Map();
25
+ constructor(debug, bodySizeLimit) {
26
+ super();
27
+ this.debug = debug;
28
+ this.bodySizeLimit = bodySizeLimit;
29
+ }
30
+ // avoid restarting
31
+ // sort of singleton
32
+ async start() {
33
+ if (this._started) {
34
+ throw new Error("Transport already started");
35
+ }
36
+ this._started = true;
37
+ }
38
+ async close() {
39
+ this._singleResponseCollectors?.forEach((collector) => {
40
+ if (!collector.res.headersSent) {
41
+ collector.res.writeHead(503).end(JSON.stringify({
42
+ jsonrpc: "2.0",
43
+ error: {
44
+ code: -32000,
45
+ message: "Service unavailable: Server shutting down",
46
+ },
47
+ id: null,
48
+ }));
49
+ }
50
+ });
51
+ this._singleResponseCollectors?.clear();
52
+ this._requestToCollectorMapping?.clear();
53
+ }
54
+ async send(message) {
55
+ const requestId = message.id;
56
+ if (requestId === undefined || requestId === null) {
57
+ // In stateless mode, we can't handle notifications without request IDs
58
+ if (this.debug) {
59
+ console.log("[StatelessHTTP] Dropping notification without request ID");
60
+ }
61
+ return;
62
+ }
63
+ const collectorId = this._requestToCollectorMapping?.get(requestId);
64
+ if (collectorId) {
65
+ const collector = this._singleResponseCollectors?.get(collectorId);
66
+ if (collector &&
67
+ (message.result !== undefined || message.error !== undefined)) {
68
+ collector.responses.push(message);
69
+ collector.requestIds.delete(requestId);
70
+ if (collector.requestIds.size === 0) {
71
+ const headers = {
72
+ "Content-Type": "application/json",
73
+ };
74
+ const responseBody = collector.responses.length === 1
75
+ ? collector.responses[0]
76
+ : collector.responses;
77
+ collector.res
78
+ .writeHead(200, headers)
79
+ .end(JSON.stringify(responseBody));
80
+ this._singleResponseCollectors?.delete(collectorId);
81
+ for (const response of collector.responses) {
82
+ if (response.id !== undefined && response.id !== null) {
83
+ this._requestToCollectorMapping?.delete(response.id);
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ async handleRequest(req, res, parsedBody) {
91
+ // Only support POST in stateless mode
92
+ if (req.method !== "POST") {
93
+ res.writeHead(405).end(JSON.stringify({
94
+ jsonrpc: "2.0",
95
+ error: {
96
+ code: -32000,
97
+ message: "Method not allowed.",
98
+ },
99
+ id: null,
100
+ }));
101
+ return;
102
+ }
103
+ await this.handlePOST(req, res, parsedBody);
104
+ }
105
+ async handlePOST(req, res, parsedBody) {
106
+ try {
107
+ const acceptHeader = req.headers.accept;
108
+ const acceptsJson = acceptHeader?.includes("application/json");
109
+ if (!acceptsJson) {
110
+ res.writeHead(406).end(JSON.stringify({
111
+ jsonrpc: "2.0",
112
+ error: {
113
+ code: -32000,
114
+ message: "Not Acceptable: Client must accept application/json",
115
+ },
116
+ id: null,
117
+ }));
118
+ return;
119
+ }
120
+ let rawMessage;
121
+ if (parsedBody !== undefined) {
122
+ rawMessage = parsedBody;
123
+ }
124
+ else {
125
+ const ct = req.headers["content-type"];
126
+ if (!ct || !ct.includes("application/json")) {
127
+ res.writeHead(415).end(JSON.stringify({
128
+ jsonrpc: "2.0",
129
+ error: {
130
+ code: -32000,
131
+ message: "Unsupported Media Type: Content-Type must be application/json",
132
+ },
133
+ id: null,
134
+ }));
135
+ return;
136
+ }
137
+ const parsedCt = content_type_1.default.parse(ct);
138
+ const body = await (0, raw_body_1.default)(req, {
139
+ limit: this.bodySizeLimit,
140
+ encoding: parsedCt.parameters.charset ?? "utf-8",
141
+ });
142
+ rawMessage = JSON.parse(body.toString());
143
+ }
144
+ const messages = Array.isArray(rawMessage)
145
+ ? rawMessage
146
+ : [rawMessage];
147
+ const hasRequests = messages.some((msg) => msg.method && msg.id !== undefined);
148
+ if (!hasRequests) {
149
+ // Handle notifications (no response expected)
150
+ res.writeHead(202).end();
151
+ return;
152
+ }
153
+ // Handle requests that expect responses
154
+ const requestIds = messages
155
+ .filter((msg) => msg.method && msg.id !== undefined)
156
+ .map((msg) => msg.id);
157
+ if (requestIds.length === 0) {
158
+ res.writeHead(202).end();
159
+ return;
160
+ }
161
+ const responseCollector = [];
162
+ const expectedResponses = requestIds.length;
163
+ const collectorId = (0, node_crypto_1.randomUUID)();
164
+ this._singleResponseCollectors =
165
+ this._singleResponseCollectors || new Map();
166
+ this._singleResponseCollectors.set(collectorId, {
167
+ res,
168
+ requestIds: new Set(requestIds),
169
+ responses: responseCollector,
170
+ expectedCount: expectedResponses,
171
+ });
172
+ for (const requestId of requestIds) {
173
+ this._requestToCollectorMapping =
174
+ this._requestToCollectorMapping || new Map();
175
+ this._requestToCollectorMapping.set(requestId, collectorId);
176
+ }
177
+ // MCP SDK transport interface mandatory
178
+ for (const message of messages) {
179
+ if (this.onmessage) {
180
+ this.onmessage(message);
181
+ }
182
+ }
183
+ }
184
+ catch (error) {
185
+ res.writeHead(400).end(JSON.stringify({
186
+ jsonrpc: "2.0",
187
+ error: {
188
+ code: -32700,
189
+ message: "Parse error",
190
+ data: String(error),
191
+ },
192
+ id: null,
193
+ }));
194
+ }
195
+ }
196
+ }
197
+ exports.StatelessHttpServerTransport = StatelessHttpServerTransport;
198
+ // Stateless HTTP Transport wrapper
199
+ class StatelessStreamableHTTPTransport {
200
+ app;
201
+ server;
202
+ port;
203
+ endpoint;
204
+ debug;
205
+ options;
206
+ createServerFn;
207
+ corsConfig;
208
+ oauthProxy;
209
+ middlewares;
210
+ constructor(createServerFn, options = {}, corsConfig = {}, oauthConfig, middlewares) {
211
+ this.options = {
212
+ ...options,
213
+ };
214
+ this.app = (0, express_1.default)();
215
+ this.server = http_1.default.createServer(this.app);
216
+ this.port = options.port ?? parseInt(process.env.PORT || "3001", 10);
217
+ this.endpoint = options.endpoint ?? "/mcp";
218
+ this.debug = options.debug ?? false;
219
+ this.createServerFn = createServerFn;
220
+ this.corsConfig = corsConfig;
221
+ this.middlewares = middlewares;
222
+ // setup oauth proxy if configuration is provided
223
+ if (oauthConfig) {
224
+ this.oauthProxy = (0, oauth_1.createOAuthProxy)(oauthConfig);
225
+ }
226
+ this.setupMiddleware(options.bodySizeLimit || "10mb");
227
+ this.setupRoutes();
228
+ }
229
+ log(message, ...args) {
230
+ if (this.debug) {
231
+ console.log(`[StatelessHTTP] ${message}`, ...args);
232
+ }
233
+ }
234
+ setupMiddleware(bodySizeLimit) {
235
+ this.app.use((req, res, next) => {
236
+ const cors = this.corsConfig;
237
+ // set cors headers dynamically
238
+ (0, setup_cors_1.setResponseCorsHeaders)(cors, res);
239
+ next();
240
+ });
241
+ this.app.use(express_1.default.json({ limit: bodySizeLimit }));
242
+ this.app.use((req, _res, next) => {
243
+ this.log(`${req.method} ${req.path}`);
244
+ next();
245
+ });
246
+ }
247
+ setupRoutes() {
248
+ this.app.get("/health", (_req, res) => {
249
+ res.status(200).json({
250
+ status: "ok",
251
+ transport: "streamable-http",
252
+ mode: "stateless",
253
+ });
254
+ });
255
+ this.app.get("/", (_req, res) => {
256
+ res.send((0, home_1.default)(this.endpoint));
257
+ });
258
+ if (this.oauthProxy) {
259
+ this.app.use(this.oauthProxy.router);
260
+ }
261
+ // isolate requests context
262
+ this.app.use((req, _res, next) => {
263
+ const id = (0, node_crypto_1.randomUUID)();
264
+ (0, http_context_1.httpContextProvider)({ id, headers: req.headers }, () => {
265
+ next();
266
+ });
267
+ });
268
+ // routes beyond this point get intercepted by the middleware
269
+ if (this.middlewares && this.middlewares.length > 0) {
270
+ this.app.use(this.middlewares);
271
+ }
272
+ if (this.oauthProxy) {
273
+ this.app.use(this.oauthProxy.middleware);
274
+ }
275
+ this.app.use(this.endpoint, async (req, res) => {
276
+ await this.handleStatelessRequest(req, res);
277
+ });
278
+ }
279
+ async handleStatelessRequest(req, res) {
280
+ try {
281
+ // Create new instances for complete isolation
282
+ const server = await this.createServerFn();
283
+ const transport = new StatelessHttpServerTransport(this.debug, this.options.bodySizeLimit || "10mb");
284
+ // cleanup when request/connection closes
285
+ res.on("close", () => {
286
+ transport.close();
287
+ server.close();
288
+ });
289
+ await server.connect(transport);
290
+ await transport.handleRequest(req, res, req.body);
291
+ }
292
+ catch (error) {
293
+ console.error("[HTTP-server] Error handling MCP request:", error);
294
+ if (!res.headersSent) {
295
+ res.status(500).json({
296
+ jsonrpc: "2.0",
297
+ error: {
298
+ code: -32603,
299
+ message: "Internal server error",
300
+ },
301
+ id: null,
302
+ });
303
+ }
304
+ }
305
+ }
306
+ start() {
307
+ const host = this.options.host || "127.0.0.1";
308
+ this.server.listen(this.port, host, () => {
309
+ console.log(`${cli_icons_1.greenCheck} MCP Server running on http://${host}:${this.port}${this.endpoint}`);
310
+ if (this.oauthProxy && this.debug) {
311
+ console.log(`🔐 OAuth endpoints available:`);
312
+ console.log(` Discovery: http://${host}:${this.port}/.well-known/oauth-authorization-server`);
313
+ console.log(` Authorize: http://${host}:${this.port}/oauth2/authorize`);
314
+ console.log(` Token: http://${host}:${this.port}/oauth2/token`);
315
+ console.log(` Revoke: http://${host}:${this.port}/oauth2/revoke`);
316
+ console.log(` Introspect: http://${host}:${this.port}/oauth2/introspect`);
317
+ }
318
+ this.setupShutdownHandlers();
319
+ });
320
+ }
321
+ setupShutdownHandlers() {
322
+ process.on("SIGINT", this.shutdown.bind(this));
323
+ process.on("SIGTERM", this.shutdown.bind(this));
324
+ }
325
+ shutdown() {
326
+ this.log("Shutting down server");
327
+ this.server.close();
328
+ process.exit(0);
329
+ }
330
+ }
331
+ exports.StatelessStreamableHTTPTransport = StatelessStreamableHTTPTransport;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
4
+ const server_1 = require("../../utils/server");
5
+ class StdioTransport {
6
+ mcpServer;
7
+ transport;
8
+ debug;
9
+ constructor(mcpServer, debug = false) {
10
+ this.mcpServer = mcpServer;
11
+ this.transport = new stdio_js_1.StdioServerTransport();
12
+ this.debug = debug;
13
+ }
14
+ start() {
15
+ try {
16
+ this.mcpServer.connect(this.transport);
17
+ if (this.debug) {
18
+ console.log("[STDIO] MCP Server running with STDIO transport");
19
+ }
20
+ this.setupShutdownHandlers();
21
+ }
22
+ catch (error) {
23
+ if (this.debug) {
24
+ console.error("[STDIO] Error starting STDIO transport:", error);
25
+ }
26
+ process.exit(1);
27
+ }
28
+ }
29
+ setupShutdownHandlers() {
30
+ const shutdownHandler = () => {
31
+ if (this.debug) {
32
+ console.log("[STDIO] Shutting down STDIO transport");
33
+ }
34
+ process.exit(0);
35
+ };
36
+ process.on("SIGINT", shutdownHandler);
37
+ process.on("SIGTERM", shutdownHandler);
38
+ }
39
+ shutdown() {
40
+ if (this.debug) {
41
+ console.log("[STDIO] Shutting down STDIO transport");
42
+ }
43
+ process.exit(0);
44
+ }
45
+ }
46
+ // @ts-expect-error: injected by compiler
47
+ const debug = STDIO_CONFIG.debug || false;
48
+ (0, server_1.createServer)().then((mcpServer) => {
49
+ const stdioTransport = new StdioTransport(mcpServer, debug);
50
+ stdioTransport.start();
51
+ });
@@ -0,0 +1,42 @@
1
+ import { Server as McpServer } from "@modelcontextprotocol/sdk/server/index.js";
2
+ export type ToolFile = {
3
+ metadata: unknown;
4
+ schema: unknown;
5
+ default: (args: Record<string, unknown>) => Promise<unknown> | unknown;
6
+ };
7
+ export declare const injectedTools: Record<string, () => Promise<ToolFile>>;
8
+ export declare const INJECTED_CONFIG: {
9
+ readonly name: "MCP Server";
10
+ readonly version: "0.0.1";
11
+ readonly capabilities: {
12
+ readonly tools: {
13
+ readonly listChanged: true;
14
+ };
15
+ };
16
+ };
17
+ /** Loads tools and injects them into the server */
18
+ export declare function configureServer(server: McpServer, toolModules: Map<string, ToolFile>): Promise<McpServer>;
19
+ export declare function loadTools(): readonly [Promise<void>[], Map<string, ToolFile>];
20
+ export declare function createServer(): Promise<McpServer<{
21
+ method: string;
22
+ params?: {
23
+ [x: string]: unknown;
24
+ _meta?: {
25
+ [x: string]: unknown;
26
+ progressToken?: string | number | undefined;
27
+ } | undefined;
28
+ } | undefined;
29
+ }, {
30
+ method: string;
31
+ params?: {
32
+ [x: string]: unknown;
33
+ _meta?: {
34
+ [x: string]: unknown;
35
+ } | undefined;
36
+ } | undefined;
37
+ }, {
38
+ [x: string]: unknown;
39
+ _meta?: {
40
+ [x: string]: unknown;
41
+ } | undefined;
42
+ }>>;