import { SpawnOptions, ChildProcessWithoutNullStreams } from 'node:child_process'; import { Readable, Writable } from 'node:stream'; import http from 'node:http'; import { Server } from 'tiny-stdio-mcp-server'; interface MachineIdentity { hostname: string; username: string; } interface EncryptedFileStoreFileSystem { readFile(path: string, encoding: BufferEncoding): Promise; writeFile(path: string, data: string | NodeJS.ArrayBufferView, options?: { encoding?: BufferEncoding; flag?: string; mode?: number; }): Promise; mkdir(path: string, options?: { recursive?: boolean; }): Promise; rename(oldPath: string, newPath: string): Promise; lstat(path: string): Promise<{ isSymbolicLink(): boolean; }>; unlink(path: string): Promise; chmod(path: string, mode: number): Promise; } interface EncryptedFileStoreInput { fs?: EncryptedFileStoreFileSystem; filePath?: string; salt: string; defaultDirectory?: string; defaultFileName?: string; getMachineIdentity?: () => MachineIdentity | Promise; getHomeDirectory?: () => string; getRandomBytes?: (size: number) => Buffer; } interface KeychainCommandResult { stdout: string; stderr: string; exitCode: number; } interface KeychainCommandOptions { stdin?: string; } type KeychainCommandRunner = (command: string, args: string[], options?: KeychainCommandOptions) => Promise; interface KeychainStoreInput { runCommand?: KeychainCommandRunner; service: string; account: string; } type StoreBackend = "file" | "keychain"; interface CreateSecretStoreInput { backend?: StoreBackend; env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform; backendEnvVar?: string; fileStore?: EncryptedFileStoreInput; keychainStore?: KeychainStoreInput; } type OAuthMetadataFetch = (input: string | URL, init?: RequestInit) => Promise; interface OAuthProtectedResourceMetadata extends Record { resource: string; authorization_servers: string[]; } interface OAuthAuthorizationServerMetadata extends Record { issuer: string; authorization_endpoint: string; token_endpoint: string; registration_endpoint?: string; response_types_supported: string[]; code_challenge_methods_supported: string[]; authorization_response_iss_parameter_supported?: boolean; } interface OAuthDiscoveryResult { resource: string; resourceMetadataUrl: string; resourceMetadata: OAuthProtectedResourceMetadata; authorizationServer: string; authorizationServerMetadataUrl: string; authorizationServerMetadata: OAuthAuthorizationServerMetadata; } interface OAuthUnauthorizedChallenge { scheme: "Bearer"; params: Record; raw: string; } interface OAuthClientProvider { authorizeRequest?(input: { requestUrl: URL; headers: Headers; fetch: OAuthMetadataFetch; }): Promise | void; handleUnauthorized(input: { requestUrl: URL; response: Response; challenge: OAuthUnauthorizedChallenge | null; discovery: OAuthDiscoveryResult; fetch: OAuthMetadataFetch; }): Promise<{ action: "retry"; } | { action: "fail"; error?: Error; }> | { action: "retry"; } | { action: "fail"; error?: Error; }; } interface OAuthClientMetadata { clientName?: string; scope?: string; softwareId?: string; softwareVersion?: string; } interface StoredOAuthTokens { accessToken: string; refreshToken?: string; tokenType: "Bearer"; expiresAt: number | null; scope?: string; } interface StoredOAuthSession { resource: string; authorizationServer: string; client: { clientId: string; clientSecret?: string; }; tokens?: StoredOAuthTokens; discovery: { resourceMetadataUrl: string; resourceMetadata: Record; authorizationServerMetadata: Record; }; } interface OAuthSessionStore { load(resource: string): Promise; save(resource: string, session: StoredOAuthSession): Promise; clear(resource: string): Promise; } interface DefaultOAuthClientProviderOptions { client: { mode: "dynamic"; clientId?: string; clientSecret?: string; metadata?: OAuthClientMetadata; } | { mode: "static"; clientId: string; clientSecret?: string; metadata?: OAuthClientMetadata; }; browser: { openBrowser(url: string): Promise; readLine?: () => Promise; createServer?: () => http.Server; landingPage?: { title: string; body: string; }; }; sessionStore?: OAuthSessionStore; authStore?: CreateSecretStoreInput; now?: () => number; } type OAuthClientProviderOptions = { provider: OAuthClientProvider; } | DefaultOAuthClientProviderOptions; interface OAuthDiscoveryCache { get(resourceUrl: string): OAuthDiscoveryResult | null | undefined | Promise; set(resourceUrl: string, value: OAuthDiscoveryResult): void | Promise; } interface OAuthMetadataDiscoveryOptions { fetch?: OAuthMetadataFetch; cache?: OAuthDiscoveryCache; } interface OAuthMetadataLookupOptions { resourceMetadataUrl?: string | URL; } declare class OAuthMetadataDiscovery { private readonly fetchImpl; private readonly cache; private readonly memoryCache; constructor({ fetch, cache }?: OAuthMetadataDiscoveryOptions); discover(resourceUrl: string | URL, { resourceMetadataUrl }?: OAuthMetadataLookupOptions): Promise; } declare function discoverOAuthMetadata(resourceUrl: string | URL, options?: OAuthMetadataDiscoveryOptions & OAuthMetadataLookupOptions): Promise; type RequestId = number | string; interface Implementation { name: string; version: string; } interface ClientCapabilities { roots?: { listChanged?: boolean; [key: string]: unknown; }; sampling?: { [key: string]: unknown; }; experimental?: Record; } interface ServerCapabilities { prompts?: { listChanged?: boolean; [key: string]: unknown; }; resources?: { subscribe?: boolean; listChanged?: boolean; [key: string]: unknown; }; tools?: { listChanged?: boolean; [key: string]: unknown; }; logging?: { [key: string]: unknown; }; completions?: { [key: string]: unknown; }; experimental?: Record; } interface InitializeParams { protocolVersion: string; capabilities: ClientCapabilities; clientInfo: Implementation; } interface InitializeResult { protocolVersion: string; capabilities: ServerCapabilities; serverInfo: Implementation; instructions?: string; } interface McpClientOptions { clientInfo: Implementation; requestTimeoutMs?: number; capabilities?: ClientCapabilities; onToolsChanged?: () => void | Promise; onResourcesChanged?: () => void | Promise; onResourceUpdated?: (uri: string) => void | Promise; onPromptsChanged?: () => void | Promise; onLog?: (message: LogMessage) => void | Promise; onProgress?: (params: ProgressParams) => void | Promise; onSamplingRequest?: (params: CreateMessageParams) => CreateMessageResult | Promise; onRootsList?: () => Root[] | Promise; } declare class McpClient { private currentState; private currentServerCapabilities; private currentClientCapabilities; private currentServerInfo; private currentInstructions; private readonly subscribedResourceUris; private readonly activeProgressTokens; private readonly options; private transport; private messageLayer; constructor(options: McpClientOptions); get state(): "disconnected" | "initializing" | "ready" | "closed"; get serverCapabilities(): ServerCapabilities | null; get serverInfo(): Implementation | null; get instructions(): string | undefined; private getMessageLayerOrThrow; connect(transport: McpTransport): Promise; private getServerCapabilitiesOrThrow; listTools(params?: PaginatedParams): Promise<{ tools: Tool[]; nextCursor?: string; }>; callTool(params: CallToolParams, options?: CallToolOptions): Promise; listResources(params?: PaginatedParams): Promise<{ resources: Resource[]; nextCursor?: string; }>; listResourceTemplates(params?: PaginatedParams): Promise<{ resourceTemplates: ResourceTemplate[]; nextCursor?: string; }>; readResource(params: ReadResourceParams): Promise<{ contents: ResourceContents[]; }>; subscribe(uri: string): Promise; unsubscribe(uri: string): Promise; listPrompts(params?: PaginatedParams): Promise<{ prompts: Prompt[]; nextCursor?: string; }>; getPrompt(params: GetPromptParams): Promise; complete(params: CompleteParams): Promise; setLogLevel(level: LogLevel): Promise; cancel(requestId: RequestId, reason?: string): Promise; sendRootsChanged(): Promise; ping(): Promise; close(): Promise; } interface Tool { name: string; title?: string; description?: string; inputSchema: Record; outputSchema?: Record; annotations?: ToolAnnotations; } interface ToolAnnotations { title?: string; readOnlyHint?: boolean; destructiveHint?: boolean; idempotentHint?: boolean; openWorldHint?: boolean; } interface CallToolParams { name: string; arguments?: Record; } interface CallToolOptions { signal?: AbortSignal; progressToken?: ProgressToken; } interface ReadResourceParams { uri: string; } interface Resource { uri: string; name: string; description?: string; mimeType?: string; size?: number; } interface ResourceTemplate { uriTemplate: string; name: string; description?: string; mimeType?: string; } interface PaginatedParams { cursor?: string; } interface PaginatedResult { nextCursor?: string; } interface TextResourceContents { uri: string; mimeType?: string; text: string; } interface BlobResourceContents { uri: string; mimeType?: string; blob: string; } type ResourceContents = TextResourceContents | BlobResourceContents; interface TextContent { type: "text"; text: string; } interface ImageContent { type: "image"; data: string; mimeType: string; } interface AudioContent { type: "audio"; data: string; mimeType: string; } interface EmbeddedResource { type: "resource"; resource: ResourceContents; } type ContentItem = TextContent | ImageContent | AudioContent | EmbeddedResource; interface Prompt { name: string; description?: string; arguments?: PromptArgument[]; } interface PromptArgument { name: string; description?: string; required?: boolean; } interface PromptMessage { role: "user" | "assistant"; content: ContentItem; } interface GetPromptResult { description?: string; messages: PromptMessage[]; } interface GetPromptParams { name: string; arguments?: Record; } interface CallToolResult { content: ContentItem[]; structuredContent?: Record; isError?: boolean; } interface Root { uri: string; name?: string; } type LogLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"; interface LogMessage { level: LogLevel; logger?: string; data: unknown; } type ProgressToken = RequestId; interface ProgressParams { progressToken: ProgressToken; progress: number; total?: number; message?: string; } interface ModelHint { name?: string; } interface ModelPreferences { hints?: ModelHint[]; costPriority?: number; speedPriority?: number; intelligencePriority?: number; } interface SamplingMessage { role: "user" | "assistant"; content: ContentItem | ContentItem[]; } type IncludeContext = "none" | "thisServer" | "allServers"; interface CreateMessageParams { messages: SamplingMessage[]; modelPreferences?: ModelPreferences; systemPrompt?: string; includeContext?: IncludeContext; temperature?: number; maxTokens: number; stopSequences?: string[]; metadata?: Record; } interface CreateMessageResult { model: string; content: ContentItem | ContentItem[]; role: "user" | "assistant"; stopReason: string; } interface PromptReference { type: "ref/prompt"; name: string; } interface ResourceReference { type: "ref/resource"; uri: string; } interface CompleteArgument { name: string; value: string; } interface CompleteParams { ref: PromptReference | ResourceReference; argument: CompleteArgument; } interface Completion { values: string[]; hasMore?: boolean; total?: number; } interface CompleteResult { completion: Completion; } declare const ERROR_PARSE = -32700; declare const ERROR_INVALID_REQUEST = -32600; declare const ERROR_METHOD_NOT_FOUND = -32601; declare const ERROR_INVALID_PARAMS = -32602; declare const ERROR_INTERNAL = -32603; interface McpTransportClosedEvent { reason: Error; code?: number; signal?: NodeJS.Signals; } interface McpTransport { readable: Readable; writable: Writable; closed: Promise; dispose(reason?: Error): void; } interface InMemoryServerTransport { readable: Readable; writable: Writable; } interface InMemoryTransportPair { clientTransport: McpTransport; serverTransport: InMemoryServerTransport; } declare function createInMemoryTransportPair(): InMemoryTransportPair; interface McpClientConnection { connect(transport: McpTransport): Promise; close(): Promise; } interface SdkServerConnection { connect(transport: unknown): Promise; } interface SdkTestPair { client: TClient; cleanup: () => Promise; } declare function createSdkTestPair(server: SdkServerConnection, createClient: () => TClient): Promise>; declare function createTestPair(server: Server, createClient: () => TClient): Promise>; type StdioSpawn = (command: string, args: ReadonlyArray, options: SpawnOptions) => ChildProcessWithoutNullStreams; interface StdioTransportOptions { command: string; args?: string[]; cwd?: string; env?: NodeJS.ProcessEnv; spawn?: StdioSpawn; } type HttpTransportFetch = (input: string | URL, init?: RequestInit) => Promise; interface HttpTransportOptions { url: string; headers?: HeadersInit; fetch?: HttpTransportFetch; oauth?: OAuthClientProviderOptions; oauthDiscoveryCache?: OAuthDiscoveryCache; } declare class StdioTransport implements McpTransport { readonly readable: Readable; readonly writable: Writable; readonly closed: Promise; private readonly child; private disposed; private stderrOutput; private static readonly STDERR_MAX_LENGTH; constructor({ command, args, cwd, env, spawn: spawnProcess, }: StdioTransportOptions); getStderrOutput(): string; private appendStderrOutput; dispose(reason?: Error): void; } declare class HttpTransport implements McpTransport { readonly readable: Readable; readonly writable: Writable; readonly closed: Promise; private readonly url; private readonly headers; private readonly fetchImpl; private readonly readStream; private readonly writeStream; private resolveClosed; private sessionId; private lastEventId; private getSseStreamStarted; private disposed; private readonly oauthProvider; private readonly oauthMetadataDiscovery; private readonly inFlightFetchAbortControllers; private readonly openSseReaders; constructor({ url, headers, fetch: fetchImpl, oauth, oauthDiscoveryCache, }: HttpTransportOptions); dispose(reason?: Error): void; private closeWithSessionTermination; private abortInFlightFetches; private cancelOpenSseReaders; private fetchWithAbort; private consumeWrittenLines; private createPostHeaders; private createGetHeaders; private createDeleteHeaders; private authorizeRequestHeaders; private captureSessionId; private maybeOpenGetSseStream; private sendSessionTerminationRequest; private consumeGetSseStream; private throwForPostHttpError; private maybeHandleUnauthorizedResponse; private forwardResponseMessages; private forwardSseResponseMessages; private forwardJsonResponseMessage; private writeSseMessages; private writeReadableLine; private fetchWithOAuthRetry; private readOAuthChallengeError; } interface JsonRpcRequest { jsonrpc: "2.0"; id: RequestId; method: string; params?: unknown; } interface JsonRpcNotification { jsonrpc: "2.0"; method: string; params?: unknown; } interface JsonRpcErrorObject { code: number; message: string; data?: unknown; } declare class McpError extends Error { readonly code: number; readonly data?: unknown; constructor(code: number, message: string, data?: unknown); } interface JsonRpcSuccessResponse { jsonrpc: "2.0"; id: RequestId; result: unknown; } interface JsonRpcErrorResponse { jsonrpc: "2.0"; id: RequestId; error: JsonRpcErrorObject; } type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse; type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse; interface JsonRpcRequestOptions { timeoutMs?: number; onRequestId?: (requestId: RequestId) => void; onTimeout?: (requestId: RequestId) => void; } interface JsonRpcRequestContext { id: RequestId; method: string; } type JsonRpcRequestHandler = (params: unknown, context: JsonRpcRequestContext) => unknown | Promise; interface JsonRpcNotificationContext { method: string; } type JsonRpcNotificationHandler = (params: unknown, context: JsonRpcNotificationContext) => unknown | Promise; declare class JsonRpcMessageLayer { readonly requestTimeoutMs: number; private readonly input; private readonly output; private readonly inputClosedReason; private nextRequestId; private disposedError; private readonly pendingRequests; private readonly activeIncomingRequests; private readonly requestHandlers; private readonly notificationHandlers; constructor(input: Readable, output: Writable, requestTimeoutMs?: number, inputClosedReason?: Promise); sendNotification(method: string, params?: unknown): void; onRequest(method: string, handler: JsonRpcRequestHandler): void; onNotification(method: string, handler: JsonRpcNotificationHandler): void; sendRequest(method: string, params?: unknown, options?: JsonRpcRequestOptions): Promise; cancelRequest(requestId: RequestId, reason: unknown): boolean; dispose(reason?: Error): void; private consumeInput; private resolveInputStreamClosedReason; private processParsedMessage; private handleIncomingRequest; private handleCancellationNotification; } export { ERROR_INTERNAL, ERROR_INVALID_PARAMS, ERROR_INVALID_REQUEST, ERROR_METHOD_NOT_FOUND, ERROR_PARSE, HttpTransport, JsonRpcMessageLayer, McpClient, McpError, OAuthMetadataDiscovery, StdioTransport, createInMemoryTransportPair, createSdkTestPair, createTestPair, discoverOAuthMetadata }; export type { AudioContent, BlobResourceContents, CallToolOptions, CallToolParams, CallToolResult, ClientCapabilities, CompleteArgument, CompleteParams, CompleteResult, Completion, ContentItem, CreateMessageParams, CreateMessageResult, EmbeddedResource, GetPromptParams, GetPromptResult, HttpTransportFetch, HttpTransportOptions, ImageContent, Implementation, InMemoryTransportPair, IncludeContext, InitializeParams, InitializeResult, JsonRpcErrorObject, JsonRpcErrorResponse, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcRequestOptions, JsonRpcResponse, JsonRpcSuccessResponse, LogLevel, LogMessage, McpClientConnection, McpClientOptions, McpTransport, McpTransportClosedEvent, ModelHint, ModelPreferences, OAuthAuthorizationServerMetadata, OAuthClientProvider, OAuthClientProviderOptions, OAuthDiscoveryCache, OAuthDiscoveryResult, OAuthMetadataFetch, OAuthProtectedResourceMetadata, OAuthSessionStore, OAuthUnauthorizedChallenge, PaginatedParams, PaginatedResult, ProgressParams, ProgressToken, Prompt, PromptArgument, PromptMessage, PromptReference, ReadResourceParams, RequestId, Resource, ResourceContents, ResourceReference, ResourceTemplate, Root, SamplingMessage, SdkTestPair, ServerCapabilities, StdioSpawn, StdioTransportOptions, StoredOAuthSession, TextContent, TextResourceContents, Tool, ToolAnnotations };