Skip to content

McpClient

Defined in: src/mcp.ts:55

MCP Client for interacting with Model Context Protocol servers.

new McpClient(args): McpClient;

Defined in: src/mcp.ts:70

ParameterType
argsMcpClientConfig

McpClient

readonly static DEFAULT_TTL: 60000 = 60000;

Defined in: src/mcp.ts:57

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


readonly static DEFAULT_POLL_TIMEOUT: 300000 = 300000;

Defined in: src/mcp.ts:60

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

get client(): Client;

Defined in: src/mcp.ts:84

Client

connect(reconnect?): Promise<void>;

Defined in: src/mcp.ts:95

Connects the MCP client to the server.

This function is exposed to allow consumers to connect manually, but will be called lazily before any operations that require a connection.

ParameterTypeDefault value
reconnectbooleanfalse

Promise<void>

A promise that resolves when the connection is established.


disconnect(): Promise<void>;

Defined in: src/mcp.ts:115

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

Promise<void>

A promise that resolves when the disconnection is complete.


listTools(): Promise<McpTool[]>;

Defined in: src/mcp.ts:127

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): Promise<JSONValue>;

Defined in: src/mcp.ts:154

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.

ParameterTypeDescription
toolMcpToolThe McpTool instance to invoke.
argsJSONValueThe arguments to pass to the tool.

Promise<JSONValue>

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