@casys/mcp-server 0.27.0 → 0.27.2

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 (253) hide show
  1. package/CHANGELOG.md +18 -1764
  2. package/README.md +21 -631
  3. package/esm/mod.d.ts +1 -102
  4. package/esm/mod.js +1 -103
  5. package/package.json +17 -25
  6. package/esm/_dnt.polyfills.d.ts +0 -12
  7. package/esm/_dnt.polyfills.d.ts.map +0 -1
  8. package/esm/_dnt.polyfills.js +0 -15
  9. package/esm/_dnt.shims.d.ts +0 -2
  10. package/esm/_dnt.shims.d.ts.map +0 -1
  11. package/esm/_dnt.shims.js +0 -57
  12. package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts +0 -33
  13. package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts.map +0 -1
  14. package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.js +0 -48
  15. package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts +0 -106
  16. package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts.map +0 -1
  17. package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.js +0 -636
  18. package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts +0 -67
  19. package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts.map +0 -1
  20. package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.js +0 -1393
  21. package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts +0 -44
  22. package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts.map +0 -1
  23. package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.js +0 -117
  24. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts +0 -3
  25. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts.map +0 -1
  26. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.js +0 -103
  27. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts +0 -3
  28. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts.map +0 -1
  29. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.js +0 -32
  30. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts +0 -3
  31. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts.map +0 -1
  32. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.js +0 -96
  33. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts +0 -3
  34. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts.map +0 -1
  35. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.js +0 -159
  36. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts +0 -3
  37. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts.map +0 -1
  38. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.js +0 -14
  39. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts +0 -3
  40. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts.map +0 -1
  41. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.js +0 -10
  42. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts +0 -3
  43. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts.map +0 -1
  44. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.js +0 -22
  45. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts +0 -3
  46. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts.map +0 -1
  47. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.js +0 -29
  48. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts +0 -3
  49. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts.map +0 -1
  50. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.js +0 -19
  51. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts +0 -3
  52. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts.map +0 -1
  53. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.js +0 -30
  54. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts +0 -3
  55. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts.map +0 -1
  56. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.js +0 -10
  57. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts +0 -3
  58. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts.map +0 -1
  59. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.js +0 -14
  60. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts +0 -3
  61. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts.map +0 -1
  62. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.js +0 -9
  63. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts +0 -3
  64. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts.map +0 -1
  65. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.js +0 -81
  66. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts +0 -3
  67. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts.map +0 -1
  68. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.js +0 -20
  69. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts +0 -32
  70. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts.map +0 -1
  71. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.js +0 -6
  72. package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts +0 -4
  73. package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts.map +0 -1
  74. package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.js +0 -13
  75. package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts +0 -51
  76. package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts.map +0 -1
  77. package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.js +0 -53
  78. package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts +0 -79
  79. package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts.map +0 -1
  80. package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.js +0 -91
  81. package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts +0 -100
  82. package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts.map +0 -1
  83. package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.js +0 -33
  84. package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts +0 -111
  85. package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts.map +0 -1
  86. package/esm/deps/jsr.io/@std/yaml/1.2.0/types.js +0 -104
  87. package/esm/mod.d.ts.map +0 -1
  88. package/esm/package.json +0 -3
  89. package/esm/src/auth/as-metadata-proxy.d.ts +0 -112
  90. package/esm/src/auth/as-metadata-proxy.d.ts.map +0 -1
  91. package/esm/src/auth/as-metadata-proxy.js +0 -171
  92. package/esm/src/auth/config.d.ts +0 -117
  93. package/esm/src/auth/config.d.ts.map +0 -1
  94. package/esm/src/auth/config.js +0 -219
  95. package/esm/src/auth/jwt-provider.d.ts +0 -157
  96. package/esm/src/auth/jwt-provider.d.ts.map +0 -1
  97. package/esm/src/auth/jwt-provider.js +0 -187
  98. package/esm/src/auth/middleware.d.ts +0 -61
  99. package/esm/src/auth/middleware.d.ts.map +0 -1
  100. package/esm/src/auth/middleware.js +0 -209
  101. package/esm/src/auth/mod.d.ts +0 -23
  102. package/esm/src/auth/mod.d.ts.map +0 -1
  103. package/esm/src/auth/mod.js +0 -27
  104. package/esm/src/auth/multi-tenant-middleware.d.ts +0 -131
  105. package/esm/src/auth/multi-tenant-middleware.d.ts.map +0 -1
  106. package/esm/src/auth/multi-tenant-middleware.js +0 -128
  107. package/esm/src/auth/presets.d.ts +0 -231
  108. package/esm/src/auth/presets.d.ts.map +0 -1
  109. package/esm/src/auth/presets.js +0 -223
  110. package/esm/src/auth/provider.d.ts +0 -47
  111. package/esm/src/auth/provider.d.ts.map +0 -1
  112. package/esm/src/auth/provider.js +0 -34
  113. package/esm/src/auth/scope-middleware.d.ts +0 -30
  114. package/esm/src/auth/scope-middleware.d.ts.map +0 -1
  115. package/esm/src/auth/scope-middleware.js +0 -48
  116. package/esm/src/auth/static-token-provider.d.ts +0 -155
  117. package/esm/src/auth/static-token-provider.d.ts.map +0 -1
  118. package/esm/src/auth/static-token-provider.js +0 -256
  119. package/esm/src/auth/types.d.ts +0 -151
  120. package/esm/src/auth/types.d.ts.map +0 -1
  121. package/esm/src/auth/types.js +0 -64
  122. package/esm/src/client-auth/callback-server.d.ts +0 -34
  123. package/esm/src/client-auth/callback-server.d.ts.map +0 -1
  124. package/esm/src/client-auth/callback-server.js +0 -141
  125. package/esm/src/client-auth/client-id-metadata.d.ts +0 -29
  126. package/esm/src/client-auth/client-id-metadata.d.ts.map +0 -1
  127. package/esm/src/client-auth/client-id-metadata.js +0 -149
  128. package/esm/src/client-auth/connect.d.ts +0 -32
  129. package/esm/src/client-auth/connect.d.ts.map +0 -1
  130. package/esm/src/client-auth/connect.js +0 -47
  131. package/esm/src/client-auth/mod.d.ts +0 -19
  132. package/esm/src/client-auth/mod.d.ts.map +0 -1
  133. package/esm/src/client-auth/mod.js +0 -19
  134. package/esm/src/client-auth/provider.d.ts +0 -78
  135. package/esm/src/client-auth/provider.d.ts.map +0 -1
  136. package/esm/src/client-auth/provider.js +0 -246
  137. package/esm/src/client-auth/token-store/file-store.d.ts +0 -20
  138. package/esm/src/client-auth/token-store/file-store.d.ts.map +0 -1
  139. package/esm/src/client-auth/token-store/file-store.js +0 -62
  140. package/esm/src/client-auth/token-store/memory-store.d.ts +0 -14
  141. package/esm/src/client-auth/token-store/memory-store.d.ts.map +0 -1
  142. package/esm/src/client-auth/token-store/memory-store.js +0 -25
  143. package/esm/src/client-auth/types.d.ts +0 -89
  144. package/esm/src/client-auth/types.d.ts.map +0 -1
  145. package/esm/src/client-auth/types.js +0 -10
  146. package/esm/src/concurrency/rate-limiter.d.ts +0 -87
  147. package/esm/src/concurrency/rate-limiter.d.ts.map +0 -1
  148. package/esm/src/concurrency/rate-limiter.js +0 -165
  149. package/esm/src/concurrency/request-queue.d.ts +0 -71
  150. package/esm/src/concurrency/request-queue.d.ts.map +0 -1
  151. package/esm/src/concurrency/request-queue.js +0 -128
  152. package/esm/src/http/body.d.ts +0 -20
  153. package/esm/src/http/body.d.ts.map +0 -1
  154. package/esm/src/http/body.js +0 -63
  155. package/esm/src/http/request-guards.d.ts +0 -54
  156. package/esm/src/http/request-guards.d.ts.map +0 -1
  157. package/esm/src/http/request-guards.js +0 -114
  158. package/esm/src/http/wire.d.ts +0 -26
  159. package/esm/src/http/wire.d.ts.map +0 -1
  160. package/esm/src/http/wire.js +0 -35
  161. package/esm/src/inspector/launcher.d.ts +0 -48
  162. package/esm/src/inspector/launcher.d.ts.map +0 -1
  163. package/esm/src/inspector/launcher.js +0 -100
  164. package/esm/src/mcp-app.d.ts +0 -728
  165. package/esm/src/mcp-app.d.ts.map +0 -1
  166. package/esm/src/mcp-app.js +0 -3530
  167. package/esm/src/middleware/backpressure.d.ts +0 -24
  168. package/esm/src/middleware/backpressure.d.ts.map +0 -1
  169. package/esm/src/middleware/backpressure.js +0 -31
  170. package/esm/src/middleware/mod.d.ts +0 -11
  171. package/esm/src/middleware/mod.d.ts.map +0 -1
  172. package/esm/src/middleware/mod.js +0 -11
  173. package/esm/src/middleware/rate-limit.d.ts +0 -22
  174. package/esm/src/middleware/rate-limit.d.ts.map +0 -1
  175. package/esm/src/middleware/rate-limit.js +0 -33
  176. package/esm/src/middleware/runner.d.ts +0 -32
  177. package/esm/src/middleware/runner.d.ts.map +0 -1
  178. package/esm/src/middleware/runner.js +0 -49
  179. package/esm/src/middleware/types.d.ts +0 -76
  180. package/esm/src/middleware/types.d.ts.map +0 -1
  181. package/esm/src/middleware/types.js +0 -9
  182. package/esm/src/middleware/validation.d.ts +0 -24
  183. package/esm/src/middleware/validation.d.ts.map +0 -1
  184. package/esm/src/middleware/validation.js +0 -30
  185. package/esm/src/mrtr/capability-check.d.ts +0 -75
  186. package/esm/src/mrtr/capability-check.d.ts.map +0 -1
  187. package/esm/src/mrtr/capability-check.js +0 -233
  188. package/esm/src/mrtr/mod.d.ts +0 -18
  189. package/esm/src/mrtr/mod.d.ts.map +0 -1
  190. package/esm/src/mrtr/mod.js +0 -12
  191. package/esm/src/mrtr/replay-store.d.ts +0 -50
  192. package/esm/src/mrtr/replay-store.d.ts.map +0 -1
  193. package/esm/src/mrtr/replay-store.js +0 -61
  194. package/esm/src/mrtr/request-state.d.ts +0 -181
  195. package/esm/src/mrtr/request-state.d.ts.map +0 -1
  196. package/esm/src/mrtr/request-state.js +0 -313
  197. package/esm/src/mrtr/retry-guard.d.ts +0 -61
  198. package/esm/src/mrtr/retry-guard.d.ts.map +0 -1
  199. package/esm/src/mrtr/retry-guard.js +0 -53
  200. package/esm/src/mrtr/types.d.ts +0 -99
  201. package/esm/src/mrtr/types.d.ts.map +0 -1
  202. package/esm/src/mrtr/types.js +0 -14
  203. package/esm/src/observability/metrics.d.ts +0 -104
  204. package/esm/src/observability/metrics.d.ts.map +0 -1
  205. package/esm/src/observability/metrics.js +0 -207
  206. package/esm/src/observability/mod.d.ts +0 -12
  207. package/esm/src/observability/mod.d.ts.map +0 -1
  208. package/esm/src/observability/mod.js +0 -11
  209. package/esm/src/observability/otel.d.ts +0 -73
  210. package/esm/src/observability/otel.d.ts.map +0 -1
  211. package/esm/src/observability/otel.js +0 -260
  212. package/esm/src/runtime/runtime.d.ts +0 -10
  213. package/esm/src/runtime/runtime.d.ts.map +0 -1
  214. package/esm/src/runtime/runtime.deno.d.ts +0 -50
  215. package/esm/src/runtime/runtime.deno.d.ts.map +0 -1
  216. package/esm/src/runtime/runtime.deno.js +0 -120
  217. package/esm/src/runtime/runtime.js +0 -41
  218. package/esm/src/runtime/runtime.node.d.ts +0 -51
  219. package/esm/src/runtime/runtime.node.d.ts.map +0 -1
  220. package/esm/src/runtime/runtime.node.js +0 -268
  221. package/esm/src/runtime/types.d.ts +0 -107
  222. package/esm/src/runtime/types.d.ts.map +0 -1
  223. package/esm/src/runtime/types.js +0 -12
  224. package/esm/src/security/channel-hmac.d.ts +0 -43
  225. package/esm/src/security/channel-hmac.d.ts.map +0 -1
  226. package/esm/src/security/channel-hmac.js +0 -135
  227. package/esm/src/security/csp.d.ts +0 -50
  228. package/esm/src/security/csp.d.ts.map +0 -1
  229. package/esm/src/security/csp.js +0 -63
  230. package/esm/src/security/message-signer.d.ts +0 -88
  231. package/esm/src/security/message-signer.d.ts.map +0 -1
  232. package/esm/src/security/message-signer.js +0 -166
  233. package/esm/src/subscriptions/subscription-registry.d.ts +0 -256
  234. package/esm/src/subscriptions/subscription-registry.d.ts.map +0 -1
  235. package/esm/src/subscriptions/subscription-registry.js +0 -406
  236. package/esm/src/tasks/mod.d.ts +0 -13
  237. package/esm/src/tasks/mod.d.ts.map +0 -1
  238. package/esm/src/tasks/mod.js +0 -11
  239. package/esm/src/tasks/task-store.d.ts +0 -342
  240. package/esm/src/tasks/task-store.d.ts.map +0 -1
  241. package/esm/src/tasks/task-store.js +0 -649
  242. package/esm/src/transport/request-headers.d.ts +0 -145
  243. package/esm/src/transport/request-headers.d.ts.map +0 -1
  244. package/esm/src/transport/request-headers.js +0 -525
  245. package/esm/src/types.d.ts +0 -776
  246. package/esm/src/types.d.ts.map +0 -1
  247. package/esm/src/types.js +0 -92
  248. package/esm/src/ui/viewer-utils.d.ts +0 -45
  249. package/esm/src/ui/viewer-utils.d.ts.map +0 -1
  250. package/esm/src/ui/viewer-utils.js +0 -97
  251. package/esm/src/validation/schema-validator.d.ts +0 -115
  252. package/esm/src/validation/schema-validator.d.ts.map +0 -1
  253. package/esm/src/validation/schema-validator.js +0 -249
@@ -1,128 +0,0 @@
1
- /**
2
- * Multi-tenant resolution middleware for MCP servers.
3
- *
4
- * Extends the auth pipeline with tenant identification and validation.
5
- * Consumers provide a {@link TenantResolver} that knows how to map an
6
- * authenticated request to a tenant identifier — typically by combining
7
- * the HTTP Host header (subdomain-based tenancy) with a custom JWT claim.
8
- *
9
- * The resolved `tenantId` is injected into `ctx.authInfo.tenantId` so
10
- * downstream middlewares and tool handlers can scope data access.
11
- *
12
- * This middleware is **optional**. Single-tenant servers do not need it.
13
- * When used, it MUST be placed AFTER the auth middleware (which populates
14
- * `ctx.authInfo`) and BEFORE the scope middleware and tool handlers.
15
- *
16
- * @example Pipeline wiring
17
- * ```typescript
18
- * server.use(createAuthMiddleware(authProvider));
19
- * server.use(createMultiTenantMiddleware(new MyTenantResolver(), {
20
- * onRejection: (ctx, reason) => auditLog.warn("tenant_reject", { reason }),
21
- * }));
22
- * server.use(createScopeMiddleware(toolScopes));
23
- * ```
24
- *
25
- * @module lib/server/auth/multi-tenant-middleware
26
- */
27
- import { AuthError } from "./middleware.js";
28
- /**
29
- * Create a tenant resolution middleware.
30
- *
31
- * Pipeline behaviour:
32
- *
33
- * - **STDIO transport** (no `ctx.request`) → pass through unchanged. STDIO
34
- * is a local trusted transport with no meaningful notion of tenant.
35
- *
36
- * - **HTTP without `ctx.authInfo`** → throws a configuration error. This
37
- * indicates the auth middleware is missing from the pipeline. Fail fast
38
- * rather than silently skipping tenant enforcement.
39
- *
40
- * - **HTTP with `ctx.authInfo`** → calls `resolver.resolve(ctx)`:
41
- * - On success with a non-empty `tenantId`: copies `authInfo`, injects
42
- * `tenantId`, re-freezes, continues.
43
- * - On rejection (`ok: false`, thrown, or empty `tenantId`): calls
44
- * `onRejection`, then throws {@link AuthError}`("invalid_token")` —
45
- * the client sees a generic 401 with no tenant details leaked.
46
- *
47
- * @param resolver - Implementation that maps requests to tenant ids
48
- * @param options - Optional hooks (notably `onRejection` for audit logging)
49
- */
50
- export function createMultiTenantMiddleware(resolver, options = {}) {
51
- return async (ctx, next) => {
52
- // STDIO transport: no request, tenant routing does not apply
53
- if (!ctx.request) {
54
- return next();
55
- }
56
- // Auth middleware MUST have populated authInfo before we run.
57
- // MiddlewareContext is indexed as `[key: string]: unknown` for extensibility,
58
- // so every auth-aware middleware in this lib casts to the concrete type —
59
- // matches the convention in middleware.ts and scope-middleware.ts.
60
- const authInfo = ctx.authInfo;
61
- if (!authInfo) {
62
- throw new Error("[MultiTenantMiddleware] ctx.authInfo is not set. Ensure auth " +
63
- "middleware is placed BEFORE multi-tenant middleware in the pipeline.");
64
- }
65
- // Resolve the tenant — any failure path collapses to a generic 401
66
- let resolution;
67
- try {
68
- resolution = await resolver.resolve(ctx);
69
- }
70
- catch (err) {
71
- const reason = err instanceof Error ? err.message : String(err);
72
- throw await rejectWithAudit(ctx, reason, options.onRejection);
73
- }
74
- if (!resolution.ok) {
75
- throw await rejectWithAudit(ctx, resolution.reason, options.onRejection);
76
- }
77
- // Defense-in-depth: reject empty string tenantId even when the resolver
78
- // reports success. Some consumers use truthy guards (`if (tenantId)`),
79
- // and an empty string would slip past them without being noticed.
80
- if (!resolution.tenantId) {
81
- throw await rejectWithAudit(ctx, "resolver returned empty tenantId", options.onRejection);
82
- }
83
- // Re-freeze authInfo with tenantId injected. Two reasons for the re-freeze:
84
- // 1. Preserves the immutability guarantee downstream middleware and
85
- // tool handlers rely on — they must never observe a mutable tenantId.
86
- // 2. The original authInfo is already frozen by the auth middleware,
87
- // so in-place mutation is impossible anyway. We must spread-copy.
88
- ctx.authInfo = Object.freeze({
89
- ...authInfo,
90
- tenantId: resolution.tenantId,
91
- });
92
- return next();
93
- };
94
- }
95
- /**
96
- * Run the audit hook (if any) and return a generic `invalid_token` AuthError.
97
- *
98
- * The hook is intentionally shielded with try/catch: a crashing audit hook
99
- * must NEVER change the client-visible response. If the hook throws, the
100
- * audit is lost (logged to stderr as a last resort) but the client still
101
- * receives the standard 401 AuthError — preserving the non-leak guarantee.
102
- *
103
- * @internal
104
- */
105
- async function rejectWithAudit(ctx, reason, onRejection) {
106
- if (onRejection) {
107
- try {
108
- await onRejection(ctx, reason);
109
- }
110
- catch (hookErr) {
111
- // Last-resort logging: stderr is the only safe channel here — we must
112
- // not rethrow (would defeat the non-leak guarantee) and we must not
113
- // silently drop (would leave no trace of an audit failure).
114
- console.error("[MultiTenantMiddleware] onRejection hook threw; audit entry lost:", hookErr);
115
- }
116
- }
117
- return buildAuthError(ctx);
118
- }
119
- /**
120
- * Build a generic `invalid_token` AuthError using the resource metadata URL
121
- * already set by the upstream auth middleware. If the URL is missing (should
122
- * not happen in a well-formed pipeline), fall back to an empty string — the
123
- * AuthError still produces a valid 401 response.
124
- */
125
- function buildAuthError(ctx) {
126
- const metadataUrl = ctx.resourceMetadataUrl ?? "";
127
- return new AuthError("invalid_token", metadataUrl);
128
- }
@@ -1,231 +0,0 @@
1
- /**
2
- * OIDC auth provider presets.
3
- *
4
- * Factory functions for common OIDC providers. Each preset pre-configures
5
- * the issuer, JWKS URI, and authorization server for the provider.
6
- *
7
- * Bridge layer (0.16.0): presets accept raw `string` fields for `resource`,
8
- * `resourceMetadataUrl`, and `authorizationServers`, then wrap them through
9
- * {@link httpsUrl} before passing to the branded {@link JwtAuthProviderOptions}
10
- * constructor. This keeps the YAML/env config pipeline (`createAuthProviderFromConfig`)
11
- * working with raw strings while the core `JwtAuthProvider` API enforces the
12
- * `HttpsUrl` brand at the type level.
13
- *
14
- * @module lib/server/auth/presets
15
- */
16
- import { JwtAuthProvider } from "./jwt-provider.js";
17
- /**
18
- * Base options shared by all presets.
19
- */
20
- export interface PresetOptions {
21
- /** JWT audience (aud claim) */
22
- audience: string;
23
- /**
24
- * RFC 9728 § 2 resource identifier, as a raw string. Presets detect
25
- * whether this is an HTTP(S) URL or an opaque URI and pick the correct
26
- * {@link JwtAuthProviderOptions} branch internally. When opaque, you
27
- * MUST also supply {@link resourceMetadataUrl}.
28
- */
29
- resource: string;
30
- /** Scopes supported by this server */
31
- scopesSupported?: string[];
32
- /**
33
- * Absolute HTTP(S) URL where the `/.well-known/oauth-protected-resource`
34
- * metadata document is served publicly (RFC 9728 § 3). Required when
35
- * `resource` is an opaque URI; optional when `resource` is itself an
36
- * HTTP(S) URL (in which case the preset auto-derives). Empty and
37
- * whitespace-only values are treated as absent.
38
- */
39
- resourceMetadataUrl?: string;
40
- }
41
- /**
42
- * Options for {@link createOIDCAuthProvider}. Unlike 0.15.x where this
43
- * function accepted `JwtAuthProviderOptions` directly, 0.16.0 exposes a
44
- * preset-style interface with raw string fields — the preset wraps them
45
- * through {@link httpsUrl} internally.
46
- *
47
- * BREAKING: callers that previously passed a pre-built
48
- * `JwtAuthProviderOptions` to `createOIDCAuthProvider` must now pass
49
- * raw strings. Migration: just drop the `httpsUrl()` wrappers you'd
50
- * otherwise need at the call site.
51
- */
52
- export interface OIDCPresetOptions extends PresetOptions {
53
- /** OIDC issuer (typically an HTTPS URL) */
54
- issuer: string;
55
- /**
56
- * JWKS URI for signature validation. Defaults to
57
- * `{issuer}/.well-known/jwks.json`.
58
- */
59
- jwksUri?: string;
60
- /**
61
- * Authorization servers, as raw strings. Defaults to `[issuer]` when
62
- * omitted. Each entry must be a valid absolute HTTP(S) URL — the preset
63
- * validates via {@link httpsUrl}.
64
- */
65
- authorizationServers?: string[];
66
- }
67
- /**
68
- * GitHub Actions OIDC provider.
69
- *
70
- * Validates tokens issued by GitHub Actions workflows.
71
- * Issuer: https://token.actions.githubusercontent.com
72
- *
73
- * @example
74
- * ```typescript
75
- * const provider = createGitHubAuthProvider({
76
- * audience: "https://my-mcp.example.com",
77
- * resource: "https://my-mcp.example.com",
78
- * });
79
- * ```
80
- */
81
- export declare function createGitHubAuthProvider(options: PresetOptions): JwtAuthProvider;
82
- /**
83
- * Google OIDC provider.
84
- *
85
- * Validates tokens issued by Google accounts.
86
- * Issuer: https://accounts.google.com
87
- *
88
- * @example
89
- * ```typescript
90
- * const provider = createGoogleAuthProvider({
91
- * audience: "https://my-mcp.example.com",
92
- * resource: "https://my-mcp.example.com",
93
- * });
94
- * ```
95
- */
96
- export declare function createGoogleAuthProvider(options: PresetOptions): JwtAuthProvider;
97
- /**
98
- * Auth0 OIDC provider.
99
- *
100
- * Validates tokens issued by an Auth0 tenant.
101
- * Issuer: https://{domain}/
102
- *
103
- * @example
104
- * ```typescript
105
- * const provider = createAuth0AuthProvider({
106
- * domain: "my-tenant.auth0.com",
107
- * audience: "https://my-mcp.example.com",
108
- * resource: "https://my-mcp.example.com",
109
- * });
110
- * ```
111
- */
112
- export declare function createAuth0AuthProvider(options: PresetOptions & {
113
- domain: string;
114
- }): JwtAuthProvider;
115
- /**
116
- * Generic OIDC provider.
117
- *
118
- * For any OIDC-compliant provider not covered by presets.
119
- *
120
- * @example
121
- * ```typescript
122
- * const provider = createOIDCAuthProvider({
123
- * issuer: "https://my-idp.example.com",
124
- * audience: "https://my-mcp.example.com",
125
- * resource: "https://my-mcp.example.com",
126
- * authorizationServers: ["https://my-idp.example.com"],
127
- * });
128
- * ```
129
- */
130
- export declare function createOIDCAuthProvider(options: OIDCPresetOptions): JwtAuthProvider;
131
- /**
132
- * Raw-string options accepted by {@link buildJwtAuthProvider}. Mirrors
133
- * {@link JwtAuthProviderOptions} but with all URL fields as plain `string`
134
- * instead of {@link HttpsUrl}, and without the `kind` discriminant tag
135
- * (the bridge auto-detects).
136
- *
137
- * Exported for 3rd-party OIDC provider implementations that want to accept
138
- * YAML/env-style raw string config and delegate URL validation to the
139
- * bridge instead of reimplementing it. See `createGitHubAuthProvider`,
140
- * `createGoogleAuthProvider`, `createAuth0AuthProvider`, and
141
- * `createOIDCAuthProvider` for built-in consumers.
142
- */
143
- export interface BuildJwtAuthProviderOptions {
144
- /** JWT issuer (iss claim) */
145
- issuer: string;
146
- /** JWT audience (aud claim) */
147
- audience: string;
148
- /**
149
- * JWKS URI for signature validation. Defaults to
150
- * `{issuer}/.well-known/jwks.json` when omitted.
151
- */
152
- jwksUri?: string;
153
- /**
154
- * Authorization servers that issue valid tokens, as raw strings. Each
155
- * entry must be a valid absolute HTTP(S) URL — the bridge validates
156
- * via {@link httpsUrl} and throws with a preset-named error if invalid.
157
- */
158
- authorizationServers: string[];
159
- /** Scopes supported by this server */
160
- scopesSupported?: string[];
161
- /**
162
- * RFC 9728 § 2 resource identifier, as a raw string. The bridge detects
163
- * whether this is an HTTP(S) URL or an opaque URI and picks the correct
164
- * {@link JwtAuthProviderOptions} branch internally. When opaque, you
165
- * MUST also supply {@link resourceMetadataUrl}.
166
- */
167
- resource: string;
168
- /**
169
- * Absolute HTTP(S) URL where the `/.well-known/oauth-protected-resource`
170
- * metadata document is served publicly (RFC 9728 § 3). Required when
171
- * `resource` is an opaque URI; optional when `resource` is itself an
172
- * HTTP(S) URL. Empty and whitespace-only values are treated as absent.
173
- */
174
- resourceMetadataUrl?: string;
175
- }
176
- /**
177
- * Bridge raw-string options to a fully-constructed `JwtAuthProvider`.
178
- *
179
- * This is the shared validation + DU-branch-selection pathway used by all
180
- * four built-in preset factories (`createGitHubAuthProvider` et al). 0.17.0
181
- * exports it as public API so 3rd-party OIDC provider implementations
182
- * (Keycloak, Zitadel custom, Okta, ...) can reuse the same pathway instead
183
- * of reimplementing URL-vs-opaque detection, `HttpsUrl` wrapping, and
184
- * empty-metadata fall-through.
185
- *
186
- * Rules:
187
- * - `authorizationServers[]`: every entry must be a valid absolute HTTP(S)
188
- * URL. Invalid entries throw with a `[${label}] authorizationServers[i]`
189
- * prefix for pinpointing.
190
- * - `resource`: if parseable as HTTP(S) URL → `UrlResource` branch (metadata
191
- * URL derivable per RFC 9728 § 3.1). Otherwise → `OpaqueResource` branch
192
- * requiring explicit `resourceMetadataUrl`.
193
- * - `resourceMetadataUrl`: empty or whitespace-only strings are treated as
194
- * absent (matches YAML-key-with-no-value semantics from 0.15.1).
195
- *
196
- * @param opts Raw-string options, as from YAML/env config.
197
- * @param label Identifier used in error messages — REQUIRED. Pass your
198
- * factory name so error prefixes point at the actual caller rather than
199
- * the anonymous bridge layer. E.g., `"createKeycloakAuthProvider"`.
200
- * (0.17.0: required, was optional with a misleading default in the
201
- * draft — type-design review recommendation Q4.)
202
- *
203
- * @example Custom OIDC provider factory
204
- * ```typescript
205
- * import { buildJwtAuthProvider, type JwtAuthProvider } from "@casys/mcp-server";
206
- *
207
- * export interface KeycloakPresetOptions {
208
- * keycloakHost: string;
209
- * realm: string;
210
- * audience: string;
211
- * resource: string;
212
- * resourceMetadataUrl?: string;
213
- * }
214
- *
215
- * export function createKeycloakAuthProvider(
216
- * options: KeycloakPresetOptions,
217
- * ): JwtAuthProvider {
218
- * const issuer = `https://${options.keycloakHost}/realms/${options.realm}`;
219
- * return buildJwtAuthProvider({
220
- * issuer,
221
- * audience: options.audience,
222
- * authorizationServers: [issuer],
223
- * jwksUri: `${issuer}/protocol/openid-connect/certs`,
224
- * resource: options.resource,
225
- * resourceMetadataUrl: options.resourceMetadataUrl,
226
- * }, "createKeycloakAuthProvider");
227
- * }
228
- * ```
229
- */
230
- export declare function buildJwtAuthProvider(opts: BuildJwtAuthProviderOptions, label: string): JwtAuthProvider;
231
- //# sourceMappingURL=presets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../../src/src/auth/presets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,aAAa,GACrB,eAAe,CASjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,aAAa,GACrB,eAAe,CAUjB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1C,eAAe,CAWjB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,iBAAiB,GACzB,eAAe,CAUjB;AAMD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,2BAA2B;IAC1C,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,sCAAsC;IACtC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,2BAA2B,EACjC,KAAK,EAAE,MAAM,GACZ,eAAe,CA0DjB"}
@@ -1,223 +0,0 @@
1
- /**
2
- * OIDC auth provider presets.
3
- *
4
- * Factory functions for common OIDC providers. Each preset pre-configures
5
- * the issuer, JWKS URI, and authorization server for the provider.
6
- *
7
- * Bridge layer (0.16.0): presets accept raw `string` fields for `resource`,
8
- * `resourceMetadataUrl`, and `authorizationServers`, then wrap them through
9
- * {@link httpsUrl} before passing to the branded {@link JwtAuthProviderOptions}
10
- * constructor. This keeps the YAML/env config pipeline (`createAuthProviderFromConfig`)
11
- * working with raw strings while the core `JwtAuthProvider` API enforces the
12
- * `HttpsUrl` brand at the type level.
13
- *
14
- * @module lib/server/auth/presets
15
- */
16
- import { JwtAuthProvider } from "./jwt-provider.js";
17
- import { httpsUrl, tryHttpsUrl } from "./types.js";
18
- /**
19
- * GitHub Actions OIDC provider.
20
- *
21
- * Validates tokens issued by GitHub Actions workflows.
22
- * Issuer: https://token.actions.githubusercontent.com
23
- *
24
- * @example
25
- * ```typescript
26
- * const provider = createGitHubAuthProvider({
27
- * audience: "https://my-mcp.example.com",
28
- * resource: "https://my-mcp.example.com",
29
- * });
30
- * ```
31
- */
32
- export function createGitHubAuthProvider(options) {
33
- return buildJwtAuthProvider({
34
- issuer: "https://token.actions.githubusercontent.com",
35
- audience: options.audience,
36
- authorizationServers: ["https://token.actions.githubusercontent.com"],
37
- scopesSupported: options.scopesSupported,
38
- resource: options.resource,
39
- resourceMetadataUrl: options.resourceMetadataUrl,
40
- }, "createGitHubAuthProvider");
41
- }
42
- /**
43
- * Google OIDC provider.
44
- *
45
- * Validates tokens issued by Google accounts.
46
- * Issuer: https://accounts.google.com
47
- *
48
- * @example
49
- * ```typescript
50
- * const provider = createGoogleAuthProvider({
51
- * audience: "https://my-mcp.example.com",
52
- * resource: "https://my-mcp.example.com",
53
- * });
54
- * ```
55
- */
56
- export function createGoogleAuthProvider(options) {
57
- return buildJwtAuthProvider({
58
- issuer: "https://accounts.google.com",
59
- audience: options.audience,
60
- authorizationServers: ["https://accounts.google.com"],
61
- jwksUri: "https://www.googleapis.com/oauth2/v3/certs",
62
- scopesSupported: options.scopesSupported,
63
- resource: options.resource,
64
- resourceMetadataUrl: options.resourceMetadataUrl,
65
- }, "createGoogleAuthProvider");
66
- }
67
- /**
68
- * Auth0 OIDC provider.
69
- *
70
- * Validates tokens issued by an Auth0 tenant.
71
- * Issuer: https://{domain}/
72
- *
73
- * @example
74
- * ```typescript
75
- * const provider = createAuth0AuthProvider({
76
- * domain: "my-tenant.auth0.com",
77
- * audience: "https://my-mcp.example.com",
78
- * resource: "https://my-mcp.example.com",
79
- * });
80
- * ```
81
- */
82
- export function createAuth0AuthProvider(options) {
83
- const issuer = `https://${options.domain}/`;
84
- return buildJwtAuthProvider({
85
- issuer,
86
- audience: options.audience,
87
- authorizationServers: [issuer],
88
- jwksUri: `${issuer}.well-known/jwks.json`,
89
- scopesSupported: options.scopesSupported,
90
- resource: options.resource,
91
- resourceMetadataUrl: options.resourceMetadataUrl,
92
- }, "createAuth0AuthProvider");
93
- }
94
- /**
95
- * Generic OIDC provider.
96
- *
97
- * For any OIDC-compliant provider not covered by presets.
98
- *
99
- * @example
100
- * ```typescript
101
- * const provider = createOIDCAuthProvider({
102
- * issuer: "https://my-idp.example.com",
103
- * audience: "https://my-mcp.example.com",
104
- * resource: "https://my-mcp.example.com",
105
- * authorizationServers: ["https://my-idp.example.com"],
106
- * });
107
- * ```
108
- */
109
- export function createOIDCAuthProvider(options) {
110
- return buildJwtAuthProvider({
111
- issuer: options.issuer,
112
- audience: options.audience,
113
- jwksUri: options.jwksUri,
114
- authorizationServers: options.authorizationServers ?? [options.issuer],
115
- scopesSupported: options.scopesSupported,
116
- resource: options.resource,
117
- resourceMetadataUrl: options.resourceMetadataUrl,
118
- }, "createOIDCAuthProvider");
119
- }
120
- /**
121
- * Bridge raw-string options to a fully-constructed `JwtAuthProvider`.
122
- *
123
- * This is the shared validation + DU-branch-selection pathway used by all
124
- * four built-in preset factories (`createGitHubAuthProvider` et al). 0.17.0
125
- * exports it as public API so 3rd-party OIDC provider implementations
126
- * (Keycloak, Zitadel custom, Okta, ...) can reuse the same pathway instead
127
- * of reimplementing URL-vs-opaque detection, `HttpsUrl` wrapping, and
128
- * empty-metadata fall-through.
129
- *
130
- * Rules:
131
- * - `authorizationServers[]`: every entry must be a valid absolute HTTP(S)
132
- * URL. Invalid entries throw with a `[${label}] authorizationServers[i]`
133
- * prefix for pinpointing.
134
- * - `resource`: if parseable as HTTP(S) URL → `UrlResource` branch (metadata
135
- * URL derivable per RFC 9728 § 3.1). Otherwise → `OpaqueResource` branch
136
- * requiring explicit `resourceMetadataUrl`.
137
- * - `resourceMetadataUrl`: empty or whitespace-only strings are treated as
138
- * absent (matches YAML-key-with-no-value semantics from 0.15.1).
139
- *
140
- * @param opts Raw-string options, as from YAML/env config.
141
- * @param label Identifier used in error messages — REQUIRED. Pass your
142
- * factory name so error prefixes point at the actual caller rather than
143
- * the anonymous bridge layer. E.g., `"createKeycloakAuthProvider"`.
144
- * (0.17.0: required, was optional with a misleading default in the
145
- * draft — type-design review recommendation Q4.)
146
- *
147
- * @example Custom OIDC provider factory
148
- * ```typescript
149
- * import { buildJwtAuthProvider, type JwtAuthProvider } from "@casys/mcp-server";
150
- *
151
- * export interface KeycloakPresetOptions {
152
- * keycloakHost: string;
153
- * realm: string;
154
- * audience: string;
155
- * resource: string;
156
- * resourceMetadataUrl?: string;
157
- * }
158
- *
159
- * export function createKeycloakAuthProvider(
160
- * options: KeycloakPresetOptions,
161
- * ): JwtAuthProvider {
162
- * const issuer = `https://${options.keycloakHost}/realms/${options.realm}`;
163
- * return buildJwtAuthProvider({
164
- * issuer,
165
- * audience: options.audience,
166
- * authorizationServers: [issuer],
167
- * jwksUri: `${issuer}/protocol/openid-connect/certs`,
168
- * resource: options.resource,
169
- * resourceMetadataUrl: options.resourceMetadataUrl,
170
- * }, "createKeycloakAuthProvider");
171
- * }
172
- * ```
173
- */
174
- export function buildJwtAuthProvider(opts, label) {
175
- const wrappedAuthServers = opts.authorizationServers.map((raw, i) => {
176
- try {
177
- return httpsUrl(raw);
178
- }
179
- catch (err) {
180
- throw new Error(`[${label}] authorizationServers[${i}] is not a valid ` +
181
- `HTTP(S) URL: ${err.message}`);
182
- }
183
- });
184
- const explicitMetadata = opts.resourceMetadataUrl &&
185
- opts.resourceMetadataUrl.trim().length > 0
186
- ? httpsUrl(opts.resourceMetadataUrl)
187
- : undefined;
188
- const base = {
189
- issuer: opts.issuer,
190
- audience: opts.audience,
191
- jwksUri: opts.jwksUri,
192
- authorizationServers: wrappedAuthServers,
193
- scopesSupported: opts.scopesSupported,
194
- };
195
- const resourceUrl = tryHttpsUrl(opts.resource);
196
- if (resourceUrl !== null) {
197
- // URL resource branch — metadata URL optional (derivable). 0.17.0 sets
198
- // the explicit `kind: "url"` tag so the DU narrowing in the constructor
199
- // body is structurally sound.
200
- return new JwtAuthProvider({
201
- ...base,
202
- kind: "url",
203
- resource: resourceUrl,
204
- resourceMetadataUrl: explicitMetadata,
205
- });
206
- }
207
- // Opaque resource branch — metadata URL required
208
- if (!explicitMetadata) {
209
- throw new Error(`[${label}] resourceMetadataUrl is required when 'resource' is ` +
210
- `not an HTTP(S) URL (got resource=${JSON.stringify(opts.resource)}). ` +
211
- `Per RFC 9728 § 2, 'resource' can be an opaque URI (e.g., an OIDC ` +
212
- `project ID used as JWT audience); in that case the metadata ` +
213
- `document URL is a separate concept and must be provided explicitly. ` +
214
- `Set 'resourceMetadataUrl' to the HTTPS URL where your ` +
215
- `/.well-known/oauth-protected-resource endpoint is served publicly.`);
216
- }
217
- return new JwtAuthProvider({
218
- ...base,
219
- kind: "opaque",
220
- resource: opts.resource,
221
- resourceMetadataUrl: explicitMetadata,
222
- });
223
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * AuthProvider abstract class.
3
- *
4
- * Abstract class (not interface) for DI compatibility with diod tokens.
5
- * Implement this to provide custom token validation (API keys, opaque tokens, etc.)
6
- *
7
- * @module lib/server/auth/provider
8
- */
9
- import type { AuthInfo, ProtectedResourceMetadata } from "./types.js";
10
- /**
11
- * Base class for authentication providers.
12
- *
13
- * @example
14
- * ```typescript
15
- * class ApiKeyProvider extends AuthProvider {
16
- * async verifyToken(token: string): Promise<AuthInfo | null> {
17
- * const user = await db.findByApiKey(token);
18
- * if (!user) return null;
19
- * return { subject: user.id, scopes: user.scopes };
20
- * }
21
- *
22
- * getResourceMetadata(): ProtectedResourceMetadata {
23
- * return {
24
- * resource: "https://my-mcp.example.com",
25
- * resource_metadata_url:
26
- * "https://my-mcp.example.com/.well-known/oauth-protected-resource",
27
- * authorization_servers: ["https://auth.example.com"],
28
- * bearer_methods_supported: ["header"],
29
- * };
30
- * }
31
- * }
32
- * ```
33
- */
34
- export declare abstract class AuthProvider {
35
- /**
36
- * Validate a token and extract auth information.
37
- *
38
- * @param token - The raw Bearer token string
39
- * @returns AuthInfo if valid, null if invalid/expired
40
- */
41
- abstract verifyToken(token: string): Promise<AuthInfo | null>;
42
- /**
43
- * Return RFC 9728 Protected Resource Metadata for this provider.
44
- */
45
- abstract getResourceMetadata(): ProtectedResourceMetadata;
46
- }
47
- //# sourceMappingURL=provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/src/auth/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,8BAAsB,YAAY;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAE7D;;OAEG;IACH,QAAQ,CAAC,mBAAmB,IAAI,yBAAyB;CAC1D"}
@@ -1,34 +0,0 @@
1
- /**
2
- * AuthProvider abstract class.
3
- *
4
- * Abstract class (not interface) for DI compatibility with diod tokens.
5
- * Implement this to provide custom token validation (API keys, opaque tokens, etc.)
6
- *
7
- * @module lib/server/auth/provider
8
- */
9
- /**
10
- * Base class for authentication providers.
11
- *
12
- * @example
13
- * ```typescript
14
- * class ApiKeyProvider extends AuthProvider {
15
- * async verifyToken(token: string): Promise<AuthInfo | null> {
16
- * const user = await db.findByApiKey(token);
17
- * if (!user) return null;
18
- * return { subject: user.id, scopes: user.scopes };
19
- * }
20
- *
21
- * getResourceMetadata(): ProtectedResourceMetadata {
22
- * return {
23
- * resource: "https://my-mcp.example.com",
24
- * resource_metadata_url:
25
- * "https://my-mcp.example.com/.well-known/oauth-protected-resource",
26
- * authorization_servers: ["https://auth.example.com"],
27
- * bearer_methods_supported: ["header"],
28
- * };
29
- * }
30
- * }
31
- * ```
32
- */
33
- export class AuthProvider {
34
- }