@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 @@
1
+ {"version":3,"file":"client-id-metadata.d.ts","sourceRoot":"","sources":["../../../src/src/client-auth/client-id-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,MAAM,mBAAmB,GAC3B,sBAAsB,GACtB,2BAA2B,GAC3B,qBAAqB,GACrB,kBAAkB,GAClB,mBAAmB,GACnB,wBAAwB,GACxB,mBAAmB,GACnB,4BAA4B,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,oBAAoB,CAAC;AAE9D,qBAAa,eAAgB,SAAQ,KAAK;aAEtB,IAAI,EAAE,mBAAmB;aAEzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;aAChC,QAAQ,EAAE,MAAM;gBAHhB,IAAI,EAAE,mBAAmB,EACzC,OAAO,EAAE,MAAM,EACC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,QAAQ,EAAE,MAAM,EAChC,OAAO,CAAC,EAAE,YAAY;CAKzB;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,EAAE,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;IACrD,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC;IACzB,0BAA0B,EAAE,MAAM,CAAC;IACnC,mFAAmF;IACnF,gBAAgB,EAAE,QAAQ,GAAG,KAAK,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,iBAAiB,GACxB,MAAM,IAAI,gBAAgB,CAE5B;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAyD5E;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,gBAAgB,GACvB,wBAAwB,CA4B1B;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,MAAM,IAAI,gBAAgB,CAgFpC"}
@@ -0,0 +1,149 @@
1
+ export class CimdConfigError extends Error {
2
+ code;
3
+ context;
4
+ recovery;
5
+ constructor(code, message, context, recovery, options) {
6
+ super(message, options);
7
+ this.code = code;
8
+ this.context = context;
9
+ this.recovery = recovery;
10
+ this.name = "CimdConfigError";
11
+ }
12
+ }
13
+ export function isCimdConfig(config) {
14
+ return config.clientRegistration?.method === "client_id_metadata";
15
+ }
16
+ export function resolveClientMode(config) {
17
+ const raw = config;
18
+ const hasClientId = raw.clientId !== undefined;
19
+ const hasClientRegistration = raw.clientRegistration !== undefined;
20
+ if (hasClientId && hasClientRegistration) {
21
+ throw new CimdConfigError("cimd_config_conflict", "OAuth client config cannot include both clientId and clientRegistration", { hasClientId: true, hasClientRegistration: true }, "Choose either static clientId mode or client_id_metadata mode.");
22
+ }
23
+ if (hasClientRegistration) {
24
+ const registration = raw.clientRegistration;
25
+ if (registration === null || typeof registration !== "object" ||
26
+ Array.isArray(registration)) {
27
+ throw new CimdConfigError("cimd_registration_missing", "clientRegistration must be an object with a registration method", { clientRegistration: registration }, 'Provide clientRegistration.method = "client_id_metadata".');
28
+ }
29
+ const method = registration.method;
30
+ if (method === undefined) {
31
+ throw new CimdConfigError("cimd_registration_missing", "clientRegistration.method is required", { method }, 'Provide clientRegistration.method = "client_id_metadata".');
32
+ }
33
+ if (method !== "client_id_metadata") {
34
+ throw new CimdConfigError("cimd_method_invalid", 'Unsupported clientRegistration.method; expected "client_id_metadata"', { method }, 'Set clientRegistration.method to "client_id_metadata".');
35
+ }
36
+ return "client_id_metadata";
37
+ }
38
+ if (typeof raw.clientId !== "string") {
39
+ throw new CimdConfigError("cimd_registration_missing", "OAuth client config requires either clientId or clientRegistration", { hasClientId: false, hasClientRegistration: false }, "Provide clientId for static mode or clientRegistration for CIMD mode.");
40
+ }
41
+ return "static";
42
+ }
43
+ export function buildClientIdMetadataDocument(config) {
44
+ validateCimdClientConfig(config);
45
+ const { clientRegistration } = config;
46
+ const document = {
47
+ ...clientRegistration.metadata?.extra,
48
+ client_uri: clientRegistration.metadata?.client_uri,
49
+ logo_uri: clientRegistration.metadata?.logo_uri,
50
+ contacts: clientRegistration.metadata?.contacts,
51
+ client_id: clientRegistration.clientIdMetadataUrl,
52
+ client_name: config.clientName,
53
+ redirect_uris: [clientRegistration.redirectUri],
54
+ grant_types: ["authorization_code", "refresh_token"],
55
+ response_types: ["code"],
56
+ token_endpoint_auth_method: "none",
57
+ application_type: "native",
58
+ };
59
+ if (config.scopes?.length) {
60
+ document.scope = config.scopes.join(" ");
61
+ }
62
+ for (const key of ["client_uri", "logo_uri", "contacts"]) {
63
+ if (document[key] === undefined) {
64
+ delete document[key];
65
+ }
66
+ }
67
+ return document;
68
+ }
69
+ export function validateCimdClientConfig(config) {
70
+ const mode = resolveClientMode(config);
71
+ if (mode !== "client_id_metadata") {
72
+ throw new CimdConfigError("cimd_registration_missing", "CIMD config requires clientRegistration", { mode }, 'Provide clientRegistration.method = "client_id_metadata".');
73
+ }
74
+ const raw = config;
75
+ const registration = raw.clientRegistration;
76
+ const metadataUrl = registration.clientIdMetadataUrl;
77
+ try {
78
+ if (typeof metadataUrl !== "string") {
79
+ throw new Error("expected string");
80
+ }
81
+ const parsed = new URL(metadataUrl);
82
+ if (parsed.protocol !== "https:") {
83
+ throw new Error("expected https scheme");
84
+ }
85
+ }
86
+ catch (cause) {
87
+ throw new CimdConfigError("cimd_url_invalid", "clientIdMetadataUrl must be an absolute HTTPS URL", { clientIdMetadataUrl: metadataUrl }, "Provide an absolute https:// URL for clientRegistration.clientIdMetadataUrl.", { cause });
88
+ }
89
+ if (typeof raw.callbackPort !== "number" || raw.callbackPort === 0 ||
90
+ !Number.isFinite(raw.callbackPort)) {
91
+ throw new CimdConfigError("cimd_port_unfixed", "CIMD mode requires a fixed callbackPort", { callbackPort: raw.callbackPort }, "Set callbackPort to a fixed non-zero port and publish the same port in redirectUri.");
92
+ }
93
+ if (typeof raw.clientName !== "string" || raw.clientName.trim().length === 0) {
94
+ throw new CimdConfigError("cimd_name_missing", "CIMD mode requires an explicit clientName", { clientName: raw.clientName }, "Set clientName to the user-facing application name for the metadata document.");
95
+ }
96
+ const redirectUri = registration.redirectUri;
97
+ try {
98
+ if (typeof redirectUri !== "string") {
99
+ throw new Error("expected string");
100
+ }
101
+ const parsedRedirect = new URL(redirectUri);
102
+ if (parsedRedirect.protocol !== "http:") {
103
+ throw new Error("redirect scheme must be http");
104
+ }
105
+ if (parsedRedirect.hostname !== "127.0.0.1") {
106
+ throw new Error("redirect host must be 127.0.0.1");
107
+ }
108
+ if (parsedRedirect.pathname !== "/callback") {
109
+ throw new Error("redirect path must be /callback");
110
+ }
111
+ if (parsedRedirect.port !== String(raw.callbackPort)) {
112
+ throw new Error("redirect port differs from callbackPort");
113
+ }
114
+ }
115
+ catch (cause) {
116
+ throw new CimdConfigError("cimd_redirect_mismatch", "redirectUri must match the fixed callbackPort", { redirectUri, callbackPort: raw.callbackPort }, "Set clientRegistration.redirectUri to the exact loopback callback URL that will be used at runtime.", { cause });
117
+ }
118
+ validateExtraMetadataKeys(registration.metadata);
119
+ }
120
+ const RESERVED_METADATA_KEYS = new Set([
121
+ "scope",
122
+ "client_id",
123
+ "client_name",
124
+ "client_uri",
125
+ "logo_uri",
126
+ "contacts",
127
+ "redirect_uris",
128
+ "grant_types",
129
+ "response_types",
130
+ "token_endpoint_auth_method",
131
+ "application_type",
132
+ ]);
133
+ function validateExtraMetadataKeys(metadata) {
134
+ if (metadata === null || typeof metadata !== "object") {
135
+ return;
136
+ }
137
+ const extra = metadata.extra;
138
+ if (extra === undefined) {
139
+ return;
140
+ }
141
+ if (extra === null || typeof extra !== "object" || Array.isArray(extra)) {
142
+ return;
143
+ }
144
+ for (const key of Object.keys(extra)) {
145
+ if (RESERVED_METADATA_KEYS.has(key)) {
146
+ throw new CimdConfigError("cimd_reserved_metadata_key", "clientRegistration.metadata.extra cannot contain reserved metadata keys", { key }, "Move reserved OAuth client metadata fields to their dedicated config fields.");
147
+ }
148
+ }
149
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Sugar helper for preparing an authenticated MCP transport.
3
+ *
4
+ * Wires together OAuthClientProviderImpl with a CallbackServer.
5
+ * The consumer is responsible for creating the StreamableHTTPClientTransport
6
+ * and passing `result.provider` as the `authProvider` option.
7
+ *
8
+ * @module lib/server/client-auth/connect
9
+ */
10
+ import { OAuthClientProviderImpl } from "./provider.js";
11
+ import type { OAuthClientConfig } from "./types.js";
12
+ import { CallbackServer } from "./callback-server.js";
13
+ export interface PrepareOAuthResult {
14
+ /** The configured provider — pass as authProvider to StreamableHTTPClientTransport */
15
+ provider: OAuthClientProviderImpl;
16
+ /** The callback server instance (caller must close on error paths) */
17
+ callbackServer: CallbackServer;
18
+ /** The actual port the callback server is listening on */
19
+ callbackPort: number;
20
+ }
21
+ /**
22
+ * Prepare an OAuth client provider with a running callback server.
23
+ *
24
+ * Usage:
25
+ * ```typescript
26
+ * const { provider, callbackServer } = await prepareOAuthProvider(serverUrl, config);
27
+ * const transport = new StreamableHTTPClientTransport(new URL(serverUrl), { authProvider: provider });
28
+ * await client.connect(transport);
29
+ * ```
30
+ */
31
+ export declare function prepareOAuthProvider(serverUrl: string, config: OAuthClientConfig): Promise<PrepareOAuthResult>;
32
+ //# sourceMappingURL=connect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../src/src/client-auth/connect.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAOtD,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,QAAQ,EAAE,uBAAuB,CAAC;IAClC,sEAAsE;IACtE,cAAc,EAAE,cAAc,CAAC;IAC/B,0DAA0D;IAC1D,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,kBAAkB,CAAC,CA8B7B"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Sugar helper for preparing an authenticated MCP transport.
3
+ *
4
+ * Wires together OAuthClientProviderImpl with a CallbackServer.
5
+ * The consumer is responsible for creating the StreamableHTTPClientTransport
6
+ * and passing `result.provider` as the `authProvider` option.
7
+ *
8
+ * @module lib/server/client-auth/connect
9
+ */
10
+ import { OAuthClientProviderImpl } from "./provider.js";
11
+ import { CallbackServer } from "./callback-server.js";
12
+ import { CimdConfigError, isCimdConfig, resolveClientMode, } from "./client-id-metadata.js";
13
+ /**
14
+ * Prepare an OAuth client provider with a running callback server.
15
+ *
16
+ * Usage:
17
+ * ```typescript
18
+ * const { provider, callbackServer } = await prepareOAuthProvider(serverUrl, config);
19
+ * const transport = new StreamableHTTPClientTransport(new URL(serverUrl), { authProvider: provider });
20
+ * await client.connect(transport);
21
+ * ```
22
+ */
23
+ export async function prepareOAuthProvider(serverUrl, config) {
24
+ const mode = resolveClientMode(config);
25
+ const provider = new OAuthClientProviderImpl(serverUrl, config);
26
+ const callbackServer = new CallbackServer({
27
+ port: config.callbackPort ?? 0,
28
+ hostname: mode === "client_id_metadata" ? "127.0.0.1" : "localhost",
29
+ timeout: config.authTimeout ?? 120_000,
30
+ });
31
+ const { port } = await callbackServer.start();
32
+ if (isCimdConfig(config)) {
33
+ if (port !== config.callbackPort) {
34
+ await callbackServer.close();
35
+ throw new CimdConfigError("cimd_redirect_mismatch", "CIMD callback server bound to a different port than callbackPort", {
36
+ callbackPort: config.callbackPort,
37
+ boundPort: port,
38
+ redirectUri: config.clientRegistration.redirectUri,
39
+ }, "Set callbackPort to the fixed port used by the callback server and publish the same port in redirectUri.");
40
+ }
41
+ provider.setRedirectUrl(config.clientRegistration.redirectUri);
42
+ }
43
+ else {
44
+ provider.setRedirectUrl(`http://localhost:${port}/callback`);
45
+ }
46
+ return { provider, callbackServer, callbackPort: port };
47
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * OAuth client-auth helpers for MCP clients.
3
+ *
4
+ * Includes the local callback server, OAuth client provider wiring, token
5
+ * stores, and Client ID Metadata Document (CIMD) helpers.
6
+ *
7
+ * @module lib/server/client-auth
8
+ */
9
+ export { prepareOAuthProvider } from "./connect.js";
10
+ export type { PrepareOAuthResult } from "./connect.js";
11
+ export { OAuthClientProviderImpl } from "./provider.js";
12
+ export { CallbackServer } from "./callback-server.js";
13
+ export type { CallbackServerOptions } from "./callback-server.js";
14
+ export type { CimdClientConfig, OAuthClientConfig, OAuthClientConfigBase, StaticClientConfig, StoredCredentials, TokenStore, } from "./types.js";
15
+ export { MemoryTokenStore } from "./token-store/memory-store.js";
16
+ export { FileTokenStore } from "./token-store/file-store.js";
17
+ export { buildClientIdMetadataDocument, CimdConfigError, isCimdConfig, } from "./client-id-metadata.js";
18
+ export type { CimdConfigErrorCode, ClientIdMetadataDocument, } from "./client-id-metadata.js";
19
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/client-auth/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAGlE,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,OAAO,EACL,6BAA6B,EAC7B,eAAe,EACf,YAAY,GACb,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,yBAAyB,CAAC"}
@@ -6,39 +6,14 @@
6
6
  *
7
7
  * @module lib/server/client-auth
8
8
  */
9
-
10
9
  // OAuth provider wiring
11
10
  export { prepareOAuthProvider } from "./connect.js";
12
- export type { PrepareOAuthResult } from "./connect.js";
13
-
14
11
  // OAuthClientProvider implementation
15
12
  export { OAuthClientProviderImpl } from "./provider.js";
16
-
17
13
  // Local callback server
18
14
  export { CallbackServer } from "./callback-server.js";
19
- export type { CallbackServerOptions } from "./callback-server.js";
20
-
21
- // Types
22
- export type {
23
- CimdClientConfig,
24
- OAuthClientConfig,
25
- OAuthClientConfigBase,
26
- StaticClientConfig,
27
- StoredCredentials,
28
- TokenStore,
29
- } from "./types.js";
30
-
31
15
  // Token stores
32
16
  export { MemoryTokenStore } from "./token-store/memory-store.js";
33
17
  export { FileTokenStore } from "./token-store/file-store.js";
34
-
35
18
  // Client ID Metadata Documents (CIMD)
36
- export {
37
- buildClientIdMetadataDocument,
38
- CimdConfigError,
39
- isCimdConfig,
40
- } from "./client-id-metadata.js";
41
- export type {
42
- CimdConfigErrorCode,
43
- ClientIdMetadataDocument,
44
- } from "./client-id-metadata.js";
19
+ export { buildClientIdMetadataDocument, CimdConfigError, isCimdConfig, } from "./client-id-metadata.js";
@@ -0,0 +1,78 @@
1
+ /**
2
+ * OAuth client provider implementation.
3
+ *
4
+ * Implements OAuthClientProvider from the MCP SDK for authenticating
5
+ * against OAuth-protected MCP servers. Handles token storage,
6
+ * PKCE flow, and browser-based authorization.
7
+ *
8
+ * @module lib/server/client-auth/provider
9
+ */
10
+ import type { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
11
+ import type { OAuthClientProvider, OAuthDiscoveryState } from "@modelcontextprotocol/sdk/client/auth.js";
12
+ import type { OAuthClientConfig } from "./types.js";
13
+ export declare class OAuthClientProviderImpl implements OAuthClientProvider {
14
+ private serverUrl;
15
+ private config;
16
+ private _codeVerifier;
17
+ private _clientInfo;
18
+ private _redirectUrl;
19
+ /**
20
+ * Issuer the SDK resolved for the request currently being authorized
21
+ * (SEP-2352). Set by {@link saveDiscoveryState}, which `auth()` calls after
22
+ * discovery and before it asks for tokens.
23
+ */
24
+ private _currentIssuer;
25
+ constructor(serverUrl: string, config: OAuthClientConfig);
26
+ get redirectUrl(): string | URL;
27
+ /** Set the redirect URL (called after CallbackServer binds to a port). */
28
+ setRedirectUrl(url: string): void;
29
+ get clientMetadata(): OAuthClientMetadata;
30
+ clientInformation(): Promise<OAuthClientInformationMixed | undefined>;
31
+ saveClientInformation(info: OAuthClientInformationMixed): Promise<void>;
32
+ /**
33
+ * Record the authorization server the SDK just resolved (SEP-2352).
34
+ *
35
+ * `auth()` calls this after RFC 9728 discovery and before {@link tokens},
36
+ * which is what makes the check there possible.
37
+ *
38
+ * The binding is the **discovered URL**, not `metadata.issuer`. That
39
+ * distinction is the whole protection: `issuer` is a field the authorization
40
+ * server publishes about itself, so an attacker's server reached at
41
+ * `https://attacker.example.com` can claim
42
+ * `issuer: "https://as-one.example.com"` and, since SDK 1.29 validates the
43
+ * metadata's shape without checking it against the URL it was fetched from,
44
+ * would be handed the credentials minted by the real AS-one. The URL the
45
+ * client actually resolved is the one thing in this exchange the server
46
+ * cannot forge.
47
+ *
48
+ * RFC 8414 does require `issuer` to match the discovery URL. A mismatch is
49
+ * therefore a broken or hostile authorization server, and it is logged —
50
+ * but nothing here depends on the claim being honest.
51
+ */
52
+ saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
53
+ /**
54
+ * Stored tokens, unless they were issued by a different authorization server.
55
+ *
56
+ * SEP-2352 makes this a MUST, and the reason is concrete rather than
57
+ * bureaucratic. `auth()` hands whatever this returns to
58
+ * `refreshAuthorization(authorizationServerUrl, …)`, where the URL comes from
59
+ * the MCP server's own protected-resource metadata. A server that changes —
60
+ * or is made to advertise — a different authorization server would therefore
61
+ * receive a refresh token minted by the previous one. The client must not let
62
+ * the resource server pick who sees its credentials.
63
+ *
64
+ * The check only runs once an issuer is known, which is the case inside
65
+ * `auth()`. A transport asking for the bearer to attach to an ordinary
66
+ * request has no issuer in hand, and that path is not the exposure: those
67
+ * tokens go to the MCP server they were minted for, not to an authorization
68
+ * server.
69
+ */
70
+ tokens(): Promise<OAuthTokens | undefined>;
71
+ saveTokens(tokens: OAuthTokens): Promise<void>;
72
+ private log;
73
+ redirectToAuthorization(authorizationUrl: URL): Promise<void>;
74
+ saveCodeVerifier(codeVerifier: string): Promise<void>;
75
+ codeVerifier(): Promise<string>;
76
+ invalidateCredentials(scope: "all" | "client" | "tokens" | "verifier" | "discovery"): Promise<void>;
77
+ }
78
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/src/client-auth/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,2BAA2B,EAC3B,mBAAmB,EACnB,WAAW,EACZ,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA0CpD,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,aAAa,CAAM;IAC3B,OAAO,CAAC,WAAW,CAA0C;IAC7D,OAAO,CAAC,YAAY,CAAqB;IACzC;;;;OAIG;IACH,OAAO,CAAC,cAAc,CAAqB;gBAE/B,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;IASxD,IAAI,WAAW,IAAI,MAAM,GAAG,GAAG,CAK9B;IAED,0EAA0E;IAC1E,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAkBjC,IAAI,cAAc,IAAI,mBAAmB,CASxC;IAED,iBAAiB,IAAI,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAarE,qBAAqB,CACnB,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB7D;;;;;;;;;;;;;;;;OAgBG;IACG,MAAM,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAmC1C,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAkCpD,OAAO,CAAC,GAAG;IAIL,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAInE,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrD,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAIzB,qBAAqB,CACzB,KAAK,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,GAC5D,OAAO,CAAC,IAAI,CAAC;CAiBjB"}
@@ -0,0 +1,246 @@
1
+ /**
2
+ * OAuth client provider implementation.
3
+ *
4
+ * Implements OAuthClientProvider from the MCP SDK for authenticating
5
+ * against OAuth-protected MCP servers. Handles token storage,
6
+ * PKCE flow, and browser-based authorization.
7
+ *
8
+ * @module lib/server/client-auth/provider
9
+ */
10
+ import { CimdConfigError, isCimdConfig, resolveClientMode, validateCimdClientConfig, } from "./client-id-metadata.js";
11
+ /**
12
+ * Normalise an authorization server identifier before comparing it.
13
+ *
14
+ * `https://as.example.com` and `https://as.example.com/` name the same server,
15
+ * and so do `HTTPS://AS.Example.com` and an explicit `:443`. Comparing raw
16
+ * strings would read those as a server change and wipe valid credentials on
17
+ * every call — a self-inflicted login loop. Falls back to the raw string if it
18
+ * does not parse, which then simply never matches.
19
+ */
20
+ function canonicalIssuer(value) {
21
+ try {
22
+ return new URL(value).href;
23
+ }
24
+ catch {
25
+ return value;
26
+ }
27
+ }
28
+ /**
29
+ * An authorization server URL, safe to put in a log line.
30
+ *
31
+ * A URL may carry `userinfo` credentials, and a query string may carry a token
32
+ * or an internal identifier. Origin and path are enough to tell an operator
33
+ * which server is involved; the rest is only a way for secrets to reach a log
34
+ * aggregator.
35
+ */
36
+ function redactUrl(value) {
37
+ try {
38
+ const url = new URL(value);
39
+ return `${url.origin}${url.pathname}`;
40
+ }
41
+ catch {
42
+ return "<unparseable url>";
43
+ }
44
+ }
45
+ export class OAuthClientProviderImpl {
46
+ serverUrl;
47
+ config;
48
+ _codeVerifier = "";
49
+ _clientInfo;
50
+ _redirectUrl;
51
+ /**
52
+ * Issuer the SDK resolved for the request currently being authorized
53
+ * (SEP-2352). Set by {@link saveDiscoveryState}, which `auth()` calls after
54
+ * discovery and before it asks for tokens.
55
+ */
56
+ _currentIssuer;
57
+ constructor(serverUrl, config) {
58
+ const mode = resolveClientMode(config);
59
+ if (mode === "client_id_metadata") {
60
+ validateCimdClientConfig(config);
61
+ }
62
+ this.serverUrl = serverUrl;
63
+ this.config = config;
64
+ }
65
+ get redirectUrl() {
66
+ if (isCimdConfig(this.config)) {
67
+ return this.config.clientRegistration.redirectUri;
68
+ }
69
+ return this._redirectUrl ?? "http://localhost:0/callback";
70
+ }
71
+ /** Set the redirect URL (called after CallbackServer binds to a port). */
72
+ setRedirectUrl(url) {
73
+ if (isCimdConfig(this.config)) {
74
+ if (url !== this.config.clientRegistration.redirectUri) {
75
+ throw new CimdConfigError("cimd_redirect_mismatch", "CIMD redirectUrl cannot differ from configured redirectUri", {
76
+ redirectUrl: url,
77
+ configuredRedirectUri: this.config.clientRegistration.redirectUri,
78
+ }, "Use clientRegistration.redirectUri as the runtime redirect URL.");
79
+ }
80
+ return;
81
+ }
82
+ this._redirectUrl = url;
83
+ }
84
+ get clientMetadata() {
85
+ return {
86
+ client_name: this.config.clientName ?? "PML Client",
87
+ redirect_uris: [String(this.redirectUrl)],
88
+ grant_types: ["authorization_code", "refresh_token"],
89
+ response_types: ["code"],
90
+ token_endpoint_auth_method: "none", // public client, PKCE only
91
+ application_type: "native", // loopback CLI/desktop — prevents AS rejection of http://127.0.0.1 redirects
92
+ };
93
+ }
94
+ clientInformation() {
95
+ if (isCimdConfig(this.config)) {
96
+ return Promise.resolve({
97
+ client_id: this.config.clientRegistration.clientIdMetadataUrl,
98
+ });
99
+ }
100
+ return Promise.resolve(this._clientInfo ?? {
101
+ client_id: this.config.clientId,
102
+ });
103
+ }
104
+ saveClientInformation(info) {
105
+ this._clientInfo = info;
106
+ return Promise.resolve();
107
+ }
108
+ /**
109
+ * Record the authorization server the SDK just resolved (SEP-2352).
110
+ *
111
+ * `auth()` calls this after RFC 9728 discovery and before {@link tokens},
112
+ * which is what makes the check there possible.
113
+ *
114
+ * The binding is the **discovered URL**, not `metadata.issuer`. That
115
+ * distinction is the whole protection: `issuer` is a field the authorization
116
+ * server publishes about itself, so an attacker's server reached at
117
+ * `https://attacker.example.com` can claim
118
+ * `issuer: "https://as-one.example.com"` and, since SDK 1.29 validates the
119
+ * metadata's shape without checking it against the URL it was fetched from,
120
+ * would be handed the credentials minted by the real AS-one. The URL the
121
+ * client actually resolved is the one thing in this exchange the server
122
+ * cannot forge.
123
+ *
124
+ * RFC 8414 does require `issuer` to match the discovery URL. A mismatch is
125
+ * therefore a broken or hostile authorization server, and it is logged —
126
+ * but nothing here depends on the claim being honest.
127
+ */
128
+ saveDiscoveryState(state) {
129
+ const resolved = canonicalIssuer(state.authorizationServerUrl);
130
+ const claimed = state.authorizationServerMetadata?.issuer;
131
+ if (claimed !== undefined && canonicalIssuer(claimed) !== resolved) {
132
+ this.log(`authorization server at ${redactUrl(state.authorizationServerUrl)} ` +
133
+ `claims issuer "${redactUrl(claimed)}" ` +
134
+ "(RFC 8414 requires them to match); " +
135
+ "binding credentials to the discovered URL");
136
+ }
137
+ this._currentIssuer = resolved;
138
+ return Promise.resolve();
139
+ }
140
+ /**
141
+ * Stored tokens, unless they were issued by a different authorization server.
142
+ *
143
+ * SEP-2352 makes this a MUST, and the reason is concrete rather than
144
+ * bureaucratic. `auth()` hands whatever this returns to
145
+ * `refreshAuthorization(authorizationServerUrl, …)`, where the URL comes from
146
+ * the MCP server's own protected-resource metadata. A server that changes —
147
+ * or is made to advertise — a different authorization server would therefore
148
+ * receive a refresh token minted by the previous one. The client must not let
149
+ * the resource server pick who sees its credentials.
150
+ *
151
+ * The check only runs once an issuer is known, which is the case inside
152
+ * `auth()`. A transport asking for the bearer to attach to an ordinary
153
+ * request has no issuer in hand, and that path is not the exposure: those
154
+ * tokens go to the MCP server they were minted for, not to an authorization
155
+ * server.
156
+ */
157
+ async tokens() {
158
+ const stored = await this.config.tokenStore.get(this.serverUrl);
159
+ if (!stored)
160
+ return undefined;
161
+ if (this._currentIssuer === undefined)
162
+ return stored.tokens;
163
+ if (stored.authServerUrl === undefined) {
164
+ // Written before this binding existed: nothing proves which authorization
165
+ // server minted them. Treated as unusable rather than trusted once —
166
+ // the whole point is to stop handing credentials to an unverified party,
167
+ // and "probably fine" is the assumption this check exists to remove. The
168
+ // cost is one re-authorization per stored credential, at upgrade time.
169
+ await this.config.tokenStore.delete(this.serverUrl);
170
+ this.log("discarding stored credentials with no recorded issuer (SEP-2352); re-authorization required");
171
+ return undefined;
172
+ }
173
+ if (canonicalIssuer(stored.authServerUrl) !== this._currentIssuer) {
174
+ // A legitimate migration lands here too, and is handled the same way:
175
+ // drop the old credentials and let the flow re-authorize against the new
176
+ // server. What must not happen is the old refresh token travelling there.
177
+ await this.config.tokenStore.delete(this.serverUrl);
178
+ this.log(`authorization server changed for ${redactUrl(this.serverUrl)} ` +
179
+ `(${redactUrl(stored.authServerUrl)} → ` +
180
+ `${redactUrl(this._currentIssuer)}); ` +
181
+ "stored credentials discarded, re-authorization required");
182
+ return undefined;
183
+ }
184
+ return stored.tokens;
185
+ }
186
+ async saveTokens(tokens) {
187
+ // Sequential guard only: keep an existing refresh_token when a later save omits it.
188
+ // This get/set is not atomic; concurrent saves for one serverUrl are unsupported
189
+ // because refresh is serialized by the caller.
190
+ const stored = await this.config.tokenStore.get(this.serverUrl);
191
+ // …but only from the same authorization server. `auth({ authorizationCode })`
192
+ // reaches here without going through `tokens()`, so this is the one path
193
+ // where a credential from a previous issuer can survive: if the code
194
+ // exchange returns no refresh token, carrying the old one over would
195
+ // re-label another server's secret with the new issuer and hand it over on
196
+ // the next refresh. A legacy record has no recorded issuer, so it cannot
197
+ // clear this bar either.
198
+ const inheritable = stored?.authServerUrl !== undefined &&
199
+ this._currentIssuer !== undefined &&
200
+ canonicalIssuer(stored.authServerUrl) === this._currentIssuer;
201
+ const tokensToStore = tokens.refresh_token === undefined &&
202
+ inheritable && stored?.tokens.refresh_token !== undefined
203
+ ? { ...tokens, refresh_token: stored.tokens.refresh_token }
204
+ : tokens;
205
+ await this.config.tokenStore.set(this.serverUrl, {
206
+ serverUrl: this.serverUrl,
207
+ tokens: tokensToStore,
208
+ obtainedAt: Date.now(),
209
+ // Binds the credentials to their minter. Without it every save produces
210
+ // exactly the legacy record `tokens()` has to throw away.
211
+ ...(this._currentIssuer !== undefined
212
+ ? { authServerUrl: this._currentIssuer }
213
+ : {}),
214
+ });
215
+ }
216
+ log(message) {
217
+ this.config.logger?.(`[client-auth] ${message}`);
218
+ }
219
+ async redirectToAuthorization(authorizationUrl) {
220
+ await this.config.openBrowser(authorizationUrl.toString());
221
+ }
222
+ saveCodeVerifier(codeVerifier) {
223
+ this._codeVerifier = codeVerifier;
224
+ return Promise.resolve();
225
+ }
226
+ codeVerifier() {
227
+ return Promise.resolve(this._codeVerifier);
228
+ }
229
+ async invalidateCredentials(scope) {
230
+ if (scope === "all" || scope === "tokens") {
231
+ await this.config.tokenStore.delete(this.serverUrl);
232
+ }
233
+ if (scope === "all" || scope === "verifier") {
234
+ this._codeVerifier = "";
235
+ }
236
+ if (scope === "all" || scope === "client") {
237
+ this._clientInfo = undefined;
238
+ }
239
+ if (scope === "all" || scope === "discovery") {
240
+ // Keeping a stale issuer would make the next `tokens()` compare against
241
+ // an authorization server the SDK has already given up on, and discard
242
+ // credentials that are in fact still valid.
243
+ this._currentIssuer = undefined;
244
+ }
245
+ }
246
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * File-based token store.
3
+ *
4
+ * Stores OAuth credentials as JSON files with restrictive permissions (0o600).
5
+ * One file per MCP server, keyed by SHA-256 hash of the server URL.
6
+ *
7
+ * @module lib/server/client-auth/token-store/file-store
8
+ */
9
+ import type { StoredCredentials, TokenStore } from "../types.js";
10
+ export declare class FileTokenStore implements TokenStore {
11
+ private baseDir;
12
+ constructor(baseDir: string);
13
+ private filePath;
14
+ private ensureDir;
15
+ get(serverUrl: string): Promise<StoredCredentials | null>;
16
+ set(serverUrl: string, credentials: StoredCredentials): Promise<void>;
17
+ delete(serverUrl: string): Promise<void>;
18
+ list(): Promise<string[]>;
19
+ }
20
+ //# sourceMappingURL=file-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-store.d.ts","sourceRoot":"","sources":["../../../../src/src/client-auth/token-store/file-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAiBjE,qBAAa,cAAe,YAAW,UAAU;IACnC,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,MAAM;YAErB,QAAQ;YAKR,SAAS;IAIjB,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAMzD,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrE,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAgBhC"}