@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.
- package/CHANGELOG.md +1779 -0
- package/LICENSE +21 -0
- package/README.md +15 -4
- package/esm/_dnt.polyfills.d.ts +12 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +15 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts +33 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.js +48 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts +106 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.js +636 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts +67 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.js +1393 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts +44 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.js +117 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.js +103 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.js +32 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.js +96 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.js +159 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.js +14 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.js +10 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.js +22 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.js +29 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.js +19 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.js +30 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.js +10 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.js +14 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.js +9 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.js +81 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.js +20 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts +32 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.js +6 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts +4 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.js +13 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts +51 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.js +53 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts +79 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.js +91 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts +100 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.js +33 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts +111 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.js +104 -0
- package/esm/mod.d.ts +102 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +103 -0
- package/esm/package.json +3 -0
- package/esm/src/auth/as-metadata-proxy.d.ts +112 -0
- package/esm/src/auth/as-metadata-proxy.d.ts.map +1 -0
- package/esm/src/auth/as-metadata-proxy.js +171 -0
- package/esm/src/auth/config.d.ts +117 -0
- package/esm/src/auth/config.d.ts.map +1 -0
- package/esm/src/auth/config.js +219 -0
- package/esm/src/auth/jwt-provider.d.ts +157 -0
- package/esm/src/auth/jwt-provider.d.ts.map +1 -0
- package/esm/src/auth/jwt-provider.js +187 -0
- package/esm/src/auth/middleware.d.ts +61 -0
- package/esm/src/auth/middleware.d.ts.map +1 -0
- package/esm/src/auth/middleware.js +209 -0
- package/esm/src/auth/mod.d.ts +23 -0
- package/esm/src/auth/mod.d.ts.map +1 -0
- package/esm/src/auth/mod.js +27 -0
- package/esm/src/auth/multi-tenant-middleware.d.ts +131 -0
- package/esm/src/auth/multi-tenant-middleware.d.ts.map +1 -0
- package/esm/src/auth/multi-tenant-middleware.js +128 -0
- package/esm/src/auth/presets.d.ts +231 -0
- package/esm/src/auth/presets.d.ts.map +1 -0
- package/esm/src/auth/presets.js +223 -0
- package/{src/auth/provider.ts → esm/src/auth/provider.d.ts} +13 -15
- package/esm/src/auth/provider.d.ts.map +1 -0
- package/esm/src/auth/provider.js +34 -0
- package/esm/src/auth/scope-middleware.d.ts +30 -0
- package/esm/src/auth/scope-middleware.d.ts.map +1 -0
- package/esm/src/auth/scope-middleware.js +48 -0
- package/esm/src/auth/static-token-provider.d.ts +155 -0
- package/esm/src/auth/static-token-provider.d.ts.map +1 -0
- package/esm/src/auth/static-token-provider.js +256 -0
- package/esm/src/auth/types.d.ts +151 -0
- package/esm/src/auth/types.d.ts.map +1 -0
- package/esm/src/auth/types.js +64 -0
- package/esm/src/client-auth/callback-server.d.ts +34 -0
- package/esm/src/client-auth/callback-server.d.ts.map +1 -0
- package/esm/src/client-auth/callback-server.js +141 -0
- package/esm/src/client-auth/client-id-metadata.d.ts +29 -0
- package/esm/src/client-auth/client-id-metadata.d.ts.map +1 -0
- package/esm/src/client-auth/client-id-metadata.js +149 -0
- package/esm/src/client-auth/connect.d.ts +32 -0
- package/esm/src/client-auth/connect.d.ts.map +1 -0
- package/esm/src/client-auth/connect.js +47 -0
- package/esm/src/client-auth/mod.d.ts +19 -0
- package/esm/src/client-auth/mod.d.ts.map +1 -0
- package/{src/client-auth/mod.ts → esm/src/client-auth/mod.js} +1 -26
- package/esm/src/client-auth/provider.d.ts +78 -0
- package/esm/src/client-auth/provider.d.ts.map +1 -0
- package/esm/src/client-auth/provider.js +246 -0
- package/esm/src/client-auth/token-store/file-store.d.ts +20 -0
- package/esm/src/client-auth/token-store/file-store.d.ts.map +1 -0
- package/esm/src/client-auth/token-store/file-store.js +62 -0
- package/esm/src/client-auth/token-store/memory-store.d.ts +14 -0
- package/esm/src/client-auth/token-store/memory-store.d.ts.map +1 -0
- package/esm/src/client-auth/token-store/memory-store.js +25 -0
- package/esm/src/client-auth/types.d.ts +89 -0
- package/esm/src/client-auth/types.d.ts.map +1 -0
- package/esm/src/client-auth/types.js +10 -0
- package/esm/src/concurrency/rate-limiter.d.ts +87 -0
- package/esm/src/concurrency/rate-limiter.d.ts.map +1 -0
- package/esm/src/concurrency/rate-limiter.js +165 -0
- package/esm/src/concurrency/request-queue.d.ts +71 -0
- package/esm/src/concurrency/request-queue.d.ts.map +1 -0
- package/esm/src/concurrency/request-queue.js +128 -0
- package/esm/src/http/body.d.ts +20 -0
- package/esm/src/http/body.d.ts.map +1 -0
- package/esm/src/http/body.js +63 -0
- package/esm/src/http/request-guards.d.ts +54 -0
- package/esm/src/http/request-guards.d.ts.map +1 -0
- package/esm/src/http/request-guards.js +114 -0
- package/esm/src/http/wire.d.ts +26 -0
- package/esm/src/http/wire.d.ts.map +1 -0
- package/{src/http/wire.ts → esm/src/http/wire.js} +13 -19
- package/esm/src/inspector/launcher.d.ts +48 -0
- package/esm/src/inspector/launcher.d.ts.map +1 -0
- package/esm/src/inspector/launcher.js +100 -0
- package/esm/src/mcp-app.d.ts +728 -0
- package/esm/src/mcp-app.d.ts.map +1 -0
- package/esm/src/mcp-app.js +3530 -0
- package/{src/middleware/backpressure.ts → esm/src/middleware/backpressure.d.ts} +2 -14
- package/esm/src/middleware/backpressure.d.ts.map +1 -0
- package/esm/src/middleware/backpressure.js +31 -0
- package/esm/src/middleware/mod.d.ts +11 -0
- package/esm/src/middleware/mod.d.ts.map +1 -0
- package/{src/middleware/mod.ts → esm/src/middleware/mod.js} +0 -10
- package/{src/middleware/rate-limit.ts → esm/src/middleware/rate-limit.d.ts} +2 -25
- package/esm/src/middleware/rate-limit.d.ts.map +1 -0
- package/esm/src/middleware/rate-limit.js +33 -0
- package/esm/src/middleware/runner.d.ts +32 -0
- package/esm/src/middleware/runner.d.ts.map +1 -0
- package/esm/src/middleware/runner.js +49 -0
- package/esm/src/middleware/types.d.ts +76 -0
- package/esm/src/middleware/types.d.ts.map +1 -0
- package/esm/src/middleware/types.js +9 -0
- package/esm/src/middleware/validation.d.ts +24 -0
- package/esm/src/middleware/validation.d.ts.map +1 -0
- package/esm/src/middleware/validation.js +30 -0
- package/esm/src/mrtr/capability-check.d.ts +75 -0
- package/esm/src/mrtr/capability-check.d.ts.map +1 -0
- package/esm/src/mrtr/capability-check.js +233 -0
- package/esm/src/mrtr/mod.d.ts +18 -0
- package/esm/src/mrtr/mod.d.ts.map +1 -0
- package/esm/src/mrtr/mod.js +12 -0
- package/esm/src/mrtr/replay-store.d.ts +50 -0
- package/esm/src/mrtr/replay-store.d.ts.map +1 -0
- package/esm/src/mrtr/replay-store.js +61 -0
- package/esm/src/mrtr/request-state.d.ts +181 -0
- package/esm/src/mrtr/request-state.d.ts.map +1 -0
- package/esm/src/mrtr/request-state.js +313 -0
- package/esm/src/mrtr/retry-guard.d.ts +61 -0
- package/esm/src/mrtr/retry-guard.d.ts.map +1 -0
- package/esm/src/mrtr/retry-guard.js +53 -0
- package/esm/src/mrtr/types.d.ts +99 -0
- package/esm/src/mrtr/types.d.ts.map +1 -0
- package/esm/src/mrtr/types.js +14 -0
- package/esm/src/observability/metrics.d.ts +104 -0
- package/esm/src/observability/metrics.d.ts.map +1 -0
- package/esm/src/observability/metrics.js +207 -0
- package/{src/observability/mod.ts → esm/src/observability/mod.d.ts} +2 -11
- package/esm/src/observability/mod.d.ts.map +1 -0
- package/esm/src/observability/mod.js +11 -0
- package/esm/src/observability/otel.d.ts +73 -0
- package/esm/src/observability/otel.d.ts.map +1 -0
- package/esm/src/observability/otel.js +260 -0
- package/esm/src/runtime/runtime.d.ts +10 -0
- package/esm/src/runtime/runtime.d.ts.map +1 -0
- package/esm/src/runtime/runtime.deno.d.ts +50 -0
- package/esm/src/runtime/runtime.deno.d.ts.map +1 -0
- package/esm/src/runtime/runtime.deno.js +120 -0
- package/{src/runtime/runtime.ts → esm/src/runtime/runtime.js} +5 -14
- package/esm/src/runtime/runtime.node.d.ts +51 -0
- package/esm/src/runtime/runtime.node.d.ts.map +1 -0
- package/esm/src/runtime/runtime.node.js +268 -0
- package/{src/runtime/types.ts → esm/src/runtime/types.d.ts} +28 -51
- package/esm/src/runtime/types.d.ts.map +1 -0
- package/esm/src/runtime/types.js +12 -0
- package/esm/src/security/channel-hmac.d.ts +43 -0
- package/esm/src/security/channel-hmac.d.ts.map +1 -0
- package/{src/security/channel-hmac.ts → esm/src/security/channel-hmac.js} +12 -17
- package/esm/src/security/csp.d.ts +50 -0
- package/esm/src/security/csp.d.ts.map +1 -0
- package/esm/src/security/csp.js +63 -0
- package/esm/src/security/message-signer.d.ts +88 -0
- package/esm/src/security/message-signer.d.ts.map +1 -0
- package/esm/src/security/message-signer.js +166 -0
- package/esm/src/subscriptions/subscription-registry.d.ts +256 -0
- package/esm/src/subscriptions/subscription-registry.d.ts.map +1 -0
- package/esm/src/subscriptions/subscription-registry.js +406 -0
- package/{src/tasks/mod.ts → esm/src/tasks/mod.d.ts} +3 -23
- package/esm/src/tasks/mod.d.ts.map +1 -0
- package/esm/src/tasks/mod.js +11 -0
- package/esm/src/tasks/task-store.d.ts +342 -0
- package/esm/src/tasks/task-store.d.ts.map +1 -0
- package/esm/src/tasks/task-store.js +649 -0
- package/esm/src/transport/request-headers.d.ts +145 -0
- package/esm/src/transport/request-headers.d.ts.map +1 -0
- package/esm/src/transport/request-headers.js +525 -0
- package/esm/src/types.d.ts +776 -0
- package/esm/src/types.d.ts.map +1 -0
- package/esm/src/types.js +92 -0
- package/esm/src/ui/viewer-utils.d.ts +45 -0
- package/esm/src/ui/viewer-utils.d.ts.map +1 -0
- package/esm/src/ui/viewer-utils.js +97 -0
- package/esm/src/validation/schema-validator.d.ts +115 -0
- package/esm/src/validation/schema-validator.d.ts.map +1 -0
- package/esm/src/validation/schema-validator.js +249 -0
- package/package.json +35 -24
- package/mod.ts +0 -302
- package/src/auth/as-metadata-proxy.ts +0 -288
- package/src/auth/config.ts +0 -368
- package/src/auth/jwt-provider.ts +0 -327
- package/src/auth/middleware.ts +0 -257
- package/src/auth/mod.ts +0 -89
- package/src/auth/multi-tenant-middleware.ts +0 -236
- package/src/auth/presets.ts +0 -351
- package/src/auth/scope-middleware.ts +0 -59
- package/src/auth/static-token-provider.ts +0 -197
- package/src/auth/types.ts +0 -207
- package/src/client-auth/callback-server.ts +0 -166
- package/src/client-auth/client-id-metadata.ts +0 -260
- package/src/client-auth/connect.ts +0 -72
- package/src/client-auth/provider.ts +0 -300
- package/src/client-auth/token-store/file-store.ts +0 -73
- package/src/client-auth/token-store/memory-store.ts +0 -32
- package/src/client-auth/types.ts +0 -95
- package/src/concurrency/rate-limiter.ts +0 -190
- package/src/concurrency/request-queue.ts +0 -140
- package/src/http/body.ts +0 -72
- package/src/http/request-guards.ts +0 -137
- package/src/inspector/launcher.ts +0 -131
- package/src/mcp-app.ts +0 -4595
- package/src/middleware/runner.ts +0 -63
- package/src/middleware/types.ts +0 -104
- package/src/middleware/validation.ts +0 -28
- package/src/mrtr/capability-check.ts +0 -303
- package/src/mrtr/mod.ts +0 -54
- package/src/mrtr/replay-store.ts +0 -103
- package/src/mrtr/request-state.ts +0 -435
- package/src/mrtr/retry-guard.ts +0 -110
- package/src/mrtr/types.ts +0 -107
- package/src/observability/metrics.ts +0 -336
- package/src/observability/otel.ts +0 -330
- package/src/runtime/runtime.deno.ts +0 -149
- package/src/runtime/runtime.node.ts +0 -324
- package/src/security/csp.ts +0 -89
- package/src/security/message-signer.ts +0 -223
- package/src/subscriptions/subscription-registry.ts +0 -558
- package/src/tasks/task-store.ts +0 -1014
- package/src/transport/request-headers.ts +0 -661
- package/src/types.ts +0 -908
- package/src/ui/viewer-utils.ts +0 -117
- package/src/validation/schema-validator.ts +0 -307
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth module for McpApp.
|
|
3
|
+
*
|
|
4
|
+
* @module lib/server/auth
|
|
5
|
+
*/
|
|
6
|
+
// HttpsUrl brand factories (0.16.0) — construct branded URL values for
|
|
7
|
+
// `JwtAuthProviderOptions`, `ProtectedResourceMetadata`, and anywhere else
|
|
8
|
+
// that requires a validated absolute HTTP(S) URL.
|
|
9
|
+
export { httpsUrl, tryHttpsUrl } from "./types.js";
|
|
10
|
+
// Provider base class
|
|
11
|
+
export { AuthProvider } from "./provider.js";
|
|
12
|
+
// Middleware and utilities
|
|
13
|
+
export { AuthError, createAuthMiddleware, createForbiddenResponse, createUnauthorizedResponse, extractBearerToken, } from "./middleware.js";
|
|
14
|
+
// Scope enforcement
|
|
15
|
+
export { createScopeMiddleware } from "./scope-middleware.js";
|
|
16
|
+
// Multi-tenant resolution (tenant enforcement on top of auth)
|
|
17
|
+
export { createMultiTenantMiddleware } from "./multi-tenant-middleware.js";
|
|
18
|
+
// JWT Provider
|
|
19
|
+
export { JwtAuthProvider } from "./jwt-provider.js";
|
|
20
|
+
// OIDC Presets
|
|
21
|
+
export { buildJwtAuthProvider, createAuth0AuthProvider, createGitHubAuthProvider, createGoogleAuthProvider, createOIDCAuthProvider, } from "./presets.js";
|
|
22
|
+
// AS Metadata Proxy (DCR discovery for IdPs without native RFC 7591)
|
|
23
|
+
export { createAsMetadataHandler } from "./as-metadata-proxy.js";
|
|
24
|
+
// Config loader (YAML + env)
|
|
25
|
+
export { createAuthProviderFromConfig, loadAuthConfig } from "./config.js";
|
|
26
|
+
// Static Token Provider (opaque pre-shared bearer tokens; no OIDC/JWT infra)
|
|
27
|
+
export { createStaticTokenAuthProvider, StaticTokenAuthProvider, } from "./static-token-provider.js";
|
|
@@ -0,0 +1,131 @@
|
|
|
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 type { Middleware, MiddlewareContext } from "../middleware/types.js";
|
|
28
|
+
/**
|
|
29
|
+
* Result of a tenant resolution attempt.
|
|
30
|
+
*
|
|
31
|
+
* Use `{ ok: true, tenantId }` when the request is valid and the tenant
|
|
32
|
+
* has been identified. Use `{ ok: false, reason }` to reject the request
|
|
33
|
+
* (the reason is passed to `onRejection` for logging but NEVER returned
|
|
34
|
+
* to the client, to avoid leaking tenant topology).
|
|
35
|
+
*/
|
|
36
|
+
export type TenantResolution = {
|
|
37
|
+
ok: true;
|
|
38
|
+
tenantId: string;
|
|
39
|
+
} | {
|
|
40
|
+
ok: false;
|
|
41
|
+
reason: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Resolves and validates the tenant for an incoming MCP request.
|
|
45
|
+
*
|
|
46
|
+
* Implementations typically:
|
|
47
|
+
* 1. Read a tenant hint from the request (subdomain, path, header, …)
|
|
48
|
+
* 2. Read the authoritative tenant from `ctx.authInfo.claims`
|
|
49
|
+
* 3. Validate they match
|
|
50
|
+
* 4. Return the tenant identifier, or a rejection reason
|
|
51
|
+
*
|
|
52
|
+
* @example Subdomain + JWT claim matching
|
|
53
|
+
* ```typescript
|
|
54
|
+
* class SubdomainTenantResolver implements TenantResolver {
|
|
55
|
+
* async resolve(ctx: MiddlewareContext): Promise<TenantResolution> {
|
|
56
|
+
* const host = ctx.request!.headers.get("host") ?? "";
|
|
57
|
+
* const subdomain = host.split(".")[0];
|
|
58
|
+
*
|
|
59
|
+
* const authInfo = ctx.authInfo as AuthInfo;
|
|
60
|
+
* const claim = authInfo.claims?.["urn:my-app:tenant_id"];
|
|
61
|
+
*
|
|
62
|
+
* if (typeof claim !== "string") {
|
|
63
|
+
* return { ok: false, reason: "tenant_id claim missing or not a string" };
|
|
64
|
+
* }
|
|
65
|
+
* if (claim !== subdomain) {
|
|
66
|
+
* return { ok: false, reason: `subdomain=${subdomain} claim=${claim}` };
|
|
67
|
+
* }
|
|
68
|
+
* return { ok: true, tenantId: subdomain };
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export interface TenantResolver {
|
|
74
|
+
/**
|
|
75
|
+
* Resolve the tenant for this request.
|
|
76
|
+
*
|
|
77
|
+
* @param ctx - Middleware context with `ctx.request` and `ctx.authInfo` populated
|
|
78
|
+
* @returns A successful resolution with the tenant id, or a rejection with a reason
|
|
79
|
+
* @throws May throw — throwing is treated identically to returning `{ ok: false }`
|
|
80
|
+
*/
|
|
81
|
+
resolve(ctx: MiddlewareContext): Promise<TenantResolution>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Options for {@link createMultiTenantMiddleware}.
|
|
85
|
+
*/
|
|
86
|
+
export interface MultiTenantMiddlewareOptions {
|
|
87
|
+
/**
|
|
88
|
+
* Called whenever a request is rejected — either because the resolver
|
|
89
|
+
* returned `{ ok: false }`, threw an exception, or returned an empty
|
|
90
|
+
* `tenantId`.
|
|
91
|
+
*
|
|
92
|
+
* Typical use: write an audit log entry for compliance / forensics.
|
|
93
|
+
* The `reason` string may contain sensitive details (tenant ids, claim
|
|
94
|
+
* values) — log it server-side but never expose it to clients.
|
|
95
|
+
*
|
|
96
|
+
* Awaited before the client receives the 401 response, so audit writes
|
|
97
|
+
* are guaranteed to land before the error is observable. Keep it fast —
|
|
98
|
+
* slow callbacks delay the rejection.
|
|
99
|
+
*
|
|
100
|
+
* If this hook itself throws, the exception is **caught and logged to
|
|
101
|
+
* stderr** but NOT rethrown — the client still receives the standard
|
|
102
|
+
* generic `invalid_token` AuthError. A crashing audit hook must never
|
|
103
|
+
* change client-visible behaviour, otherwise a buggy audit path becomes
|
|
104
|
+
* an observable oracle for attackers probing tenant topology.
|
|
105
|
+
*/
|
|
106
|
+
onRejection?: (ctx: MiddlewareContext, reason: string) => void | Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Create a tenant resolution middleware.
|
|
110
|
+
*
|
|
111
|
+
* Pipeline behaviour:
|
|
112
|
+
*
|
|
113
|
+
* - **STDIO transport** (no `ctx.request`) → pass through unchanged. STDIO
|
|
114
|
+
* is a local trusted transport with no meaningful notion of tenant.
|
|
115
|
+
*
|
|
116
|
+
* - **HTTP without `ctx.authInfo`** → throws a configuration error. This
|
|
117
|
+
* indicates the auth middleware is missing from the pipeline. Fail fast
|
|
118
|
+
* rather than silently skipping tenant enforcement.
|
|
119
|
+
*
|
|
120
|
+
* - **HTTP with `ctx.authInfo`** → calls `resolver.resolve(ctx)`:
|
|
121
|
+
* - On success with a non-empty `tenantId`: copies `authInfo`, injects
|
|
122
|
+
* `tenantId`, re-freezes, continues.
|
|
123
|
+
* - On rejection (`ok: false`, thrown, or empty `tenantId`): calls
|
|
124
|
+
* `onRejection`, then throws {@link AuthError}`("invalid_token")` —
|
|
125
|
+
* the client sees a generic 401 with no tenant details leaked.
|
|
126
|
+
*
|
|
127
|
+
* @param resolver - Implementation that maps requests to tenant ids
|
|
128
|
+
* @param options - Optional hooks (notably `onRejection` for audit logging)
|
|
129
|
+
*/
|
|
130
|
+
export declare function createMultiTenantMiddleware(resolver: TenantResolver, options?: MultiTenantMiddlewareOptions): Middleware;
|
|
131
|
+
//# sourceMappingURL=multi-tenant-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-tenant-middleware.d.ts","sourceRoot":"","sources":["../../../src/src/auth/multi-tenant-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAI5E;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC5D;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,CAAC,EAAE,CACZ,GAAG,EAAE,iBAAiB,EACtB,MAAM,EAAE,MAAM,KACX,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE,4BAAiC,GACzC,UAAU,CAuDZ"}
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|