/** * MCP OAuth Auto-Discovery * * Automatically detects OAuth requirements from MCP server responses * and extracts authentication endpoints. */ import type { AddressResolver } from "../web/insane/url-guard"; export interface OAuthEndpoints { authorizationUrl: string; tokenUrl: string; clientId?: string; scopes?: string; /** Issuer recorded from the validated metadata document (RFC 9207). */ issuer?: string; /** `authorization_response_iss_parameter_supported` from the same metadata. */ authorizationResponseIssSupported?: boolean; } export interface AuthDetectionResult { requiresAuth: boolean; authType?: "oauth" | "apikey" | "unknown"; oauth?: OAuthEndpoints; authServerUrl?: string; message?: string; } interface OAuthDiscoveryOptions { fetch?: (input: string | URL | Request, init?: BunFetchRequestInit) => Promise; resolver?: AddressResolver; maxRequests?: number; maxNodes?: number; maxRedirects?: number; timeoutMs?: number; signal?: AbortSignal; } export declare function extractMcpAuthServerUrl(error: Error): string | undefined; /** * Detect if an error indicates authentication is required. * Checks for common auth error patterns. */ export declare function detectAuthError(error: Error): boolean; /** * Extract OAuth endpoints from error response. * Looks for WWW-Authenticate header format or JSON error bodies. */ export declare function extractOAuthEndpoints(error: Error): OAuthEndpoints | null; /** * Analyze an error to determine authentication requirements. * Returns structured info about what auth is needed. */ export declare function analyzeAuthError(error: Error): AuthDetectionResult; /** * Try to discover OAuth endpoints by querying the server's well-known endpoints. * This is a fallback when error responses don't include OAuth metadata. */ export declare function discoverOAuthEndpoints(serverUrl: string, authServerUrl?: string, options?: OAuthDiscoveryOptions): Promise; export {};