Desktop MCP integration
The Desktop MCP integration gives MCP (Model Context Protocol) clients a local interface to Polar's network, Bitcoin, Lightning, Taproot Asset, and Litd operations. An Electron HTTP bridge receives client requests and passes them to the renderer's MCP model, which applies the operation through Polar's application state and service layers.
System boundary
The bridge sits between an MCP client and the running Polar desktop application. It starts with the Electron main window and remains a local access point for tool discovery and execution while that application session is active.
Interface flow
The following flow shows how a client request moves from the local HTTP interface to a Polar operation and back to the client.
flowchart LR
C[MCP client] -->|HTTP on localhost| B[Electron MCP bridge]
B -->|Electron IPC| R[Renderer MCP model]
R -->|Tool registry and store actions| P[Polar network and asset services]
P --> R
R --> B
B --> C
The bridge does not operate nodes by itself. It forwards work to the renderer, so MCP actions use the same application state and service paths as the desktop experience. The bridge starts after the main window is created as part of the Electron startup sequence. See Electron desktop runtime for the wider application lifecycle.
References: electron/mcpBridge.ts• L194-216 electron/windowManager.ts• L22-34
Local HTTP interface
The bridge exposes a small HTTP interface on localhost. An MCP server or another local client can use the health route to check availability, the tools route to discover the current tool catalog, and the execute route to run one named tool.
| Method and route | Purpose | Result |
|---|---|---|
GET /health | Check that the bridge responds | JSON health status |
GET /api/mcp/tools | Discover available tools and input schemas | Tool definitions |
POST /api/mcp/execute | Run one tool with its arguments | Tool result or error |
The port is 37373 by default. POLAR_MCP_PORT can select another port before Electron starts. The bridge binds only to localhost, which keeps this interface local to the desktop host.
References: electron/mcpBridge.ts• L118-187 electron/mcpBridge.ts• L194-215 electron/constants.ts• L6-7
Renderer IPC interface
The main process uses two Electron IPC (inter-process communication) channels to reach the renderer. One channel requests tool definitions. The other carries a tool name, its arguments, and a temporary response channel for execution.
The renderer registers these listeners during store initialization. It returns the shared tool catalog for discovery and sends each execution result or error to the response channel supplied by the bridge. The channel names are defined in src/…/ipcChannels.ts and must stay aligned between both processes.
References: src/…/ipcChannels.ts• L8-10 src/…/ipc.ts• L50-79 src/…/index.ts• L70-76
Tool catalog
The tool catalog is the client-facing description of what Polar can do through MCP. Each entry combines a stable tool name, a plain-language description, and an input schema with the store action that performs the work.
Network control
Network tools let an MCP client inspect and manage local Lightning network definitions. They cover the network lifecycle and the node-level changes needed to prepare a network for a test or simulation.
- List, create, import, export, rename, start, stop, and delete networks.
- Add, remove, rename, start, stop, and restart nodes.
- Select Lightning and Tap backends.
- Inspect available node versions and update node commands.
Network creation checks the requested node types, versions, and basic backend relationships before it changes application state. For example, Lightning nodes need a Bitcoin backend and Tap nodes need suitable LND support. The wider network lifecycle is described by backend proxy services where operations reach local node services.
References: src/…/toolRegistry.ts• L87-165 src/…/createNetwork.ts• L392-437 src/…/createNetwork.ts• L263-305
Bitcoin and Lightning operations
Bitcoin and Lightning tools provide the actions that make a local network useful for tests. They let clients advance the simulated chain, inspect wallets and nodes, create or pay invoices, and manage Lightning channels.
| Operation group | Main capability |
|---|---|
| Bitcoin | Mine blocks, control auto-mining, inspect chain and wallet state, send Bitcoin, and get addresses |
| Lightning | Open or close channels, inspect channels and node information, manage wallet funds, and create or pay invoices |
| Litd | Add, list, and revoke Litd sessions |
These tools address a selected network and node where the operation needs node context. Their results return data for the MCP client instead of requiring the client to read the desktop UI.
References: src/…/toolRegistry.ts• L166-233 src/…/toolRegistry.ts• L276-289 src/…/types.ts• L14-24
Taproot Asset operations
Taproot Asset tools expose asset state and asset movement through Tapd or Litd nodes. They cover asset discovery, address work, minting, transfer, Universe sync, and asset-backed Lightning payments.
- Read asset lists and balances.
- Create and decode Taproot Asset addresses.
- Mint normal assets or collectibles.
- Send assets and synchronize with Tap Universe.
- Create and pay asset invoices and inspect assets in channels.
The tools resolve a node from the selected network before they call the asset service. A Litd node can serve asset requests because it includes integrated Tapd capability, while asset invoice tools require a Litd node with the needed channel state.
References: src/…/toolRegistry.ts• L234-274 src/…/getTapBalances.ts• L21-41 src/…/mintTapAsset.ts• L39-101 src/…/createAssetInvoice.ts• L33-61
Request lifecycle
Discovery and execution use the same bridge but have different contracts. Discovery reads the catalog from the renderer, while execution selects a registered action and waits for its result.
Tool discovery
When a client requests /api/mcp/tools, the bridge asks the renderer for the current definitions. The renderer returns the catalog from the central registry, so the client receives the names and schemas that the running application can execute.
This design keeps tool metadata and tool dispatch linked. A tool is not advertised by the bridge unless its definition is present in the renderer registry.
References: electron/mcpBridge.ts• L57-79 electron/mcpBridge.ts• L147-161 src/…/toolRegistry.ts• L80-87 src/…/toolRegistry.ts• L296-310
Tool execution
When a client posts a tool name and argument object, the bridge validates that a name exists and sends the request to the renderer. The renderer looks up the name in the registry, calls the matching store action, converts the result for MCP use, and sends it back through the temporary response channel.
The bridge waits up to 30 seconds for execution. Tool discovery has a separate five-second wait. These limits prevent a client request from waiting without bound when the renderer or a node service does not respond.
sequenceDiagram
participant Client as MCP client
participant Bridge as HTTP bridge
participant Renderer as Renderer MCP model
participant Store as Polar store and services
Client->>Bridge: POST /api/mcp/execute
Bridge->>Renderer: tool, arguments, response channel
Renderer->>Store: Run registered tool action
Store-->>Renderer: Result or error
Renderer-->>Bridge: Result or error
Bridge-->>Client: JSON response
References: electron/mcpBridge.ts• L82-113 electron/mcpBridge.ts• L164-183 src/…/ipc.ts• L18-48
Data and error contracts
MCP clients use JSON at the bridge boundary. The renderer keeps the application-specific work behind the tool contract and makes selected state values easier for an external client to read.
Tool input and result contract
Each tool definition states the input shape that a client should send. Tools commonly identify a network with networkId and a node with nodeName; the tool then resolves those identifiers against the current Polar state before it performs the operation.
Tool validation rejects missing IDs, names, and other required values before service work starts. The same path also checks operation-specific limits such as positive amounts and supported asset types. A successful response contains the tool's result object. A failure is returned as an error response rather than as an unstructured process failure.
References: src/…/types.ts• L4-24 src/…/helpers.ts• L127-216 src/…/helpers.ts• L219-260 electron/mcpBridge.ts• L164-191
Status serialization
The renderer changes numeric application status values into their string labels before it returns a tool result. This preserves the result structure while making node and network status easier for MCP clients and language models to interpret.
The conversion applies through nested plain objects and arrays. It does not change unrelated values, so clients can rely on the tool's result shape while receiving readable status fields.
References: src/…/ipc.ts• L27-47 src/…/helpers.ts• L5-55
Operating boundary
The bridge is a local adapter, not a remote service. Its availability depends on the Electron session, the main window, the renderer store, and the local node services that a selected tool reaches.
Access controls and limits
The bridge accepts local requests without an authentication step. Its boundary relies on localhost binding and a localhost-only CORS (Cross-Origin Resource Sharing) rule for browser clients.
| Boundary | Policy |
|---|---|
| Network binding | Localhost only |
| Browser origins | http://localhost with an optional port |
| Request body | Maximum 1 MB |
| Tool discovery wait | 5 seconds |
| Tool execution wait | 30 seconds |
The lack of authentication is safe only within the intended local-host boundary. A deployment that exposes the port beyond the local machine would need a stronger access model.
References: electron/mcpBridge.ts• L21-45 electron/mcpBridge.ts• L123-138 electron/mcpBridge.ts• L205-215
Node service boundary
MCP tools reach Bitcoin, Lightning, Tapd, or Litd behavior through Polar's service and proxy layers. The MCP bridge therefore shares the same node readiness and service availability limits as the desktop application.
An MCP client should treat a successful bridge response as the result of the requested application action. It should not assume that a node operation can succeed when the selected network or its backend is stopped. See backend proxy services for the local service boundary below this integration.
References: src/…/ipcChannels.ts• L11-50 src/…/index.ts• L107-166
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the HTTP route names and JSON shapes aligned with the MCP client that discovers and calls them.
- Keep
mcpChannelsnames aligned between the Electron bridge and renderer listeners. - Add a tool definition and a registry executor together. Otherwise a tool can be described without a working dispatch path or remain callable without discoverable metadata.
- Preserve the node lookup rules when changing network, Tapd, Litd, or asset tool inputs.
- Review the localhost binding and CORS rule together if the bridge port or access boundary changes.
- Recheck timeout values when a tool begins a longer node or chain operation.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| MCP bridge port is already in use | The bridge logs an address-in-use error and cannot accept requests on that port | Set POLAR_MCP_PORT to a free local port and point the MCP client to it |
| Main window or renderer is not ready | Tool discovery or execution waits and then returns a timeout error | Start the bridge only after the main window exists and retry after the desktop app is ready |
| Unknown tool name | Renderer dispatch fails and the client receives an error | Discover tools first and use the registry name exactly |
| Missing network or node identifier | The tool cannot resolve the target and returns a validation or lookup error | Use a current networkId and nodeName from Polar state |
| Backend dependency is stopped or incompatible | Network, Lightning, or asset work fails in the downstream service layer | Start the network and satisfy the required Bitcoin, LND, or Litd relationship before the operation |
| Request body exceeds 1 MB | The bridge rejects the request while parsing it | Keep execution arguments within the local request limit |
Key files
| File | Why to read it |
|---|---|
| electron/mcpBridge.ts | Defines the local HTTP interface, request limits, timeouts, and main-to-renderer handoff |
| electron/windowManager.ts | Shows when the bridge starts in relation to the Electron main window and other local services |
| electron/constants.ts | Defines the default MCP port and its environment override |
| src/…/ipc.ts | Defines renderer-side discovery and execution handling |
| src/…/toolRegistry.ts | Provides the central mapping between tool metadata and executable store actions |
| src/…/index.ts | Shows the MCP model surface that the renderer exposes to the application store |
| src/…/helpers.ts | Defines shared node lookup, input checks, and readable status conversion |
| src/…/ipcChannels.ts | Defines the IPC names shared by the Electron and renderer processes |
| src/…/createNetwork.ts | Illustrates how a high-level network request is checked against node dependencies |
| src/…/mintTapAsset.ts | Illustrates the asset operation contract for Tapd and Litd nodes |