Implementation:A9T9 RPA McpBridgeClient
| Knowledge Sources | |
|---|---|
| Domains | MCP, WebSocket |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for connecting the Ui.Vision extension to the local MCP bridge process via WebSocket, provided by the Ui.Vision MCP bridge client.
Description
The McpBridgeClient class (`src/services/mcp_bridge/index.ts`) is the extension-side counterpart to the MCP bridge process. It manages a WebSocket connection to the local bridge server (`ws://127.0.0.1:{port}`), handles reconnection with backoff, pairs with the bridge (dev/test browsers connect without a token; regular installs require pairing), and dispatches incoming tool calls to `MacroAgentTools.executeToolCall`.
Key methods and exports:
- `McpBridgeClient.connect()`: establish or re-establish the WebSocket connection
- `McpBridgeClient.onStoreChange(key)`: react to settings changes (enabled/port/token) by reconnecting
- `initMcpBridge()`: idempotent initialization called from the side panel — subscribes to the Redux store so settings take effect immediately
- `emergencyStopMcp()`: stop the current tool call from the side panel's STOP button
The client tracks the current tool call, supports cancellation, and logs connection state changes to the Logs tab with an `[MCP]` marker.
Usage
The client is initialized automatically when the side panel loads and MCP is enabled. Call `initMcpBridge()` once from the side panel's mount lifecycle; `emergencyStopMcp()` from the STOP button.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/services/mcp_bridge/index.ts
- Lines: L60-L400 (McpBridgeClient class, connect at L176), L1035-L1063 (initMcpBridge), L1064-L1066 (emergencyStopMcp)
Signature
class McpBridgeClient {
connect(): void
onStoreChange(key: string): void
emergencyStop(): void
private getConfig(): { enabled: boolean, port: number, token: string }
}
export function initMcpBridge(): void
export function emergencyStopMcp(): void
export { isDevTestBrowser } from './detect'
Import
import { initMcpBridge, emergencyStopMcp } from '@/services/mcp_bridge'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config.enabled | boolean | Yes | Whether MCP bridge is enabled |
| config.port | number | Yes | WebSocket port (default 50888) |
| config.token | string | No | Pairing token (required for regular installs, omitted for dev browsers) |
| tool_call | object | Yes (incoming) | WebSocket message with tool name and args from the bridge |
Outputs
| Name | Type | Description |
|---|---|---|
| toolResult | object | Tool execution result sent back over WebSocket |
| connection state | log entries | [MCP] log entries in the Logs tab |
Usage Examples
Initialize the Bridge Client
import { initMcpBridge } from '@/services/mcp_bridge'
// Called from side panel componentDidMount:
initMcpBridge()
// The client subscribes to store changes; enabling/disabling MCP
// or editing the port in Settings > AI takes effect immediately.
Emergency Stop
import { emergencyStopMcp } from '@/services/mcp_bridge'
// Called from the side panel STOP button:
emergencyStopMcp()
Related Pages
Implements Principle
Requires Environment
- Environment:A9T9_RPA_Chromium_Browser_Environment
- Environment:A9T9_RPA_Firefox_Browser_Environment
- Environment:A9T9_RPA_Node_JS_MCP_Bridge