import { type JWK } from "jose"; import { type AuthorizationServerStore, type AuthorizationGrantRecord, type AuthorizationTransactionRecord, type OAuthAuthorizationServerSigningKey } from "../../mcp-oauth-server/dist/index.js"; import type { HttpAdditionalRequestHandler, TinyHttpMcpServerOAuthOptions } from "../../tiny-http-mcp-server/dist/server.js"; export type HostedOAuthLoginFieldName = "email" | "password" | "apiKey" | (string & {}); export interface HostedOAuthLoginField { name: HostedOAuthLoginFieldName; label?: string; type?: "text" | "email" | "password"; } export interface HostedOAuthCredentialStore { get(subject: string): Promise; set(subject: string, credential: TCredential): Promise; delete(subject: string): Promise; update(subject: string, update: (credential: TCredential) => Promise | TCredential): Promise; } export interface HostedOAuthStorageCapabilities { durable: boolean; encryptedCredentials: boolean; stableKeys: boolean; shared: boolean; } export interface HostedOAuthInteractionStore { set(transaction: AuthorizationTransactionRecord): Promise; get(transactionId: string): Promise; delete(transactionId: string): Promise; } export interface HostedOAuthStorage { authorizationServer: AuthorizationServerStore; interactions: HostedOAuthInteractionStore; credentials: HostedOAuthCredentialStore; capabilities: HostedOAuthStorageCapabilities; signingKey(): Promise; resolveSubject(providerName: string, accountId: string): Promise; healthCheck?(): Promise; cleanup?(now?: number): Promise; onGrantRevoked?(grant: AuthorizationGrantRecord): Promise | void; } export interface HostedOAuthCredentialAccess { read(): Promise; update(update: (credential: TCredential) => Promise | TCredential): Promise; delete(): Promise; } export interface HostedOAuthIdentity { issuer: string; subject: string; clientId: string; scopes: readonly string[]; resource: string; } export interface HostedOAuthProvider { name: string; login?: { fields: readonly (HostedOAuthLoginFieldName | HostedOAuthLoginField)[]; }; connect?(fields: Readonly> & { signal: AbortSignal; }): Promise<{ accountId: string; credential: TCredential; }>; services(input: { credentials: HostedOAuthCredentialAccess; identity: HostedOAuthIdentity; }): Promise> | Partial; } export interface HostedOAuthInteractionAdapter { paths: readonly string[]; start(context: { request: Request; transaction: AuthorizationTransactionRecord; }): Promise | Response; handle(context: { request: Request; complete(input: { transactionId: string; accountId: string; credential: TCredential; }): Promise; }): Promise | Response; } export interface HostedOAuthAdvancedOptions { scopes?: readonly string[]; branding?: { title?: string; }; accessTokenTtlSeconds?: number; authorizationCodeTtlSeconds?: number; authorizationTransactionTtlSeconds?: number; refreshTokenTtlSeconds?: number; additionalPublicJwks?: readonly JWK[]; interaction?: HostedOAuthInteractionAdapter; } export interface HostedOAuthOptions { publicUrl: string; storage: HostedOAuthStorage; provider: HostedOAuthProvider; advanced?: HostedOAuthAdvancedOptions; } export interface PreparedHostedOAuth { publicUrl: URL; issuer: URL; scopes: readonly string[]; } export interface HostedOAuthConfiguration extends HostedOAuthOptions { readonly kind: "hosted"; prepare(options?: { production?: boolean; }): Promise; assertProductionReady(): Promise; } export declare function isHostedOAuthConfiguration(value: unknown): value is HostedOAuthConfiguration; export declare function hostedOAuth(options: HostedOAuthOptions): HostedOAuthConfiguration; export declare class HostedOAuthLoginError extends Error { constructor(message: string); } export interface HostedOAuthRuntime { mcpPath: string; oauth: TinyHttpMcpServerOAuthOptions; requestHandler: HttpAdditionalRequestHandler; requestServices(identity: HostedOAuthIdentity): Promise>; } export declare function createInMemoryHostedOAuthStorage(options: { development: true; }): HostedOAuthStorage;