@casys/mcp-server 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1779 -0
- package/LICENSE +21 -0
- package/README.md +19 -5
- 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 -23
- 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 -4426
- 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 -46
- package/src/mrtr/replay-store.ts +0 -103
- package/src/mrtr/request-state.ts +0 -435
- 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/testdata/stdio-e2e-server.ts +0 -110
- package/src/transport/request-headers.ts +0 -661
- package/src/types.ts +0 -907
- package/src/ui/viewer-utils.ts +0 -117
- package/src/validation/schema-validator.ts +0 -307
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// deno-lint-ignore-file require-await
|
|
2
|
+
/**
|
|
3
|
+
* Static (opaque) bearer-token auth provider.
|
|
4
|
+
*
|
|
5
|
+
* Validates a fixed set of pre-shared bearer tokens with no OIDC/JWT
|
|
6
|
+
* infrastructure — no issuer, no JWKS endpoint, no key management. Suited to
|
|
7
|
+
* same-network deployments (Docker, VPN, LAN), server-to-server integrations,
|
|
8
|
+
* and CI pipelines where a full OAuth flow is disproportionate.
|
|
9
|
+
*
|
|
10
|
+
* The original string-list form maps every valid token to one shared
|
|
11
|
+
* {@link AuthInfo}. An identity-aware credential form can instead assign a
|
|
12
|
+
* distinct subject and scopes to each token. For externally issued identity,
|
|
13
|
+
* expiry, rotation policy, or SSO, use {@link JwtAuthProvider} / the OIDC
|
|
14
|
+
* presets instead.
|
|
15
|
+
*
|
|
16
|
+
* Per RFC 9728 the emitted {@link ProtectedResourceMetadata} carries an empty
|
|
17
|
+
* `authorization_servers` array: there is no authorization server in a static
|
|
18
|
+
* token scheme — tokens are provisioned out of band — which is the correct
|
|
19
|
+
* signal for clients not to attempt AS discovery.
|
|
20
|
+
*
|
|
21
|
+
* @module lib/server/auth/static-token-provider
|
|
22
|
+
*/
|
|
23
|
+
import { AuthProvider } from "./provider.js";
|
|
24
|
+
import { httpsUrl, } from "./types.js";
|
|
25
|
+
function freezeScopes(scopes) {
|
|
26
|
+
return Object.freeze([...scopes]);
|
|
27
|
+
}
|
|
28
|
+
function freezeAuthInfo(subject, scopes) {
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
subject,
|
|
31
|
+
scopes: freezeScopes(scopes),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function normalizeScopeList(value, field) {
|
|
35
|
+
if (!Array.isArray(value)) {
|
|
36
|
+
throw new Error(`[StaticTokenAuthProvider] ${field} must be an array of non-empty strings`);
|
|
37
|
+
}
|
|
38
|
+
const normalized = [];
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
for (const [index, rawScope] of value.entries()) {
|
|
41
|
+
if (typeof rawScope !== "string" || rawScope.trim().length === 0) {
|
|
42
|
+
throw new Error(`[StaticTokenAuthProvider] ${field} contains an invalid scope at index ${index}`);
|
|
43
|
+
}
|
|
44
|
+
const scope = rawScope.trim();
|
|
45
|
+
if (!seen.has(scope)) {
|
|
46
|
+
seen.add(scope);
|
|
47
|
+
normalized.push(scope);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return normalized;
|
|
51
|
+
}
|
|
52
|
+
function normalizeCredentialScopes(value, index) {
|
|
53
|
+
if (value === undefined)
|
|
54
|
+
return [];
|
|
55
|
+
return normalizeScopeList(value, `credential at index ${index} scopes`);
|
|
56
|
+
}
|
|
57
|
+
function containsAsciiControl(value) {
|
|
58
|
+
for (const character of value) {
|
|
59
|
+
const codePoint = character.codePointAt(0);
|
|
60
|
+
if (codePoint <= 0x1f || codePoint === 0x7f)
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* {@link AuthProvider} that accepts a fixed set of opaque bearer tokens.
|
|
67
|
+
*
|
|
68
|
+
* Token lookup is O(1) via a pre-built `Map`. The string-list form stores the
|
|
69
|
+
* same frozen {@link AuthInfo} for every token; the credential form stores one
|
|
70
|
+
* distinct frozen value per token. Tokens are trimmed to match the bearer value
|
|
71
|
+
* the HTTP middleware extracts. Note that `Map.get()` is not constant-time —
|
|
72
|
+
* prefer long, high-entropy tokens (>= 32 random bytes) and rotate them
|
|
73
|
+
* regularly.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const provider = new StaticTokenAuthProvider(
|
|
78
|
+
* [Deno.env.get("MCP_AUTH_TOKEN")!],
|
|
79
|
+
* { resource: "https://my-mcp.example.com", scopes: ["tools:invoke"] },
|
|
80
|
+
* );
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example Identity-aware credentials
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const provider = new StaticTokenAuthProvider(
|
|
86
|
+
* [
|
|
87
|
+
* { token: aliceToken, subject: "alice", scopes: ["erp:read"] },
|
|
88
|
+
* {
|
|
89
|
+
* token: automationToken,
|
|
90
|
+
* subject: "automation",
|
|
91
|
+
* scopes: ["erp:read", "erp:write"],
|
|
92
|
+
* },
|
|
93
|
+
* ],
|
|
94
|
+
* { resource: "https://my-mcp.example.com" },
|
|
95
|
+
* );
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export class StaticTokenAuthProvider extends AuthProvider {
|
|
99
|
+
authByToken;
|
|
100
|
+
resource;
|
|
101
|
+
resourceMetadataUrl;
|
|
102
|
+
scopesSupported;
|
|
103
|
+
constructor(entries, options) {
|
|
104
|
+
super();
|
|
105
|
+
if (entries.length === 0) {
|
|
106
|
+
throw new Error("[StaticTokenAuthProvider] `tokens` must contain at least one token");
|
|
107
|
+
}
|
|
108
|
+
const rawEntries = entries;
|
|
109
|
+
const allStrings = rawEntries.every((entry) => typeof entry === "string");
|
|
110
|
+
const allObjects = rawEntries.every((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry));
|
|
111
|
+
if (!allStrings && !allObjects) {
|
|
112
|
+
throw new Error("[StaticTokenAuthProvider] entries must be either all token strings or all credential objects");
|
|
113
|
+
}
|
|
114
|
+
const authByToken = new Map();
|
|
115
|
+
let scopesSupported;
|
|
116
|
+
if (allStrings) {
|
|
117
|
+
const tokens = rawEntries;
|
|
118
|
+
if (tokens.some((token) => token.trim().length === 0)) {
|
|
119
|
+
throw new Error("[StaticTokenAuthProvider] `tokens` must not contain empty entries");
|
|
120
|
+
}
|
|
121
|
+
// Keep the original shared-authority contract exactly: normalized
|
|
122
|
+
// duplicates collapse, and every token resolves to this same object.
|
|
123
|
+
const sharedAuthInfo = freezeAuthInfo(options.subject ?? "static-token-user", options.scopes ?? []);
|
|
124
|
+
const scopes = sharedAuthInfo.scopes;
|
|
125
|
+
for (const token of tokens)
|
|
126
|
+
authByToken.set(token.trim(), sharedAuthInfo);
|
|
127
|
+
scopesSupported = options.scopesSupported !== undefined
|
|
128
|
+
? freezeScopes(options.scopesSupported)
|
|
129
|
+
: (scopes.length > 0 ? scopes : undefined);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (options.subject !== undefined || options.scopes !== undefined) {
|
|
133
|
+
throw new Error("[StaticTokenAuthProvider] identity-aware credentials cannot be combined with shared `subject` or `scopes` options");
|
|
134
|
+
}
|
|
135
|
+
const grantedScopes = [];
|
|
136
|
+
const grantedScopeSet = new Set();
|
|
137
|
+
for (const [index, rawEntry] of rawEntries.entries()) {
|
|
138
|
+
const entry = rawEntry;
|
|
139
|
+
if (typeof entry.token !== "string" || entry.token.trim().length === 0) {
|
|
140
|
+
throw new Error(`[StaticTokenAuthProvider] credential at index ${index} must contain a non-empty token`);
|
|
141
|
+
}
|
|
142
|
+
const token = entry.token.trim();
|
|
143
|
+
if (authByToken.has(token)) {
|
|
144
|
+
throw new Error(`[StaticTokenAuthProvider] duplicate token mapping at credential index ${index}`);
|
|
145
|
+
}
|
|
146
|
+
if (typeof entry.subject !== "string" ||
|
|
147
|
+
entry.subject.trim().length === 0 ||
|
|
148
|
+
entry.subject.trim() === "unknown" ||
|
|
149
|
+
containsAsciiControl(entry.subject.trim())) {
|
|
150
|
+
throw new Error(`[StaticTokenAuthProvider] credential at index ${index} must contain a non-empty, non-reserved subject without control characters`);
|
|
151
|
+
}
|
|
152
|
+
const subject = entry.subject.trim();
|
|
153
|
+
const scopes = normalizeCredentialScopes(entry.scopes, index);
|
|
154
|
+
for (const scope of scopes) {
|
|
155
|
+
if (!grantedScopeSet.has(scope)) {
|
|
156
|
+
grantedScopeSet.add(scope);
|
|
157
|
+
grantedScopes.push(scope);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
authByToken.set(token, freezeAuthInfo(subject, scopes));
|
|
161
|
+
}
|
|
162
|
+
if (options.scopesSupported !== undefined) {
|
|
163
|
+
const declaredScopes = normalizeScopeList(options.scopesSupported, "`scopesSupported`");
|
|
164
|
+
const declaredSet = new Set(declaredScopes);
|
|
165
|
+
if (grantedScopes.some((scope) => !declaredSet.has(scope))) {
|
|
166
|
+
throw new Error("[StaticTokenAuthProvider] `scopesSupported` must include every scope granted by an identity-aware credential");
|
|
167
|
+
}
|
|
168
|
+
scopesSupported = freezeScopes(declaredScopes);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
scopesSupported = grantedScopes.length > 0
|
|
172
|
+
? freezeScopes(grantedScopes)
|
|
173
|
+
: undefined;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (!options.resource?.trim()) {
|
|
177
|
+
throw new Error("[StaticTokenAuthProvider] `resource` is required");
|
|
178
|
+
}
|
|
179
|
+
// Validate `resource` as an absolute HTTP(S) URL unconditionally, so the
|
|
180
|
+
// documented guarantee holds even when `resourceMetadataUrl` is supplied.
|
|
181
|
+
const resourceUrl = httpsUrl(options.resource);
|
|
182
|
+
this.authByToken = authByToken;
|
|
183
|
+
// Store the caller's raw resource string (RFC 9728 allows opaque URIs, and
|
|
184
|
+
// JwtAuthProvider does the same); `resourceUrl` above is used only for
|
|
185
|
+
// validation and metadata-URL derivation.
|
|
186
|
+
this.resource = options.resource;
|
|
187
|
+
this.scopesSupported = scopesSupported;
|
|
188
|
+
// RFC 9728 § 3.1: when `resourceMetadataUrl` is omitted, insert the
|
|
189
|
+
// well-known suffix between the resource's origin and its path/query
|
|
190
|
+
// (identical derivation to JwtAuthProvider).
|
|
191
|
+
if (options.resourceMetadataUrl?.trim()) {
|
|
192
|
+
this.resourceMetadataUrl = httpsUrl(options.resourceMetadataUrl);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
const parsed = new URL(resourceUrl);
|
|
196
|
+
const pathPart = parsed.pathname === "/" ? "" : parsed.pathname;
|
|
197
|
+
this.resourceMetadataUrl = httpsUrl(`${parsed.origin}/.well-known/oauth-protected-resource${pathPart}${parsed.search}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async verifyToken(token) {
|
|
201
|
+
// Trim to match how tokens are stored (and how the HTTP middleware extracts
|
|
202
|
+
// the bearer), so direct callers and the middleware path behave identically.
|
|
203
|
+
return this.authByToken.get(token.trim()) ?? null;
|
|
204
|
+
}
|
|
205
|
+
getResourceMetadata() {
|
|
206
|
+
// Fresh object per call (matching JwtAuthProvider) so a caller cannot
|
|
207
|
+
// mutate shared metadata — e.g. the `authorization_servers` array.
|
|
208
|
+
return {
|
|
209
|
+
resource: this.resource,
|
|
210
|
+
resource_metadata_url: this.resourceMetadataUrl,
|
|
211
|
+
// No authorization server: static tokens are provisioned out of band.
|
|
212
|
+
authorization_servers: [],
|
|
213
|
+
scopes_supported: this.scopesSupported,
|
|
214
|
+
bearer_methods_supported: ["header"],
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Create a static (opaque) bearer-token {@link AuthProvider}.
|
|
220
|
+
*
|
|
221
|
+
* @param entries Either a non-empty shared-authority list of bearer tokens, or
|
|
222
|
+
* a non-empty list of identity-aware credentials. Load tokens from env / a
|
|
223
|
+
* secrets manager — never hard-code them in source.
|
|
224
|
+
* @param options Provider configuration; `options.resource` is required.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* import { createStaticTokenAuthProvider, McpApp } from "@casys/mcp-server";
|
|
229
|
+
*
|
|
230
|
+
* const app = new McpApp({
|
|
231
|
+
* name: "my-server",
|
|
232
|
+
* version: "1.0.0",
|
|
233
|
+
* auth: {
|
|
234
|
+
* provider: createStaticTokenAuthProvider(
|
|
235
|
+
* (Deno.env.get("MCP_AUTH_TOKENS") ?? "").split(",").filter(Boolean),
|
|
236
|
+
* { resource: "https://my-mcp.example.com" },
|
|
237
|
+
* ),
|
|
238
|
+
* },
|
|
239
|
+
* });
|
|
240
|
+
* await app.startHttp({ port: 7654, requireAuth: true });
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @example Identity and scopes per credential
|
|
244
|
+
* ```typescript
|
|
245
|
+
* const provider = createStaticTokenAuthProvider(
|
|
246
|
+
* [
|
|
247
|
+
* { token: aliceToken, subject: "alice", scopes: ["read"] },
|
|
248
|
+
* { token: ciToken, subject: "ci", scopes: ["read", "write"] },
|
|
249
|
+
* ],
|
|
250
|
+
* { resource: "https://my-mcp.example.com" },
|
|
251
|
+
* );
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
export function createStaticTokenAuthProvider(entries, options) {
|
|
255
|
+
return new StaticTokenAuthProvider(entries, options);
|
|
256
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication types for McpApp.
|
|
3
|
+
*
|
|
4
|
+
* Types follow RFC 9728 (OAuth Protected Resource Metadata)
|
|
5
|
+
* and MCP Auth spec (draft 2025-11-25).
|
|
6
|
+
*
|
|
7
|
+
* @module lib/server/auth/types
|
|
8
|
+
*/
|
|
9
|
+
declare const httpsUrlBrand: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* A string that has been validated as a syntactically valid absolute HTTP(S)
|
|
12
|
+
* URL. Cannot be constructed by type assertion — callers MUST go through
|
|
13
|
+
* {@link httpsUrl} (which parses, normalizes, and throws on invalid input) so
|
|
14
|
+
* the invariant is enforced at both the type level and runtime.
|
|
15
|
+
*
|
|
16
|
+
* Added in 0.16.0 to lift `resource_metadata_url`, `authorization_servers`,
|
|
17
|
+
* and the URL-resource branch of {@link JwtAuthProviderOptions} from raw
|
|
18
|
+
* `string` into a type that structurally encodes the invariant. The motivating
|
|
19
|
+
* incident was 0.14.x silently producing `"://host/.well-known/..."` in
|
|
20
|
+
* `WWW-Authenticate` headers when callers mis-set `resource` — a class of bug
|
|
21
|
+
* that 0.15.x closed with runtime guards and 0.16.0 closes at the type level.
|
|
22
|
+
*/
|
|
23
|
+
export type HttpsUrl = string & {
|
|
24
|
+
readonly [httpsUrlBrand]: never;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Parse, validate, and normalize a string as an absolute HTTP(S) URL.
|
|
28
|
+
*
|
|
29
|
+
* Trims leading/trailing whitespace before parsing so YAML keys with trailing
|
|
30
|
+
* spaces don't produce unparseable URLs. Delegates parsing to `new URL()`,
|
|
31
|
+
* which lowercases the scheme — so `HTTPS://foo.com` is accepted and returned
|
|
32
|
+
* as `https://foo.com/`.
|
|
33
|
+
*
|
|
34
|
+
* @throws if the string is empty/whitespace-only, unparseable as a URL, or
|
|
35
|
+
* uses a non-HTTP(S) scheme (RFC 9728 § 3 requires HTTPS for metadata
|
|
36
|
+
* documents; http is permitted here for local dev only).
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const url = httpsUrl("https://my-mcp.example.com");
|
|
41
|
+
* // url is of type HttpsUrl and can be passed wherever HttpsUrl is required.
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function httpsUrl(raw: string): HttpsUrl;
|
|
45
|
+
/**
|
|
46
|
+
* Non-throwing variant of {@link httpsUrl}. Returns the normalized `HttpsUrl`
|
|
47
|
+
* on success, `null` on any validation failure. Use this when you need to
|
|
48
|
+
* branch on validity without catching exceptions — typically to detect whether
|
|
49
|
+
* an RFC 9728 § 2 `resource` identifier is an HTTP(S) URL (the URL-resource
|
|
50
|
+
* branch) or an opaque URI (the opaque-resource branch that requires an
|
|
51
|
+
* explicit metadata URL).
|
|
52
|
+
*/
|
|
53
|
+
export declare function tryHttpsUrl(raw: string): HttpsUrl | null;
|
|
54
|
+
/**
|
|
55
|
+
* Information extracted from a validated token.
|
|
56
|
+
* Frozen (Object.freeze) before being passed to tool handlers.
|
|
57
|
+
*/
|
|
58
|
+
export interface AuthInfo {
|
|
59
|
+
/** User ID (sub claim from JWT) */
|
|
60
|
+
subject: string;
|
|
61
|
+
/** OAuth client ID (optional - azp or client_id claim) */
|
|
62
|
+
clientId?: string;
|
|
63
|
+
/** Granted scopes */
|
|
64
|
+
scopes: string[];
|
|
65
|
+
/** Additional JWT claims */
|
|
66
|
+
claims?: Record<string, unknown>;
|
|
67
|
+
/** Token expiration timestamp (Unix epoch seconds) */
|
|
68
|
+
expiresAt?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Tenant identifier for multi-tenant servers.
|
|
71
|
+
*
|
|
72
|
+
* Populated by `createMultiTenantMiddleware` when a `TenantResolver`
|
|
73
|
+
* is configured. Undefined on single-tenant servers.
|
|
74
|
+
*
|
|
75
|
+
* Tool handlers in multi-tenant servers should read this (never trust
|
|
76
|
+
* raw JWT claims directly) to scope data access to the current tenant.
|
|
77
|
+
*/
|
|
78
|
+
tenantId?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Auth configuration slot for {@link McpAppOptions.auth}.
|
|
82
|
+
*
|
|
83
|
+
* 0.17.0: slimmed to a single `provider` field. Previously exposed
|
|
84
|
+
* `authorizationServers`, `resource`, and `scopesSupported` fields that
|
|
85
|
+
* were NEVER read by `McpApp` at runtime (only `provider` was consumed at
|
|
86
|
+
* `mcp-app.ts:1061`). Those fields were vestigial from a pre-0.15 design
|
|
87
|
+
* where `McpApp` could auto-construct a `JwtAuthProvider` from its own
|
|
88
|
+
* `auth:` option; that auto-construction path was removed when
|
|
89
|
+
* `createAuthProviderFromConfig` took over YAML/env provider construction,
|
|
90
|
+
* but the dead fields stayed in the interface. 0.17.0 deletes them as part
|
|
91
|
+
* of the auth-module cleanup (Casys-AI/mcp-server#13).
|
|
92
|
+
*
|
|
93
|
+
* The interface is kept (rather than reducing `McpAppOptions.auth` to a
|
|
94
|
+
* bare `AuthProvider`) so that future additions like pipeline-level auth
|
|
95
|
+
* hooks have a named extension point without another BC break.
|
|
96
|
+
*/
|
|
97
|
+
export interface AuthOptions {
|
|
98
|
+
/**
|
|
99
|
+
* The `AuthProvider` that validates bearer tokens and produces RFC 9728
|
|
100
|
+
* metadata. Construct via {@link JwtAuthProvider}, any of the preset
|
|
101
|
+
* factories (`createGitHubAuthProvider`, `createGoogleAuthProvider`,
|
|
102
|
+
* `createAuth0AuthProvider`, `createOIDCAuthProvider`), or a custom
|
|
103
|
+
* `AuthProvider` subclass for non-JWT token schemes.
|
|
104
|
+
*/
|
|
105
|
+
provider: AuthProvider;
|
|
106
|
+
}
|
|
107
|
+
import type { AuthProvider } from "./provider.js";
|
|
108
|
+
/**
|
|
109
|
+
* RFC 9728 Protected Resource Metadata.
|
|
110
|
+
* Returned by /.well-known/oauth-protected-resource
|
|
111
|
+
*
|
|
112
|
+
* @see https://datatracker.ietf.org/doc/html/rfc9728
|
|
113
|
+
*/
|
|
114
|
+
export interface ProtectedResourceMetadata {
|
|
115
|
+
/**
|
|
116
|
+
* RFC 9728 § 2 resource identifier. URI that identifies the protected
|
|
117
|
+
* resource — used as the JWT `aud` claim. Can be an HTTP(S) URL OR an
|
|
118
|
+
* opaque URI (e.g., an OIDC project ID). Stays `string` because RFC 9728
|
|
119
|
+
* explicitly allows opaque URIs; callers must NOT assume it parses as
|
|
120
|
+
* an URL.
|
|
121
|
+
*/
|
|
122
|
+
resource: string;
|
|
123
|
+
/**
|
|
124
|
+
* Absolute HTTP(S) URL where this metadata document is served publicly.
|
|
125
|
+
* Per RFC 9728 § 3, this is the URL a client discovers via the
|
|
126
|
+
* WWW-Authenticate challenge. Always an HTTP(S) URL, regardless of
|
|
127
|
+
* whether `resource` itself is an URL or an opaque URI.
|
|
128
|
+
*
|
|
129
|
+
* 0.16.0: typed as {@link HttpsUrl} (branded). The invariant is now
|
|
130
|
+
* structurally enforced — producers must construct the value via
|
|
131
|
+
* {@link httpsUrl}, which validates at runtime AND returns the brand.
|
|
132
|
+
* Prior to 0.16.0 this was a raw `string` guarded only by a runtime
|
|
133
|
+
* validator in the `JwtAuthProvider` constructor (0.15.1).
|
|
134
|
+
*/
|
|
135
|
+
resource_metadata_url: HttpsUrl;
|
|
136
|
+
/**
|
|
137
|
+
* Authorization servers that can issue valid tokens.
|
|
138
|
+
*
|
|
139
|
+
* 0.16.0: each element is branded as {@link HttpsUrl} so downstream
|
|
140
|
+
* consumers (e.g., MCP clients building discovery URLs) can rely on
|
|
141
|
+
* them being parseable absolute URLs without re-validation. Construct
|
|
142
|
+
* via {@link httpsUrl}.
|
|
143
|
+
*/
|
|
144
|
+
authorization_servers: HttpsUrl[];
|
|
145
|
+
/** Scopes this resource supports */
|
|
146
|
+
scopes_supported?: string[];
|
|
147
|
+
/** How bearer tokens can be presented (always ["header"]) */
|
|
148
|
+
bearer_methods_supported: string[];
|
|
149
|
+
}
|
|
150
|
+
export {};
|
|
151
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/src/auth/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,CAAC,MAAM,aAAa,EAAE,OAAO,MAAM,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,aAAa,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CA4B9C;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAMxD;AAMD;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAEhB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,qBAAqB;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEjC,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;OAMG;IACH,QAAQ,EAAE,YAAY,CAAC;CACxB;AAGD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;;;;;;OAWG;IACH,qBAAqB,EAAE,QAAQ,CAAC;IAEhC;;;;;;;OAOG;IACH,qBAAqB,EAAE,QAAQ,EAAE,CAAC;IAElC,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE5B,6DAA6D;IAC7D,wBAAwB,EAAE,MAAM,EAAE,CAAC;CACpC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication types for McpApp.
|
|
3
|
+
*
|
|
4
|
+
* Types follow RFC 9728 (OAuth Protected Resource Metadata)
|
|
5
|
+
* and MCP Auth spec (draft 2025-11-25).
|
|
6
|
+
*
|
|
7
|
+
* @module lib/server/auth/types
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Parse, validate, and normalize a string as an absolute HTTP(S) URL.
|
|
11
|
+
*
|
|
12
|
+
* Trims leading/trailing whitespace before parsing so YAML keys with trailing
|
|
13
|
+
* spaces don't produce unparseable URLs. Delegates parsing to `new URL()`,
|
|
14
|
+
* which lowercases the scheme — so `HTTPS://foo.com` is accepted and returned
|
|
15
|
+
* as `https://foo.com/`.
|
|
16
|
+
*
|
|
17
|
+
* @throws if the string is empty/whitespace-only, unparseable as a URL, or
|
|
18
|
+
* uses a non-HTTP(S) scheme (RFC 9728 § 3 requires HTTPS for metadata
|
|
19
|
+
* documents; http is permitted here for local dev only).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const url = httpsUrl("https://my-mcp.example.com");
|
|
24
|
+
* // url is of type HttpsUrl and can be passed wherever HttpsUrl is required.
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function httpsUrl(raw) {
|
|
28
|
+
const trimmed = raw.trim();
|
|
29
|
+
if (trimmed.length === 0) {
|
|
30
|
+
throw new Error(`[httpsUrl] empty or whitespace-only string is not a valid URL. ` +
|
|
31
|
+
`Expected an absolute HTTP(S) URL like ` +
|
|
32
|
+
`"https://my-mcp.example.com/.well-known/oauth-protected-resource".`);
|
|
33
|
+
}
|
|
34
|
+
let parsed;
|
|
35
|
+
try {
|
|
36
|
+
parsed = new URL(trimmed);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
throw new Error(`[httpsUrl] not a parseable URL: ${JSON.stringify(raw)}. ` +
|
|
40
|
+
`Expected an absolute HTTP(S) URL like ` +
|
|
41
|
+
`"https://my-mcp.example.com/.well-known/oauth-protected-resource".`);
|
|
42
|
+
}
|
|
43
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
44
|
+
throw new Error(`[httpsUrl] must use http:// or https:// scheme, got ${JSON.stringify(parsed.protocol)} in ${JSON.stringify(raw)}. Per RFC 9728 § 3, the protected resource ` +
|
|
45
|
+
`metadata document must be served over HTTP(S).`);
|
|
46
|
+
}
|
|
47
|
+
return parsed.toString();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Non-throwing variant of {@link httpsUrl}. Returns the normalized `HttpsUrl`
|
|
51
|
+
* on success, `null` on any validation failure. Use this when you need to
|
|
52
|
+
* branch on validity without catching exceptions — typically to detect whether
|
|
53
|
+
* an RFC 9728 § 2 `resource` identifier is an HTTP(S) URL (the URL-resource
|
|
54
|
+
* branch) or an opaque URI (the opaque-resource branch that requires an
|
|
55
|
+
* explicit metadata URL).
|
|
56
|
+
*/
|
|
57
|
+
export function tryHttpsUrl(raw) {
|
|
58
|
+
try {
|
|
59
|
+
return httpsUrl(raw);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localhost callback server for OAuth PKCE redirect capture.
|
|
3
|
+
*
|
|
4
|
+
* Starts a temporary HTTP server on localhost to receive the
|
|
5
|
+
* authorization code from the OAuth redirect. Shuts down
|
|
6
|
+
* after receiving the code or on timeout.
|
|
7
|
+
*
|
|
8
|
+
* @module lib/server/client-auth/callback-server
|
|
9
|
+
*/
|
|
10
|
+
export interface CallbackServerOptions {
|
|
11
|
+
/** Port to listen on (0 = auto-assign, default: 0) */
|
|
12
|
+
port?: number;
|
|
13
|
+
/** Hostname to bind (default: 127.0.0.1) */
|
|
14
|
+
hostname?: string;
|
|
15
|
+
/** Timeout in ms (default: 120_000) */
|
|
16
|
+
timeout?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class CallbackServer {
|
|
19
|
+
private port;
|
|
20
|
+
private hostname;
|
|
21
|
+
private timeout;
|
|
22
|
+
private server;
|
|
23
|
+
private timerId;
|
|
24
|
+
private closeTimerId;
|
|
25
|
+
constructor(options?: CallbackServerOptions);
|
|
26
|
+
start(): Promise<{
|
|
27
|
+
port: number;
|
|
28
|
+
codePromise: Promise<string>;
|
|
29
|
+
}>;
|
|
30
|
+
close(): Promise<void>;
|
|
31
|
+
private clearTimers;
|
|
32
|
+
private cleanupAfterStartFailure;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=callback-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback-server.d.ts","sourceRoot":"","sources":["../../../src/src/client-auth/callback-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,WAAW,qBAAqB;IACpC,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAoBD,qBAAa,cAAc;IACzB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,OAAO,CAA8C;IAC7D,OAAO,CAAC,YAAY,CAA8C;gBAEtD,OAAO,CAAC,EAAE,qBAAqB;IAMrC,KAAK,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC;IAkFhE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B,OAAO,CAAC,WAAW;YAWL,wBAAwB;CAWvC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localhost callback server for OAuth PKCE redirect capture.
|
|
3
|
+
*
|
|
4
|
+
* Starts a temporary HTTP server on localhost to receive the
|
|
5
|
+
* authorization code from the OAuth redirect. Shuts down
|
|
6
|
+
* after receiving the code or on timeout.
|
|
7
|
+
*
|
|
8
|
+
* @module lib/server/client-auth/callback-server
|
|
9
|
+
*/
|
|
10
|
+
import { serve } from "../runtime/runtime.js";
|
|
11
|
+
const SUCCESS_HTML = `<!DOCTYPE html>
|
|
12
|
+
<html><head><title>PML Auth</title><style>
|
|
13
|
+
body{font-family:system-ui;display:flex;justify-content:center;align-items:center;height:100vh;margin:0;background:#08080a;color:#fff}
|
|
14
|
+
.card{text-align:center;padding:2rem}h1{color:#FFB86F}
|
|
15
|
+
</style></head><body><div class="card">
|
|
16
|
+
<h1>Authentication successful</h1>
|
|
17
|
+
<p>You can close this tab and return to the terminal.</p>
|
|
18
|
+
</div></body></html>`;
|
|
19
|
+
const ERROR_HTML = `<!DOCTYPE html>
|
|
20
|
+
<html><head><title>PML Auth Error</title><style>
|
|
21
|
+
body{font-family:system-ui;display:flex;justify-content:center;align-items:center;height:100vh;margin:0;background:#08080a;color:#fff}
|
|
22
|
+
.card{text-align:center;padding:2rem}h1{color:#ff6b6b}
|
|
23
|
+
</style></head><body><div class="card">
|
|
24
|
+
<h1>Authentication failed</h1>
|
|
25
|
+
<p>Missing authorization code. Please try again.</p>
|
|
26
|
+
</div></body></html>`;
|
|
27
|
+
export class CallbackServer {
|
|
28
|
+
port;
|
|
29
|
+
hostname;
|
|
30
|
+
timeout;
|
|
31
|
+
server = null;
|
|
32
|
+
timerId = null;
|
|
33
|
+
closeTimerId = null;
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.port = options?.port ?? 0;
|
|
36
|
+
this.hostname = options?.hostname ?? "127.0.0.1";
|
|
37
|
+
this.timeout = options?.timeout ?? 120_000;
|
|
38
|
+
}
|
|
39
|
+
async start() {
|
|
40
|
+
let resolveCode;
|
|
41
|
+
let rejectCode;
|
|
42
|
+
const codePromise = new Promise((resolve, reject) => {
|
|
43
|
+
resolveCode = resolve;
|
|
44
|
+
rejectCode = reject;
|
|
45
|
+
});
|
|
46
|
+
let resolveListen;
|
|
47
|
+
let rejectListen;
|
|
48
|
+
const listenPromise = new Promise((resolve) => {
|
|
49
|
+
resolveListen = resolve;
|
|
50
|
+
});
|
|
51
|
+
const bindPromise = new Promise((_, reject) => {
|
|
52
|
+
rejectListen = reject;
|
|
53
|
+
});
|
|
54
|
+
this.timerId = setTimeout(() => {
|
|
55
|
+
this.timerId = null;
|
|
56
|
+
rejectCode(new Error("OAuth callback timeout — no authorization code received"));
|
|
57
|
+
this.close();
|
|
58
|
+
}, this.timeout);
|
|
59
|
+
try {
|
|
60
|
+
this.server = serve({
|
|
61
|
+
port: this.port,
|
|
62
|
+
hostname: this.hostname,
|
|
63
|
+
onListen: ({ port }) => {
|
|
64
|
+
this.port = port;
|
|
65
|
+
resolveListen(port);
|
|
66
|
+
},
|
|
67
|
+
onError: (err) => {
|
|
68
|
+
rejectListen(err);
|
|
69
|
+
},
|
|
70
|
+
}, (req) => {
|
|
71
|
+
const url = new URL(req.url);
|
|
72
|
+
if (url.pathname === "/callback") {
|
|
73
|
+
const code = url.searchParams.get("code");
|
|
74
|
+
if (!code) {
|
|
75
|
+
return new Response(ERROR_HTML, {
|
|
76
|
+
status: 400,
|
|
77
|
+
headers: { "Content-Type": "text/html" },
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (this.timerId) {
|
|
81
|
+
clearTimeout(this.timerId);
|
|
82
|
+
this.timerId = null;
|
|
83
|
+
}
|
|
84
|
+
resolveCode(code);
|
|
85
|
+
// Schedule close after response is sent
|
|
86
|
+
this.closeTimerId = setTimeout(() => {
|
|
87
|
+
this.closeTimerId = null;
|
|
88
|
+
this.close();
|
|
89
|
+
}, 100);
|
|
90
|
+
return new Response(SUCCESS_HTML, {
|
|
91
|
+
status: 200,
|
|
92
|
+
headers: { "Content-Type": "text/html" },
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return new Response("Not Found", { status: 404 });
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
await this.cleanupAfterStartFailure();
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
let port;
|
|
103
|
+
try {
|
|
104
|
+
port = await Promise.race([listenPromise, bindPromise]);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
await this.cleanupAfterStartFailure();
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
return { port, codePromise };
|
|
111
|
+
}
|
|
112
|
+
async close() {
|
|
113
|
+
this.clearTimers();
|
|
114
|
+
if (this.server) {
|
|
115
|
+
await this.server.shutdown();
|
|
116
|
+
this.server = null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
clearTimers() {
|
|
120
|
+
if (this.timerId) {
|
|
121
|
+
clearTimeout(this.timerId);
|
|
122
|
+
this.timerId = null;
|
|
123
|
+
}
|
|
124
|
+
if (this.closeTimerId) {
|
|
125
|
+
clearTimeout(this.closeTimerId);
|
|
126
|
+
this.closeTimerId = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async cleanupAfterStartFailure() {
|
|
130
|
+
this.clearTimers();
|
|
131
|
+
if (this.server) {
|
|
132
|
+
try {
|
|
133
|
+
await this.server.shutdown();
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Ignore shutdown failures after a failed bind.
|
|
137
|
+
}
|
|
138
|
+
this.server = null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CimdClientConfig, OAuthClientConfig } from "./types.js";
|
|
2
|
+
export type CimdConfigErrorCode = "cimd_config_conflict" | "cimd_registration_missing" | "cimd_method_invalid" | "cimd_url_invalid" | "cimd_port_unfixed" | "cimd_redirect_mismatch" | "cimd_name_missing" | "cimd_reserved_metadata_key";
|
|
3
|
+
export type OAuthClientMode = "static" | "client_id_metadata";
|
|
4
|
+
export declare class CimdConfigError extends Error {
|
|
5
|
+
readonly code: CimdConfigErrorCode;
|
|
6
|
+
readonly context: Record<string, unknown>;
|
|
7
|
+
readonly recovery: string;
|
|
8
|
+
constructor(code: CimdConfigErrorCode, message: string, context: Record<string, unknown>, recovery: string, options?: ErrorOptions);
|
|
9
|
+
}
|
|
10
|
+
export interface ClientIdMetadataDocument {
|
|
11
|
+
client_id: string;
|
|
12
|
+
client_name: string;
|
|
13
|
+
redirect_uris: string[];
|
|
14
|
+
grant_types: ["authorization_code", "refresh_token"];
|
|
15
|
+
response_types: ["code"];
|
|
16
|
+
token_endpoint_auth_method: "none";
|
|
17
|
+
/** RFC 7591 application type. Always "native" for loopback CLI/desktop clients. */
|
|
18
|
+
application_type: "native" | "web";
|
|
19
|
+
scope?: string;
|
|
20
|
+
client_uri?: string;
|
|
21
|
+
logo_uri?: string;
|
|
22
|
+
contacts?: string[];
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
export declare function isCimdConfig(config: OAuthClientConfig): config is CimdClientConfig;
|
|
26
|
+
export declare function resolveClientMode(config: OAuthClientConfig): OAuthClientMode;
|
|
27
|
+
export declare function buildClientIdMetadataDocument(config: CimdClientConfig): ClientIdMetadataDocument;
|
|
28
|
+
export declare function validateCimdClientConfig(config: OAuthClientConfig): asserts config is CimdClientConfig;
|
|
29
|
+
//# sourceMappingURL=client-id-metadata.d.ts.map
|