McpClient
Defined in: src/mcp.ts:55
MCP Client for interacting with Model Context Protocol servers.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new McpClient(args): McpClient;Defined in: src/mcp.ts:70
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
args | McpClientConfig |
Returns
Section titled “Returns”McpClient
Properties
Section titled “Properties”DEFAULT_TTL
Section titled “DEFAULT_TTL”readonly static DEFAULT_TTL: 60000 = 60000;Defined in: src/mcp.ts:57
Default TTL for task polling in milliseconds (60 seconds).
DEFAULT_POLL_TIMEOUT
Section titled “DEFAULT_POLL_TIMEOUT”readonly static DEFAULT_POLL_TIMEOUT: 300000 = 300000;Defined in: src/mcp.ts:60
Default poll timeout for task completion in milliseconds (5 minutes).
Accessors
Section titled “Accessors”client
Section titled “client”Get Signature
Section titled “Get Signature”get client(): Client;Defined in: src/mcp.ts:84
Returns
Section titled “Returns”Client
Methods
Section titled “Methods”connect()
Section titled “connect()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
reconnect | boolean | false |
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the connection is established.
disconnect()
Section titled “disconnect()”disconnect(): Promise<void>;Defined in: src/mcp.ts:115
Disconnects the MCP client from the server and cleans up resources.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the disconnection is complete.
listTools()
Section titled “listTools()”listTools(): Promise<McpTool[]>;Defined in: src/mcp.ts:127
Lists the tools available on the server and returns them as executable McpTool instances.
Returns
Section titled “Returns”Promise<McpTool[]>
A promise that resolves with an array of McpTool instances.
callTool()
Section titled “callTool()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
tool | McpTool | The McpTool instance to invoke. |
args | JSONValue | The arguments to pass to the tool. |
Returns
Section titled “Returns”Promise<JSONValue>
A promise that resolves with the result of the tool invocation.