@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
package/src/types.ts DELETED
@@ -1,907 +0,0 @@
1
- /**
2
- * Type definitions for the MCP Concurrent Server Framework
3
- *
4
- * This module provides TypeScript types for building high-performance
5
- * MCP servers with built-in concurrency control and backpressure.
6
- *
7
- * @module lib/server/types
8
- */
9
-
10
- import type { McpUiToolMeta as McpUiToolMetaBase } from "@modelcontextprotocol/ext-apps";
11
- import type {
12
- ClientCapabilities,
13
- Implementation,
14
- } from "@modelcontextprotocol/sdk/types.js";
15
-
16
- /**
17
- * Rate limit configuration
18
- */
19
- export interface RateLimitOptions {
20
- /** Maximum requests per window */
21
- maxRequests: number;
22
-
23
- /** Time window in milliseconds */
24
- windowMs: number;
25
-
26
- /**
27
- * Function to extract client identifier from request context
28
- * Default: uses "default" for all requests (global rate limit)
29
- */
30
- keyExtractor?: (context: RateLimitContext) => string;
31
-
32
- /**
33
- * Behavior when rate limit is exceeded
34
- * - 'reject': Return error immediately
35
- * - 'wait': Wait for slot with backoff (default)
36
- */
37
- onLimitExceeded?: "reject" | "wait";
38
- }
39
-
40
- /**
41
- * Context passed to rate limit key extractor
42
- */
43
- export interface RateLimitContext {
44
- /** Tool being called */
45
- toolName: string;
46
-
47
- /** Tool arguments */
48
- args: Record<string, unknown>;
49
- }
50
-
51
- /**
52
- * Configuration options for McpApp
53
- */
54
- export interface McpAppOptions {
55
- /** Server name (shown in MCP protocol) */
56
- name: string;
57
-
58
- /** Server version */
59
- version: string;
60
-
61
- /** Maximum concurrent requests (default: 10) */
62
- maxConcurrent?: number;
63
-
64
- /** Backpressure strategy when at capacity (default: 'sleep') */
65
- backpressureStrategy?: "sleep" | "queue" | "reject";
66
-
67
- /** Sleep duration in ms for 'sleep' strategy (default: 10) */
68
- backpressureSleepMs?: number;
69
-
70
- /**
71
- * Rate limiting configuration
72
- * If provided, requests will be rate limited per client
73
- */
74
- rateLimit?: RateLimitOptions;
75
-
76
- /**
77
- * Enable JSON Schema validation for tool arguments (default: false)
78
- * When enabled, validates arguments against tool's inputSchema before execution
79
- */
80
- validateSchema?: boolean;
81
-
82
- /**
83
- * @deprecated No-op as of 0.24.0. The SamplingBridge was removed in the
84
- * MCP 2026-07-28 spec drop. Passing this option has zero effect and emits
85
- * a console warning at startup. Will be removed in 0.25.0.
86
- */
87
- enableSampling?: boolean;
88
-
89
- /**
90
- * Instructions for the LLM on how to use this server's tools.
91
- * Sent in the MCP initialize response. The LLM sees this before any tool call.
92
- */
93
- instructions?: string;
94
-
95
- /**
96
- * @deprecated No-op as of 0.24.0. The SamplingBridge was removed in the
97
- * MCP 2026-07-28 spec drop. Passing this option has zero effect and emits
98
- * a console warning at startup. Will be removed in 0.25.0.
99
- */
100
- samplingClient?: SamplingClient;
101
-
102
- /** Custom logger function (default: console.error) */
103
- logger?: (msg: string) => void;
104
-
105
- /**
106
- * Custom error handler for tool execution errors.
107
- *
108
- * When set, errors thrown by tool handlers are passed to this function.
109
- * Return a message string to produce `{ content: [{type:"text", text: msg}], isError: true }`
110
- * instead of re-throwing. Return null to rethrow as a JSON-RPC error.
111
- *
112
- * Default: undefined (all errors are re-thrown, existing behaviour).
113
- */
114
- toolErrorMapper?: ToolErrorMapper;
115
-
116
- /**
117
- * OAuth2/Bearer authentication configuration.
118
- * When provided, HTTP requests require a valid Bearer token.
119
- * STDIO transport is unaffected (local, no auth needed).
120
- */
121
- auth?: import("./auth/types.js").AuthOptions;
122
-
123
- /**
124
- * Content Security Policy for HTML resources (MCP Apps).
125
- * When provided, injects a CSP `<meta>` tag into HTML content before serving.
126
- * This protects against XSS even in STDIO mode where HTTP headers are unavailable.
127
- *
128
- * @example
129
- * ```typescript
130
- * resourceCsp: { allowInline: true }
131
- * ```
132
- */
133
- resourceCsp?: import("./security/csp.js").CspOptions;
134
-
135
- /**
136
- * Pre-declare the `resources` capability before transport connection.
137
- *
138
- * When true, installs `resources/list` and `resources/read` handlers at
139
- * construction time (before start/startHttp). Resources can then be added
140
- * dynamically after startup via registerResource() without hitting the
141
- * SDK's "Cannot register capabilities after connecting to transport" error.
142
- *
143
- * Use this when resources are discovered asynchronously (e.g., MCP relay/proxy
144
- * that discovers child servers after the stdio handshake).
145
- */
146
- expectResources?: boolean;
147
-
148
- /**
149
- * HTTP transport mode. Only `"stateless"` is supported as of spec 2026-07-28.
150
- *
151
- * Per-request transport: no handshake, no `Mcp-Session-Id`.
152
- * `protocolVersion` is read from
153
- * `params._meta["io.modelcontextprotocol/protocolVersion"]` on every
154
- * request. `GET /mcp` returns 405; use `subscriptions/listen` instead.
155
- */
156
- transport?: "stateless";
157
-
158
- /**
159
- * Cache hints emitted on list and read results (spec 2026-07-28,
160
- * `CacheableResult`, SEP-2549).
161
- *
162
- * `ttlMs` and `cacheScope` are **required** fields of those results, so the
163
- * framework always emits them. The defaults are deliberately inert:
164
- *
165
- * - `ttlMs: 0` — "revalidate every time", the HTTP `max-age=0` equivalent.
166
- * Caching is a per-deployment decision: a server whose tool list is built
167
- * from a live database must not have a stale window chosen for it. Opt in
168
- * with a real value.
169
- * - `cacheScope: "private"` — shared intermediaries must not cache the
170
- * response. Anything else would be unsafe by default here, since results can
171
- * be scoped to the authenticated principal or tenant. Use `"public"` only for
172
- * a server whose lists are genuinely identical for every caller.
173
- */
174
- cache?: {
175
- /** Freshness window in milliseconds. Default `0`. */
176
- ttlMs?: number;
177
- /** Whether shared caches may store the response. Default `"private"`. */
178
- scope?: "public" | "private";
179
- };
180
-
181
- /**
182
- * Authorization key a task is bound to, derived from the request that created it.
183
- *
184
- * A task can only be read, answered or cancelled by a caller whose key matches.
185
- * The default is the authenticated subject, which is right for a
186
- * single-authority deployment and **not enough** for anything that authorizes on
187
- * more than identity: a tenant-scoped server where the same subject may act for
188
- * several tenants needs the tenant in the key, or a task created under one
189
- * tenant stays reachable from another.
190
- *
191
- * The framework cannot derive that itself — tenancy lives in a consumer's own
192
- * middleware — so it is a hook rather than a guess. Return a stable string; it is
193
- * compared verbatim.
194
- *
195
- * **It must derive everything from its two arguments.** `tasks/*` requests do
196
- * not run the middleware pipeline, so anything a middleware injects into the
197
- * pipeline context — the built-in tenant middleware's `tenantId`, for instance —
198
- * is NOT visible here. Read the header, or resolve it yourself; the hook may be
199
- * async precisely so a lookup is possible. A hook that expects pipeline state
200
- * silently sees `undefined` on every call, which collapses every caller onto one
201
- * key.
202
- *
203
- * Returning an empty or non-string value is refused rather than accepted, since
204
- * that is what the obvious implementation yields when the value it reads is
205
- * absent, and accepting it would share tasks between callers.
206
- *
207
- * Called on task creation and on every `tasks/get` / `tasks/update` /
208
- * `tasks/cancel`. It must return the same key for the same caller across those
209
- * calls, or the creator stops being able to reach its own task (fail-closed).
210
- *
211
- * @example
212
- * ```typescript
213
- * taskOwnerKey: (authInfo, request) =>
214
- * `${authInfo?.subject}@${request.headers.get("x-tenant-id")}`
215
- * ```
216
- */
217
- taskOwnerKey?: (
218
- authInfo: import("./auth/types.js").AuthInfo | undefined,
219
- request: Request,
220
- ) => string | Promise<string>;
221
-
222
- /**
223
- * Multi Round-Trip Requests (spec 2026-07-28, SEP-2322).
224
- *
225
- * Configures how `requestState` is protected when a tool handler asks the
226
- * client for input mid-call. Only consulted on the stateless transport with a
227
- * negotiated `2026-07-28`: MRTR replaces the server-initiated request pattern
228
- * that earlier revisions still use, so it has no meaning on the legacy path.
229
- *
230
- * Without `signingKey`, `requestState` travels unprotected and the server logs
231
- * a warning at startup. That is only acceptable when tampering with it can
232
- * cause nothing worse than the request failing.
233
- */
234
- mrtr?: import("./mrtr/mod.js").MrtrOptions;
235
-
236
- /**
237
- * Protocol extensions this server declares (spec 2026-07-28).
238
- *
239
- * Keyed by reverse-DNS extension identifier — e.g.
240
- * `{ "io.modelcontextprotocol/tasks": {} }`. Surfaced under
241
- * `capabilities.extensions` on `server/discover` and `initialize`, and only
242
- * when non-empty: an empty object would assert "no extensions supported",
243
- * which is a claim the framework cannot make on a consumer's behalf.
244
- *
245
- * Declaring an extension here does not implement it — it advertises what the
246
- * consumer has wired up.
247
- */
248
- extensions?: Readonly<Record<string, unknown>>;
249
- }
250
-
251
- // ============================================
252
- // MCP Apps Types (SEP-1865)
253
- // ============================================
254
-
255
- /**
256
- * MCP Apps UI metadata for tools (SEP-1865 + PML extensions)
257
- *
258
- * Extends the base `McpUiToolMeta` from `@modelcontextprotocol/ext-apps`
259
- * (the official MCP Apps contract) with PML-specific `emits`/`accepts`
260
- * fields for cross-UI sync rules. The server narrows/extends the spec type;
261
- * the contract itself is owned upstream by the protocol, not by this repo.
262
- *
263
- * @example
264
- * ```typescript
265
- * const tool: MCPTool = {
266
- * name: "query_table",
267
- * description: "Query database table",
268
- * inputSchema: { ... },
269
- * _meta: {
270
- * ui: {
271
- * resourceUri: "ui://mcp-std/table-viewer",
272
- * emits: ["filter", "select"],
273
- * accepts: ["setData", "highlight"]
274
- * }
275
- * }
276
- * };
277
- * ```
278
- */
279
- export interface McpUiToolMeta extends McpUiToolMetaBase {
280
- /**
281
- * Resource URI for the UI. MUST use ui:// scheme.
282
- * Narrows the optional base field to required for server tools.
283
- * @example "ui://mcp-std/table-viewer"
284
- */
285
- resourceUri: string;
286
-
287
- /**
288
- * Events this UI can emit (PML extension for sync rules)
289
- * Used by PML orchestrator to build cross-UI event routing
290
- * @example ["filter", "select", "sort", "paginate"]
291
- */
292
- emits?: string[];
293
-
294
- /**
295
- * Events this UI can accept (PML extension for sync rules)
296
- * Used by PML orchestrator to build cross-UI event routing
297
- * @example ["setData", "highlight", "scrollTo"]
298
- */
299
- accepts?: string[];
300
- }
301
-
302
- /**
303
- * MCP Tool metadata container.
304
- *
305
- * Carries optional UI hints and routing metadata for MCP Apps (SEP-1865).
306
- */
307
- export interface MCPToolMeta {
308
- /** UI configuration for rendering this tool's output in an MCP App */
309
- ui?: McpUiToolMeta;
310
- }
311
-
312
- /**
313
- * MCP Resource definition for registration
314
- */
315
- export interface MCPResource {
316
- /**
317
- * Resource URI. SHOULD use ui:// scheme for MCP Apps.
318
- * @example "ui://mcp-std/table-viewer"
319
- */
320
- uri: string;
321
-
322
- /** Human-readable name */
323
- name: string;
324
-
325
- /** Description of the resource */
326
- description?: string;
327
-
328
- /** Optional display title, distinct from the protocol-required `name`. */
329
- title?: string;
330
-
331
- /** Optional visual hints advertised in `resources/list`. */
332
- icons?: Array<{
333
- src: string;
334
- mimeType?: string;
335
- sizes?: string[];
336
- theme?: "light" | "dark";
337
- }>;
338
-
339
- /** Optional client-facing resource annotations. */
340
- annotations?: {
341
- audience?: Array<"user" | "assistant">;
342
- priority?: number;
343
- lastModified?: string;
344
- };
345
-
346
- /** Optional protocol/extension metadata advertised in `resources/list`. */
347
- _meta?: Record<string, unknown>;
348
-
349
- /** MIME type, when known before the resource is read. */
350
- mimeType?: string;
351
-
352
- /**
353
- * Byte size of the resource when it is known.
354
- *
355
- * This is an exact byte-size attestation: when supplied, every read must
356
- * return exactly this many UTF-8 bytes for `text`, or decoded bytes for
357
- * `blob`. It is surfaced in `resources/list` so clients can make loading
358
- * decisions before reading. Must be a non-negative safe integer.
359
- */
360
- size?: number;
361
- }
362
-
363
- /**
364
- * Common fields of every resource response.
365
- */
366
- interface ResourceContentBase {
367
- /** URI of the resource. It must exactly match the URI that was requested. */
368
- uri: string;
369
- /** Non-empty MIME type of the content. */
370
- mimeType: string;
371
- /** Optional MCP metadata passed through to the protocol response. */
372
- _meta?: Record<string, unknown>;
373
- }
374
-
375
- /** A UTF-8/text resource response. */
376
- export interface TextResourceContent extends ResourceContentBase {
377
- /** Text payload, including HTML for MCP Apps. */
378
- text: string;
379
- /** Text and blob payloads are mutually exclusive. */
380
- blob?: never;
381
- }
382
-
383
- /** A binary resource response encoded as canonical standard base64. */
384
- export interface BlobResourceContent extends ResourceContentBase {
385
- /** Standard, padded base64 payload. */
386
- blob: string;
387
- /** Text and blob payloads are mutually exclusive. */
388
- text?: never;
389
- }
390
-
391
- /**
392
- * Content returned by a resource handler.
393
- *
394
- * Exactly one payload form is allowed: `text` for text/HTML, or `blob` for
395
- * binary content encoded as canonical standard base64. The framework validates
396
- * the same XOR contract at runtime before writing the response, which keeps
397
- * JavaScript consumers and unchecked handler results on the protocol-safe path.
398
- */
399
- export type ResourceContent = TextResourceContent | BlobResourceContent;
400
-
401
- /**
402
- * Resource handler callback
403
- *
404
- * @param uri - The requested resource URI as URL object
405
- * @returns A text or base64-blob ResourceContent whose URI matches `uri`
406
- *
407
- * @example
408
- * ```typescript
409
- * const handler: ResourceHandler = async (uri) => ({
410
- * uri: uri.toString(),
411
- * mimeType: MCP_APP_MIME_TYPE,
412
- * text: "<html>...</html>"
413
- * });
414
- *
415
- * // For binary content, return `blob` instead of `text`:
416
- * // { uri: uri.toString(), mimeType: "image/png", blob: "iVBORw0KGgo..." }
417
- * ```
418
- */
419
- export type ResourceHandler = (
420
- uri: URL,
421
- ) => Promise<ResourceContent> | ResourceContent;
422
-
423
- /** MCP Apps MIME type constant */
424
- export const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app" as const;
425
-
426
- /** URI scheme for MCP Apps resources */
427
- export const MCP_APP_URI_SCHEME = "ui:" as const;
428
-
429
- /**
430
- * Well-known extension identifier for the MCP Apps protocol.
431
- *
432
- * Clients advertise MCP Apps support by including this key in
433
- * `clientCapabilities.extensions` (per the MCP SDK 1.29 extensions
434
- * feature). Servers read it via {@link getMcpAppsCapability} to decide
435
- * whether to register UI-rendering tools or fall back to text-only.
436
- *
437
- * @see {@link https://github.com/modelcontextprotocol/ext-apps | MCP Apps spec}
438
- */
439
- export const MCP_APPS_EXTENSION_ID = "io.modelcontextprotocol/ui" as const;
440
-
441
- /**
442
- * MCP Apps protocol spec version this package targets.
443
- *
444
- * Matches the dated spec at
445
- * https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx
446
- *
447
- * Bump this constant in the same commit that adopts a newer dated spec.
448
- */
449
- export const MCP_APPS_PROTOCOL_VERSION = "2026-01-26" as const;
450
-
451
- /**
452
- * MCP Apps capability advertised by a client.
453
- *
454
- * Returned by {@link getMcpAppsCapability} after reading
455
- * `clientCapabilities.extensions[MCP_APPS_EXTENSION_ID]`.
456
- *
457
- * The capability object is intentionally minimal — the spec keeps it
458
- * extensible by adding fields rather than removing them, so consumers
459
- * MUST tolerate unknown fields.
460
- */
461
- export interface McpAppsClientCapability {
462
- /**
463
- * MIME types the client can render as MCP Apps.
464
- *
465
- * Typically includes `"text/html;profile=mcp-app"`. An empty or
466
- * absent array means the client advertised support but listed no
467
- * concrete mime types — defensively assume nothing.
468
- */
469
- mimeTypes?: string[];
470
- }
471
-
472
- /**
473
- * Read the MCP Apps capability from a client's advertised capabilities.
474
- *
475
- * Best-effort, defensive reader. Returns `undefined` for any of:
476
- * - `null` / `undefined` input
477
- * - `clientCapabilities` without an `extensions` field
478
- * - `extensions` without the {@link MCP_APPS_EXTENSION_ID} key
479
- * - extension value that is not a plain object (string, number, null, ...)
480
- *
481
- * Malformed `mimeTypes` (wrong type, non-string entries) are silently
482
- * filtered rather than thrown — agents reading this function need a
483
- * predictable contract that never crashes downstream consumers on
484
- * untrusted client data.
485
- *
486
- * **Validation scope:** this function only validates the *type* of
487
- * `mimeTypes` entries (must be string). It does NOT validate that the
488
- * strings look like valid mime types (e.g. empty strings or garbage
489
- * content pass through). Consumers should compare against known
490
- * constants like {@link MCP_APP_MIME_TYPE} via `.includes()` rather
491
- * than treating the array as a generic allowlist.
492
- *
493
- * @param clientCapabilities - The `ClientCapabilities` object from the
494
- * MCP SDK initialize handshake. May be `null` or `undefined` if the
495
- * client never sent capabilities.
496
- * @returns The MCP Apps capability if the client advertised support,
497
- * otherwise `undefined`.
498
- *
499
- * @example
500
- * ```typescript
501
- * const cap = getMcpAppsCapability(client.getClientCapabilities());
502
- * if (cap?.mimeTypes?.includes(MCP_APP_MIME_TYPE)) {
503
- * // register UI-rendering tools
504
- * } else {
505
- * // register text-only fallback tools
506
- * }
507
- * ```
508
- */
509
- export function getMcpAppsCapability(
510
- clientCapabilities:
511
- | (Record<string, unknown> & { extensions?: Record<string, unknown> })
512
- | null
513
- | undefined,
514
- ): McpAppsClientCapability | undefined {
515
- if (clientCapabilities === null || clientCapabilities === undefined) {
516
- return undefined;
517
- }
518
- const extensions = clientCapabilities.extensions;
519
- if (extensions === null || typeof extensions !== "object") {
520
- return undefined;
521
- }
522
- const raw = extensions[MCP_APPS_EXTENSION_ID];
523
- if (raw === null || typeof raw !== "object") {
524
- return undefined;
525
- }
526
- // We have a capability object — extract known fields defensively.
527
- const result: McpAppsClientCapability = {};
528
- const rawMimeTypes = (raw as Record<string, unknown>).mimeTypes;
529
- if (Array.isArray(rawMimeTypes)) {
530
- const validMimeTypes = rawMimeTypes.filter(
531
- (m): m is string => typeof m === "string",
532
- );
533
- if (validMimeTypes.length > 0) {
534
- result.mimeTypes = validMimeTypes;
535
- }
536
- }
537
- return result;
538
- }
539
-
540
- // ============================================
541
- // MCP Tool Types
542
- // ============================================
543
-
544
- /**
545
- * Behavioural hints for model clients (MCP SDK 1.27 ToolAnnotations).
546
- * Passed through in tools/list so hosts can adapt their UI accordingly.
547
- */
548
- export interface ToolAnnotations {
549
- /** Short human-readable title, may differ from tool name */
550
- title?: string;
551
- /** If true, tool has no side-effects and is safe to call speculatively */
552
- readOnlyHint?: boolean;
553
- /** If true, executing may produce irreversible effects */
554
- destructiveHint?: boolean;
555
- /** If true, repeated calls with same args produce same result */
556
- idempotentHint?: boolean;
557
- /** If true, tool may interact with entities outside the MCP system */
558
- openWorldHint?: boolean;
559
- }
560
-
561
- /**
562
- * MCP Tool definition (compatible with MCP protocol)
563
- */
564
- export interface MCPTool {
565
- /** Tool name */
566
- name: string;
567
-
568
- /** Human-readable description */
569
- description: string;
570
-
571
- /** JSON Schema for tool input */
572
- inputSchema: Record<string, unknown>;
573
-
574
- /**
575
- * JSON Schema for the tool's structured output (MCP SDK 1.27).
576
- * Passed through in tools/list so hosts can validate tool results.
577
- */
578
- outputSchema?: Record<string, unknown>;
579
-
580
- /** Behavioural hints passed to model clients */
581
- annotations?: ToolAnnotations;
582
-
583
- /**
584
- * Tool metadata including UI configuration for MCP Apps
585
- * @see McpUiToolMeta
586
- */
587
- _meta?: MCPToolMeta;
588
-
589
- /**
590
- * Required OAuth scopes to call this tool.
591
- * Only enforced when auth is configured on the server.
592
- * If empty or undefined, no scope check is performed.
593
- */
594
- requiredScopes?: string[];
595
- }
596
-
597
- /**
598
- * Tool handler function.
599
- *
600
- * Receives validated arguments and returns a result (or throws).
601
- * The return value is serialised as JSON inside a `text` content block.
602
- *
603
- * **Security**: Never pass `args` values directly to shell commands or SQL.
604
- * Always validate / sanitise inside the handler or via `inputSchema`.
605
- *
606
- * @param args - Validated tool arguments from the MCP client
607
- * @returns Tool result (string, object, or Promise thereof)
608
- *
609
- * @example
610
- * ```typescript
611
- * const handler: ToolHandler = async (args) => {
612
- * const rows = await db.query(args.sql as string);
613
- * return { rows, count: rows.length };
614
- * };
615
- * ```
616
- */
617
- export interface ToolHandlerContext {
618
- readonly toolName: string;
619
- readonly request?: Request;
620
- readonly sessionId?: string;
621
- readonly authInfo?: import("./auth/types.js").AuthInfo;
622
- readonly clientInfo?: Implementation;
623
- readonly clientCapabilities?: ClientCapabilities;
624
-
625
- /**
626
- * Answers to a previous `InputRequiredResult`, keyed by the ids the server
627
- * assigned (spec 2026-07-28 MRTR).
628
- *
629
- * Present only on a retry. Read from `params.inputResponses` — a sibling of
630
- * `_meta`, not a member of it, unlike every other per-request field. Getting
631
- * that wrong yields a silent `undefined` even when the client sent them.
632
- */
633
- readonly inputResponses?: Record<string, unknown>;
634
-
635
- /**
636
- * True when the client echoed a `requestState` that passed integrity
637
- * verification, so the handler may trust this is a legitimate retry of its own
638
- * earlier request.
639
- *
640
- * The token carries no application state — it binds the principal, method,
641
- * argument digest and expiry. Since the digest guarantees the arguments are
642
- * byte-identical to the original call, a handler reconstructs its context from
643
- * those arguments rather than from the token.
644
- */
645
- readonly retryVerified?: boolean;
646
-
647
- /**
648
- * Log level requested for this call (spec 2026-07-28), read from
649
- * `params._meta["io.modelcontextprotocol/logLevel"]`.
650
- *
651
- * `undefined` means the client requested no logging. A handler **MUST NOT**
652
- * emit `notifications/message` in that case — the level is not a filter you
653
- * may default, it is the client's opt-in.
654
- */
655
- readonly logLevel?: import("./middleware/types.js").McpLogLevel;
656
- }
657
-
658
- export type ToolHandler = (
659
- args: Record<string, unknown>,
660
- ctx?: ToolHandlerContext,
661
- ) => Promise<unknown> | unknown;
662
-
663
- /**
664
- * Structured tool result: separates the LLM text summary (content)
665
- * from the machine-readable payload (structuredContent).
666
- *
667
- * When a ToolHandler returns this shape, the framework produces a
668
- * CallToolResult with both `content` and `structuredContent` set,
669
- * keeping heavy data out of the LLM context.
670
- */
671
- export interface StructuredToolResult {
672
- /** Human-readable summary shown in content[0].text */
673
- content: string;
674
- /** Structured data conforming to the tool's outputSchema */
675
- structuredContent: Record<string, unknown>;
676
- }
677
-
678
- /**
679
- * Maps a thrown error to either a business error result (isError: true)
680
- * or signals that the error should be re-thrown as a JSON-RPC error.
681
- *
682
- * @returns A message string to produce `{ isError: true }`, or null to rethrow.
683
- */
684
- export type ToolErrorMapper = (
685
- error: unknown,
686
- toolName: string,
687
- ) => string | null;
688
-
689
- /**
690
- * Sampling client interface — no-op as of 0.24.0. The SamplingBridge was
691
- * removed with MCP 2026-07-28. This type is kept for source compatibility
692
- * only and will be removed in 0.25.0.
693
- *
694
- * @deprecated No-op as of 0.24.0. Will be removed in 0.25.0.
695
- */
696
- export interface SamplingClient {
697
- /**
698
- * Request LLM completion from the client
699
- * @param params - Sampling parameters (messages, tools, etc.)
700
- * @returns Completion result with content and stop reason
701
- */
702
- createMessage(params: SamplingParams): Promise<SamplingResult>;
703
- }
704
-
705
- /**
706
- * Parameters for sampling request — no-op as of 0.24.0.
707
- *
708
- * @deprecated No-op as of 0.24.0. Will be removed in 0.25.0.
709
- */
710
- export interface SamplingParams {
711
- messages: Array<{ role: "user" | "assistant"; content: string }>;
712
- /** Tools available for the agent to use. Client handles execution. */
713
- tools?: Array<{
714
- name: string;
715
- description: string;
716
- inputSchema: Record<string, unknown>;
717
- }>;
718
- /** "auto" = LLM decides, "required" = must use tool, "none" = no tools */
719
- toolChoice?: "auto" | "required" | "none";
720
- maxTokens?: number;
721
- /** Hint for client: max agentic loop iterations */
722
- maxIterations?: number;
723
- /** Tool name patterns to filter (e.g., ['git_*', 'vfs_*']) */
724
- allowedToolPatterns?: string[];
725
- }
726
-
727
- /**
728
- * Result from sampling request — no-op as of 0.24.0.
729
- *
730
- * @deprecated No-op as of 0.24.0. Will be removed in 0.25.0.
731
- */
732
- export interface SamplingResult {
733
- content: Array<{
734
- type: string;
735
- text?: string;
736
- name?: string;
737
- input?: Record<string, unknown>;
738
- }>;
739
- stopReason: "end_turn" | "tool_use" | "max_tokens";
740
- }
741
-
742
- /**
743
- * Queue metrics for monitoring
744
- */
745
- export interface QueueMetrics {
746
- /** Number of requests currently executing */
747
- inFlight: number;
748
-
749
- /** Number of requests waiting in queue */
750
- queued: number;
751
- }
752
-
753
- /**
754
- * Promise resolver for pending requests
755
- */
756
- export interface PromiseResolver<T = unknown> {
757
- resolve: (value: T) => void;
758
- reject: (error: Error) => void;
759
- }
760
-
761
- /**
762
- * Request queue options
763
- */
764
- export interface QueueOptions {
765
- maxConcurrent: number;
766
- strategy: "sleep" | "queue" | "reject";
767
- sleepMs: number;
768
- }
769
-
770
- // ============================================
771
- // HTTP Server Types
772
- // ============================================
773
-
774
- /**
775
- * Context passed to HTTP rate limit key extractor
776
- */
777
- export interface HttpRateLimitContext {
778
- /** Client IP address (from x-forwarded-for/x-real-ip) */
779
- ip: string;
780
-
781
- /** HTTP method */
782
- method: string;
783
-
784
- /** HTTP path (e.g. /mcp) */
785
- path: string;
786
-
787
- /** HTTP headers */
788
- headers: Headers;
789
-
790
- /** MCP session ID, if present */
791
- sessionId?: string;
792
- }
793
-
794
- /**
795
- * HTTP rate limit configuration
796
- */
797
- export interface HttpRateLimitOptions {
798
- /** Maximum requests per window */
799
- maxRequests: number;
800
-
801
- /** Time window in milliseconds */
802
- windowMs: number;
803
-
804
- /**
805
- * Function to extract client identifier from HTTP context
806
- * Default: uses IP address
807
- */
808
- keyExtractor?: (context: HttpRateLimitContext) => string;
809
-
810
- /**
811
- * Behavior when rate limit is exceeded
812
- * - 'reject': Return error immediately
813
- * - 'wait': Wait for slot with backoff
814
- */
815
- onLimitExceeded?: "reject" | "wait";
816
- }
817
-
818
- /**
819
- * Options for starting an HTTP server
820
- */
821
- // Re-exported from the runtime port so consumers can import the canonical
822
- // fetch handler type from the same module as HttpServerOptions.
823
- export type { FetchHandler } from "./runtime/types.js";
824
- import type { FetchHandler } from "./runtime/types.js";
825
-
826
- export interface HttpServerOptions {
827
- /**
828
- * Port to listen on. Ignored when {@link embedded} is `true`.
829
- */
830
- port: number;
831
-
832
- /** Hostname to bind to (default: "0.0.0.0") */
833
- hostname?: string;
834
-
835
- /** Enable CORS (default: true) */
836
- cors?: boolean;
837
-
838
- /**
839
- * Allowed CORS origins (default: "*")
840
- * Use an allowlist in production.
841
- */
842
- corsOrigins?: "*" | string[];
843
-
844
- /**
845
- * Maximum request body size in bytes (default: 1_000_000).
846
- * Set to null to disable the limit.
847
- */
848
- maxBodyBytes?: number | null;
849
-
850
- /**
851
- * Require auth for HTTP mode. If true and auth is not configured, startHttp throws.
852
- */
853
- requireAuth?: boolean;
854
-
855
- /**
856
- * IP-based rate limiting for HTTP endpoints.
857
- */
858
- ipRateLimit?: HttpRateLimitOptions;
859
-
860
- /**
861
- * Custom HTTP routes registered alongside MCP protocol routes.
862
- * Uses Web standard Request/Response (no framework dependency).
863
- */
864
- customRoutes?: Array<{
865
- method: "get" | "post";
866
- path: string;
867
- handler: (req: Request) => Response | Promise<Response>;
868
- }>;
869
-
870
- /**
871
- * Callback when server is ready
872
- * @param info - Server address info
873
- */
874
- onListen?: (info: { hostname: string; port: number }) => void;
875
-
876
- /**
877
- * Embedded mode: skip binding a port and instead surface the Hono fetch
878
- * handler via the {@link embeddedHandlerCallback} option. Used by
879
- * {@link McpApp.getFetchHandler} so consumers (Fresh, Hono,
880
- * Express, etc.) can mount the MCP HTTP stack inside their own server
881
- * without giving up port ownership.
882
- *
883
- * When `true`, `port`, `hostname`, and `onListen` are ignored.
884
- */
885
- embedded?: boolean;
886
-
887
- /**
888
- * Receives the Hono fetch handler when running in embedded mode.
889
- * Required when {@link embedded} is `true`. Called exactly once,
890
- * synchronously, before `startHttp` returns.
891
- *
892
- * Most consumers should use {@link McpApp.getFetchHandler}
893
- * instead of setting this directly.
894
- */
895
- embeddedHandlerCallback?: (handler: FetchHandler) => void;
896
- }
897
-
898
- /**
899
- * HTTP server instance returned by startHttp
900
- */
901
- export interface HttpServerInstance {
902
- /** Shutdown the HTTP server */
903
- shutdown(): Promise<void>;
904
-
905
- /** Server address info */
906
- addr: { hostname: string; port: number };
907
- }