import { Client, type GetPromptResult, type ReadResourceResult, type RequestOptions, type UrlElicitationRequiredError } from "@modelcontextprotocol/client"; import { type McpTool, type McpResource, type McpPrompt, type ServerDefinition, type ServerStreamResultPatchNotification, type Transport, type McpTraceSettings } from "./types.ts"; import { type McpOAuthRuntime } from "./mcp-auth-flow.ts"; import type { AuthStorageOptions } from "./mcp-auth.ts"; import { type ServerSamplingConfig } from "./sampling-handler.ts"; import { type ServerElicitationConfig } from "./elicitation-handler.ts"; export interface ServerConnection { client: Client; transport: Transport; definition: ServerDefinition; tools: McpTool[]; resources: McpResource[]; prompts: McpPrompt[]; /** True when prompts were advertised but prompts/list failed. */ promptDiscoveryFailed?: boolean; instructions?: string; lastUsedAt: number; inFlight: number; status: "connected" | "closed" | "needs-auth"; } type UiStreamListener = (serverName: string, notification: ServerStreamResultPatchNotification["params"]) => void; type MetadataListChangedListener = (serverName: string, reason: string) => void; interface ConnectOptions { /** Programmatic Streamable HTTP sources must never silently become legacy SSE. */ allowLegacySseFallback?: boolean; /** Secret-free definition retained after launch for request/runtime policy. */ retainedDefinition?: ServerDefinition; /** Programmatic values are callback-resolved and must not consult process.env. */ values?: "config" | "resolved"; } export declare class McpServerManager { private readonly defaultCwd?; private connections; private connectPromises; private reconnectPromises; private uiStreamListeners; private samplingConfig; private metadataListChangedListener; private elicitationConfig; private authStorageOptions; private oauthRuntime; private acceptedUrlElicitations; private defaultRequestTimeoutMs; private runtimeSignal; private closePromises; private closeGenerations; private connectAttempts; private traceSettings; private traceWriter; private stopped; /** Default cwd for stdio servers without an explicit config `cwd`. */ constructor(defaultCwd?: string | undefined); setSamplingConfig(config: ServerSamplingConfig | undefined): void; setMetadataListChangedListener(listener: MetadataListChangedListener | undefined): void; setElicitationConfig(config: ServerElicitationConfig | undefined): void; setRuntimeSignal(signal: AbortSignal | undefined): void; setDefaultRequestTimeoutMs(timeoutMs: number | undefined): void; setTraceConfig(settings: McpTraceSettings | undefined): void; setAuthStorageOptions(options: AuthStorageOptions): void; setOAuthRuntime(runtime: McpOAuthRuntime): void; getRequestOptions(name: string, signal?: AbortSignal): RequestOptions | undefined; private getResolvedRequestTimeoutMs; private buildRequestOptions; connect(name: string, definition: ServerDefinition, signal?: AbortSignal, options?: ConnectOptions): Promise; /** * Reconnect a server whose connection was proven stale (e.g. by a 404 * "session no longer exists" response). Single-flight per server name — * concurrent callers that raced to the same failure share one reconnect — * and identity-guarded: `staleConnection` is only torn down if it is * still the manager's current connection for `name`. If a concurrent * reconnect (or an unrelated connect()) already replaced it with a fresh * connection, that fresh connection is returned untouched. */ reconnect(name: string, definition: ServerDefinition, staleConnection: ServerConnection, signal?: AbortSignal): Promise; private doReconnect; private createConnection; private enrichHttpConnectionError; private connectClientWithAbort; private buildClientCapabilities; private createClient; private handleToolsListChanged; private handlePromptsListChanged; private handleResourcesListChanged; handleUrlElicitationRequired(serverName: string, error: UrlElicitationRequiredError): Promise<"accept" | "decline" | "cancel">; private rememberUrlElicitation; private connectHttpClient; private fetchAllTools; private fetchAllPrompts; private fetchAllResources; private invokeDetachedCallback; private reportDetachedCallbackFailure; private attachAdapterNotificationHandlers; registerUiStreamListener(streamToken: string, listener: UiStreamListener): void; removeUiStreamListener(streamToken: string): void; getPrompt(name: string, promptName: string, args?: Record, signal?: AbortSignal): Promise; readResource(name: string, uri: string, signal?: AbortSignal): Promise; close(name: string): Promise; private disposeConnection; closeAll(): Promise; private containsCleanupFailure; getConnection(name: string): ServerConnection | undefined; getAllConnections(): Map; touch(name: string): void; incrementInFlight(name: string): void; decrementInFlight(name: string): void; isIdle(name: string, timeoutMs: number): boolean; } export {};