import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import type { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js'; import { type ServerCapabilities, type Implementation, type LoggingMessageNotificationParams } from '@modelcontextprotocol/sdk/types.js'; import type { JSONValue } from './types/json.js'; import type { ElicitationCallback } from './types/elicitation.js'; import { McpTool } from './tools/mcp-tool.js'; /** * Widened transport type that accepts MCP transport implementations without requiring explicit casts. * * Under `exactOptionalPropertyTypes`, `StreamableHTTPClientTransport` is not directly assignable * to `Transport` because its `sessionId` getter returns `string | undefined`, while `Transport` * declares `sessionId?: string` (absent or string, but not explicitly undefined). * This type relaxes that constraint so users can pass any MCP transport without `as Transport`. */ export type McpTransport = Omit & { sessionId?: string | undefined; }; /** Temporary placeholder for RuntimeConfig */ export interface RuntimeConfig { applicationName?: string; applicationVersion?: string; } /** * Configuration for MCP task-augmented tool execution. * * WARNING: MCP Tasks is an experimental feature in both the MCP specification and this SDK. * The API may change without notice in future versions. * * When provided to McpClient, enables task-based tool invocation which supports * long-running tools with progress tracking. Without this config, tools are * called directly without task management. */ export interface TasksConfig { /** * Time-to-live in milliseconds for task polling. * Defaults to 60000 (60 seconds). */ ttl?: number; /** * Maximum time in milliseconds to wait for task completion during polling. * Defaults to 300000 (5 minutes). */ pollTimeout?: number; } /** Connection state of an MCP client. */ export type McpConnectionState = 'disconnected' | 'connected' | 'failed'; /** Options for MCP tool invocation. */ export interface McpCallToolOptions { /** AbortSignal to cancel the in-flight request. */ signal?: AbortSignal; } /** OAuth client credentials for machine-to-machine authentication. */ export interface McpClientCredentials { clientId: string; clientSecret: string; /** OAuth scopes to request. Joined with spaces before sending to the token endpoint. */ scopes?: string[]; } /** Behavioral options shared by all MCP client configurations. */ export interface McpClientOptions extends RuntimeConfig { /** Disable OpenTelemetry MCP instrumentation. */ disableMcpInstrumentation?: boolean; /** * Configuration for task-augmented tool execution (experimental). * When provided (even as empty object), enables MCP task-based tool invocation. * When undefined, tools are called directly without task management. */ tasksConfig?: TasksConfig; /** * Callback to handle server-initiated elicitation requests. * When provided, the client advertises elicitation support (form + url modes) * and routes incoming elicitation requests to this callback. */ elicitationCallback?: ElicitationCallback; /** When true, connection failures are logged as warnings instead of throwing. */ continueOnError?: boolean; /** Called when the server emits a log message. Defaults to routing through the Strands logger. */ logHandler?: (params: LoggingMessageNotificationParams) => void; } /** Arguments for configuring an MCP Client. */ export type McpClientConfig = McpClientOptions & { /** Pre-constructed transport. Mutually exclusive with `url`. */ transport?: McpTransport; /** Server URL. When provided, a StreamableHTTP transport is constructed automatically. */ url?: string | URL; /** Client credentials for OAuth machine-to-machine auth. Requires `url`. */ auth?: McpClientCredentials; /** Custom OAuth provider for advanced auth flows. Requires `url`. Mutually exclusive with `auth`. */ authProvider?: OAuthClientProvider; /** Custom headers to include on every request to the server. Requires `url`. */ headers?: Record; }; /** MCP Client for interacting with Model Context Protocol servers. */ export declare class McpClient { /** Default TTL for task polling in milliseconds (60 seconds). */ static readonly DEFAULT_TTL = 60000; /** Default poll timeout for task completion in milliseconds (5 minutes). */ static readonly DEFAULT_POLL_TIMEOUT = 300000; private _clientName; private _clientVersion; private _transport; private _state; private _client; private _continueOnError; private _logHandler; private _disableMcpInstrumentation; private _tasksConfig; private _elicitationCallback; private _registeredToolNames; private _onToolsChanged; private _refreshingTools; private _pendingRefresh; constructor(args: McpClientConfig); private static _resolveTransport; get client(): Client; get serverCapabilities(): ServerCapabilities | undefined; get serverVersion(): Implementation | undefined; get serverInstructions(): string | undefined; get connectionState(): McpConnectionState; get clientName(): string; get continueOnError(): boolean; /** * Connects the MCP client to the server. * * Called lazily before any operation that requires a connection. When `continueOnError` is true, * connection failures are swallowed and the client enters a `'failed'` state — subsequent * calls are no-ops until `connect(true)` is called explicitly to retry. * * @param reconnect - When true, forces a reconnect even if already connected or failed. * @returns A promise that resolves when the connection is established. */ connect(reconnect?: boolean): Promise; /** * Disconnects the MCP client from the server and cleans up resources. * * @returns A promise that resolves when the disconnection is complete. */ disconnect(): Promise; /** * Enables the `await using` pattern for automatic resource cleanup. * Delegates to {@link McpClient.disconnect}. */ [Symbol.asyncDispose](): Promise; /** * Lists the tools available on the server and returns them as executable McpTool instances. * * @returns A promise that resolves with an array of McpTool instances. */ listTools(): Promise; /** * Sets a callback invoked when the MCP server's tool list changes at runtime. * * @param callback - Handler receiving the previous tool names and the refreshed tool instances, * or undefined to remove the callback. */ set onToolsChanged(callback: ((oldTools: string[], newTools: McpTool[]) => void) | undefined); private _handleToolsChanged; /** * Invoke a tool on the connected MCP server using an McpTool instance. * * When `tasksConfig` was provided to the client constructor, uses experimental * task-based invocation which supports long-running tools with progress tracking. * Otherwise, calls tools directly without task management. * * @param tool - The McpTool instance to invoke. * @param args - The arguments to pass to the tool. * @param options - Optional settings for the request. * @returns A promise that resolves with the result of the tool invocation. */ callTool(tool: McpTool, args: JSONValue, options?: McpCallToolOptions): Promise; } //# sourceMappingURL=mcp.d.ts.map