@lostgradient/mcp 0.1.0 → 0.2.1
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/README.md +68 -8
- package/dist/chunk-3ek3knfm.js +73 -0
- package/dist/{chunk-v14p4gng.js → chunk-3rr24vhh.js} +4 -1
- package/dist/chunk-6ekjtvcq.js +273 -0
- package/dist/chunk-7dpts3r9.js +909 -0
- package/dist/chunk-88nhf6xt.js +449 -0
- package/dist/{chunk-psnez3q2.js → chunk-k6fm3cmk.js} +23 -2
- package/dist/chunk-rxnyn7tf.js +19 -0
- package/dist/{chunk-mf3t0afg.js → chunk-wfty87ws.js} +1 -1
- package/dist/{chunk-wmkqd45r.js → chunk-xcf742mf.js} +1 -1
- package/dist/chunk-yf4nw40e.js +1102 -0
- package/dist/conformance.d.ts +43 -0
- package/dist/env.d.ts +1 -1
- package/dist/env.js +2 -2
- package/dist/environment-schema.d.ts +1 -1
- package/dist/environment-schema.js +1 -1
- package/dist/http/authenticate.d.ts +35 -0
- package/dist/http/authorization-header.d.ts +5 -0
- package/dist/http/grant-revocation-channel.d.ts +24 -0
- package/dist/http/handler.d.ts +32 -0
- package/dist/http/index.d.ts +27 -0
- package/dist/http/index.js +813 -0
- package/dist/http/request-context.d.ts +17 -0
- package/dist/http/responses.d.ts +11 -0
- package/dist/http/serving-layer.d.ts +18 -0
- package/dist/http/user-handler-cache.d.ts +37 -0
- package/dist/http/user-server-event-bus.d.ts +35 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +230 -940
- package/dist/logger.d.ts +20 -0
- package/dist/logger.js +9 -5
- package/dist/oauth/authorize-endpoint.d.ts +5 -0
- package/dist/oauth/canonicalize-ip-address.d.ts +20 -0
- package/dist/oauth/client-authentication.d.ts +10 -0
- package/dist/oauth/client-metadata-documents.d.ts +52 -0
- package/dist/oauth/client-metadata-documents.js +19 -0
- package/dist/oauth/discovery-metadata.d.ts +19 -0
- package/dist/oauth/endpoint-rate-limits.d.ts +10 -0
- package/dist/oauth/endpoint-responses.d.ts +10 -0
- package/dist/oauth/index.d.ts +214 -0
- package/dist/oauth/index.js +69 -0
- package/dist/oauth/network-identity.d.ts +32 -0
- package/dist/oauth/pkce-validation.d.ts +2 -0
- package/dist/oauth/postgres/client-store.d.ts +12 -0
- package/dist/oauth/postgres/code-store.d.ts +14 -0
- package/dist/oauth/postgres/database.d.ts +18 -0
- package/dist/oauth/postgres/index.d.ts +11 -0
- package/dist/oauth/postgres/index.js +584 -0
- package/dist/oauth/postgres/schema.d.ts +1455 -0
- package/dist/oauth/postgres/token-store.d.ts +16 -0
- package/dist/oauth/postgres/transaction-store.d.ts +14 -0
- package/dist/oauth/redirect-uri-matching.d.ts +2 -0
- package/dist/oauth/registration-endpoint.d.ts +2 -0
- package/dist/oauth/request-body.d.ts +14 -0
- package/dist/oauth/revocation-endpoint.d.ts +2 -0
- package/dist/oauth/safe-public-https-fetch.d.ts +28 -0
- package/dist/oauth/scope-utilities.d.ts +15 -0
- package/dist/oauth/security-utilities.d.ts +8 -0
- package/dist/oauth/stores.d.ts +225 -0
- package/dist/oauth/stores.js +0 -0
- package/dist/oauth/testing/contract-fixtures.d.ts +134 -0
- package/dist/oauth/testing/index.d.ts +56 -0
- package/dist/oauth/testing/index.js +330 -0
- package/dist/oauth/token-endpoint.d.ts +2 -0
- package/dist/oauth-scope-configuration.d.ts +3 -0
- package/dist/rate-limit/in-memory-sliding-window-store.d.ts +3 -0
- package/dist/rate-limit/index.d.ts +23 -0
- package/dist/rate-limit/index.js +29 -0
- package/dist/rate-limit/mcp-concurrency-limiter.d.ts +26 -0
- package/dist/rate-limit/rate-limit-response.d.ts +1 -0
- package/dist/rate-limit/redis-sliding-window-store.d.ts +2 -0
- package/dist/rate-limit/request-rate-limiter.d.ts +10 -0
- package/dist/rate-limit/sliding-window-rate-limiter.d.ts +16 -0
- package/dist/scopes.d.ts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/sveltekit-mount-state.d.ts +4 -0
- package/dist/sveltekit-mount.d.ts +43 -0
- package/dist/sveltekit-mount.js +332 -0
- package/dist/tool-response.d.ts +6 -0
- package/dist/types/primitives.d.ts +1 -1
- package/dist/ui-extension-support.d.ts +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +56 -4
package/dist/logger.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import pino from 'pino';
|
|
2
2
|
import type { DestinationStream } from 'pino';
|
|
3
|
+
/**
|
|
4
|
+
* The complete logging surface used by the MCP engine. Hosts can satisfy
|
|
5
|
+
* this structurally with their existing logger; no pino import or pino type
|
|
6
|
+
* is required. A child must preserve the same four-method contract.
|
|
7
|
+
*/
|
|
8
|
+
export interface McpLogger {
|
|
9
|
+
info(bindingsOrMessage: Record<string, unknown> | string, message?: string): void;
|
|
10
|
+
warn(bindingsOrMessage: Record<string, unknown> | string, message?: string): void;
|
|
11
|
+
error(bindingsOrMessage: Record<string, unknown> | string, message?: string): void;
|
|
12
|
+
child(bindings: Record<string, unknown>): McpLogger;
|
|
13
|
+
}
|
|
3
14
|
/**
|
|
4
15
|
* OBS-001 / S-14: `logger.ts` previously declared no redaction paths at
|
|
5
16
|
* all, so any structured field that happened to carry a credential-shaped
|
|
@@ -35,5 +46,14 @@ export declare const redactionPaths: readonly string[];
|
|
|
35
46
|
export declare function createLogger(options?: {
|
|
36
47
|
destination?: DestinationStream;
|
|
37
48
|
}): pino.Logger;
|
|
49
|
+
/**
|
|
50
|
+
* Replaces the engine's logging sink with a host-owned logger. Existing
|
|
51
|
+
* callers that never call `setLogger` continue to use the lazy pino logger.
|
|
52
|
+
* The exported `logger` and `getLogger()` retain their complete pino contract;
|
|
53
|
+
* injection changes only the engine's internal sink.
|
|
54
|
+
*/
|
|
55
|
+
export declare function setLogger(nextLogger: McpLogger): void;
|
|
38
56
|
export declare function getLogger(): pino.Logger;
|
|
57
|
+
/** Package-internal facade that selects the host sink when one is configured. */
|
|
58
|
+
export declare const engineLogger: McpLogger;
|
|
39
59
|
export declare const logger: pino.Logger;
|
package/dist/logger.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createLogger,
|
|
3
|
+
engineLogger,
|
|
3
4
|
getLogger,
|
|
4
5
|
logger,
|
|
5
|
-
redactionPaths
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import"./chunk-
|
|
6
|
+
redactionPaths,
|
|
7
|
+
setLogger
|
|
8
|
+
} from "./chunk-k6fm3cmk.js";
|
|
9
|
+
import"./chunk-3rr24vhh.js";
|
|
10
|
+
import"./chunk-xcf742mf.js";
|
|
9
11
|
export {
|
|
10
12
|
createLogger,
|
|
13
|
+
engineLogger,
|
|
11
14
|
getLogger,
|
|
12
15
|
logger,
|
|
13
|
-
redactionPaths
|
|
16
|
+
redactionPaths,
|
|
17
|
+
setLogger
|
|
14
18
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OAuthHostSeams, OAuthRequestContext } from './index.js';
|
|
2
|
+
export declare const authorizeFormParameterNames: readonly ["transaction_id", "csrf_token"];
|
|
3
|
+
export declare function handleOauthAuthorizeGet<Scope extends string>(context: OAuthRequestContext, seams: OAuthHostSeams<Scope>): Promise<Response>;
|
|
4
|
+
export declare function handleOauthAuthorizeApprove<Scope extends string>(context: OAuthRequestContext, seams: OAuthHostSeams<Scope>): Promise<Response>;
|
|
5
|
+
export declare function handleOauthAuthorizeDeny<Scope extends string>(context: OAuthRequestContext, seams: OAuthHostSeams<Scope>): Promise<Response>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expands an IPv6 address (including one with an embedded IPv4 dotted-quad
|
|
3
|
+
* suffix, e.g. `::ffff:192.168.1.1`) into its eight zero-padded hextet
|
|
4
|
+
* groups. Exported so trusted-proxy CIDR matching can reuse the same
|
|
5
|
+
* parsing instead of re-deriving it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function expandIpv6Groups(address: string): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Strips a trailing `:port` suffix from an address/port pair, handling
|
|
10
|
+
* both bracketed IPv6 (`[2001:db8::1]:4711`) and IPv4 (`1.2.3.4:5678`)
|
|
11
|
+
* forms. Returns the input unchanged when no port suffix is present.
|
|
12
|
+
*/
|
|
13
|
+
export declare function stripPort(input: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Canonicalizes an IPv4, IPv4-mapped IPv6, or IPv6 address string into one
|
|
16
|
+
* consistent representation: lowercase, zone-id stripped, IPv4-mapped IPv6
|
|
17
|
+
* collapsed to plain IPv4, and IPv6 compressed per RFC 5952. Addresses that
|
|
18
|
+
* are not valid IPv4/IPv6 are returned lowercased and trimmed as-is.
|
|
19
|
+
*/
|
|
20
|
+
export declare function canonicalizeIpAddress(input: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RegisteredClient } from './stores.js';
|
|
2
|
+
import type { OAuthStatelessHostSeams } from './index.js';
|
|
3
|
+
export type OauthClientAuthenticationResult = {
|
|
4
|
+
ok: true;
|
|
5
|
+
client: RegisteredClient;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
};
|
|
9
|
+
/** Sole client-authentication choke point shared by token and revocation endpoints. */
|
|
10
|
+
export declare function authenticateOauthClient<Scope extends string>(clientId: string, clientSecret: string | undefined, seams: OAuthStatelessHostSeams<Scope>): Promise<OauthClientAuthenticationResult>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type DnsLookupAllFunction } from './safe-public-https-fetch.js';
|
|
2
|
+
export { ClientMetadataDocumentFetchError, resetDnsLookupConcurrencyLimiterForTests, safeFetchPublicHttpsUrl, } from './safe-public-https-fetch.js';
|
|
3
|
+
export type { DnsLookupAllFunction, SafePublicHttpsFetchOptions, } from './safe-public-https-fetch.js';
|
|
4
|
+
export type ClientMetadataDocumentFetchDependencies = {
|
|
5
|
+
fetchImpl?: typeof fetch;
|
|
6
|
+
lookupImpl?: DnsLookupAllFunction;
|
|
7
|
+
now?: () => number;
|
|
8
|
+
/**
|
|
9
|
+
* Deadline for the DNS-resolution phase of `assertHostnameIsPubliclyRoutable`, in
|
|
10
|
+
* milliseconds. Defaults to the safe fetch's five-second budget -- the same bound already
|
|
11
|
+
* applied to the HTTP fetch that follows, so the whole preflight (resolve + connect) has one
|
|
12
|
+
* consistent time budget rather than an unbounded resolve step ahead of a bounded fetch.
|
|
13
|
+
* Overridable so tests can exercise the timeout path without a 5-second wait.
|
|
14
|
+
*/
|
|
15
|
+
dnsTimeoutMs?: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A `client_id` is a Client ID Metadata Document identifier only if it is
|
|
19
|
+
* an HTTPS URL with a non-root path component (the MCP spec's own
|
|
20
|
+
* requirement, matching the CIMD draft: `https://example.com/client.json`,
|
|
21
|
+
* never bare `https://example.com`), no fragment, and no embedded userinfo.
|
|
22
|
+
* A DCR `client_id` is always a `randomUUID()`, so this never collides with
|
|
23
|
+
* one.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isClientIdMetadataDocumentUrl(clientId: string): boolean;
|
|
26
|
+
export type ClientIdMetadataDocument = {
|
|
27
|
+
clientId: string;
|
|
28
|
+
clientName: string;
|
|
29
|
+
redirectUris: string[];
|
|
30
|
+
grantTypes: string[];
|
|
31
|
+
responseTypes: string[];
|
|
32
|
+
applicationType: 'web' | 'native' | null;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Fetches, validates, and caches the Client ID Metadata Document at
|
|
36
|
+
* `clientId`. Returns `null` for every failure mode (not publicly
|
|
37
|
+
* routable, unreachable, wrong content type, oversized, malformed JSON,
|
|
38
|
+
* schema violation, a `client_id` field that does not exactly match this
|
|
39
|
+
* URL) rather than throwing, so every caller has exactly one branch to
|
|
40
|
+
* handle: "no usable document" — never a distinguishable error a caller
|
|
41
|
+
* could use to probe internal network shape.
|
|
42
|
+
*/
|
|
43
|
+
export declare function fetchClientIdMetadataDocument(clientId: string, dependencies?: ClientMetadataDocumentFetchDependencies): Promise<ClientIdMetadataDocument | null>;
|
|
44
|
+
/** Test-only: clears the module-local cache so tests don't leak state across files/cases. */
|
|
45
|
+
export declare function clearClientIdMetadataDocumentCacheForTests(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Test-only: resets the DNS lookup concurrency limiter's process-global
|
|
48
|
+
* state. `outstandingDnsLookupCount` and `inFlightDnsLookupsByHostname` are
|
|
49
|
+
* shared across every test file in the same process -- without this, a test
|
|
50
|
+
* that saturates the limiter (or leaves a lookup in flight past its own
|
|
51
|
+
* test's lifetime) would leak that state into the next test file's run.
|
|
52
|
+
*/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClientMetadataDocumentFetchError,
|
|
3
|
+
clearClientIdMetadataDocumentCacheForTests,
|
|
4
|
+
fetchClientIdMetadataDocument,
|
|
5
|
+
isClientIdMetadataDocumentUrl,
|
|
6
|
+
resetDnsLookupConcurrencyLimiterForTests,
|
|
7
|
+
safeFetchPublicHttpsUrl
|
|
8
|
+
} from "../chunk-88nhf6xt.js";
|
|
9
|
+
import"../chunk-k6fm3cmk.js";
|
|
10
|
+
import"../chunk-3rr24vhh.js";
|
|
11
|
+
import"../chunk-xcf742mf.js";
|
|
12
|
+
export {
|
|
13
|
+
ClientMetadataDocumentFetchError,
|
|
14
|
+
clearClientIdMetadataDocumentCacheForTests,
|
|
15
|
+
fetchClientIdMetadataDocument,
|
|
16
|
+
isClientIdMetadataDocumentUrl,
|
|
17
|
+
resetDnsLookupConcurrencyLimiterForTests,
|
|
18
|
+
safeFetchPublicHttpsUrl
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { McpRegistry } from '../scope-vocabulary.js';
|
|
2
|
+
import type { OAuthConfiguration, OAuthRequestContext } from './index.js';
|
|
3
|
+
export type OAuthDiscoveryConfiguration = Pick<OAuthConfiguration, 'issuer' | 'baseUrl' | 'mcpUiExtension'> & {
|
|
4
|
+
resource: URL;
|
|
5
|
+
serverName: string;
|
|
6
|
+
mcpProtocolVersion: string;
|
|
7
|
+
serviceDocumentation?: URL;
|
|
8
|
+
privacyPolicy?: URL;
|
|
9
|
+
termsOfService?: URL;
|
|
10
|
+
};
|
|
11
|
+
export declare const oauthCorsHeaders: {
|
|
12
|
+
'Access-Control-Allow-Origin': string;
|
|
13
|
+
'Access-Control-Allow-Methods': string;
|
|
14
|
+
'Access-Control-Allow-Headers': string;
|
|
15
|
+
'Access-Control-Expose-Headers': string;
|
|
16
|
+
};
|
|
17
|
+
export declare function handleOauthAuthorizationMetadataGet(_context: OAuthRequestContext, configuration: OAuthDiscoveryConfiguration, registry: McpRegistry): Response;
|
|
18
|
+
export declare function handleOauthProtectedResourceMetadataGet(_context: OAuthRequestContext, configuration: OAuthDiscoveryConfiguration, registry: McpRegistry): Response;
|
|
19
|
+
export declare function handleOauthProtectedResourceMcpMetadataGet(_context: OAuthRequestContext, configuration: OAuthDiscoveryConfiguration, registry: McpRegistry): Response;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OAuthRateLimitCategory, OAuthRequestContext, OAuthStatelessHostSeams } from './index.js';
|
|
2
|
+
export declare function networkIdentity<Scope extends string>(context: OAuthRequestContext, seams: OAuthStatelessHostSeams<Scope>): string;
|
|
3
|
+
export declare function rateLimitResponse<Scope extends string>(input: {
|
|
4
|
+
context: OAuthRequestContext;
|
|
5
|
+
seams: OAuthStatelessHostSeams<Scope>;
|
|
6
|
+
category: OAuthRateLimitCategory;
|
|
7
|
+
identifier?: string;
|
|
8
|
+
}): Promise<Response | undefined>;
|
|
9
|
+
export declare function isAuthenticationLockedOut<Scope extends string>(context: OAuthRequestContext, seams: OAuthStatelessHostSeams<Scope>): Promise<boolean>;
|
|
10
|
+
export declare function recordFailedAuthentication<Scope extends string>(context: OAuthRequestContext, seams: OAuthStatelessHostSeams<Scope>): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const oauthNoStoreHeaders: {
|
|
2
|
+
'Cache-Control': string;
|
|
3
|
+
Pragma: string;
|
|
4
|
+
'Access-Control-Allow-Origin': string;
|
|
5
|
+
'Access-Control-Allow-Methods': string;
|
|
6
|
+
'Access-Control-Allow-Headers': string;
|
|
7
|
+
'Access-Control-Expose-Headers': string;
|
|
8
|
+
};
|
|
9
|
+
export declare function oauthJson(body: unknown, status?: number, headers?: HeadersInit): Response;
|
|
10
|
+
export declare function oauthBodyError(error: unknown): Response;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { McpScopeVocabulary } from '../scope-vocabulary.js';
|
|
2
|
+
import type { McpUserProfile } from '../types/primitives.js';
|
|
3
|
+
import type { ClientStore, CodeStore, OAuthStores, TokenStore } from './stores.js';
|
|
4
|
+
import type { ClientIdMetadataDocument } from './client-metadata-documents.js';
|
|
5
|
+
import * as clientMetadataDocuments from './client-metadata-documents.js';
|
|
6
|
+
import * as securityUtilities from './security-utilities.js';
|
|
7
|
+
import * as canonicalAddressUtilities from './canonicalize-ip-address.js';
|
|
8
|
+
export { handleOauthAuthorizationMetadataGet, handleOauthProtectedResourceMetadataGet, handleOauthProtectedResourceMcpMetadataGet, oauthCorsHeaders, } from './discovery-metadata.js';
|
|
9
|
+
export type { OAuthDiscoveryConfiguration } from './discovery-metadata.js';
|
|
10
|
+
export declare const fetchClientIdMetadataDocument: typeof clientMetadataDocuments.fetchClientIdMetadataDocument;
|
|
11
|
+
export declare const isClientIdMetadataDocumentUrl: typeof clientMetadataDocuments.isClientIdMetadataDocumentUrl;
|
|
12
|
+
export declare const safeFetchPublicHttpsUrl: typeof clientMetadataDocuments.safeFetchPublicHttpsUrl;
|
|
13
|
+
export declare const isAddressInCidr: typeof securityUtilities.isAddressInCidr;
|
|
14
|
+
export declare const isValidCidr: typeof securityUtilities.isValidCidr;
|
|
15
|
+
export declare const isValidRedirectUri: typeof securityUtilities.isValidRedirectUri;
|
|
16
|
+
export declare const isValidClientName: typeof securityUtilities.isValidClientName;
|
|
17
|
+
export declare const isExactContentType: typeof securityUtilities.isExactContentType;
|
|
18
|
+
export declare const withDeadline: typeof securityUtilities.withDeadline;
|
|
19
|
+
export declare const canonicalizeIpAddress: typeof canonicalAddressUtilities.canonicalizeIpAddress;
|
|
20
|
+
export declare const expandIpv6Groups: typeof canonicalAddressUtilities.expandIpv6Groups;
|
|
21
|
+
export declare const stripPort: typeof canonicalAddressUtilities.stripPort;
|
|
22
|
+
export type { ClientIdMetadataDocument, ClientMetadataDocumentFetchDependencies, DnsLookupAllFunction, SafePublicHttpsFetchOptions, } from './client-metadata-documents.js';
|
|
23
|
+
export type TrustedProxyHeader = 'x-forwarded-for' | 'forwarded' | 'cf-connecting-ip';
|
|
24
|
+
export type TrustedProxyConfiguration = {
|
|
25
|
+
/** CIDR blocks whose immediate socket peer may supply the configured forwarding header. */
|
|
26
|
+
trustedProxyCidrs: string[];
|
|
27
|
+
/** Undefined means forwarding headers are never trusted. */
|
|
28
|
+
trustedProxyHeader: TrustedProxyHeader | undefined;
|
|
29
|
+
/** Number of trusted proxy hops preceding the client in a multi-value header. */
|
|
30
|
+
trustedProxyHopCount: number;
|
|
31
|
+
};
|
|
32
|
+
export type OAuthRequestContext = {
|
|
33
|
+
request: Request;
|
|
34
|
+
requestUrl: URL;
|
|
35
|
+
requestId: string;
|
|
36
|
+
/**
|
|
37
|
+
* The immediate socket peer, not an adapter-resolved forwarding header.
|
|
38
|
+
* The library combines this with `request.headers` and the trusted-proxy
|
|
39
|
+
* configuration before deriving a rate-limit or lockout identity.
|
|
40
|
+
*/
|
|
41
|
+
socketAddress?: string;
|
|
42
|
+
/** Durable host subject and opaque consent binding, resolved together. */
|
|
43
|
+
identity: OAuthIdentity | null;
|
|
44
|
+
};
|
|
45
|
+
export type OAuthIdentity = {
|
|
46
|
+
/** Durable subject identifier persisted on grants and tokens. */
|
|
47
|
+
subjectId: string;
|
|
48
|
+
/** Opaque account or session value used only to bind consent. */
|
|
49
|
+
consentBinding: string;
|
|
50
|
+
};
|
|
51
|
+
/** Resolves durable attribution and an opaque consent binding in one host lookup. */
|
|
52
|
+
export type ResolveIdentityBinding = (request: Request) => Promise<OAuthIdentity | null>;
|
|
53
|
+
/** Resolves the host profile required to construct MCP context for a token subject. */
|
|
54
|
+
export type ResolveUserProfile = (subjectId: string) => Promise<McpUserProfile | null>;
|
|
55
|
+
/** Starts or otherwise handles host authentication for an authorization request. */
|
|
56
|
+
export type HandleUnauthenticatedAuthorization = (request: Request) => Response | Promise<Response>;
|
|
57
|
+
export type ConsentPresentation = {
|
|
58
|
+
mode: 'error';
|
|
59
|
+
error: string;
|
|
60
|
+
} | {
|
|
61
|
+
mode: 'prompt';
|
|
62
|
+
transactionId: string;
|
|
63
|
+
/** One-time plaintext value rendered into approve and deny submissions. */
|
|
64
|
+
csrfToken: string;
|
|
65
|
+
/** Verified client redirect URI shown as consent destination context. */
|
|
66
|
+
redirectUri: string;
|
|
67
|
+
client: {
|
|
68
|
+
id: string;
|
|
69
|
+
name: string;
|
|
70
|
+
};
|
|
71
|
+
requester: McpUserProfile;
|
|
72
|
+
scopes: Array<{
|
|
73
|
+
scope: string;
|
|
74
|
+
description: string;
|
|
75
|
+
}>;
|
|
76
|
+
};
|
|
77
|
+
export type RenderConsent = (presentation: ConsentPresentation) => Response | Promise<Response>;
|
|
78
|
+
export type OAuthScopeConfiguration<Scope extends string> = {
|
|
79
|
+
vocabulary: McpScopeVocabulary<Scope>;
|
|
80
|
+
/** Production scopes mechanically derived from the registry being served. */
|
|
81
|
+
supportedScopes: readonly Scope[];
|
|
82
|
+
};
|
|
83
|
+
export type SlidingWindowRateLimiterResult = {
|
|
84
|
+
allowed: boolean;
|
|
85
|
+
retryAfterSeconds: number;
|
|
86
|
+
remainingRequests: number;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Performs one indivisible prune-count-admit operation. Splitting admission
|
|
90
|
+
* across remove, count, and add round trips reopens the concurrency race this
|
|
91
|
+
* contract exists to prevent.
|
|
92
|
+
*/
|
|
93
|
+
export type AtomicSlidingWindowStore = {
|
|
94
|
+
consume(input: {
|
|
95
|
+
key: string;
|
|
96
|
+
nowMilliseconds: number;
|
|
97
|
+
windowMilliseconds: number;
|
|
98
|
+
maximumRequests: number;
|
|
99
|
+
member: string;
|
|
100
|
+
}): Promise<{
|
|
101
|
+
allowed: boolean;
|
|
102
|
+
retryAfterMilliseconds: number;
|
|
103
|
+
remainingRequests: number;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Best-effort and non-atomic. This is suitable only for advisory checks
|
|
107
|
+
* that tolerate an off-by-one race, never for admission control.
|
|
108
|
+
*/
|
|
109
|
+
peek(input: {
|
|
110
|
+
key: string;
|
|
111
|
+
nowMilliseconds: number;
|
|
112
|
+
windowMilliseconds: number;
|
|
113
|
+
}): Promise<number>;
|
|
114
|
+
};
|
|
115
|
+
export type ConcurrencySlot = {
|
|
116
|
+
readonly id: string;
|
|
117
|
+
};
|
|
118
|
+
export interface ConcurrencySlotStore {
|
|
119
|
+
acquire(key: string, maximumConcurrent: number, ttlMilliseconds: number): Promise<ConcurrencySlot | null>;
|
|
120
|
+
renew(key: string, slot: ConcurrencySlot, ttlMilliseconds: number): Promise<boolean>;
|
|
121
|
+
release(key: string, slot: ConcurrencySlot): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
export type RateLimitCategoryConfiguration = {
|
|
124
|
+
maximumRequests: number;
|
|
125
|
+
windowSeconds: number;
|
|
126
|
+
};
|
|
127
|
+
export type OAuthRateLimitCategory = 'oauth_authorize' | 'oauth_register' | 'oauth_token_network' | 'oauth_token_client' | 'oauth_revoke' | 'mcp_network' | 'mcp_user' | 'failed_authentication';
|
|
128
|
+
export type RateLimitConfiguration = {
|
|
129
|
+
categories: Readonly<Record<OAuthRateLimitCategory, RateLimitCategoryConfiguration>>;
|
|
130
|
+
/** Maximum live operations admitted through the concurrency slot store. */
|
|
131
|
+
maximumConcurrent: number;
|
|
132
|
+
/**
|
|
133
|
+
* Optional isolation for shared backing stores. Real deployments leave it
|
|
134
|
+
* empty; concurrent test runs use distinct values instead of weakening the
|
|
135
|
+
* limits they are meant to exercise.
|
|
136
|
+
*/
|
|
137
|
+
keyNamespace?: string;
|
|
138
|
+
};
|
|
139
|
+
/** Only the Redis operations required by the library-provided store factories. */
|
|
140
|
+
export interface MinimalRedisClient {
|
|
141
|
+
eval(script: string, options: {
|
|
142
|
+
keys: string[];
|
|
143
|
+
arguments: string[];
|
|
144
|
+
}): Promise<unknown>;
|
|
145
|
+
zRem(key: string, member: string): Promise<number>;
|
|
146
|
+
}
|
|
147
|
+
export type OAuthConfiguration = {
|
|
148
|
+
/** Exact OAuth issuer identifier. Consumers must use this same value in authorization responses. */
|
|
149
|
+
issuer: string;
|
|
150
|
+
baseUrl: URL;
|
|
151
|
+
/** Canonical RFC 8707 resource identifier accepted by both token grants. */
|
|
152
|
+
resource: URL;
|
|
153
|
+
accessTokenTtlSeconds: number;
|
|
154
|
+
refreshTokenTtlSeconds: number;
|
|
155
|
+
clientSecretTtlSeconds: number;
|
|
156
|
+
isTrustedOrigin(origin: string): boolean;
|
|
157
|
+
trustedProxy: TrustedProxyConfiguration;
|
|
158
|
+
rateLimits: RateLimitConfiguration;
|
|
159
|
+
/**
|
|
160
|
+
* Authorization-server metadata advertises MCP Apps support only when this
|
|
161
|
+
* is enabled and the injected registry contains an MCP App resource.
|
|
162
|
+
*/
|
|
163
|
+
mcpUiExtension: {
|
|
164
|
+
enabled: boolean;
|
|
165
|
+
};
|
|
166
|
+
rateLimitStores?: {
|
|
167
|
+
slidingWindow: AtomicSlidingWindowStore;
|
|
168
|
+
concurrencySlots?: ConcurrencySlotStore;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
export type CrossInstanceMessaging = {
|
|
172
|
+
publish(channel: string, message: string): Promise<void>;
|
|
173
|
+
subscribe(channel: string, onMessage: (message: string) => void): Promise<() => Promise<void>>;
|
|
174
|
+
};
|
|
175
|
+
export type OAuthHostSeams<Scope extends string> = {
|
|
176
|
+
fetchClientIdMetadataDocument(clientId: string): Promise<ClientIdMetadataDocument | null>;
|
|
177
|
+
resolveIdentityBinding: ResolveIdentityBinding;
|
|
178
|
+
resolveUserProfile: ResolveUserProfile;
|
|
179
|
+
handleUnauthenticatedAuthorization: HandleUnauthenticatedAuthorization;
|
|
180
|
+
renderConsent: RenderConsent;
|
|
181
|
+
stores: OAuthStores;
|
|
182
|
+
scopes: OAuthScopeConfiguration<Scope>;
|
|
183
|
+
configuration: OAuthConfiguration;
|
|
184
|
+
/** Existing host credential hash function; plaintext authorization codes never enter stores. */
|
|
185
|
+
hashCredential(value: string): string;
|
|
186
|
+
crossInstanceMessaging?: CrossInstanceMessaging;
|
|
187
|
+
/** Preserve host metrics and structured logs without coupling the library to a logger. */
|
|
188
|
+
recordEvent?(event: {
|
|
189
|
+
category: 'authorization' | 'registration' | 'client_authentication' | 'token_exchange' | 'refresh' | 'revocation';
|
|
190
|
+
outcome: string;
|
|
191
|
+
attributes?: Readonly<Record<string, string | boolean>>;
|
|
192
|
+
}): void;
|
|
193
|
+
};
|
|
194
|
+
/** Host capabilities needed by endpoints that do not render application UI. */
|
|
195
|
+
export type OAuthStatelessHostSeams<Scope extends string> = Pick<OAuthHostSeams<Scope>, 'scopes' | 'configuration' | 'crossInstanceMessaging' | 'recordEvent'> & {
|
|
196
|
+
stores: {
|
|
197
|
+
clients: ClientStore;
|
|
198
|
+
codes: CodeStore;
|
|
199
|
+
tokens: TokenStore;
|
|
200
|
+
};
|
|
201
|
+
/** Existing host credential hash function; plaintext credentials never cross into stores. */
|
|
202
|
+
hashCredential(value: string): string;
|
|
203
|
+
/** Disconnect or notify live grants after a replay or explicit revocation. */
|
|
204
|
+
publishGrantRevocation?(subjectId: string): Promise<void>;
|
|
205
|
+
};
|
|
206
|
+
export { authenticateOauthClient } from './client-authentication.js';
|
|
207
|
+
export { constantTimeEquals } from './security-utilities.js';
|
|
208
|
+
export { handleOauthRegisterPost } from './registration-endpoint.js';
|
|
209
|
+
export { handleOauthTokenPost } from './token-endpoint.js';
|
|
210
|
+
export { handleOauthRevokePost } from './revocation-endpoint.js';
|
|
211
|
+
export { authorizeFormParameterNames, handleOauthAuthorizeApprove, handleOauthAuthorizeDeny, handleOauthAuthorizeGet, } from './authorize-endpoint.js';
|
|
212
|
+
export { isValidPkceCodeChallenge, isValidPkceCodeVerifier } from './pkce-validation.js';
|
|
213
|
+
export { isSocketPeerTrusted, resolveOauthNetworkIdentity } from './network-identity.js';
|
|
214
|
+
export type { AccessToken, AuthorizationCode, AuthorizationTransaction, RefreshToken, RegisteredClient, } from './stores.js';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authenticateOauthClient,
|
|
3
|
+
authorizeFormParameterNames,
|
|
4
|
+
canonicalizeIpAddress,
|
|
5
|
+
expandIpv6Groups,
|
|
6
|
+
fetchClientIdMetadataDocument,
|
|
7
|
+
handleOauthAuthorizationMetadataGet,
|
|
8
|
+
handleOauthAuthorizeApprove,
|
|
9
|
+
handleOauthAuthorizeDeny,
|
|
10
|
+
handleOauthAuthorizeGet,
|
|
11
|
+
handleOauthProtectedResourceMcpMetadataGet,
|
|
12
|
+
handleOauthProtectedResourceMetadataGet,
|
|
13
|
+
handleOauthRegisterPost,
|
|
14
|
+
handleOauthRevokePost,
|
|
15
|
+
handleOauthTokenPost,
|
|
16
|
+
isAddressInCidr,
|
|
17
|
+
isClientIdMetadataDocumentUrl,
|
|
18
|
+
isExactContentType,
|
|
19
|
+
isSocketPeerTrusted,
|
|
20
|
+
isValidCidr,
|
|
21
|
+
isValidClientName,
|
|
22
|
+
isValidPkceCodeChallenge,
|
|
23
|
+
isValidPkceCodeVerifier,
|
|
24
|
+
isValidRedirectUri,
|
|
25
|
+
oauthCorsHeaders,
|
|
26
|
+
resolveOauthNetworkIdentity,
|
|
27
|
+
safeFetchPublicHttpsUrl,
|
|
28
|
+
stripPort,
|
|
29
|
+
withDeadline
|
|
30
|
+
} from "../chunk-yf4nw40e.js";
|
|
31
|
+
import {
|
|
32
|
+
constantTimeEquals
|
|
33
|
+
} from "../chunk-88nhf6xt.js";
|
|
34
|
+
import"../chunk-3ek3knfm.js";
|
|
35
|
+
import"../chunk-rxnyn7tf.js";
|
|
36
|
+
import"../chunk-k6fm3cmk.js";
|
|
37
|
+
import"../chunk-3rr24vhh.js";
|
|
38
|
+
import"../chunk-xcf742mf.js";
|
|
39
|
+
export {
|
|
40
|
+
authenticateOauthClient,
|
|
41
|
+
authorizeFormParameterNames,
|
|
42
|
+
canonicalizeIpAddress,
|
|
43
|
+
constantTimeEquals,
|
|
44
|
+
expandIpv6Groups,
|
|
45
|
+
fetchClientIdMetadataDocument,
|
|
46
|
+
handleOauthAuthorizationMetadataGet,
|
|
47
|
+
handleOauthAuthorizeApprove,
|
|
48
|
+
handleOauthAuthorizeDeny,
|
|
49
|
+
handleOauthAuthorizeGet,
|
|
50
|
+
handleOauthProtectedResourceMcpMetadataGet,
|
|
51
|
+
handleOauthProtectedResourceMetadataGet,
|
|
52
|
+
handleOauthRegisterPost,
|
|
53
|
+
handleOauthRevokePost,
|
|
54
|
+
handleOauthTokenPost,
|
|
55
|
+
isAddressInCidr,
|
|
56
|
+
isClientIdMetadataDocumentUrl,
|
|
57
|
+
isExactContentType,
|
|
58
|
+
isSocketPeerTrusted,
|
|
59
|
+
isValidCidr,
|
|
60
|
+
isValidClientName,
|
|
61
|
+
isValidPkceCodeChallenge,
|
|
62
|
+
isValidPkceCodeVerifier,
|
|
63
|
+
isValidRedirectUri,
|
|
64
|
+
oauthCorsHeaders,
|
|
65
|
+
resolveOauthNetworkIdentity,
|
|
66
|
+
safeFetchPublicHttpsUrl,
|
|
67
|
+
stripPort,
|
|
68
|
+
withDeadline
|
|
69
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type TrustedProxyHeader = 'x-forwarded-for' | 'forwarded' | 'cf-connecting-ip';
|
|
2
|
+
export type TrustedProxyConfiguration = {
|
|
3
|
+
/** CIDR blocks (IPv4 or IPv6) whose immediate socket peer is trusted to supply a forwarding header. Empty means nothing is trusted. */
|
|
4
|
+
trustedProxyCidrs: string[];
|
|
5
|
+
/** Which forwarding header to trust, once the peer is verified trusted. `undefined` means never trust any header. */
|
|
6
|
+
trustedProxyHeader: TrustedProxyHeader | undefined;
|
|
7
|
+
/** How many trusted proxy hops precede the real client in a multi-value header. */
|
|
8
|
+
trustedProxyHopCount: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Whether the immediate socket peer is one of the configured trusted
|
|
12
|
+
* proxies -- exported so any caller that needs to decide "can I trust a
|
|
13
|
+
* self-reported header from whoever is directly connected to me" can reuse
|
|
14
|
+
* this exact check, rather than re-deriving it (see
|
|
15
|
+
* `bearer-credential-authentication.ts`'s `isPlaintextTransport`, which
|
|
16
|
+
* uses this to decide whether `X-Forwarded-Proto` is trustworthy, the same
|
|
17
|
+
* way `resolveNetworkIdentity` below uses it to decide whether a
|
|
18
|
+
* forwarded-for-style header is).
|
|
19
|
+
*/
|
|
20
|
+
export declare function isSocketPeerTrusted(canonicalSocketAddress: string, configuration: TrustedProxyConfiguration): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves the network identity of a request: the socket address, unless
|
|
23
|
+
* that socket address is itself a trusted proxy, in which case the
|
|
24
|
+
* configured forwarding header (read only from the trusted side of the
|
|
25
|
+
* chain) is trusted instead. Every result is canonicalized so IPv4,
|
|
26
|
+
* IPv4-mapped IPv6, and alternate IPv6 spellings collapse to one identity.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveOauthNetworkIdentity(input: {
|
|
29
|
+
socketAddress: string | undefined;
|
|
30
|
+
headers: Headers;
|
|
31
|
+
configuration: TrustedProxyConfiguration;
|
|
32
|
+
}): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ClientStore, RegisteredClient } from '../stores.js';
|
|
2
|
+
import { type PostgresOAuthDatabase } from './database.js';
|
|
3
|
+
import type { PostgresOAuthSchema } from './schema.js';
|
|
4
|
+
export declare class PostgresClientStore implements ClientStore {
|
|
5
|
+
private readonly database;
|
|
6
|
+
private readonly schema;
|
|
7
|
+
constructor(database: PostgresOAuthDatabase, schema: PostgresOAuthSchema);
|
|
8
|
+
register(record: RegisteredClient): Promise<void>;
|
|
9
|
+
upsert(record: RegisteredClient): Promise<void>;
|
|
10
|
+
findById(clientId: string): Promise<RegisteredClient | null>;
|
|
11
|
+
update(clientId: string, patch: Partial<RegisteredClient>): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AuthorizationCode, CodeStore, ConsumedAuthorizationCode } from '../stores.js';
|
|
2
|
+
import { type PostgresOAuthDatabase } from './database.js';
|
|
3
|
+
import type { PostgresOAuthSchema } from './schema.js';
|
|
4
|
+
export declare class PostgresCodeStore implements CodeStore {
|
|
5
|
+
private readonly database;
|
|
6
|
+
private readonly schema;
|
|
7
|
+
constructor(database: PostgresOAuthDatabase, schema: PostgresOAuthSchema);
|
|
8
|
+
issue(record: AuthorizationCode): Promise<void>;
|
|
9
|
+
findByHash(codeHash: string): Promise<AuthorizationCode | null>;
|
|
10
|
+
consume(codeHash: string, now: Date): Promise<ConsumedAuthorizationCode | null>;
|
|
11
|
+
unconsume(codeHash: string, usedAt: Date): Promise<boolean>;
|
|
12
|
+
deleteAllForUser(userId: string): Promise<number>;
|
|
13
|
+
purgeExpired(now: Date): Promise<number>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { sql, type SQL } from 'drizzle-orm';
|
|
2
|
+
export type PostgresOAuthExecutor = {
|
|
3
|
+
execute(query: SQL): Promise<unknown>;
|
|
4
|
+
};
|
|
5
|
+
export type PostgresOAuthDatabase = PostgresOAuthExecutor & {
|
|
6
|
+
transaction<T>(callback: (transaction: PostgresOAuthExecutor) => Promise<T>): Promise<T>;
|
|
7
|
+
};
|
|
8
|
+
export declare function hashOpaqueValue(value: string): string;
|
|
9
|
+
export declare function resultRows<T>(result: unknown): T[];
|
|
10
|
+
export declare function affectedRows(result: unknown): number;
|
|
11
|
+
export declare function countRows(result: unknown): number;
|
|
12
|
+
export declare function columnIdentifier(column: {
|
|
13
|
+
name: string;
|
|
14
|
+
}): import("drizzle-orm").Name;
|
|
15
|
+
export declare function qualifiedColumnIdentifier(alias: string, column: {
|
|
16
|
+
name: string;
|
|
17
|
+
}): SQL;
|
|
18
|
+
export { sql };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { createPostgresOAuthSchema } from './schema.js';
|
|
2
|
+
export type { PostgresOAuthSchema, PostgresOAuthSchemaOptions } from './schema.js';
|
|
3
|
+
export type { PostgresOAuthDatabase } from './database.js';
|
|
4
|
+
export { PostgresTransactionStore } from './transaction-store.js';
|
|
5
|
+
export { PostgresCodeStore } from './code-store.js';
|
|
6
|
+
export { PostgresTokenStore } from './token-store.js';
|
|
7
|
+
export { PostgresClientStore } from './client-store.js';
|
|
8
|
+
import type { OAuthStores } from '../stores.js';
|
|
9
|
+
import type { PostgresOAuthDatabase } from './database.js';
|
|
10
|
+
import type { PostgresOAuthSchema } from './schema.js';
|
|
11
|
+
export declare function createPostgresOAuthStores(database: PostgresOAuthDatabase, schema: PostgresOAuthSchema): OAuthStores;
|