import { Client, type CallToolResult, type ElicitRequestParams, type ElicitResult, type ReadResourceResult, type Transport } from "@modelcontextprotocol/client"; import { type Config, type ServerConfig } from "./config.js"; import { type CatalogTool } from "./catalog.js"; import { type CompletionTarget, type TemplateTarget, type CatalogResource, type DiscoveryKind } from "./resources.js"; import { type CredentialStoreFactory } from "./auth.js"; import { type ScopeChallenge } from "./authorization.js"; import { type CatalogPrompt } from "./prompts.js"; import { type ElicitationUI } from "./elicitation.js"; import { type Diagnostic } from "./diagnostics.js"; export interface ServerStatus { name: string; state: "disabled" | "connecting" | "failed" | "connected" | "disconnected"; catalogSize?: number; error?: Diagnostic; } export declare class ToolContractError extends Error { } export interface Discovery { tools: CatalogTool[]; resources: CatalogResource[]; templates?: CatalogResource[]; prompts?: CatalogPrompt[]; unavailable: string[]; diagnostics: Diagnostic[]; warnings: string[]; } export interface ConnectionHandlers { scopeChallenge?: (scope: string | undefined) => void; toolsChanged?: () => void; resourcesChanged?: () => void; promptsChanged?: () => void; /** Supplied only in interactive sessions; its presence declares elicitation support. */ elicit?: (params: ElicitRequestParams, signal: AbortSignal) => Promise; elicitationComplete?: (elicitationId: string) => void; } export type ConnectFactory = (name: string, config: ServerConfig, signal: AbortSignal, handlers?: ConnectionHandlers) => Promise<{ client: Client; transport: Transport; }>; /** One SDK client per connection. Protocol behavior stays in the SDK. */ export declare function createClient(config: ServerConfig, handlers?: ConnectionHandlers): Client; export declare function waitFor(promise: Promise, signal?: AbortSignal): Promise; export declare const createSdkConnector: (storeFactory?: CredentialStoreFactory) => ConnectFactory; export declare const connectSdk: ConnectFactory; export declare class McpRuntime { readonly config: Config; readonly cwd: string; private readonly cacheDir; private readonly connect; /** Interactive sessions declare elicitation support to servers. */ private readonly options; private readonly states; private readonly scopeChallenges; private readonly lifetime; private closing?; constructor(config: Config, cwd: string, cacheDir: string, connect?: ConnectFactory, /** Interactive sessions declare elicitation support to servers. */ options?: { interactive?: boolean; }); /** Challenges are session-local, expire, and never survive configuration changes. */ authorizationChallenge(name: string): ScopeChallenge | undefined; clearAuthorizationChallenge(name: string, approved: ScopeChallenge): void; onResourceUpdated?: (server: string, uri: string) => void; private subscriptionGeneration; private subscriptionCleanup; identity(name: string): string; private definition; private state; private client; catalog(name: string, signal?: AbortSignal, refresh?: boolean): Promise; /** Resource catalog caches are memory-only; bodies are never cataloged or cached. */ resourceCatalog(name: string, signal?: AbortSignal, refresh?: boolean, templates?: boolean): Promise; /** Metadata only, memory-only; SDK pagination and notifications own protocol behavior. */ promptCatalog(name: string, signal?: AbortSignal, refresh?: boolean): Promise; /** Explicit command only. No model-facing get operation, cached bodies, or retries. */ getPrompt(name: string, promptName: string, args: Record, signal?: AbortSignal): Promise<{ [x: string]: unknown; messages: { role: "user" | "assistant"; content: { type: "text"; text: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; } | { type: "image"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; } | { type: "audio"; data: string; mimeType: string; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; } | { uri: string; name: string; type: "resource_link"; description?: string | undefined; mimeType?: string | undefined; size?: number | undefined; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; theme?: "light" | "dark" | undefined; }[] | undefined; title?: string | undefined; } | { type: "resource"; resource: { uri: string; text: string; mimeType?: string | undefined; _meta?: { [x: string]: unknown; } | undefined; } | { uri: string; blob: string; mimeType?: string | undefined; _meta?: { [x: string]: unknown; } | undefined; }; annotations?: { audience?: ("user" | "assistant")[] | undefined; priority?: number | undefined; lastModified?: string | undefined; } | undefined; _meta?: { [x: string]: unknown; } | undefined; }; }[]; _meta?: { [x: string]: unknown; "io.modelcontextprotocol/serverInfo"?: { version: string; name: string; websiteUrl?: string | undefined; description?: string | undefined; icons?: { src: string; mimeType?: string | undefined; sizes?: string[] | undefined; theme?: "light" | "dark" | undefined; }[] | undefined; title?: string | undefined; } | undefined; } | undefined; description?: string | undefined; }>; expandResourceTemplate(target: TemplateTarget, signal?: AbortSignal): Promise; completeResource(target: CompletionTarget, signal?: AbortSignal): Promise<{ values: string[]; total: number | undefined; hasMore: boolean | undefined; }>; resourceSubscriptions(): { uri: string; changed: boolean; server: string; }[]; setResourceSubscription(name: string, uri: string, subscribe: boolean, signal?: AbortSignal): Promise; clearResourceSubscriptions(): Promise; readResource(name: string, uri: string, signal?: AbortSignal): Promise; discover(server?: string | string[], signal?: AbortSignal, kind?: DiscoveryKind): Promise; call(tool: CatalogTool, args: Record, signal?: AbortSignal, progress?: (message: string) => void, /** Present server requests for input during this call. */ ui?: ElicitationUI): Promise; /** Server dialogs appear one at a time, in arrival order. */ private dialogs; private dialog; /** Accept requests only while a tool call to this server can show them. */ private elicit; /** Present a required browser step; never replay the refused call. */ private completeRequired; /** Close related OAuth connections without reconnecting, including disabled servers. */ disconnect(names: string[]): Promise; reconnect(name: string): Promise; serverStatuses(): ServerStatus[]; status(server?: string): string; close(): Promise; private shutdown; private failure; private readCache; private writeCache; }