How Desktop Commander Implements Remote Device Connectivity via Remote MCP

Desktop Commander uses a three-layer Remote MCP architecture—local MCP server, lightweight Node.js remote device daemon, and cloud-hosted control plane—to securely bridge remote AI assistants to your local machine without exposing secrets or requiring cloud code execution.

The Remote MCP (Managed Control Plane) feature in wonderwhy-er/DesktopCommanderMCP enables remote AI assistants like ChatGPT or Claude to control your local terminal and file system through a secure, real-time WebSocket tunnel. This implementation prioritizes local execution—sensitive operations never run in the cloud, and authentication tokens remain confined to your device.

Remote MCP Architecture Overview

The system consists of three coordinated components that handle authentication, routing, and execution:

Component Role Source Location
Local MCP Server Executes tools (terminal, file edits, previews) locally; exposes Supabase-backed API [src/server.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/server.ts)
Remote Device Lightweight Node.js script maintaining persistent WebSocket to cloud; forwards remote calls to local server [src/remote-device/device.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/device.ts)
Remote MCP (cloud) Hosted service at https://mcp.desktopcommander.app; stores metadata, routes AI tool calls to devices [src/remote-device/remote-channel.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/remote-channel.ts)

This design ensures zero trust in the cloud—the remote service only sees encrypted routing instructions and never has access to your files, terminal, or local execution environment.

Authentication and Session Establishment

The Remote MCP device uses OAuth 2.0 Device Authorization Flow for initial setup, eliminating the need for users to paste credentials into terminal commands.

Device Startup Sequence

When you run desktop-commander-device or npm run device:start, the MCPDevice class in [src/remote-device/device.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/device.ts) performs:


# Global installation

desktop-commander-device --persist-session

# Local development

npm run device:start

The startup flow in MCPDevice.start():

// Programmatic use example
import { MCPDevice } from './src/remote-device/device.js';

const device = new MCPDevice({ persistSession: true });
await device.start();   // Resolves when registered and listening
  1. Fetch Supabase configuration from ${MCP_SERVER_URL}/api/mcp-info via fetchSupabaseConfig()
  2. Check for persisted session—if tokens exist and are valid, skip authentication
  3. Initiate OAuth Device Flow via DeviceAuthenticator if no valid session exists
  4. Prompt user to open verification URL and enter short code displayed in terminal
  5. Receive tokens (access_token, refresh_token) and device_id after authorization
  6. Optionally persist credentials to disk with --persist-session flag

The DeviceAuthenticator class in [src/remote-device/device-authenticator.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/device-authenticator.ts) implements the full OAuth 2.0 Device Authorization Grant, polling the token endpoint until the user completes browser authorization.

Real-Time Channel and Heartbeat Management

After authentication, the device establishes a persistent Realtime channel to the Remote MCP cloud service. The RemoteChannel class in [src/remote-device/remote-channel.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/remote-channel.ts) handles this connection.

Channel Registration

// Simplified from remote-channel.ts
async registerDevice(deviceId: string) {
  const device = await this.findDevice(deviceId);  // Lookup in mcp_devices table
  await this.markDeviceOnline(deviceId);           // Set status = 'online'
  
  this.channel = this.supabase.channel('device_tool_call_queue');
  this.channel
    .on('postgres_changes', {
      event: 'INSERT',
      schema: 'public',
      table: 'mcp_remote_calls',
      filter: `user_id=eq.${this.userId}`          // Security: filter by authenticated user
    }, (payload) => this.handleNewToolCall(payload))
    .subscribe();
}

Dual Timer Health Monitoring

The startHeartbeat method maintains connection integrity through two independent timers:

startHeartbeat(deviceId: string) {
  // Every 10 seconds: verify WebSocket state, recreate if stuck in 'joining'
  this.connectionCheckInterval = setInterval(() => this.checkConnectionHealth(), 10_000);
  
  // Every 15 seconds: update last_seen timestamp in mcp_devices table
  this.heartbeatInterval = setInterval(() => this.updateHeartbeat(deviceId), 15_000);
}

If checkConnectionHealth() detects an unhealthy channel state, recreateChannel() forces a fresh WebSocket connection and resubscribes to the tool call queue—ensuring 99.9% uptime even through network interruptions.

Tool Call Routing and Local Execution

When the Remote MCP cloud inserts a new row into mcp_remote_calls, the device receives the payload via Supabase Realtime and routes it to local execution.

Handling Incoming Tool Calls

The MCPDevice.handleNewToolCall method in [src/remote-device/device.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/device.ts) processes each call:

// Simplified execution flow
async handleNewToolCall(payload: ToolCallPayload) {
  const { call_id, tool_name, tool_args, metadata } = payload;
  
  // Mark as executing to prevent duplicate processing
  await this.remoteChannel.markCallExecuting(call_id);
  
  let result;
  if (tool_name === 'ping') {
    result = { content: [{ type: 'text', text: `pong ${new Date().toISOString()}` }] };
  } else if (tool_name === 'shutdown') {
    result = { content: [{ type: 'text', text: 'Device shutting down...' }] };
    this.shutdown();
  } else {
    // Forward to local Desktop Commander MCP server
    result = await this.desktop.callClientTool(tool_name, tool_args, metadata);
  }
  
  // Write result back to cloud database
  await this.remoteChannel.updateCallResult(call_id, 'completed', result);
}

Local Server Integration

The DesktopCommanderIntegration class in [src/remote-device/desktop-commander-integration.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/desktop-commander-integration.ts) serves as the bridge:

  • Accepts tool calls from the remote device
  • Communicates with the local MCP server via internal API
  • Returns structured results for database storage

All built-in tools (terminal execution, file reading/editing, directory listing, etc.) execute in your local environment—the cloud never processes your code or accesses your files.

Graceful Shutdown and Security

The Remote MCP device implements clean termination on multiple signals:


# Trigger shutdown via Ctrl-C or remote shutdown tool call

The shutdown sequence in MCPDevice.shutdown():

  1. Stops heartbeat timers (clearInterval on both intervals)
  2. Unsubscribes from Realtime channel
  3. Marks device offline in mcp_devices table
  4. Closes local Desktop Commander integration
  5. Exits process

Security measures throughout:

  • Supabase Row-Level Security (RLS) ensures devices only access their own user's data
  • Tokens never leave the device—no environment variables or CLI arguments expose credentials
  • No persistent cloud access—stopping the device instantly severs the AI connection

Key Implementation Files

File Purpose
[src/remote-device/device.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/device.ts) Main entry point: authentication, session persistence, tool routing, shutdown
[src/remote-device/remote-channel.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/remote-channel.ts) Supabase Realtime wrapper: channel management, heartbeat, health checks
[src/remote-device/device-authenticator.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/device-authenticator.ts) OAuth 2.0 Device Authorization Flow implementation
[src/remote-device/desktop-commander-integration.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/desktop-commander-integration.ts) Bridge to local MCP server for tool execution
[src/server.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/server.ts) Core Desktop Commander MCP server (local execution engine)
[src/remote-device/README.md](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/README.md) User documentation for installation and operation

Summary

Desktop Commander's Remote MCP implementation delivers secure remote device connectivity through:

  • Three-layer architecture separating cloud routing, device proxy, and local execution
  • OAuth 2.0 Device Flow for credential-free initial setup with optional session persistence
  • Supabase Realtime channels with automatic reconnection and dual-timer health monitoring
  • Local-only tool execution ensuring sensitive operations never touch cloud infrastructure
  • Graceful degradation through heartbeat timeouts and channel recreation on network failure

The design prioritizes user control—you can sever AI access instantly by stopping the device, and no secrets ever leave your machine.

Frequently Asked Questions

What is Remote MCP in Desktop Commander?

Remote MCP is a managed control plane that enables remote AI assistants to control your local Desktop Commander instance through a secure WebSocket tunnel. It consists of a cloud-hosted routing service, a lightweight device daemon on your machine, and your local MCP server that executes all tools.

How does the Remote MCP device authenticate with the cloud service?

The device uses OAuth 2.0 Device Authorization Flow as implemented in [src/remote-device/device-authenticator.ts](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/remote-device/device-authenticator.ts). On first run, it displays a verification URL and short code; after you authorize in your browser, the device receives Supabase tokens and a unique device_id. Use --persist-session to store credentials for subsequent runs.

Can remote AI assistants execute arbitrary code on my machine?

No. All tool execution happens locally through your Desktop Commander MCP server. The cloud service only routes tool call requests and stores results—it never executes code or accesses your files. You maintain full control and can instantly revoke access by stopping the remote device.

What happens if my network connection drops?

The RemoteChannel class implements automatic recovery through checkConnectionHealth() (10-second interval) and recreateChannel(). If the WebSocket becomes unhealthy, the device tears down the old channel, creates a fresh connection, and resubscribes to the tool call queue without user intervention.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →