/** * The OAuth proxy's authorization server: endpoints, grants, tokens, and * per-request verification. One runtime exists per mounted server. * * @internal */ import type { AuthInfo, OAuthMetadata } from "@modelcontextprotocol/server"; import type { Context } from "hono"; import { type ClientResolver } from "./clients.js"; import { type ConsentPageProps } from "./consent.js"; import { type ProxyKeyring } from "./crypto.js"; import type { SecureStore } from "./storage.js"; import { type Upstream, type UpstreamUser } from "./upstream.js"; /** @internal Settings fixed when the server mounts. */ export interface RuntimeConfig { resource: URL; basePath: string; store: SecureStore; keyring: () => Promise; clients: ClientResolver; upstream: Upstream; fetch: typeof globalThis.fetch; scopes: string[]; accessTokenTtl: number; consent: false | { mode: "always" | "remember"; page?: (props: ConsentPageProps) => unknown; }; /** Host of the MCP server URL, shown on the consent and sign-in pages. */ serverHost: string; } /** @internal Fields the verifier adds to `AuthInfo.extra`. */ export interface ProxyAuthExtra { upstreamUser: UpstreamUser; upstream: { accessToken: string; scopes: string[]; expiresAt?: number; }; userKey: string; } /** @internal The proxy authorization server for one canonical resource. */ export declare class ProxyRuntime { #private; readonly config: RuntimeConfig; readonly issuer: string; readonly paths: { authorize: string; consent: string; callback: string; token: string; register: string; revoke: string; }; /** @param config - Settings fixed when the server mounts. */ constructor(config: RuntimeConfig); /** Absolute URL of a proxy path. */ url(path: string): string; /** RFC 8414 metadata for this authorization server. */ static metadata(resource: URL, basePath: string, options: { dcr: boolean; cimd: boolean; scopes: readonly string[]; }): OAuthMetadata; /** `GET /oauth/authorize`: validates the request and shows consent. */ authorize(c: Context): Promise; /** `POST /oauth/consent`: records the decision and starts the upstream round. */ consent(c: Context): Promise; /** `GET /oauth/callback`: finishes the upstream round and issues a code. */ callback(c: Context): Promise; /** `POST /oauth/token`: the authorization-code and refresh-token grants. */ token(c: Context): Promise; /** `POST /oauth/register`: dynamic client registration. */ register(c: Context): Promise; /** `POST /oauth/revoke`: RFC 7009 token revocation. */ revoke(c: Context): Promise; /** CORS preflight for endpoints that browser-based clients call. */ preflight(c: Context): Response; /** Verifies a proxy access token on each MCP request. */ verifyAccessToken(token: string): Promise; } /** * @internal Describes an error for logs. An upstream error gives only its * safe summary, since its causes can hold tokens; any other error gives its * stack. */ export declare function describe(error: unknown): string;