import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js"; import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"; import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"; import type { OAuthClientInformationMixed } from "@modelcontextprotocol/sdk/shared/auth.js"; import type { FetchLike } from "@modelcontextprotocol/sdk/shared/transport.js"; import { type OAuthServerCloseInfo, type OAuthServerListeningInfo } from "../../auth/server"; import type { McpServerOAuthClientConfig, McpServerRegistration } from "./types"; export type McpSdkAuthCapableTransport = SSEClientTransport | StreamableHTTPClientTransport; export interface CreateMcpOAuthProviderContextOptions { settingsPath?: string; serverName: string; redirectUrl: string; onAuthorizationUrl?: (url: string) => void | Promise; clientInformation?: OAuthClientInformationMixed; } export interface McpOAuthProviderContext { provider: OAuthClientProvider; getLastAuthorizationUrl(): string | undefined; getLastOAuthState(): string | undefined; resetInteractiveState(): Promise; markError(errorMessage: string): Promise; markConnectionError(errorMessage: string): Promise; markAuthorizationRequired(errorMessage: string): Promise; clearError(): Promise; } export interface AuthorizeMcpServerOAuthOptions { serverName: string; filePath?: string; clientName?: string; clientVersion?: string; fetch?: FetchLike; openUrl?: (url: string) => void | Promise; callbackHost?: string; callbackPorts?: number[]; callbackPath?: string; timeoutMs?: number; successHtml?: string; onServerListening?: (info: OAuthServerListeningInfo) => void | Promise; onServerClose?: (info: OAuthServerCloseInfo) => void | Promise; signal?: AbortSignal; } export interface AuthorizeMcpServerOAuthResult { serverName: string; authorized: true; message: string; } export declare function createMcpOAuthClientInformation(config: McpServerOAuthClientConfig | undefined): OAuthClientInformationMixed | undefined; export declare function createMcpOAuthProviderContext(options: CreateMcpOAuthProviderContextOptions): McpOAuthProviderContext; export declare function createMcpSdkTransport(input: { registration: McpServerRegistration; oauthProvider?: OAuthClientProvider; fetch?: FetchLike; }): McpSdkAuthCapableTransport; /** * Recognizes a 401 from a remote MCP server across transports. The streamable * HTTP transport (and SSE message POSTs) reject with the typed * UnauthorizedError raised at the fetch boundary, but the SSE stream request * runs inside EventSource, which consumes the response and reports the HTTP * status only through SseError's code. */ export declare function isMcpUnauthorizedError(error: unknown): boolean; export declare function authorizeMcpServerOAuth(options: AuthorizeMcpServerOAuthOptions): Promise;