@casys/mcp-server 0.26.0 → 0.27.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 (299) hide show
  1. package/CHANGELOG.md +1779 -0
  2. package/LICENSE +21 -0
  3. package/README.md +19 -5
  4. package/esm/_dnt.polyfills.d.ts +12 -0
  5. package/esm/_dnt.polyfills.d.ts.map +1 -0
  6. package/esm/_dnt.polyfills.js +15 -0
  7. package/esm/_dnt.shims.d.ts +2 -0
  8. package/esm/_dnt.shims.d.ts.map +1 -0
  9. package/esm/_dnt.shims.js +57 -0
  10. package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts +33 -0
  11. package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.js +48 -0
  13. package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts +106 -0
  14. package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.js +636 -0
  16. package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts +67 -0
  17. package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.js +1393 -0
  19. package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts +44 -0
  20. package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.js +117 -0
  22. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts +3 -0
  23. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.js +103 -0
  25. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts +3 -0
  26. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.js +32 -0
  28. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts +3 -0
  29. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.js +96 -0
  31. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts +3 -0
  32. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.js +159 -0
  34. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts +3 -0
  35. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.js +14 -0
  37. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts +3 -0
  38. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.js +10 -0
  40. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts +3 -0
  41. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.js +22 -0
  43. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts +3 -0
  44. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.js +29 -0
  46. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts +3 -0
  47. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.js +19 -0
  49. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts +3 -0
  50. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.js +30 -0
  52. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts +3 -0
  53. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.js +10 -0
  55. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts +3 -0
  56. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.js +14 -0
  58. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts +3 -0
  59. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts.map +1 -0
  60. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.js +9 -0
  61. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts +3 -0
  62. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts.map +1 -0
  63. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.js +81 -0
  64. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts +3 -0
  65. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts.map +1 -0
  66. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.js +20 -0
  67. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts +32 -0
  68. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts.map +1 -0
  69. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.js +6 -0
  70. package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts +4 -0
  71. package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts.map +1 -0
  72. package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.js +13 -0
  73. package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts +51 -0
  74. package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts.map +1 -0
  75. package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.js +53 -0
  76. package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts +79 -0
  77. package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts.map +1 -0
  78. package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.js +91 -0
  79. package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts +100 -0
  80. package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts.map +1 -0
  81. package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.js +33 -0
  82. package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts +111 -0
  83. package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts.map +1 -0
  84. package/esm/deps/jsr.io/@std/yaml/1.2.0/types.js +104 -0
  85. package/esm/mod.d.ts +102 -0
  86. package/esm/mod.d.ts.map +1 -0
  87. package/esm/mod.js +103 -0
  88. package/esm/package.json +3 -0
  89. package/esm/src/auth/as-metadata-proxy.d.ts +112 -0
  90. package/esm/src/auth/as-metadata-proxy.d.ts.map +1 -0
  91. package/esm/src/auth/as-metadata-proxy.js +171 -0
  92. package/esm/src/auth/config.d.ts +117 -0
  93. package/esm/src/auth/config.d.ts.map +1 -0
  94. package/esm/src/auth/config.js +219 -0
  95. package/esm/src/auth/jwt-provider.d.ts +157 -0
  96. package/esm/src/auth/jwt-provider.d.ts.map +1 -0
  97. package/esm/src/auth/jwt-provider.js +187 -0
  98. package/esm/src/auth/middleware.d.ts +61 -0
  99. package/esm/src/auth/middleware.d.ts.map +1 -0
  100. package/esm/src/auth/middleware.js +209 -0
  101. package/esm/src/auth/mod.d.ts +23 -0
  102. package/esm/src/auth/mod.d.ts.map +1 -0
  103. package/esm/src/auth/mod.js +27 -0
  104. package/esm/src/auth/multi-tenant-middleware.d.ts +131 -0
  105. package/esm/src/auth/multi-tenant-middleware.d.ts.map +1 -0
  106. package/esm/src/auth/multi-tenant-middleware.js +128 -0
  107. package/esm/src/auth/presets.d.ts +231 -0
  108. package/esm/src/auth/presets.d.ts.map +1 -0
  109. package/esm/src/auth/presets.js +223 -0
  110. package/{src/auth/provider.ts → esm/src/auth/provider.d.ts} +13 -15
  111. package/esm/src/auth/provider.d.ts.map +1 -0
  112. package/esm/src/auth/provider.js +34 -0
  113. package/esm/src/auth/scope-middleware.d.ts +30 -0
  114. package/esm/src/auth/scope-middleware.d.ts.map +1 -0
  115. package/esm/src/auth/scope-middleware.js +48 -0
  116. package/esm/src/auth/static-token-provider.d.ts +155 -0
  117. package/esm/src/auth/static-token-provider.d.ts.map +1 -0
  118. package/esm/src/auth/static-token-provider.js +256 -0
  119. package/esm/src/auth/types.d.ts +151 -0
  120. package/esm/src/auth/types.d.ts.map +1 -0
  121. package/esm/src/auth/types.js +64 -0
  122. package/esm/src/client-auth/callback-server.d.ts +34 -0
  123. package/esm/src/client-auth/callback-server.d.ts.map +1 -0
  124. package/esm/src/client-auth/callback-server.js +141 -0
  125. package/esm/src/client-auth/client-id-metadata.d.ts +29 -0
  126. package/esm/src/client-auth/client-id-metadata.d.ts.map +1 -0
  127. package/esm/src/client-auth/client-id-metadata.js +149 -0
  128. package/esm/src/client-auth/connect.d.ts +32 -0
  129. package/esm/src/client-auth/connect.d.ts.map +1 -0
  130. package/esm/src/client-auth/connect.js +47 -0
  131. package/esm/src/client-auth/mod.d.ts +19 -0
  132. package/esm/src/client-auth/mod.d.ts.map +1 -0
  133. package/{src/client-auth/mod.ts → esm/src/client-auth/mod.js} +1 -26
  134. package/esm/src/client-auth/provider.d.ts +78 -0
  135. package/esm/src/client-auth/provider.d.ts.map +1 -0
  136. package/esm/src/client-auth/provider.js +246 -0
  137. package/esm/src/client-auth/token-store/file-store.d.ts +20 -0
  138. package/esm/src/client-auth/token-store/file-store.d.ts.map +1 -0
  139. package/esm/src/client-auth/token-store/file-store.js +62 -0
  140. package/esm/src/client-auth/token-store/memory-store.d.ts +14 -0
  141. package/esm/src/client-auth/token-store/memory-store.d.ts.map +1 -0
  142. package/esm/src/client-auth/token-store/memory-store.js +25 -0
  143. package/esm/src/client-auth/types.d.ts +89 -0
  144. package/esm/src/client-auth/types.d.ts.map +1 -0
  145. package/esm/src/client-auth/types.js +10 -0
  146. package/esm/src/concurrency/rate-limiter.d.ts +87 -0
  147. package/esm/src/concurrency/rate-limiter.d.ts.map +1 -0
  148. package/esm/src/concurrency/rate-limiter.js +165 -0
  149. package/esm/src/concurrency/request-queue.d.ts +71 -0
  150. package/esm/src/concurrency/request-queue.d.ts.map +1 -0
  151. package/esm/src/concurrency/request-queue.js +128 -0
  152. package/esm/src/http/body.d.ts +20 -0
  153. package/esm/src/http/body.d.ts.map +1 -0
  154. package/esm/src/http/body.js +63 -0
  155. package/esm/src/http/request-guards.d.ts +54 -0
  156. package/esm/src/http/request-guards.d.ts.map +1 -0
  157. package/esm/src/http/request-guards.js +114 -0
  158. package/esm/src/http/wire.d.ts +26 -0
  159. package/esm/src/http/wire.d.ts.map +1 -0
  160. package/{src/http/wire.ts → esm/src/http/wire.js} +13 -19
  161. package/esm/src/inspector/launcher.d.ts +48 -0
  162. package/esm/src/inspector/launcher.d.ts.map +1 -0
  163. package/esm/src/inspector/launcher.js +100 -0
  164. package/esm/src/mcp-app.d.ts +728 -0
  165. package/esm/src/mcp-app.d.ts.map +1 -0
  166. package/esm/src/mcp-app.js +3530 -0
  167. package/{src/middleware/backpressure.ts → esm/src/middleware/backpressure.d.ts} +2 -14
  168. package/esm/src/middleware/backpressure.d.ts.map +1 -0
  169. package/esm/src/middleware/backpressure.js +31 -0
  170. package/esm/src/middleware/mod.d.ts +11 -0
  171. package/esm/src/middleware/mod.d.ts.map +1 -0
  172. package/{src/middleware/mod.ts → esm/src/middleware/mod.js} +0 -10
  173. package/{src/middleware/rate-limit.ts → esm/src/middleware/rate-limit.d.ts} +2 -25
  174. package/esm/src/middleware/rate-limit.d.ts.map +1 -0
  175. package/esm/src/middleware/rate-limit.js +33 -0
  176. package/esm/src/middleware/runner.d.ts +32 -0
  177. package/esm/src/middleware/runner.d.ts.map +1 -0
  178. package/esm/src/middleware/runner.js +49 -0
  179. package/esm/src/middleware/types.d.ts +76 -0
  180. package/esm/src/middleware/types.d.ts.map +1 -0
  181. package/esm/src/middleware/types.js +9 -0
  182. package/esm/src/middleware/validation.d.ts +24 -0
  183. package/esm/src/middleware/validation.d.ts.map +1 -0
  184. package/esm/src/middleware/validation.js +30 -0
  185. package/esm/src/mrtr/capability-check.d.ts +75 -0
  186. package/esm/src/mrtr/capability-check.d.ts.map +1 -0
  187. package/esm/src/mrtr/capability-check.js +233 -0
  188. package/esm/src/mrtr/mod.d.ts +18 -0
  189. package/esm/src/mrtr/mod.d.ts.map +1 -0
  190. package/esm/src/mrtr/mod.js +12 -0
  191. package/esm/src/mrtr/replay-store.d.ts +50 -0
  192. package/esm/src/mrtr/replay-store.d.ts.map +1 -0
  193. package/esm/src/mrtr/replay-store.js +61 -0
  194. package/esm/src/mrtr/request-state.d.ts +181 -0
  195. package/esm/src/mrtr/request-state.d.ts.map +1 -0
  196. package/esm/src/mrtr/request-state.js +313 -0
  197. package/esm/src/mrtr/retry-guard.d.ts +61 -0
  198. package/esm/src/mrtr/retry-guard.d.ts.map +1 -0
  199. package/esm/src/mrtr/retry-guard.js +53 -0
  200. package/esm/src/mrtr/types.d.ts +99 -0
  201. package/esm/src/mrtr/types.d.ts.map +1 -0
  202. package/esm/src/mrtr/types.js +14 -0
  203. package/esm/src/observability/metrics.d.ts +104 -0
  204. package/esm/src/observability/metrics.d.ts.map +1 -0
  205. package/esm/src/observability/metrics.js +207 -0
  206. package/{src/observability/mod.ts → esm/src/observability/mod.d.ts} +2 -11
  207. package/esm/src/observability/mod.d.ts.map +1 -0
  208. package/esm/src/observability/mod.js +11 -0
  209. package/esm/src/observability/otel.d.ts +73 -0
  210. package/esm/src/observability/otel.d.ts.map +1 -0
  211. package/esm/src/observability/otel.js +260 -0
  212. package/esm/src/runtime/runtime.d.ts +10 -0
  213. package/esm/src/runtime/runtime.d.ts.map +1 -0
  214. package/esm/src/runtime/runtime.deno.d.ts +50 -0
  215. package/esm/src/runtime/runtime.deno.d.ts.map +1 -0
  216. package/esm/src/runtime/runtime.deno.js +120 -0
  217. package/{src/runtime/runtime.ts → esm/src/runtime/runtime.js} +5 -14
  218. package/esm/src/runtime/runtime.node.d.ts +51 -0
  219. package/esm/src/runtime/runtime.node.d.ts.map +1 -0
  220. package/esm/src/runtime/runtime.node.js +268 -0
  221. package/{src/runtime/types.ts → esm/src/runtime/types.d.ts} +28 -51
  222. package/esm/src/runtime/types.d.ts.map +1 -0
  223. package/esm/src/runtime/types.js +12 -0
  224. package/esm/src/security/channel-hmac.d.ts +43 -0
  225. package/esm/src/security/channel-hmac.d.ts.map +1 -0
  226. package/{src/security/channel-hmac.ts → esm/src/security/channel-hmac.js} +12 -17
  227. package/esm/src/security/csp.d.ts +50 -0
  228. package/esm/src/security/csp.d.ts.map +1 -0
  229. package/esm/src/security/csp.js +63 -0
  230. package/esm/src/security/message-signer.d.ts +88 -0
  231. package/esm/src/security/message-signer.d.ts.map +1 -0
  232. package/esm/src/security/message-signer.js +166 -0
  233. package/esm/src/subscriptions/subscription-registry.d.ts +256 -0
  234. package/esm/src/subscriptions/subscription-registry.d.ts.map +1 -0
  235. package/esm/src/subscriptions/subscription-registry.js +406 -0
  236. package/{src/tasks/mod.ts → esm/src/tasks/mod.d.ts} +3 -23
  237. package/esm/src/tasks/mod.d.ts.map +1 -0
  238. package/esm/src/tasks/mod.js +11 -0
  239. package/esm/src/tasks/task-store.d.ts +342 -0
  240. package/esm/src/tasks/task-store.d.ts.map +1 -0
  241. package/esm/src/tasks/task-store.js +649 -0
  242. package/esm/src/transport/request-headers.d.ts +145 -0
  243. package/esm/src/transport/request-headers.d.ts.map +1 -0
  244. package/esm/src/transport/request-headers.js +525 -0
  245. package/esm/src/types.d.ts +776 -0
  246. package/esm/src/types.d.ts.map +1 -0
  247. package/esm/src/types.js +92 -0
  248. package/esm/src/ui/viewer-utils.d.ts +45 -0
  249. package/esm/src/ui/viewer-utils.d.ts.map +1 -0
  250. package/esm/src/ui/viewer-utils.js +97 -0
  251. package/esm/src/validation/schema-validator.d.ts +115 -0
  252. package/esm/src/validation/schema-validator.d.ts.map +1 -0
  253. package/esm/src/validation/schema-validator.js +249 -0
  254. package/package.json +35 -23
  255. package/mod.ts +0 -302
  256. package/src/auth/as-metadata-proxy.ts +0 -288
  257. package/src/auth/config.ts +0 -368
  258. package/src/auth/jwt-provider.ts +0 -327
  259. package/src/auth/middleware.ts +0 -257
  260. package/src/auth/mod.ts +0 -89
  261. package/src/auth/multi-tenant-middleware.ts +0 -236
  262. package/src/auth/presets.ts +0 -351
  263. package/src/auth/scope-middleware.ts +0 -59
  264. package/src/auth/static-token-provider.ts +0 -197
  265. package/src/auth/types.ts +0 -207
  266. package/src/client-auth/callback-server.ts +0 -166
  267. package/src/client-auth/client-id-metadata.ts +0 -260
  268. package/src/client-auth/connect.ts +0 -72
  269. package/src/client-auth/provider.ts +0 -300
  270. package/src/client-auth/token-store/file-store.ts +0 -73
  271. package/src/client-auth/token-store/memory-store.ts +0 -32
  272. package/src/client-auth/types.ts +0 -95
  273. package/src/concurrency/rate-limiter.ts +0 -190
  274. package/src/concurrency/request-queue.ts +0 -140
  275. package/src/http/body.ts +0 -72
  276. package/src/http/request-guards.ts +0 -137
  277. package/src/inspector/launcher.ts +0 -131
  278. package/src/mcp-app.ts +0 -4426
  279. package/src/middleware/runner.ts +0 -63
  280. package/src/middleware/types.ts +0 -104
  281. package/src/middleware/validation.ts +0 -28
  282. package/src/mrtr/capability-check.ts +0 -303
  283. package/src/mrtr/mod.ts +0 -46
  284. package/src/mrtr/replay-store.ts +0 -103
  285. package/src/mrtr/request-state.ts +0 -435
  286. package/src/mrtr/types.ts +0 -107
  287. package/src/observability/metrics.ts +0 -336
  288. package/src/observability/otel.ts +0 -330
  289. package/src/runtime/runtime.deno.ts +0 -149
  290. package/src/runtime/runtime.node.ts +0 -324
  291. package/src/security/csp.ts +0 -89
  292. package/src/security/message-signer.ts +0 -223
  293. package/src/subscriptions/subscription-registry.ts +0 -558
  294. package/src/tasks/task-store.ts +0 -1014
  295. package/src/testdata/stdio-e2e-server.ts +0 -110
  296. package/src/transport/request-headers.ts +0 -661
  297. package/src/types.ts +0 -907
  298. package/src/ui/viewer-utils.ts +0 -117
  299. package/src/validation/schema-validator.ts +0 -307
@@ -1,149 +0,0 @@
1
- /**
2
- * Runtime adapter — Deno implementation
3
- *
4
- * Implements the RuntimePort contract for Deno.
5
- * Selected automatically by runtime.ts (the selector) when running under Deno.
6
- *
7
- * @see types.ts for the port contract
8
- * @module lib/server/runtime.deno
9
- */
10
-
11
- import type {
12
- FetchHandler,
13
- RuntimePort,
14
- ServeHandle,
15
- ServeOptions,
16
- } from "./types.js";
17
-
18
- // Re-export types so consumers import from a single module
19
- export type { FetchHandler, ServeHandle, ServeOptions } from "./types.js";
20
-
21
- /**
22
- * Get an environment variable.
23
- */
24
- export function env(key: string): string | undefined {
25
- return Deno.env.get(key);
26
- }
27
-
28
- /**
29
- * Read a UTF-8 text file.
30
- * Returns null if the file does not exist.
31
- */
32
- export async function readTextFile(path: string): Promise<string | null> {
33
- try {
34
- return await Deno.readTextFile(path);
35
- } catch (err) {
36
- if (err instanceof Deno.errors.NotFound) {
37
- return null;
38
- }
39
- throw err;
40
- }
41
- }
42
-
43
- /**
44
- * Write a UTF-8 text file.
45
- */
46
- export async function writeTextFile(
47
- path: string,
48
- content: string,
49
- opts?: { mode?: number },
50
- ): Promise<void> {
51
- await Deno.writeTextFile(path, content, opts);
52
- }
53
-
54
- /**
55
- * Create a directory.
56
- */
57
- export async function mkdir(
58
- path: string,
59
- opts?: { recursive?: boolean; mode?: number },
60
- ): Promise<void> {
61
- await Deno.mkdir(path, opts);
62
- }
63
-
64
- /**
65
- * Remove a file or empty directory. No-op if absent.
66
- */
67
- export async function remove(path: string): Promise<void> {
68
- try {
69
- await Deno.remove(path);
70
- } catch (err) {
71
- if (err instanceof Deno.errors.NotFound) {
72
- return;
73
- }
74
- throw err;
75
- }
76
- }
77
-
78
- /**
79
- * Read directory entry names. Returns [] if absent.
80
- */
81
- export async function readDir(path: string): Promise<string[]> {
82
- try {
83
- const names: string[] = [];
84
- for await (const entry of Deno.readDir(path)) {
85
- names.push(entry.name);
86
- }
87
- return names;
88
- } catch (err) {
89
- if (err instanceof Deno.errors.NotFound) {
90
- return [];
91
- }
92
- throw err;
93
- }
94
- }
95
-
96
- /**
97
- * Start an HTTP server with a fetch-style handler.
98
- */
99
- export function serve(
100
- options: ServeOptions,
101
- handler: FetchHandler,
102
- ): ServeHandle {
103
- let server: Deno.HttpServer | null = null;
104
- try {
105
- server = Deno.serve(
106
- {
107
- port: options.port,
108
- hostname: options.hostname,
109
- onListen: options.onListen,
110
- },
111
- handler,
112
- );
113
- } catch (err) {
114
- const error = toError(err);
115
- if (options.onError) {
116
- options.onError(error);
117
- return {
118
- shutdown: () => Promise.resolve(),
119
- };
120
- }
121
- throw error;
122
- }
123
- return {
124
- shutdown: () => server.shutdown(),
125
- };
126
- }
127
-
128
- /**
129
- * Unref a timer so it doesn't block process exit.
130
- */
131
- export function unrefTimer(id: number): void {
132
- Deno.unrefTimer(id);
133
- }
134
-
135
- /** Compile-time contract check — ensures this module satisfies RuntimePort */
136
- void ({
137
- env,
138
- readTextFile,
139
- writeTextFile,
140
- mkdir,
141
- remove,
142
- readDir,
143
- serve,
144
- unrefTimer,
145
- } satisfies RuntimePort);
146
-
147
- function toError(err: unknown): Error {
148
- return err instanceof Error ? err : new Error(String(err));
149
- }
@@ -1,324 +0,0 @@
1
- // deno-lint-ignore-file no-process-global
2
- /**
3
- * Runtime adapter — Node.js implementation
4
- *
5
- * Implements the RuntimePort contract for Node.js.
6
- * Drop-in replacement for runtime.ts (Deno) — swapped by build script.
7
- *
8
- * @see runtime-types.ts for the port contract
9
- * @module lib/server/runtime.node
10
- */
11
-
12
- import { Buffer } from "node:buffer";
13
- import {
14
- mkdir as nodeMkdir,
15
- readdir,
16
- readFile,
17
- rm,
18
- writeFile,
19
- } from "node:fs/promises";
20
- import { createServer } from "node:http";
21
- import type {
22
- FetchHandler,
23
- RuntimePort,
24
- ServeHandle,
25
- ServeOptions,
26
- } from "./types.js";
27
-
28
- // Re-export types so consumers import from a single module
29
- export type { FetchHandler, ServeHandle, ServeOptions } from "./types.js";
30
-
31
- class PayloadTooLargeError extends Error {
32
- constructor(maxBytes: number) {
33
- super(`Payload too large. Max ${maxBytes} bytes.`);
34
- this.name = "PayloadTooLargeError";
35
- }
36
- }
37
-
38
- /**
39
- * Get an environment variable.
40
- */
41
- export function env(key: string): string | undefined {
42
- return process.env[key];
43
- }
44
-
45
- /**
46
- * Read a UTF-8 text file.
47
- * Returns null if the file does not exist.
48
- */
49
- export async function readTextFile(path: string): Promise<string | null> {
50
- try {
51
- return await readFile(path, "utf-8");
52
- } catch (err: unknown) {
53
- if (
54
- err && typeof err === "object" && "code" in err && err.code === "ENOENT"
55
- ) {
56
- return null;
57
- }
58
- throw err;
59
- }
60
- }
61
-
62
- /**
63
- * Write a UTF-8 text file.
64
- */
65
- export async function writeTextFile(
66
- path: string,
67
- content: string,
68
- opts?: { mode?: number },
69
- ): Promise<void> {
70
- await writeFile(path, content, { mode: opts?.mode });
71
- }
72
-
73
- /**
74
- * Create a directory.
75
- */
76
- export async function mkdir(
77
- path: string,
78
- opts?: { recursive?: boolean; mode?: number },
79
- ): Promise<void> {
80
- await nodeMkdir(path, { recursive: opts?.recursive, mode: opts?.mode });
81
- }
82
-
83
- /**
84
- * Remove a file or empty directory. No-op if absent.
85
- */
86
- export async function remove(path: string): Promise<void> {
87
- try {
88
- await rm(path);
89
- } catch (err: unknown) {
90
- if (isNodeNotFound(err)) {
91
- return;
92
- }
93
- throw err;
94
- }
95
- }
96
-
97
- /**
98
- * Read directory entry names. Returns [] if absent.
99
- */
100
- export async function readDir(path: string): Promise<string[]> {
101
- try {
102
- return await readdir(path);
103
- } catch (err: unknown) {
104
- if (isNodeNotFound(err)) {
105
- return [];
106
- }
107
- throw err;
108
- }
109
- }
110
-
111
- /**
112
- * Start an HTTP server with a fetch-style handler.
113
- * Uses node:http with a Request/Response adapter (compatible with Hono).
114
- */
115
- export function serve(
116
- options: ServeOptions,
117
- handler: FetchHandler,
118
- ): ServeHandle {
119
- const hostname = options.hostname ?? "0.0.0.0";
120
- const maxBodyBytes = options.maxBodyBytes ?? null;
121
-
122
- const server = createServer(async (nodeReq, nodeRes) => {
123
- try {
124
- const contentLength = nodeReq.headers["content-length"];
125
- if (maxBodyBytes !== null && contentLength) {
126
- const length = Array.isArray(contentLength)
127
- ? Number(contentLength[0])
128
- : Number(contentLength);
129
- if (!Number.isNaN(length) && length > maxBodyBytes) {
130
- nodeRes.writeHead(413);
131
- nodeRes.end(`Payload too large. Max ${maxBodyBytes} bytes.`);
132
- return;
133
- }
134
- }
135
-
136
- // Convert Node.js IncomingMessage → Web Request
137
- // Prefer Host header (correct behind reverse proxy) over bound hostname
138
- const host = nodeReq.headers.host ?? `${hostname}:${options.port}`;
139
- const url = `http://${host}${nodeReq.url ?? "/"}`;
140
- const headers = new Headers();
141
- for (const [key, value] of Object.entries(nodeReq.headers)) {
142
- if (value) {
143
- if (Array.isArray(value)) {
144
- for (const v of value) headers.append(key, v);
145
- } else {
146
- headers.set(key, value);
147
- }
148
- }
149
- }
150
-
151
- const body = nodeReq.method !== "GET" && nodeReq.method !== "HEAD"
152
- ? await collectBody(nodeReq, maxBodyBytes)
153
- : undefined;
154
-
155
- const request = new Request(url, {
156
- method: nodeReq.method ?? "GET",
157
- headers,
158
- body,
159
- // @ts-ignore: duplex needed for streaming requests in Node 20+
160
- duplex: body ? "half" : undefined,
161
- });
162
-
163
- // Call the fetch handler (Hono, etc.)
164
- const response = await handler(request);
165
-
166
- // Convert Web Response → Node.js ServerResponse
167
- // Use raw header entries to preserve duplicate Set-Cookie headers
168
- const resHeaders: Record<string, string | string[]> = {};
169
- response.headers.forEach((value, key) => {
170
- const existing = resHeaders[key];
171
- if (existing !== undefined) {
172
- resHeaders[key] = Array.isArray(existing)
173
- ? [...existing, value]
174
- : [existing, value];
175
- } else {
176
- resHeaders[key] = value;
177
- }
178
- });
179
- nodeRes.writeHead(response.status, resHeaders);
180
-
181
- if (response.body) {
182
- const reader = response.body.getReader();
183
- while (true) {
184
- const { done, value } = await reader.read();
185
- if (done) break;
186
- nodeRes.write(value);
187
- }
188
- nodeRes.end();
189
- } else {
190
- nodeRes.end();
191
- }
192
- } catch (err) {
193
- if (err instanceof PayloadTooLargeError) {
194
- if (!nodeRes.headersSent) {
195
- nodeRes.writeHead(413);
196
- nodeRes.end(err.message);
197
- }
198
- return;
199
- }
200
- console.error("[runtime.node] Request handler error:", err);
201
- if (!nodeRes.headersSent) {
202
- nodeRes.writeHead(500);
203
- nodeRes.end("Internal Server Error");
204
- }
205
- }
206
- });
207
-
208
- server.on("error", (err) => {
209
- if (options.onError) {
210
- options.onError(err);
211
- return;
212
- }
213
- setTimeout(() => {
214
- throw err;
215
- }, 0);
216
- });
217
-
218
- server.listen(options.port, hostname, () => {
219
- if (options.onListen) {
220
- const address = server.address();
221
- const port = typeof address === "object" && address !== null
222
- ? address.port
223
- : options.port;
224
- options.onListen({ hostname, port });
225
- }
226
- });
227
-
228
- return {
229
- shutdown: () =>
230
- new Promise<void>((resolve, reject) => {
231
- server.close((err) => {
232
- if (err && !isNodeServerNotRunning(err)) {
233
- reject(err);
234
- return;
235
- }
236
- resolve();
237
- });
238
- }),
239
- };
240
- }
241
-
242
- /**
243
- * Unref a timer so it doesn't block process exit.
244
- */
245
- export function unrefTimer(id: number): void {
246
- // In Node.js, setTimeout returns a Timeout object (not a numeric ID).
247
- // The caller passes it as `number` for Deno compat — we cast back.
248
- try {
249
- const timer = id as unknown as { unref?: () => void };
250
- if (
251
- typeof timer === "object" && timer && typeof timer.unref === "function"
252
- ) {
253
- timer.unref();
254
- }
255
- } catch (err) {
256
- console.warn("[runtime.node] Failed to unref timer:", err);
257
- }
258
- }
259
-
260
- /** Compile-time contract check — ensures this module satisfies RuntimePort */
261
- void ({
262
- env,
263
- readTextFile,
264
- writeTextFile,
265
- mkdir,
266
- remove,
267
- readDir,
268
- serve,
269
- unrefTimer,
270
- } satisfies RuntimePort);
271
-
272
- // ─── Internal helpers ────────────────────────────────────
273
-
274
- /** Collect request body from Node.js IncomingMessage */
275
- function collectBody(
276
- req: import("node:http").IncomingMessage,
277
- maxBytes: number | null,
278
- ): Promise<ArrayBuffer> {
279
- return new Promise((resolve, reject) => {
280
- const chunks: Buffer[] = [];
281
- let total = 0;
282
- let rejected = false;
283
- req.on("data", (chunk: Buffer) => {
284
- if (rejected) return;
285
- total += chunk.length;
286
- if (maxBytes !== null && total > maxBytes) {
287
- rejected = true;
288
- req.destroy();
289
- reject(new PayloadTooLargeError(maxBytes));
290
- return;
291
- }
292
- chunks.push(chunk);
293
- });
294
- req.on("end", () => {
295
- if (!rejected) {
296
- const body = Buffer.concat(chunks);
297
- resolve(
298
- body.buffer.slice(
299
- body.byteOffset,
300
- body.byteOffset + body.byteLength,
301
- ),
302
- );
303
- }
304
- });
305
- req.on("error", (err) => {
306
- if (!rejected) {
307
- reject(err);
308
- }
309
- });
310
- });
311
- }
312
-
313
- function isNodeNotFound(err: unknown): boolean {
314
- return Boolean(
315
- err && typeof err === "object" && "code" in err && err.code === "ENOENT",
316
- );
317
- }
318
-
319
- function isNodeServerNotRunning(err: unknown): boolean {
320
- return Boolean(
321
- err && typeof err === "object" && "code" in err &&
322
- err.code === "ERR_SERVER_NOT_RUNNING",
323
- );
324
- }
@@ -1,89 +0,0 @@
1
- /**
2
- * Content Security Policy helpers for MCP Apps HTML resources.
3
- *
4
- * Provides CSP header generation and HTML meta tag injection to protect
5
- * against XSS and unauthorized resource loading in MCP App iframes.
6
- *
7
- * @module lib/server/security/csp
8
- */
9
-
10
- /** Options for generating a CSP header value. */
11
- export interface CspOptions {
12
- /** Additional allowed script sources (e.g. CDN URLs). */
13
- readonly scriptSources?: readonly string[];
14
- /** Additional allowed connect sources (e.g. WebSocket endpoints). */
15
- readonly connectSources?: readonly string[];
16
- /** Additional allowed image sources (e.g. tile servers). */
17
- readonly imgSources?: readonly string[];
18
- /** Additional allowed frame ancestors. */
19
- readonly frameAncestors?: readonly string[];
20
- /**
21
- * Allow `'unsafe-inline'` for scripts and styles (default: true).
22
- * MCP Apps typically need inline scripts/styles for single-file HTML UIs.
23
- */
24
- readonly allowInline?: boolean;
25
- }
26
-
27
- /**
28
- * Build a Content-Security-Policy header value.
29
- *
30
- * Uses `default-src 'none'` as the baseline (deny-all), then explicitly allows
31
- * only what MCP App UIs need. Inline scripts/styles are allowed by default
32
- * since MCP Apps are typically single-file HTML with inline code.
33
- *
34
- * @param options - CSP configuration
35
- * @returns CSP header value string
36
- */
37
- export function buildCspHeader(options: CspOptions = {}): string {
38
- const allowInline = options.allowInline !== false;
39
- const inlineDirective = allowInline ? " 'unsafe-inline'" : "";
40
-
41
- const scriptSrc = [
42
- `'self'${inlineDirective}`,
43
- ...(options.scriptSources ?? []),
44
- ].join(" ");
45
- const connectSrc = ["'self'", ...(options.connectSources ?? [])].join(" ");
46
- const frameAncestors = ["'self'", ...(options.frameAncestors ?? [])].join(
47
- " ",
48
- );
49
-
50
- return [
51
- `default-src 'none'`,
52
- `script-src ${scriptSrc}`,
53
- `style-src 'self'${inlineDirective}`,
54
- `img-src 'self' data: ${(options.imgSources ?? []).join(" ")}`.trim(),
55
- `font-src 'self'`,
56
- `connect-src ${connectSrc}`,
57
- `frame-ancestors ${frameAncestors}`,
58
- `base-uri 'self'`,
59
- ].join("; ");
60
- }
61
-
62
- /**
63
- * Inject a CSP meta tag into HTML content.
64
- *
65
- * Inserts `<meta http-equiv="Content-Security-Policy" content="...">` right
66
- * after the opening `<head>` tag. If no `<head>` tag exists, prepends to content.
67
- *
68
- * This provides CSP enforcement even when HTTP headers are unavailable
69
- * (e.g. STDIO transport where there are no HTTP response headers).
70
- *
71
- * @param html - Original HTML content
72
- * @param cspValue - CSP header value (from buildCspHeader)
73
- * @returns HTML with injected CSP meta tag
74
- */
75
- export function injectCspMetaTag(html: string, cspValue: string): string {
76
- const escaped = cspValue.replace(/"/g, "&quot;");
77
- const metaTag =
78
- `<meta http-equiv="Content-Security-Policy" content="${escaped}">`;
79
-
80
- // Inject right after <head> (case-insensitive, handles attributes)
81
- const headMatch = html.match(/<head[^>]*>/i);
82
- if (headMatch && headMatch.index !== undefined) {
83
- const insertPos = headMatch.index + headMatch[0].length;
84
- return html.slice(0, insertPos) + metaTag + html.slice(insertPos);
85
- }
86
-
87
- // Fallback: prepend to content
88
- return metaTag + html;
89
- }