@casys/mcp-server 0.26.1 → 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 +15 -4
  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 -24
  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 -4595
  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 -54
  284. package/src/mrtr/replay-store.ts +0 -103
  285. package/src/mrtr/request-state.ts +0 -435
  286. package/src/mrtr/retry-guard.ts +0 -110
  287. package/src/mrtr/types.ts +0 -107
  288. package/src/observability/metrics.ts +0 -336
  289. package/src/observability/otel.ts +0 -330
  290. package/src/runtime/runtime.deno.ts +0 -149
  291. package/src/runtime/runtime.node.ts +0 -324
  292. package/src/security/csp.ts +0 -89
  293. package/src/security/message-signer.ts +0 -223
  294. package/src/subscriptions/subscription-registry.ts +0 -558
  295. package/src/tasks/task-store.ts +0 -1014
  296. package/src/transport/request-headers.ts +0 -661
  297. package/src/types.ts +0 -908
  298. package/src/ui/viewer-utils.ts +0 -117
  299. package/src/validation/schema-validator.ts +0 -307
@@ -0,0 +1,20 @@
1
+ /**
2
+ * HTTP body reading, with a size ceiling.
3
+ *
4
+ * Extracted from `mcp-app.ts`: these are pure functions over Web APIs with no
5
+ * dependency on `McpApp` state, which is exactly what made them separable when
6
+ * the dispatch code was not. Keeping them here makes them unit-testable without
7
+ * standing up a server.
8
+ *
9
+ * Not re-exported from `mod.ts` — this is internal.
10
+ *
11
+ * @module lib/server/http/body
12
+ */
13
+ /** Default cap on a request body, in bytes. */
14
+ export declare const DEFAULT_MAX_BODY_BYTES = 1000000;
15
+ export declare class BodyTooLargeError extends Error {
16
+ constructor(maxBytes: number);
17
+ }
18
+ export declare function getClientIpFromHeaders(headers: Headers): string;
19
+ export declare function readBodyWithLimit(request: Request, maxBytes: number | null): Promise<Uint8Array>;
20
+ //# sourceMappingURL=body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../../src/src/http/body.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,+CAA+C;AAC/C,eAAO,MAAM,sBAAsB,UAAY,CAAC;AAEhD,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,QAAQ,EAAE,MAAM;CAI7B;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAQ/D;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,GACtB,OAAO,CAAC,UAAU,CAAC,CAmCrB"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * HTTP body reading, with a size ceiling.
3
+ *
4
+ * Extracted from `mcp-app.ts`: these are pure functions over Web APIs with no
5
+ * dependency on `McpApp` state, which is exactly what made them separable when
6
+ * the dispatch code was not. Keeping them here makes them unit-testable without
7
+ * standing up a server.
8
+ *
9
+ * Not re-exported from `mod.ts` — this is internal.
10
+ *
11
+ * @module lib/server/http/body
12
+ */
13
+ /** Default cap on a request body, in bytes. */
14
+ export const DEFAULT_MAX_BODY_BYTES = 1_000_000;
15
+ export class BodyTooLargeError extends Error {
16
+ constructor(maxBytes) {
17
+ super(`Payload too large. Max ${maxBytes} bytes.`);
18
+ this.name = "BodyTooLargeError";
19
+ }
20
+ }
21
+ export function getClientIpFromHeaders(headers) {
22
+ const forwarded = headers.get("x-forwarded-for");
23
+ if (forwarded) {
24
+ return forwarded.split(",")[0]?.trim() || "unknown";
25
+ }
26
+ return headers.get("x-real-ip") ??
27
+ headers.get("cf-connecting-ip") ??
28
+ "unknown";
29
+ }
30
+ export async function readBodyWithLimit(request, maxBytes) {
31
+ const contentLength = request.headers.get("content-length");
32
+ if (maxBytes !== null && contentLength) {
33
+ const length = Number(contentLength);
34
+ if (!Number.isNaN(length) && length > maxBytes) {
35
+ throw new BodyTooLargeError(maxBytes);
36
+ }
37
+ }
38
+ if (!request.body) {
39
+ return new Uint8Array();
40
+ }
41
+ const reader = request.body.getReader();
42
+ const chunks = [];
43
+ let total = 0;
44
+ while (true) {
45
+ const { done, value } = await reader.read();
46
+ if (done)
47
+ break;
48
+ if (!value)
49
+ continue;
50
+ total += value.length;
51
+ if (maxBytes !== null && total > maxBytes) {
52
+ throw new BodyTooLargeError(maxBytes);
53
+ }
54
+ chunks.push(value);
55
+ }
56
+ const body = new Uint8Array(total);
57
+ let offset = 0;
58
+ for (const chunk of chunks) {
59
+ body.set(chunk, offset);
60
+ offset += chunk.length;
61
+ }
62
+ return body;
63
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Request-scoped guards: who is calling, and may they touch this task.
3
+ *
4
+ * Extracted from `mcp-app.ts`. Like `body.ts`, these are pure over their
5
+ * arguments — they read no `McpApp` state — which is what let them move at all.
6
+ * `jsonRpcResponse` stays in `mcp-app.ts` and is passed in rather than imported,
7
+ * so this module has no edge back to the class.
8
+ *
9
+ * Not re-exported from `mod.ts` — internal.
10
+ *
11
+ * @module lib/server/http/request-guards
12
+ */
13
+ import type { AuthInfo } from "../auth/types.js";
14
+ import type { McpAppOptions } from "../types.js";
15
+ /**
16
+ * Principal to bind a `requestState` to.
17
+ *
18
+ * Three cases, only two of which are acceptable:
19
+ *
20
+ * 1. **No auth configured** — every caller shares one authority by definition, so
21
+ * there is no boundary to enforce and the sentinel above is honest about it.
22
+ * The method and argument bindings still apply.
23
+ * 2. **Authenticated with a subject** — the binding separates callers, which is
24
+ * the case it exists for.
25
+ * 3. **Authenticated without a usable subject** — `AuthInfo.subject` falls back to
26
+ * `"unknown"` for a valid token carrying no `sub` claim. The reserved no-auth
27
+ * sentinel is also invalid for authenticated callers. Sealing against either
28
+ * would hide an authority collision. Returns `null` so the caller fails closed.
29
+ */
30
+ export declare function callerPrincipal(authInfo: AuthInfo | undefined): string | null;
31
+ /**
32
+ * Authorization key for a task-related request.
33
+ *
34
+ * Defaults to the authenticated principal. A consumer whose authorization depends
35
+ * on more than identity — a tenant, an organisation, a workspace — supplies
36
+ * `taskOwnerKey` so that dimension becomes part of the key. Without it, binding to
37
+ * the subject alone leaves a task created under one tenant reachable from another
38
+ * by the same user.
39
+ */
40
+ export declare function taskOwnerKeyFor(options: McpAppOptions, authInfo: AuthInfo | undefined, request: Request | undefined, principal: string): Promise<string | null>;
41
+ /** The error to return when `taskOwnerKey` produced an unusable value. */
42
+ export declare function noOwnerKeyError(id: unknown, version: string): Response;
43
+ /** The error to return when no caller boundary can be established. */
44
+ export declare function noPrincipalError(id: unknown, version: string): Response;
45
+ /** Lowercase hex encoding, for the requestState nonce. */
46
+ export declare function bytesToHexLocal(bytes: Uint8Array): string;
47
+ /**
48
+ * Build a JSON-RPC response with an explicit HTTP status.
49
+ *
50
+ * Module-scoped rather than nested in `startHttp`: request-validation helpers on
51
+ * the class need it too, and duplicating the header defaults is how a response
52
+ * ends up missing its Content-Type.
53
+ */
54
+ //# sourceMappingURL=request-guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-guards.d.ts","sourceRoot":"","sources":["../../../src/src/http/request-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAc7E;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkBxB;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,CAmBtE;AAED,sEAAsE;AACtE,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,CAmBvE;AAED,0DAA0D;AAC1D,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEzD;AAED;;;;;;GAMG"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Request-scoped guards: who is calling, and may they touch this task.
3
+ *
4
+ * Extracted from `mcp-app.ts`. Like `body.ts`, these are pure over their
5
+ * arguments — they read no `McpApp` state — which is what let them move at all.
6
+ * `jsonRpcResponse` stays in `mcp-app.ts` and is passed in rather than imported,
7
+ * so this module has no edge back to the class.
8
+ *
9
+ * Not re-exported from `mod.ts` — internal.
10
+ *
11
+ * @module lib/server/http/request-guards
12
+ */
13
+ import { ErrorCode } from "@modelcontextprotocol/sdk/types.js";
14
+ import { jsonRpcResponse, MRTR_NO_AUTH_PRINCIPAL } from "./wire.js";
15
+ /**
16
+ * Principal to bind a `requestState` to.
17
+ *
18
+ * Three cases, only two of which are acceptable:
19
+ *
20
+ * 1. **No auth configured** — every caller shares one authority by definition, so
21
+ * there is no boundary to enforce and the sentinel above is honest about it.
22
+ * The method and argument bindings still apply.
23
+ * 2. **Authenticated with a subject** — the binding separates callers, which is
24
+ * the case it exists for.
25
+ * 3. **Authenticated without a usable subject** — `AuthInfo.subject` falls back to
26
+ * `"unknown"` for a valid token carrying no `sub` claim. The reserved no-auth
27
+ * sentinel is also invalid for authenticated callers. Sealing against either
28
+ * would hide an authority collision. Returns `null` so the caller fails closed.
29
+ */
30
+ export function callerPrincipal(authInfo) {
31
+ if (authInfo === undefined)
32
+ return MRTR_NO_AUTH_PRINCIPAL;
33
+ const subject = authInfo.subject;
34
+ if (subject === undefined || subject === "" || subject === "unknown" ||
35
+ subject === MRTR_NO_AUTH_PRINCIPAL) {
36
+ // `null`, not a throw: the task handlers call this outside any try/catch, so
37
+ // a throw would surface through the POST-level catch as -32700 "Parse error"
38
+ // — a diagnosis pointing nowhere near a misconfigured auth provider. The
39
+ // caller turns this into an explicit error instead.
40
+ return null;
41
+ }
42
+ return subject;
43
+ }
44
+ /**
45
+ * Authorization key for a task-related request.
46
+ *
47
+ * Defaults to the authenticated principal. A consumer whose authorization depends
48
+ * on more than identity — a tenant, an organisation, a workspace — supplies
49
+ * `taskOwnerKey` so that dimension becomes part of the key. Without it, binding to
50
+ * the subject alone leaves a task created under one tenant reachable from another
51
+ * by the same user.
52
+ */
53
+ export async function taskOwnerKeyFor(options, authInfo, request, principal) {
54
+ if (options.taskOwnerKey === undefined || request === undefined) {
55
+ return principal;
56
+ }
57
+ let key;
58
+ try {
59
+ key = await options.taskOwnerKey(authInfo, request);
60
+ }
61
+ catch {
62
+ // A throwing hook is a consumer bug, but it must fail closed and legibly —
63
+ // not escape to the POST-level catch and be reported as -32700 Parse error.
64
+ return null;
65
+ }
66
+ // An empty or non-string key would put every caller under one owner, undoing
67
+ // the isolation the hook exists to provide — and `""` is exactly what the
68
+ // obvious implementation yields when a header is missing. Refuse it rather
69
+ // than silently sharing tasks between callers.
70
+ if (typeof key !== "string" || key.length === 0)
71
+ return null;
72
+ return key;
73
+ }
74
+ /** The error to return when `taskOwnerKey` produced an unusable value. */
75
+ export function noOwnerKeyError(id, version) {
76
+ return jsonRpcResponse({
77
+ jsonrpc: "2.0",
78
+ id,
79
+ error: {
80
+ code: ErrorCode.InternalError,
81
+ message: "taskOwnerKey returned an empty or non-string value, which would place every caller under one owner.",
82
+ data: {
83
+ problem: "invalid_task_owner_key",
84
+ recovery: 'Return a non-empty string. If the value it derives from can be absent, decide explicitly what an anonymous caller\'s key is rather than letting it fall to "".',
85
+ },
86
+ },
87
+ }, 500, { "MCP-Protocol-Version": version });
88
+ }
89
+ /** The error to return when no caller boundary can be established. */
90
+ export function noPrincipalError(id, version) {
91
+ return jsonRpcResponse({
92
+ jsonrpc: "2.0",
93
+ id,
94
+ error: {
95
+ code: ErrorCode.InternalError,
96
+ message: "Server cannot establish a caller identity: the auth provider returned no usable subject for an authenticated request.",
97
+ data: {
98
+ problem: "no_caller_principal",
99
+ recovery: "Configure the auth provider to supply a subject claim, or disable auth if all callers genuinely share one authority.",
100
+ },
101
+ },
102
+ }, 500, { "MCP-Protocol-Version": version });
103
+ }
104
+ /** Lowercase hex encoding, for the requestState nonce. */
105
+ export function bytesToHexLocal(bytes) {
106
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
107
+ }
108
+ /**
109
+ * Build a JSON-RPC response with an explicit HTTP status.
110
+ *
111
+ * Module-scoped rather than nested in `startHttp`: request-validation helpers on
112
+ * the class need it too, and duplicating the header defaults is how a response
113
+ * ends up missing its Content-Type.
114
+ */
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Wire-level primitives shared by the dispatch code and its extracted guards.
3
+ *
4
+ * This module exists to keep `http/request-guards.ts` from importing
5
+ * `mcp-app.ts`, which would be a cycle. It holds only what both need: no state,
6
+ * no `McpApp` reference.
7
+ *
8
+ * Not re-exported from `mod.ts` — internal.
9
+ *
10
+ * @module lib/server/http/wire
11
+ */
12
+ /**
13
+ * Sentinel used when there is no authentication at all.
14
+ *
15
+ * Deliberately not a plausible subject value. Authenticated callers are also
16
+ * checked against this exact value before MRTR or task state is accepted, so a
17
+ * custom provider cannot create an authority collision by returning it.
18
+ */
19
+ export declare const MRTR_NO_AUTH_PRINCIPAL = "\0unauthenticated";
20
+ export declare function jsonRpcResponse(payload: Record<string, unknown>, status: number, headers?: Record<string, string>): Response;
21
+ /**
22
+ * Narrow type-guard: returns true iff `v` is a plain object (not array, not null).
23
+ * Used to safely extract fields from JSON-RPC `params` without unsafe casts.
24
+ */
25
+ export declare function isRecord(v: unknown): v is Record<string, unknown>;
26
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../src/src/http/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,sBAA0B,CAAC;AAE9D,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,QAAQ,CAQV;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEjE"}
@@ -9,33 +9,27 @@
9
9
  *
10
10
  * @module lib/server/http/wire
11
11
  */
12
-
13
12
  /**
14
13
  * Sentinel used when there is no authentication at all.
15
14
  *
16
- * Deliberately not a plausible subject value: the NUL prefix cannot appear in a
17
- * JWT `sub`, so it can never collide with a real principal.
15
+ * Deliberately not a plausible subject value. Authenticated callers are also
16
+ * checked against this exact value before MRTR or task state is accepted, so a
17
+ * custom provider cannot create an authority collision by returning it.
18
18
  */
19
19
  export const MRTR_NO_AUTH_PRINCIPAL = "\u0000unauthenticated";
20
-
21
- export function jsonRpcResponse(
22
- payload: Record<string, unknown>,
23
- status: number,
24
- headers?: Record<string, string>,
25
- ): Response {
26
- return new Response(JSON.stringify(payload), {
27
- status,
28
- headers: {
29
- "Content-Type": "application/json",
30
- ...(headers ?? {}),
31
- },
32
- });
20
+ export function jsonRpcResponse(payload, status, headers) {
21
+ return new Response(JSON.stringify(payload), {
22
+ status,
23
+ headers: {
24
+ "Content-Type": "application/json",
25
+ ...(headers ?? {}),
26
+ },
27
+ });
33
28
  }
34
-
35
29
  /**
36
30
  * Narrow type-guard: returns true iff `v` is a plain object (not array, not null).
37
31
  * Used to safely extract fields from JSON-RPC `params` without unsafe casts.
38
32
  */
39
- export function isRecord(v: unknown): v is Record<string, unknown> {
40
- return typeof v === "object" && v !== null && !Array.isArray(v);
33
+ export function isRecord(v) {
34
+ return typeof v === "object" && v !== null && !Array.isArray(v);
41
35
  }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * MCP Inspector Launcher
3
+ *
4
+ * Launches the official @modelcontextprotocol/inspector to debug
5
+ * and test MCP servers interactively in a browser.
6
+ *
7
+ * Runtime-agnostic: process spawning goes through `node:` builtins, which
8
+ * both Deno (via its Node compat layer) and Node.js support — one code path
9
+ * instead of a per-runtime adapter. The `node:` modules are imported
10
+ * dynamically inside the function bodies so nothing process-related enters
11
+ * the module graph at load time (mod.ts re-exports this module, and its
12
+ * import must stay side-effect free on constrained runtimes like
13
+ * Deno Deploy).
14
+ *
15
+ * Usage from a server script:
16
+ * ```typescript
17
+ * import { launchInspector } from "@casys/mcp-server";
18
+ *
19
+ * if (Deno.args.includes("--inspect")) {
20
+ * await launchInspector("deno", ["run", "--allow-all", "server.ts"]);
21
+ * }
22
+ * ```
23
+ *
24
+ * @module lib/server/inspector/launcher
25
+ */
26
+ /** Options for the MCP Inspector launcher. */
27
+ export interface InspectorOptions {
28
+ /** Port for the inspector web UI (default: 6274) */
29
+ port?: number;
30
+ /** Automatically open the browser (default: true) */
31
+ open?: boolean;
32
+ /** Environment variables to pass to the MCP server process */
33
+ env?: Record<string, string>;
34
+ }
35
+ /**
36
+ * Launch the MCP Inspector to debug a server.
37
+ *
38
+ * Spawns `npx @modelcontextprotocol/inspector` which:
39
+ * 1. Starts a web UI on the given port (default 6274)
40
+ * 2. Proxies stdio to the MCP server subprocess
41
+ * 3. Allows interactive tool calls, resource browsing, etc.
42
+ *
43
+ * @param serverCommand - Command to start the MCP server (e.g. "deno", "node")
44
+ * @param serverArgs - Arguments for the server command (e.g. ["run", "--allow-all", "server.ts"])
45
+ * @param options - Inspector configuration
46
+ */
47
+ export declare function launchInspector(serverCommand: string, serverArgs: string[], options?: InspectorOptions): Promise<void>;
48
+ //# sourceMappingURL=launcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../../../src/src/inspector/launcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,8CAA8C;AAC9C,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,8DAA8D;IAC9D,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAAE,EACpB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,IAAI,CAAC,CAuDf"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * MCP Inspector Launcher
3
+ *
4
+ * Launches the official @modelcontextprotocol/inspector to debug
5
+ * and test MCP servers interactively in a browser.
6
+ *
7
+ * Runtime-agnostic: process spawning goes through `node:` builtins, which
8
+ * both Deno (via its Node compat layer) and Node.js support — one code path
9
+ * instead of a per-runtime adapter. The `node:` modules are imported
10
+ * dynamically inside the function bodies so nothing process-related enters
11
+ * the module graph at load time (mod.ts re-exports this module, and its
12
+ * import must stay side-effect free on constrained runtimes like
13
+ * Deno Deploy).
14
+ *
15
+ * Usage from a server script:
16
+ * ```typescript
17
+ * import { launchInspector } from "@casys/mcp-server";
18
+ *
19
+ * if (Deno.args.includes("--inspect")) {
20
+ * await launchInspector("deno", ["run", "--allow-all", "server.ts"]);
21
+ * }
22
+ * ```
23
+ *
24
+ * @module lib/server/inspector/launcher
25
+ */
26
+ /**
27
+ * Launch the MCP Inspector to debug a server.
28
+ *
29
+ * Spawns `npx @modelcontextprotocol/inspector` which:
30
+ * 1. Starts a web UI on the given port (default 6274)
31
+ * 2. Proxies stdio to the MCP server subprocess
32
+ * 3. Allows interactive tool calls, resource browsing, etc.
33
+ *
34
+ * @param serverCommand - Command to start the MCP server (e.g. "deno", "node")
35
+ * @param serverArgs - Arguments for the server command (e.g. ["run", "--allow-all", "server.ts"])
36
+ * @param options - Inspector configuration
37
+ */
38
+ export async function launchInspector(serverCommand, serverArgs, options) {
39
+ const { spawn } = await import("node:child_process");
40
+ const { env, exit } = await import("node:process");
41
+ const port = options?.port ?? 6274;
42
+ const shouldOpen = options?.open ?? true;
43
+ // Filter out --inspect from args to avoid recursion
44
+ const filteredArgs = serverArgs.filter((a) => a !== "--inspect");
45
+ const inspectorEnv = {
46
+ ...options?.env,
47
+ CLIENT_PORT: String(port),
48
+ };
49
+ console.error(`[mcp-inspector] Starting inspector on http://localhost:${port}`);
50
+ console.error(`[mcp-inspector] Server: ${serverCommand} ${filteredArgs.join(" ")}`);
51
+ // Use npx to run the inspector
52
+ const child = spawn("npx", [
53
+ "-y",
54
+ "@modelcontextprotocol/inspector",
55
+ serverCommand,
56
+ ...filteredArgs,
57
+ ], {
58
+ env: { ...env, ...inspectorEnv },
59
+ stdio: "inherit",
60
+ });
61
+ // Open browser after a short delay
62
+ if (shouldOpen) {
63
+ setTimeout(() => {
64
+ openBrowser(`http://localhost:${port}`).catch(() => {
65
+ // Ignore — user can open manually
66
+ });
67
+ }, 2000);
68
+ }
69
+ // Wait for the inspector process to exit
70
+ const code = await new Promise((resolve, reject) => {
71
+ child.on("error", reject);
72
+ child.on("exit", (exitCode) => resolve(exitCode ?? 1));
73
+ });
74
+ if (code !== 0) {
75
+ console.error(`[mcp-inspector] Inspector exited with code ${code}`);
76
+ exit(code);
77
+ }
78
+ }
79
+ /**
80
+ * Open a URL in the default browser (cross-platform).
81
+ */
82
+ async function openBrowser(url) {
83
+ const { spawn } = await import("node:child_process");
84
+ const { platform } = await import("node:process");
85
+ let cmd;
86
+ if (platform === "darwin") {
87
+ cmd = ["open", url];
88
+ }
89
+ else if (platform === "win32") {
90
+ cmd = ["cmd", "/c", "start", url];
91
+ }
92
+ else {
93
+ cmd = ["xdg-open", url];
94
+ }
95
+ const child = spawn(cmd[0], cmd.slice(1), { stdio: "ignore" });
96
+ await new Promise((resolve, reject) => {
97
+ child.on("error", reject);
98
+ child.on("exit", () => resolve());
99
+ });
100
+ }