Class

MCPClient

MCPClient()

MCPClient class - Singleton wrapper for MCP server communication

Constructor

# new MCPClient()

Methods

# async callTool(toolName, args, userContext, timeout, _retryCount) → {Promise.<Object>}

Call an MCP tool with arguments

Parameters:
Name Type Default Description
toolName string

Name of the tool to call

args Object

Tool arguments

userContext Object null

User context for authorization (passed to tool)

timeout number 30000

Timeout in milliseconds (default: 30000)

_retryCount number 0

Internal retry counter (do not set manually)

Tool result

Promise.<Object>

# async close()

Close the connection and terminate the MCP server

# async connect()

Connect to the MCP server Spawns the server as a child process if not already running

# async ensureConnected()

Ensure we're connected before making requests

# async forceReconnect()

Force reconnect - closes existing connection and spawns fresh MCP server Use this when MCP server code has changed

# async getTool(toolName) → {Promise.<(Object|null)>}

Get a specific tool definition by name

Parameters:
Name Type Description
toolName string

Name of the tool

Tool definition or null if not found

Promise.<(Object|null)>

# isConnected() → {boolean}

Check if connected

boolean

# async listTools() → {Promise.<Array>}

List all available tools

Array of tool definitions

Promise.<Array>

# async refreshTools()

Refresh tools list from server (bypasses cache)