@casys/mcp-server 0.27.0 → 0.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -1764
- package/README.md +21 -631
- package/esm/mod.d.ts +1 -102
- package/esm/mod.js +1 -103
- package/package.json +17 -25
- package/esm/_dnt.polyfills.d.ts +0 -12
- package/esm/_dnt.polyfills.d.ts.map +0 -1
- package/esm/_dnt.polyfills.js +0 -15
- package/esm/_dnt.shims.d.ts +0 -2
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -57
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts +0 -33
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.js +0 -48
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts +0 -106
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.js +0 -636
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts +0 -67
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.js +0 -1393
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts +0 -44
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.js +0 -117
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.js +0 -103
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.js +0 -32
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.js +0 -96
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.js +0 -159
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.js +0 -14
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.js +0 -10
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.js +0 -22
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.js +0 -29
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.js +0 -19
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.js +0 -30
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.js +0 -10
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.js +0 -14
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.js +0 -9
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.js +0 -81
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.js +0 -20
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts +0 -32
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.js +0 -6
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts +0 -4
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.js +0 -13
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts +0 -51
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.js +0 -53
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts +0 -79
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.js +0 -91
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts +0 -100
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.js +0 -33
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts +0 -111
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.js +0 -104
- package/esm/mod.d.ts.map +0 -1
- package/esm/package.json +0 -3
- package/esm/src/auth/as-metadata-proxy.d.ts +0 -112
- package/esm/src/auth/as-metadata-proxy.d.ts.map +0 -1
- package/esm/src/auth/as-metadata-proxy.js +0 -171
- package/esm/src/auth/config.d.ts +0 -117
- package/esm/src/auth/config.d.ts.map +0 -1
- package/esm/src/auth/config.js +0 -219
- package/esm/src/auth/jwt-provider.d.ts +0 -157
- package/esm/src/auth/jwt-provider.d.ts.map +0 -1
- package/esm/src/auth/jwt-provider.js +0 -187
- package/esm/src/auth/middleware.d.ts +0 -61
- package/esm/src/auth/middleware.d.ts.map +0 -1
- package/esm/src/auth/middleware.js +0 -209
- package/esm/src/auth/mod.d.ts +0 -23
- package/esm/src/auth/mod.d.ts.map +0 -1
- package/esm/src/auth/mod.js +0 -27
- package/esm/src/auth/multi-tenant-middleware.d.ts +0 -131
- package/esm/src/auth/multi-tenant-middleware.d.ts.map +0 -1
- package/esm/src/auth/multi-tenant-middleware.js +0 -128
- package/esm/src/auth/presets.d.ts +0 -231
- package/esm/src/auth/presets.d.ts.map +0 -1
- package/esm/src/auth/presets.js +0 -223
- package/esm/src/auth/provider.d.ts +0 -47
- package/esm/src/auth/provider.d.ts.map +0 -1
- package/esm/src/auth/provider.js +0 -34
- package/esm/src/auth/scope-middleware.d.ts +0 -30
- package/esm/src/auth/scope-middleware.d.ts.map +0 -1
- package/esm/src/auth/scope-middleware.js +0 -48
- package/esm/src/auth/static-token-provider.d.ts +0 -155
- package/esm/src/auth/static-token-provider.d.ts.map +0 -1
- package/esm/src/auth/static-token-provider.js +0 -256
- package/esm/src/auth/types.d.ts +0 -151
- package/esm/src/auth/types.d.ts.map +0 -1
- package/esm/src/auth/types.js +0 -64
- package/esm/src/client-auth/callback-server.d.ts +0 -34
- package/esm/src/client-auth/callback-server.d.ts.map +0 -1
- package/esm/src/client-auth/callback-server.js +0 -141
- package/esm/src/client-auth/client-id-metadata.d.ts +0 -29
- package/esm/src/client-auth/client-id-metadata.d.ts.map +0 -1
- package/esm/src/client-auth/client-id-metadata.js +0 -149
- package/esm/src/client-auth/connect.d.ts +0 -32
- package/esm/src/client-auth/connect.d.ts.map +0 -1
- package/esm/src/client-auth/connect.js +0 -47
- package/esm/src/client-auth/mod.d.ts +0 -19
- package/esm/src/client-auth/mod.d.ts.map +0 -1
- package/esm/src/client-auth/mod.js +0 -19
- package/esm/src/client-auth/provider.d.ts +0 -78
- package/esm/src/client-auth/provider.d.ts.map +0 -1
- package/esm/src/client-auth/provider.js +0 -246
- package/esm/src/client-auth/token-store/file-store.d.ts +0 -20
- package/esm/src/client-auth/token-store/file-store.d.ts.map +0 -1
- package/esm/src/client-auth/token-store/file-store.js +0 -62
- package/esm/src/client-auth/token-store/memory-store.d.ts +0 -14
- package/esm/src/client-auth/token-store/memory-store.d.ts.map +0 -1
- package/esm/src/client-auth/token-store/memory-store.js +0 -25
- package/esm/src/client-auth/types.d.ts +0 -89
- package/esm/src/client-auth/types.d.ts.map +0 -1
- package/esm/src/client-auth/types.js +0 -10
- package/esm/src/concurrency/rate-limiter.d.ts +0 -87
- package/esm/src/concurrency/rate-limiter.d.ts.map +0 -1
- package/esm/src/concurrency/rate-limiter.js +0 -165
- package/esm/src/concurrency/request-queue.d.ts +0 -71
- package/esm/src/concurrency/request-queue.d.ts.map +0 -1
- package/esm/src/concurrency/request-queue.js +0 -128
- package/esm/src/http/body.d.ts +0 -20
- package/esm/src/http/body.d.ts.map +0 -1
- package/esm/src/http/body.js +0 -63
- package/esm/src/http/request-guards.d.ts +0 -54
- package/esm/src/http/request-guards.d.ts.map +0 -1
- package/esm/src/http/request-guards.js +0 -114
- package/esm/src/http/wire.d.ts +0 -26
- package/esm/src/http/wire.d.ts.map +0 -1
- package/esm/src/http/wire.js +0 -35
- package/esm/src/inspector/launcher.d.ts +0 -48
- package/esm/src/inspector/launcher.d.ts.map +0 -1
- package/esm/src/inspector/launcher.js +0 -100
- package/esm/src/mcp-app.d.ts +0 -728
- package/esm/src/mcp-app.d.ts.map +0 -1
- package/esm/src/mcp-app.js +0 -3530
- package/esm/src/middleware/backpressure.d.ts +0 -24
- package/esm/src/middleware/backpressure.d.ts.map +0 -1
- package/esm/src/middleware/backpressure.js +0 -31
- package/esm/src/middleware/mod.d.ts +0 -11
- package/esm/src/middleware/mod.d.ts.map +0 -1
- package/esm/src/middleware/mod.js +0 -11
- package/esm/src/middleware/rate-limit.d.ts +0 -22
- package/esm/src/middleware/rate-limit.d.ts.map +0 -1
- package/esm/src/middleware/rate-limit.js +0 -33
- package/esm/src/middleware/runner.d.ts +0 -32
- package/esm/src/middleware/runner.d.ts.map +0 -1
- package/esm/src/middleware/runner.js +0 -49
- package/esm/src/middleware/types.d.ts +0 -76
- package/esm/src/middleware/types.d.ts.map +0 -1
- package/esm/src/middleware/types.js +0 -9
- package/esm/src/middleware/validation.d.ts +0 -24
- package/esm/src/middleware/validation.d.ts.map +0 -1
- package/esm/src/middleware/validation.js +0 -30
- package/esm/src/mrtr/capability-check.d.ts +0 -75
- package/esm/src/mrtr/capability-check.d.ts.map +0 -1
- package/esm/src/mrtr/capability-check.js +0 -233
- package/esm/src/mrtr/mod.d.ts +0 -18
- package/esm/src/mrtr/mod.d.ts.map +0 -1
- package/esm/src/mrtr/mod.js +0 -12
- package/esm/src/mrtr/replay-store.d.ts +0 -50
- package/esm/src/mrtr/replay-store.d.ts.map +0 -1
- package/esm/src/mrtr/replay-store.js +0 -61
- package/esm/src/mrtr/request-state.d.ts +0 -181
- package/esm/src/mrtr/request-state.d.ts.map +0 -1
- package/esm/src/mrtr/request-state.js +0 -313
- package/esm/src/mrtr/retry-guard.d.ts +0 -61
- package/esm/src/mrtr/retry-guard.d.ts.map +0 -1
- package/esm/src/mrtr/retry-guard.js +0 -53
- package/esm/src/mrtr/types.d.ts +0 -99
- package/esm/src/mrtr/types.d.ts.map +0 -1
- package/esm/src/mrtr/types.js +0 -14
- package/esm/src/observability/metrics.d.ts +0 -104
- package/esm/src/observability/metrics.d.ts.map +0 -1
- package/esm/src/observability/metrics.js +0 -207
- package/esm/src/observability/mod.d.ts +0 -12
- package/esm/src/observability/mod.d.ts.map +0 -1
- package/esm/src/observability/mod.js +0 -11
- package/esm/src/observability/otel.d.ts +0 -73
- package/esm/src/observability/otel.d.ts.map +0 -1
- package/esm/src/observability/otel.js +0 -260
- package/esm/src/runtime/runtime.d.ts +0 -10
- package/esm/src/runtime/runtime.d.ts.map +0 -1
- package/esm/src/runtime/runtime.deno.d.ts +0 -50
- package/esm/src/runtime/runtime.deno.d.ts.map +0 -1
- package/esm/src/runtime/runtime.deno.js +0 -120
- package/esm/src/runtime/runtime.js +0 -41
- package/esm/src/runtime/runtime.node.d.ts +0 -51
- package/esm/src/runtime/runtime.node.d.ts.map +0 -1
- package/esm/src/runtime/runtime.node.js +0 -268
- package/esm/src/runtime/types.d.ts +0 -107
- package/esm/src/runtime/types.d.ts.map +0 -1
- package/esm/src/runtime/types.js +0 -12
- package/esm/src/security/channel-hmac.d.ts +0 -43
- package/esm/src/security/channel-hmac.d.ts.map +0 -1
- package/esm/src/security/channel-hmac.js +0 -135
- package/esm/src/security/csp.d.ts +0 -50
- package/esm/src/security/csp.d.ts.map +0 -1
- package/esm/src/security/csp.js +0 -63
- package/esm/src/security/message-signer.d.ts +0 -88
- package/esm/src/security/message-signer.d.ts.map +0 -1
- package/esm/src/security/message-signer.js +0 -166
- package/esm/src/subscriptions/subscription-registry.d.ts +0 -256
- package/esm/src/subscriptions/subscription-registry.d.ts.map +0 -1
- package/esm/src/subscriptions/subscription-registry.js +0 -406
- package/esm/src/tasks/mod.d.ts +0 -13
- package/esm/src/tasks/mod.d.ts.map +0 -1
- package/esm/src/tasks/mod.js +0 -11
- package/esm/src/tasks/task-store.d.ts +0 -342
- package/esm/src/tasks/task-store.d.ts.map +0 -1
- package/esm/src/tasks/task-store.js +0 -649
- package/esm/src/transport/request-headers.d.ts +0 -145
- package/esm/src/transport/request-headers.d.ts.map +0 -1
- package/esm/src/transport/request-headers.js +0 -525
- package/esm/src/types.d.ts +0 -776
- package/esm/src/types.d.ts.map +0 -1
- package/esm/src/types.js +0 -92
- package/esm/src/ui/viewer-utils.d.ts +0 -45
- package/esm/src/ui/viewer-utils.d.ts.map +0 -1
- package/esm/src/ui/viewer-utils.js +0 -97
- package/esm/src/validation/schema-validator.d.ts +0 -115
- package/esm/src/validation/schema-validator.d.ts.map +0 -1
- package/esm/src/validation/schema-validator.js +0 -249
package/esm/src/auth/types.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,141 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-id-metadata.d.ts","sourceRoot":"","sources":["../../../src/src/client-auth/client-id-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,MAAM,mBAAmB,GAC3B,sBAAsB,GACtB,2BAA2B,GAC3B,qBAAqB,GACrB,kBAAkB,GAClB,mBAAmB,GACnB,wBAAwB,GACxB,mBAAmB,GACnB,4BAA4B,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,oBAAoB,CAAC;AAE9D,qBAAa,eAAgB,SAAQ,KAAK;aAEtB,IAAI,EAAE,mBAAmB;aAEzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;aAChC,QAAQ,EAAE,MAAM;gBAHhB,IAAI,EAAE,mBAAmB,EACzC,OAAO,EAAE,MAAM,EACC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,QAAQ,EAAE,MAAM,EAChC,OAAO,CAAC,EAAE,YAAY;CAKzB;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,EAAE,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;IACrD,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC;IACzB,0BAA0B,EAAE,MAAM,CAAC;IACnC,mFAAmF;IACnF,gBAAgB,EAAE,QAAQ,GAAG,KAAK,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,iBAAiB,GACxB,MAAM,IAAI,gBAAgB,CAE5B;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAyD5E;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,gBAAgB,GACvB,wBAAwB,CA4B1B;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,MAAM,IAAI,gBAAgB,CAgFpC"}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
export class CimdConfigError extends Error {
|
|
2
|
-
code;
|
|
3
|
-
context;
|
|
4
|
-
recovery;
|
|
5
|
-
constructor(code, message, context, recovery, options) {
|
|
6
|
-
super(message, options);
|
|
7
|
-
this.code = code;
|
|
8
|
-
this.context = context;
|
|
9
|
-
this.recovery = recovery;
|
|
10
|
-
this.name = "CimdConfigError";
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export function isCimdConfig(config) {
|
|
14
|
-
return config.clientRegistration?.method === "client_id_metadata";
|
|
15
|
-
}
|
|
16
|
-
export function resolveClientMode(config) {
|
|
17
|
-
const raw = config;
|
|
18
|
-
const hasClientId = raw.clientId !== undefined;
|
|
19
|
-
const hasClientRegistration = raw.clientRegistration !== undefined;
|
|
20
|
-
if (hasClientId && hasClientRegistration) {
|
|
21
|
-
throw new CimdConfigError("cimd_config_conflict", "OAuth client config cannot include both clientId and clientRegistration", { hasClientId: true, hasClientRegistration: true }, "Choose either static clientId mode or client_id_metadata mode.");
|
|
22
|
-
}
|
|
23
|
-
if (hasClientRegistration) {
|
|
24
|
-
const registration = raw.clientRegistration;
|
|
25
|
-
if (registration === null || typeof registration !== "object" ||
|
|
26
|
-
Array.isArray(registration)) {
|
|
27
|
-
throw new CimdConfigError("cimd_registration_missing", "clientRegistration must be an object with a registration method", { clientRegistration: registration }, 'Provide clientRegistration.method = "client_id_metadata".');
|
|
28
|
-
}
|
|
29
|
-
const method = registration.method;
|
|
30
|
-
if (method === undefined) {
|
|
31
|
-
throw new CimdConfigError("cimd_registration_missing", "clientRegistration.method is required", { method }, 'Provide clientRegistration.method = "client_id_metadata".');
|
|
32
|
-
}
|
|
33
|
-
if (method !== "client_id_metadata") {
|
|
34
|
-
throw new CimdConfigError("cimd_method_invalid", 'Unsupported clientRegistration.method; expected "client_id_metadata"', { method }, 'Set clientRegistration.method to "client_id_metadata".');
|
|
35
|
-
}
|
|
36
|
-
return "client_id_metadata";
|
|
37
|
-
}
|
|
38
|
-
if (typeof raw.clientId !== "string") {
|
|
39
|
-
throw new CimdConfigError("cimd_registration_missing", "OAuth client config requires either clientId or clientRegistration", { hasClientId: false, hasClientRegistration: false }, "Provide clientId for static mode or clientRegistration for CIMD mode.");
|
|
40
|
-
}
|
|
41
|
-
return "static";
|
|
42
|
-
}
|
|
43
|
-
export function buildClientIdMetadataDocument(config) {
|
|
44
|
-
validateCimdClientConfig(config);
|
|
45
|
-
const { clientRegistration } = config;
|
|
46
|
-
const document = {
|
|
47
|
-
...clientRegistration.metadata?.extra,
|
|
48
|
-
client_uri: clientRegistration.metadata?.client_uri,
|
|
49
|
-
logo_uri: clientRegistration.metadata?.logo_uri,
|
|
50
|
-
contacts: clientRegistration.metadata?.contacts,
|
|
51
|
-
client_id: clientRegistration.clientIdMetadataUrl,
|
|
52
|
-
client_name: config.clientName,
|
|
53
|
-
redirect_uris: [clientRegistration.redirectUri],
|
|
54
|
-
grant_types: ["authorization_code", "refresh_token"],
|
|
55
|
-
response_types: ["code"],
|
|
56
|
-
token_endpoint_auth_method: "none",
|
|
57
|
-
application_type: "native",
|
|
58
|
-
};
|
|
59
|
-
if (config.scopes?.length) {
|
|
60
|
-
document.scope = config.scopes.join(" ");
|
|
61
|
-
}
|
|
62
|
-
for (const key of ["client_uri", "logo_uri", "contacts"]) {
|
|
63
|
-
if (document[key] === undefined) {
|
|
64
|
-
delete document[key];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return document;
|
|
68
|
-
}
|
|
69
|
-
export function validateCimdClientConfig(config) {
|
|
70
|
-
const mode = resolveClientMode(config);
|
|
71
|
-
if (mode !== "client_id_metadata") {
|
|
72
|
-
throw new CimdConfigError("cimd_registration_missing", "CIMD config requires clientRegistration", { mode }, 'Provide clientRegistration.method = "client_id_metadata".');
|
|
73
|
-
}
|
|
74
|
-
const raw = config;
|
|
75
|
-
const registration = raw.clientRegistration;
|
|
76
|
-
const metadataUrl = registration.clientIdMetadataUrl;
|
|
77
|
-
try {
|
|
78
|
-
if (typeof metadataUrl !== "string") {
|
|
79
|
-
throw new Error("expected string");
|
|
80
|
-
}
|
|
81
|
-
const parsed = new URL(metadataUrl);
|
|
82
|
-
if (parsed.protocol !== "https:") {
|
|
83
|
-
throw new Error("expected https scheme");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
catch (cause) {
|
|
87
|
-
throw new CimdConfigError("cimd_url_invalid", "clientIdMetadataUrl must be an absolute HTTPS URL", { clientIdMetadataUrl: metadataUrl }, "Provide an absolute https:// URL for clientRegistration.clientIdMetadataUrl.", { cause });
|
|
88
|
-
}
|
|
89
|
-
if (typeof raw.callbackPort !== "number" || raw.callbackPort === 0 ||
|
|
90
|
-
!Number.isFinite(raw.callbackPort)) {
|
|
91
|
-
throw new CimdConfigError("cimd_port_unfixed", "CIMD mode requires a fixed callbackPort", { callbackPort: raw.callbackPort }, "Set callbackPort to a fixed non-zero port and publish the same port in redirectUri.");
|
|
92
|
-
}
|
|
93
|
-
if (typeof raw.clientName !== "string" || raw.clientName.trim().length === 0) {
|
|
94
|
-
throw new CimdConfigError("cimd_name_missing", "CIMD mode requires an explicit clientName", { clientName: raw.clientName }, "Set clientName to the user-facing application name for the metadata document.");
|
|
95
|
-
}
|
|
96
|
-
const redirectUri = registration.redirectUri;
|
|
97
|
-
try {
|
|
98
|
-
if (typeof redirectUri !== "string") {
|
|
99
|
-
throw new Error("expected string");
|
|
100
|
-
}
|
|
101
|
-
const parsedRedirect = new URL(redirectUri);
|
|
102
|
-
if (parsedRedirect.protocol !== "http:") {
|
|
103
|
-
throw new Error("redirect scheme must be http");
|
|
104
|
-
}
|
|
105
|
-
if (parsedRedirect.hostname !== "127.0.0.1") {
|
|
106
|
-
throw new Error("redirect host must be 127.0.0.1");
|
|
107
|
-
}
|
|
108
|
-
if (parsedRedirect.pathname !== "/callback") {
|
|
109
|
-
throw new Error("redirect path must be /callback");
|
|
110
|
-
}
|
|
111
|
-
if (parsedRedirect.port !== String(raw.callbackPort)) {
|
|
112
|
-
throw new Error("redirect port differs from callbackPort");
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch (cause) {
|
|
116
|
-
throw new CimdConfigError("cimd_redirect_mismatch", "redirectUri must match the fixed callbackPort", { redirectUri, callbackPort: raw.callbackPort }, "Set clientRegistration.redirectUri to the exact loopback callback URL that will be used at runtime.", { cause });
|
|
117
|
-
}
|
|
118
|
-
validateExtraMetadataKeys(registration.metadata);
|
|
119
|
-
}
|
|
120
|
-
const RESERVED_METADATA_KEYS = new Set([
|
|
121
|
-
"scope",
|
|
122
|
-
"client_id",
|
|
123
|
-
"client_name",
|
|
124
|
-
"client_uri",
|
|
125
|
-
"logo_uri",
|
|
126
|
-
"contacts",
|
|
127
|
-
"redirect_uris",
|
|
128
|
-
"grant_types",
|
|
129
|
-
"response_types",
|
|
130
|
-
"token_endpoint_auth_method",
|
|
131
|
-
"application_type",
|
|
132
|
-
]);
|
|
133
|
-
function validateExtraMetadataKeys(metadata) {
|
|
134
|
-
if (metadata === null || typeof metadata !== "object") {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const extra = metadata.extra;
|
|
138
|
-
if (extra === undefined) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (extra === null || typeof extra !== "object" || Array.isArray(extra)) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
for (const key of Object.keys(extra)) {
|
|
145
|
-
if (RESERVED_METADATA_KEYS.has(key)) {
|
|
146
|
-
throw new CimdConfigError("cimd_reserved_metadata_key", "clientRegistration.metadata.extra cannot contain reserved metadata keys", { key }, "Move reserved OAuth client metadata fields to their dedicated config fields.");
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sugar helper for preparing an authenticated MCP transport.
|
|
3
|
-
*
|
|
4
|
-
* Wires together OAuthClientProviderImpl with a CallbackServer.
|
|
5
|
-
* The consumer is responsible for creating the StreamableHTTPClientTransport
|
|
6
|
-
* and passing `result.provider` as the `authProvider` option.
|
|
7
|
-
*
|
|
8
|
-
* @module lib/server/client-auth/connect
|
|
9
|
-
*/
|
|
10
|
-
import { OAuthClientProviderImpl } from "./provider.js";
|
|
11
|
-
import type { OAuthClientConfig } from "./types.js";
|
|
12
|
-
import { CallbackServer } from "./callback-server.js";
|
|
13
|
-
export interface PrepareOAuthResult {
|
|
14
|
-
/** The configured provider — pass as authProvider to StreamableHTTPClientTransport */
|
|
15
|
-
provider: OAuthClientProviderImpl;
|
|
16
|
-
/** The callback server instance (caller must close on error paths) */
|
|
17
|
-
callbackServer: CallbackServer;
|
|
18
|
-
/** The actual port the callback server is listening on */
|
|
19
|
-
callbackPort: number;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Prepare an OAuth client provider with a running callback server.
|
|
23
|
-
*
|
|
24
|
-
* Usage:
|
|
25
|
-
* ```typescript
|
|
26
|
-
* const { provider, callbackServer } = await prepareOAuthProvider(serverUrl, config);
|
|
27
|
-
* const transport = new StreamableHTTPClientTransport(new URL(serverUrl), { authProvider: provider });
|
|
28
|
-
* await client.connect(transport);
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare function prepareOAuthProvider(serverUrl: string, config: OAuthClientConfig): Promise<PrepareOAuthResult>;
|
|
32
|
-
//# sourceMappingURL=connect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../src/src/client-auth/connect.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAOtD,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,QAAQ,EAAE,uBAAuB,CAAC;IAClC,sEAAsE;IACtE,cAAc,EAAE,cAAc,CAAC;IAC/B,0DAA0D;IAC1D,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,kBAAkB,CAAC,CA8B7B"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sugar helper for preparing an authenticated MCP transport.
|
|
3
|
-
*
|
|
4
|
-
* Wires together OAuthClientProviderImpl with a CallbackServer.
|
|
5
|
-
* The consumer is responsible for creating the StreamableHTTPClientTransport
|
|
6
|
-
* and passing `result.provider` as the `authProvider` option.
|
|
7
|
-
*
|
|
8
|
-
* @module lib/server/client-auth/connect
|
|
9
|
-
*/
|
|
10
|
-
import { OAuthClientProviderImpl } from "./provider.js";
|
|
11
|
-
import { CallbackServer } from "./callback-server.js";
|
|
12
|
-
import { CimdConfigError, isCimdConfig, resolveClientMode, } from "./client-id-metadata.js";
|
|
13
|
-
/**
|
|
14
|
-
* Prepare an OAuth client provider with a running callback server.
|
|
15
|
-
*
|
|
16
|
-
* Usage:
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const { provider, callbackServer } = await prepareOAuthProvider(serverUrl, config);
|
|
19
|
-
* const transport = new StreamableHTTPClientTransport(new URL(serverUrl), { authProvider: provider });
|
|
20
|
-
* await client.connect(transport);
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export async function prepareOAuthProvider(serverUrl, config) {
|
|
24
|
-
const mode = resolveClientMode(config);
|
|
25
|
-
const provider = new OAuthClientProviderImpl(serverUrl, config);
|
|
26
|
-
const callbackServer = new CallbackServer({
|
|
27
|
-
port: config.callbackPort ?? 0,
|
|
28
|
-
hostname: mode === "client_id_metadata" ? "127.0.0.1" : "localhost",
|
|
29
|
-
timeout: config.authTimeout ?? 120_000,
|
|
30
|
-
});
|
|
31
|
-
const { port } = await callbackServer.start();
|
|
32
|
-
if (isCimdConfig(config)) {
|
|
33
|
-
if (port !== config.callbackPort) {
|
|
34
|
-
await callbackServer.close();
|
|
35
|
-
throw new CimdConfigError("cimd_redirect_mismatch", "CIMD callback server bound to a different port than callbackPort", {
|
|
36
|
-
callbackPort: config.callbackPort,
|
|
37
|
-
boundPort: port,
|
|
38
|
-
redirectUri: config.clientRegistration.redirectUri,
|
|
39
|
-
}, "Set callbackPort to the fixed port used by the callback server and publish the same port in redirectUri.");
|
|
40
|
-
}
|
|
41
|
-
provider.setRedirectUrl(config.clientRegistration.redirectUri);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
provider.setRedirectUrl(`http://localhost:${port}/callback`);
|
|
45
|
-
}
|
|
46
|
-
return { provider, callbackServer, callbackPort: port };
|
|
47
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth client-auth helpers for MCP clients.
|
|
3
|
-
*
|
|
4
|
-
* Includes the local callback server, OAuth client provider wiring, token
|
|
5
|
-
* stores, and Client ID Metadata Document (CIMD) helpers.
|
|
6
|
-
*
|
|
7
|
-
* @module lib/server/client-auth
|
|
8
|
-
*/
|
|
9
|
-
export { prepareOAuthProvider } from "./connect.js";
|
|
10
|
-
export type { PrepareOAuthResult } from "./connect.js";
|
|
11
|
-
export { OAuthClientProviderImpl } from "./provider.js";
|
|
12
|
-
export { CallbackServer } from "./callback-server.js";
|
|
13
|
-
export type { CallbackServerOptions } from "./callback-server.js";
|
|
14
|
-
export type { CimdClientConfig, OAuthClientConfig, OAuthClientConfigBase, StaticClientConfig, StoredCredentials, TokenStore, } from "./types.js";
|
|
15
|
-
export { MemoryTokenStore } from "./token-store/memory-store.js";
|
|
16
|
-
export { FileTokenStore } from "./token-store/file-store.js";
|
|
17
|
-
export { buildClientIdMetadataDocument, CimdConfigError, isCimdConfig, } from "./client-id-metadata.js";
|
|
18
|
-
export type { CimdConfigErrorCode, ClientIdMetadataDocument, } from "./client-id-metadata.js";
|
|
19
|
-
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/client-auth/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAGlE,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAG7D,OAAO,EACL,6BAA6B,EAC7B,eAAe,EACf,YAAY,GACb,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,yBAAyB,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth client-auth helpers for MCP clients.
|
|
3
|
-
*
|
|
4
|
-
* Includes the local callback server, OAuth client provider wiring, token
|
|
5
|
-
* stores, and Client ID Metadata Document (CIMD) helpers.
|
|
6
|
-
*
|
|
7
|
-
* @module lib/server/client-auth
|
|
8
|
-
*/
|
|
9
|
-
// OAuth provider wiring
|
|
10
|
-
export { prepareOAuthProvider } from "./connect.js";
|
|
11
|
-
// OAuthClientProvider implementation
|
|
12
|
-
export { OAuthClientProviderImpl } from "./provider.js";
|
|
13
|
-
// Local callback server
|
|
14
|
-
export { CallbackServer } from "./callback-server.js";
|
|
15
|
-
// Token stores
|
|
16
|
-
export { MemoryTokenStore } from "./token-store/memory-store.js";
|
|
17
|
-
export { FileTokenStore } from "./token-store/file-store.js";
|
|
18
|
-
// Client ID Metadata Documents (CIMD)
|
|
19
|
-
export { buildClientIdMetadataDocument, CimdConfigError, isCimdConfig, } from "./client-id-metadata.js";
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth client provider implementation.
|
|
3
|
-
*
|
|
4
|
-
* Implements OAuthClientProvider from the MCP SDK for authenticating
|
|
5
|
-
* against OAuth-protected MCP servers. Handles token storage,
|
|
6
|
-
* PKCE flow, and browser-based authorization.
|
|
7
|
-
*
|
|
8
|
-
* @module lib/server/client-auth/provider
|
|
9
|
-
*/
|
|
10
|
-
import type { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
11
|
-
import type { OAuthClientProvider, OAuthDiscoveryState } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
12
|
-
import type { OAuthClientConfig } from "./types.js";
|
|
13
|
-
export declare class OAuthClientProviderImpl implements OAuthClientProvider {
|
|
14
|
-
private serverUrl;
|
|
15
|
-
private config;
|
|
16
|
-
private _codeVerifier;
|
|
17
|
-
private _clientInfo;
|
|
18
|
-
private _redirectUrl;
|
|
19
|
-
/**
|
|
20
|
-
* Issuer the SDK resolved for the request currently being authorized
|
|
21
|
-
* (SEP-2352). Set by {@link saveDiscoveryState}, which `auth()` calls after
|
|
22
|
-
* discovery and before it asks for tokens.
|
|
23
|
-
*/
|
|
24
|
-
private _currentIssuer;
|
|
25
|
-
constructor(serverUrl: string, config: OAuthClientConfig);
|
|
26
|
-
get redirectUrl(): string | URL;
|
|
27
|
-
/** Set the redirect URL (called after CallbackServer binds to a port). */
|
|
28
|
-
setRedirectUrl(url: string): void;
|
|
29
|
-
get clientMetadata(): OAuthClientMetadata;
|
|
30
|
-
clientInformation(): Promise<OAuthClientInformationMixed | undefined>;
|
|
31
|
-
saveClientInformation(info: OAuthClientInformationMixed): Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* Record the authorization server the SDK just resolved (SEP-2352).
|
|
34
|
-
*
|
|
35
|
-
* `auth()` calls this after RFC 9728 discovery and before {@link tokens},
|
|
36
|
-
* which is what makes the check there possible.
|
|
37
|
-
*
|
|
38
|
-
* The binding is the **discovered URL**, not `metadata.issuer`. That
|
|
39
|
-
* distinction is the whole protection: `issuer` is a field the authorization
|
|
40
|
-
* server publishes about itself, so an attacker's server reached at
|
|
41
|
-
* `https://attacker.example.com` can claim
|
|
42
|
-
* `issuer: "https://as-one.example.com"` and, since SDK 1.29 validates the
|
|
43
|
-
* metadata's shape without checking it against the URL it was fetched from,
|
|
44
|
-
* would be handed the credentials minted by the real AS-one. The URL the
|
|
45
|
-
* client actually resolved is the one thing in this exchange the server
|
|
46
|
-
* cannot forge.
|
|
47
|
-
*
|
|
48
|
-
* RFC 8414 does require `issuer` to match the discovery URL. A mismatch is
|
|
49
|
-
* therefore a broken or hostile authorization server, and it is logged —
|
|
50
|
-
* but nothing here depends on the claim being honest.
|
|
51
|
-
*/
|
|
52
|
-
saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Stored tokens, unless they were issued by a different authorization server.
|
|
55
|
-
*
|
|
56
|
-
* SEP-2352 makes this a MUST, and the reason is concrete rather than
|
|
57
|
-
* bureaucratic. `auth()` hands whatever this returns to
|
|
58
|
-
* `refreshAuthorization(authorizationServerUrl, …)`, where the URL comes from
|
|
59
|
-
* the MCP server's own protected-resource metadata. A server that changes —
|
|
60
|
-
* or is made to advertise — a different authorization server would therefore
|
|
61
|
-
* receive a refresh token minted by the previous one. The client must not let
|
|
62
|
-
* the resource server pick who sees its credentials.
|
|
63
|
-
*
|
|
64
|
-
* The check only runs once an issuer is known, which is the case inside
|
|
65
|
-
* `auth()`. A transport asking for the bearer to attach to an ordinary
|
|
66
|
-
* request has no issuer in hand, and that path is not the exposure: those
|
|
67
|
-
* tokens go to the MCP server they were minted for, not to an authorization
|
|
68
|
-
* server.
|
|
69
|
-
*/
|
|
70
|
-
tokens(): Promise<OAuthTokens | undefined>;
|
|
71
|
-
saveTokens(tokens: OAuthTokens): Promise<void>;
|
|
72
|
-
private log;
|
|
73
|
-
redirectToAuthorization(authorizationUrl: URL): Promise<void>;
|
|
74
|
-
saveCodeVerifier(codeVerifier: string): Promise<void>;
|
|
75
|
-
codeVerifier(): Promise<string>;
|
|
76
|
-
invalidateCredentials(scope: "all" | "client" | "tokens" | "verifier" | "discovery"): Promise<void>;
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/src/client-auth/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,2BAA2B,EAC3B,mBAAmB,EACnB,WAAW,EACZ,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA0CpD,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,aAAa,CAAM;IAC3B,OAAO,CAAC,WAAW,CAA0C;IAC7D,OAAO,CAAC,YAAY,CAAqB;IACzC;;;;OAIG;IACH,OAAO,CAAC,cAAc,CAAqB;gBAE/B,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;IASxD,IAAI,WAAW,IAAI,MAAM,GAAG,GAAG,CAK9B;IAED,0EAA0E;IAC1E,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAkBjC,IAAI,cAAc,IAAI,mBAAmB,CASxC;IAED,iBAAiB,IAAI,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAarE,qBAAqB,CACnB,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB7D;;;;;;;;;;;;;;;;OAgBG;IACG,MAAM,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAmC1C,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAkCpD,OAAO,CAAC,GAAG;IAIL,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAInE,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrD,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAIzB,qBAAqB,CACzB,KAAK,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,GAC5D,OAAO,CAAC,IAAI,CAAC;CAiBjB"}
|