Skip to content

McpClient

Defined in: src/mcp.ts:122

MCP Client for interacting with Model Context Protocol servers.

new McpClient(args): McpClient;

Defined in: src/mcp.ts:144

| Parameter | Type | | --------- | ---------------------------------------- | | args | McpClientConfig |

McpClient

readonly static DEFAULT_TTL: 60000 = 60000;

Defined in: src/mcp.ts:124

Default TTL for task polling in milliseconds (60 seconds).


readonly static DEFAULT_POLL_TIMEOUT: 300000 = 300000;

Defined in: src/mcp.ts:127

Default poll timeout for task completion in milliseconds (5 minutes).

get client(): Client;

Defined in: src/mcp.ts:213

Client


get serverCapabilities(): any;

Defined in: src/mcp.ts:217

any


get serverVersion(): any;

Defined in: src/mcp.ts:221

any


get serverInstructions(): string;

Defined in: src/mcp.ts:225

string


get connectionState(): McpConnectionState;

Defined in: src/mcp.ts:229

McpConnectionState


get clientName(): string;

Defined in: src/mcp.ts:233

string


get continueOnError(): boolean;

Defined in: src/mcp.ts:237

boolean


set onToolsChanged(callback): void;

Defined in: src/mcp.ts:339

Sets a callback invoked when the MCP server’s tool list changes at runtime.

| Parameter | Type | Description | | ---------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------- | | callback | (oldTools, newTools) => void | Handler receiving the previous tool names and the refreshed tool instances, or undefined to remove the callback. |

void

connect(reconnect?): Promise<void>;

Defined in: src/mcp.ts:251

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.

| Parameter | Type | Default value | Description | | ----------- | --------- | ------------- | ------------------------------------------------------------------ | | reconnect | boolean | false | When true, forces a reconnect even if already connected or failed. |

Promise<void>

A promise that resolves when the connection is established.


disconnect(): Promise<void>;

Defined in: src/mcp.ts:283

Disconnects the MCP client from the server and cleans up resources.

Promise<void>

A promise that resolves when the disconnection is complete.


asyncDispose: Promise<void>;

Defined in: src/mcp.ts:294

Enables the await using pattern for automatic resource cleanup. Delegates to McpClient.disconnect.

Promise<void>


listTools(): Promise<McpTool[]>;

Defined in: src/mcp.ts:303

Lists the tools available on the server and returns them as executable McpTool instances.

Promise<McpTool[]>

A promise that resolves with an array of McpTool instances.


callTool(
tool,
args,
options?): Promise<JSONValue>;

Defined in: src/mcp.ts:377

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.

| Parameter | Type | Description | | ---------- | ---------------------------------------------- | ---------------------------------- | | tool | McpTool | The McpTool instance to invoke. | | args | JSONValue | The arguments to pass to the tool. | | options? | McpCallToolOptions | Optional settings for the request. |

Promise<JSONValue>

A promise that resolves with the result of the tool invocation.