@juexibobi/private-desktop-mcp 0.3.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +116 -0
- package/README.md +89 -38
- package/bin/cli.mjs +1056 -136
- package/bin/client-setup.mjs +151 -0
- package/bin/policy.mjs +336 -0
- package/bin/proxy.mjs +173 -45
- package/docs/agent-install.md +110 -0
- package/gateway.mjs +231 -33
- package/package.json +13 -8
- package/skills/private-desktop-mcp/SKILL.md +71 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# AGENTS.md — Guide for AI Agents Operating and Maintaining Private Desktop MCP
|
|
2
|
+
|
|
3
|
+
This document defines the behavioral contracts for AI coding agents working with **Private Desktop MCP (`@juexibobi/private-desktop-mcp`)** in two roles:
|
|
4
|
+
|
|
5
|
+
1. **Operator Mode (User Usage & Remote Multi-Device Orchestration)** — when a user asks you to connect their machine, configure an MCP client, inspect paired desktops, run commands across multiple computers, or manage read-only guardrails.
|
|
6
|
+
2. **Developer Mode (Repository Maintenance & Evolution)** — when a user asks you to modify, test, release, or deploy the connector and Cloudflare Worker relay.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Part 1: Operator Playbook (Using Private Desktop MCP for the User)
|
|
11
|
+
|
|
12
|
+
### 1. Inspect Current State First (Machine-Readable Preflight)
|
|
13
|
+
|
|
14
|
+
Always run non-destructive JSON preflight checks before changing local configuration or starting a connector:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx --yes @juexibobi/private-desktop-mcp@latest doctor --json
|
|
18
|
+
npx --yes @juexibobi/private-desktop-mcp@latest status --json
|
|
19
|
+
npx --yes @juexibobi/private-desktop-mcp@latest report --json
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Configuring an AI Client (`setup-client`)
|
|
23
|
+
|
|
24
|
+
Follow the preview-before-confirm contract in [docs/agent-install.md](docs/agent-install.md):
|
|
25
|
+
|
|
26
|
+
1. Preview the exact configuration change with `--dry-run --json` first:
|
|
27
|
+
```bash
|
|
28
|
+
npx --yes @juexibobi/private-desktop-mcp@latest setup-client <client> --dry-run --json
|
|
29
|
+
```
|
|
30
|
+
Supported `<client>` values: `claude-code`, `claude-desktop`, `cursor`, `vscode`, `codex`, `gemini`, `windsurf`, `all`.
|
|
31
|
+
2. Show the user the target file path and preview, wait for confirmation, then apply without `--dry-run`.
|
|
32
|
+
|
|
33
|
+
### 3. Starting & Pairing a Device Connector
|
|
34
|
+
|
|
35
|
+
- **Default full mode**:
|
|
36
|
+
```bash
|
|
37
|
+
npx --yes --prefer-online --package=@juexibobi/private-desktop-mcp@latest -- private-desktop-mcp connect --json
|
|
38
|
+
```
|
|
39
|
+
- **Least-privilege read-only + directory jail mode (recommended for untrusted or exploratory sessions)**:
|
|
40
|
+
```bash
|
|
41
|
+
npx --yes --prefer-online --package=@juexibobi/private-desktop-mcp@latest -- private-desktop-mcp connect --readonly --allow-dir <workspace_path> --json
|
|
42
|
+
```
|
|
43
|
+
- **Aggregating additional local stdio MCP servers alongside Desktop Commander**:
|
|
44
|
+
```bash
|
|
45
|
+
npx --yes --prefer-online --package=@juexibobi/private-desktop-mcp@latest -- private-desktop-mcp connect --servers ./client-configs/servers.example.json
|
|
46
|
+
```
|
|
47
|
+
- When a machine is not paired yet, `--json` emits a structured event:
|
|
48
|
+
```json
|
|
49
|
+
{"event":"pairing_required","deviceName":"...","code":"...","approvalUrl":"https://.../admin/devices","pairId":"...","expiresIn":3600}
|
|
50
|
+
```
|
|
51
|
+
Present the `code` and `approvalUrl` to the user so they can approve it behind Cloudflare Access.
|
|
52
|
+
|
|
53
|
+
### 4. Multi-Device Orchestration via MCP Tools, Resources & Prompts
|
|
54
|
+
|
|
55
|
+
When connected to the remote `/mcp` Streamable HTTP endpoint:
|
|
56
|
+
|
|
57
|
+
- **Resources (`resources/list`, `resources/read`)** — always available at the Cloudflare edge, even when 0 devices are online:
|
|
58
|
+
- `relay://devices`: Live inventory of paired devices, online state, OS/arch, read-only locks, and current selection.
|
|
59
|
+
- `relay://status`: Worker version, protocol features, and Access verification posture.
|
|
60
|
+
- `relay://audit`: Recent sanitized metadata-only audit log.
|
|
61
|
+
- **Built-in Edge Meta-Tools (`tools/call`)**:
|
|
62
|
+
- `relay_list_devices`: List all paired desktops and their live status.
|
|
63
|
+
- `relay_select_device`: Set the default active target desktop by `device_id` or `device_name`.
|
|
64
|
+
- `relay_ping_device`: Measure WebSocket RTT and verify local `gateway.mjs` health.
|
|
65
|
+
- `relay_set_device_policy`: Lock/unlock a device to read-only mode at the Cloudflare edge (`read_only: true|false`) or rename it (`new_name`).
|
|
66
|
+
- `relay_recent_activity`: Inspect sanitized audit entries (timestamps, actor, device, tool name, HTTP status, duration).
|
|
67
|
+
- **Per-Call Device Targeting (`_device`)**:
|
|
68
|
+
- Every upstream tool schema includes an optional `_device` string property. Pass `_device: "<device_name_or_id>"` on any tool call (e.g., `read_file`, `list_directory`, `start_process`) to route that single call to a specific machine without changing the global selection.
|
|
69
|
+
- **Self-Healing Tool Errors**:
|
|
70
|
+
- If a target device is offline or multiple devices are online without a selection, `tools/call` returns an `isError: true` structured payload containing `onlineDevices`, `selectedDeviceId`, and `nextActions`. Follow `nextActions` (e.g., call `relay_select_device` or pass `_device`) automatically.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Part 2: Developer Playbook (Maintaining the Repository)
|
|
75
|
+
|
|
76
|
+
### 1. Workspace Map
|
|
77
|
+
|
|
78
|
+
```text
|
|
79
|
+
worker/
|
|
80
|
+
index.mjs Cloudflare Worker router & SQLite-backed DeviceHub Durable Object (MCP edge lifecycle, meta-tools, resources, prompts, WebSocket relay, audit log, admin UI)
|
|
81
|
+
auth.mjs Cryptographic Cloudflare Access RS256 JWT verifier (Web Crypto API, JWKS caching + key-rotation refresh)
|
|
82
|
+
bin/
|
|
83
|
+
cli.mjs Cross-platform device connector CLI (connect, status, doctor, report, setup-client, reset; --json, heartbeat watchdog, child gateway supervisor)
|
|
84
|
+
policy.mjs Local tool governance (--readonly, --allow-dir symlink-aware path jail, allow/deny lists, self-credential guard) & outbound DLP secret redaction
|
|
85
|
+
client-setup.mjs Non-destructive MCP client config generator/merger with --dry-run preview
|
|
86
|
+
proxy.mjs System proxy autodetection (Windows WinINET, macOS scutil, environment HTTPS_PROXY/NO_PROXY)
|
|
87
|
+
activity.mjs JSON-RPC/SSE parser, correlation IDs, and TRACE/DEBUG/LIVE terminal activity formatters
|
|
88
|
+
logging.mjs Terminal secret redaction and timestamped logging helpers
|
|
89
|
+
gateway.mjs Local loopback Streamable HTTP MCP gateway fronting @wonderwhy-er/desktop-commander + optional extra stdio MCP servers (Bearer + Host + Origin guard)
|
|
90
|
+
skills/
|
|
91
|
+
private-desktop-mcp/SKILL.md Bundled Agent Skill for coding agents
|
|
92
|
+
docs/
|
|
93
|
+
agent-install.md Canonical agent-driven setup & safety runbook
|
|
94
|
+
tests/
|
|
95
|
+
*.test.mjs Node.js built-in test runner suites covering worker auth, DeviceHub DO, gateway, policy/DLP, client setup, proxy, activity, and packaging
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 2. Boundary & Security Invariants
|
|
99
|
+
|
|
100
|
+
1. **Zero secret leakage**: Never commit `device.json`, Cloudflare API keys/tokens (`cfk_`, `cfut_`, `cfat_`), Access cookies, or `.env` files. Never weaken `bin/policy.mjs` protection of the `PrivateDesktopMCP` credential directory.
|
|
101
|
+
2. **Fail-closed edge authentication**: `worker/auth.mjs` must verify RS256 signatures, `iss`, `aud`, `exp`, and `nbf` against `CF_ACCESS_TEAM_DOMAIN` + `CF_ACCESS_AUD`.
|
|
102
|
+
3. **Loopback gateway isolation**: `gateway.mjs` binds only to `127.0.0.1`, validates loopback `Host` headers (anti-DNS-rebinding), rejects browser `Origin` headers (anti-CSRF), and requires a per-launch 32-byte `MCP_LOCAL_TOKEN`.
|
|
103
|
+
4. **Edge-always-alive MCP discovery**: `initialize`, `notifications/initialized`, `ping`, `server/discover`, `tools/list`, `resources/list`, `resources/read` (`relay://*`), `prompts/list`, and `prompts/get` must succeed at the Worker edge even when zero devices are connected.
|
|
104
|
+
5. **Direct dependency declaration**: Every package imported by `bin/*.mjs` or `gateway.mjs` must be declared directly in `package.json` `dependencies` and listed in `package.json` `files` so `npx --install-strategy=nested` works on a clean machine.
|
|
105
|
+
|
|
106
|
+
### 3. Verification & Release Workflow
|
|
107
|
+
|
|
108
|
+
Run the full verification gate before opening a PR or tagging a release:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm ci --ignore-scripts --no-audit --no-fund
|
|
112
|
+
npm test
|
|
113
|
+
npm pack --dry-run --json
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Releases are published automatically via GitHub Actions OIDC Trusted Publishing (`.github/workflows/release.yml`) when a `v*` tag matching `package.json` and `server.json` `version` is pushed.
|
package/README.md
CHANGED
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
# Private Desktop MCP
|
|
2
2
|
|
|
3
|
-
Self-hosted multi-device [Model Context Protocol](https://modelcontextprotocol.io/) bridge for Desktop Commander using Cloudflare Workers, Durable Objects and a one-command
|
|
3
|
+
Self-hosted, **Agent-Native** multi-device [Model Context Protocol](https://modelcontextprotocol.io/) bridge for Desktop Commander (and optional additional local MCP servers) using Cloudflare Workers, SQLite-backed Durable Objects, and a one-command cross-platform connector.
|
|
4
4
|
|
|
5
|
-
**Transport:** Streamable HTTP to
|
|
5
|
+
**Transport:** Streamable HTTP (`POST` + `DELETE`, supporting both MCP `2025-*` and stateless `2026-07-28`) to AI clients; outgoing WebSocket with zero-cost hibernation heartbeat from each device to the relay.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Quick Start: Install with Your Coding Agent
|
|
8
|
+
|
|
9
|
+
Paste the block below into Claude Code, Codex, Cursor, VS Code Copilot, Gemini CLI, OpenClaw, or Antigravity:
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
Install and configure Private Desktop MCP for me using the official instructions at:
|
|
13
|
+
https://github.com/KFCheems/private-desktop-mcp/blob/main/docs/agent-install.md
|
|
14
|
+
Before changing anything, identify my OS and AI client, run `npx --yes @juexibobi/private-desktop-mcp@latest doctor --json`, preview client config changes with `setup-client <client> --dry-run --json`, and wait for my confirmation.
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or install directly via native agent plugin / extension marketplaces:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Claude Code
|
|
21
|
+
/plugin marketplace add KFCheems/private-desktop-mcp
|
|
22
|
+
/plugin install private-desktop-mcp@private-desktop-mcp
|
|
23
|
+
|
|
24
|
+
# Codex
|
|
25
|
+
codex plugin marketplace add KFCheems/private-desktop-mcp
|
|
26
|
+
|
|
27
|
+
# Gemini CLI
|
|
28
|
+
gemini extensions install https://github.com/KFCheems/private-desktop-mcp
|
|
29
|
+
|
|
30
|
+
# Antigravity
|
|
31
|
+
agy plugin install https://github.com/KFCheems/private-desktop-mcp
|
|
32
|
+
|
|
33
|
+
# Agent Skill only (npx skills)
|
|
34
|
+
npx --yes skills add KFCheems/private-desktop-mcp
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Public npm release (Device Connector)
|
|
8
38
|
|
|
9
39
|
```powershell
|
|
10
40
|
npx.cmd --yes --prefer-online --package=@juexibobi/private-desktop-mcp@latest -- private-desktop-mcp connect
|
|
@@ -12,59 +42,80 @@ npx.cmd --yes --prefer-online --package=@juexibobi/private-desktop-mcp@latest --
|
|
|
12
42
|
|
|
13
43
|
Each release gets its own immutable npm version. **Do not overwrite a fixed `.tgz` at a stable URL**: npm caching might start an old version.
|
|
14
44
|
|
|
15
|
-
|
|
45
|
+
## What's new in v0.5.0 (Agent-Native Edition)
|
|
16
46
|
|
|
17
|
-
|
|
47
|
+
### Agent-Native MCP Protocol & Multi-Device Self-Healing
|
|
48
|
+
- **Edge-Always-Alive MCP Lifecycle**: `initialize`, `notifications/initialized`, `ping`, `server/discover`, `tools/list`, `resources/list`, `resources/read` (`relay://*`), `prompts/list`, and `prompts/get` succeed at the Cloudflare Worker edge **even when zero devices are online or multiple devices are online without a selection**, allowing agents to connect, inspect inventory, and guide the user instead of failing with HTTP transport errors.
|
|
49
|
+
- **Dynamic Server Instructions**: `initialize` / `server/discover` automatically injects live paired-device inventory (`online/offline`, OS, read-only status, selected target) and multi-device routing guidance into MCP `instructions`.
|
|
50
|
+
- **Schema-Native `_device` Parameter**: Every upstream tool in `tools/list` (`read_file`, `start_process`, `write_file`, etc.) has an optional `_device` string property injected into its `inputSchema.properties`, enabling schema-strict agents to target any paired computer per call without mutating global selection.
|
|
51
|
+
- **Built-in Edge Meta-Tools, Resources & Prompts**:
|
|
52
|
+
- **Tools**: `relay_list_devices`, `relay_select_device`, `relay_ping_device`, `relay_set_device_policy` (lock/unlock read-only mode or rename a device in chat), and `relay_recent_activity`.
|
|
53
|
+
- **Resources**: `relay://devices`, `relay://status`, and `relay://audit` (`application/json`).
|
|
54
|
+
- **Prompts**: `multi-device-triage` and `safe-remote-maintenance`.
|
|
55
|
+
- **Self-Healing Tool Errors**: When a `tools/call` targets an offline or ambiguous device, the relay returns a structured JSON-RPC `isError: true` result containing `errorCode`, `onlineDevices`, `selectedDeviceId`, and `nextActions` so the agent recovers autonomously.
|
|
18
56
|
|
|
19
|
-
|
|
57
|
+
### Agent-Native CLI & Ecosystem Manifests
|
|
58
|
+
- **Universal `--json` Mode**: `doctor --json`, `status --json`, `report --json`, `reset --json`, `setup-client --json`, and `connect --json` (emits `{"event":"pairing_required",...}` and `{"event":"pairing_approved",...}`).
|
|
59
|
+
- **Automated Client Configurator (`setup-client`)**: Non-destructively merges the remote MCP endpoint into `claude-code`, `claude-desktop`, `cursor`, `vscode`, `codex`, `gemini`, `windsurf`, or `all`, with `--dry-run` preview support.
|
|
60
|
+
- **Cross-Platform Agent Manifests & Playbooks**: Ships [AGENTS.md](AGENTS.md), [CLAUDE.md](CLAUDE.md), [docs/agent-install.md](docs/agent-install.md), [skills/private-desktop-mcp/SKILL.md](skills/private-desktop-mcp/SKILL.md), `plugin.json`, `.claude-plugin/`, `gemini-extension.json`, and `.antigravity-plugin/`.
|
|
20
61
|
|
|
21
|
-
###
|
|
62
|
+
### Security, Governance & Reliability (v0.4.0+)
|
|
63
|
+
- **Cryptographic Cloudflare Access JWT verification (`worker/auth.mjs`)**: Verifies RS256 signatures against `https://<team>.cloudflareaccess.com/cdn-cgi/access/certs` (with automatic `kid` key-rotation refresh), `aud`, `iss`, `exp`, and `nbf`.
|
|
64
|
+
- **Hardened local gateway (`gateway.mjs`)**: Per-launch ephemeral Bearer authentication (`MCP_LOCAL_TOKEN`), loopback `Host` validation (anti-DNS-rebinding), browser `Origin` rejection (anti-CSRF), and authenticated `/healthz`.
|
|
65
|
+
- **Local policy guardrails & Outbound DLP (`bin/policy.mjs`)**: `--readonly`, `--allow-dir <dir>` (symlink-aware path jail), `--allow-tools` / `--deny-tools`, self-credential protection (`PrivateDesktopMCP/device.json`), and automatic outbound secret redaction (PEM keys, AWS/GitHub/OpenAI/Slack/Google tokens, and active relay tokens).
|
|
66
|
+
- **Zero-cost WebSocket hibernation heartbeat & auto-recovery**: RFC 6455 `ws.ping()` + DO `setWebSocketAutoResponse("ping", "pong")`, jittered backoff reset, `DELETE /mcp` + client `AbortSignal` cancel propagation, and automatic local `gateway.mjs` crash recovery.
|
|
22
67
|
|
|
23
|
-
|
|
68
|
+
## CLI commands & flags
|
|
24
69
|
|
|
25
|
-
|
|
70
|
+
```powershell
|
|
71
|
+
# Connect (default)
|
|
72
|
+
private-desktop-mcp connect
|
|
73
|
+
|
|
74
|
+
# Safe read-only mode jailed to a workspace directory
|
|
75
|
+
private-desktop-mcp connect --readonly --allow-dir C:\workspace
|
|
76
|
+
|
|
77
|
+
# Configure MCP clients (with --dry-run preview and --json for agents)
|
|
78
|
+
private-desktop-mcp setup-client claude-code --dry-run --json
|
|
79
|
+
private-desktop-mcp setup-client cursor
|
|
26
80
|
|
|
27
|
-
|
|
81
|
+
# Aggregate extra local MCP servers alongside Desktop Commander
|
|
82
|
+
private-desktop-mcp connect --servers ./client-configs/servers.example.json
|
|
28
83
|
|
|
29
|
-
|
|
84
|
+
# Machine-readable diagnostics & status
|
|
85
|
+
private-desktop-mcp doctor --json
|
|
86
|
+
private-desktop-mcp report --json
|
|
87
|
+
private-desktop-mcp status --json
|
|
88
|
+
private-desktop-mcp reset --json
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Current canonical endpoint
|
|
30
92
|
|
|
31
93
|
```text
|
|
32
94
|
https://private-desktop-device-relay.ljx2043979076.workers.dev/mcp
|
|
33
95
|
```
|
|
34
96
|
|
|
35
|
-
Set up a remote Streamable HTTP MCP connection with Cloudflare Access OAuth. The gateway and device pairing admin page share this free workers.dev host. The old qqking.top route is a temporary fallback, not a dependency of this connector.
|
|
36
|
-
|
|
37
97
|
## Pairing devices
|
|
38
98
|
|
|
39
|
-
1. On a
|
|
40
|
-
2. The first run prints an expiring pairing code and
|
|
41
|
-
3. Sign into Cloudflare Access and approve the **matching code** in
|
|
42
|
-
4. The device saves
|
|
43
|
-
5. Leave the terminal open while using tools. Press **Ctrl+C** to disconnect. No startup tasks or
|
|
44
|
-
6.
|
|
99
|
+
1. On a machine with Node.js 20.18.1+ run `private-desktop-mcp connect`.
|
|
100
|
+
2. The first run prints an expiring pairing code and opens (or prints) the Access-protected approval URL.
|
|
101
|
+
3. Sign into Cloudflare Access and approve the **matching code** in `/admin/devices`.
|
|
102
|
+
4. The device saves its scoped credential in `PrivateDesktopMCP/device.json` and connects via WebSocket. Never commit or share that credential.
|
|
103
|
+
5. Leave the terminal open while using tools. Press **Ctrl+C** to disconnect. No startup tasks or system services are installed.
|
|
104
|
+
6. With multiple devices online, switch devices directly in chat via `relay_list_devices` / `relay_select_device`, pass `_device: "<name>"` on a tool call, or select one at `/admin/devices`.
|
|
45
105
|
|
|
46
|
-
|
|
106
|
+
## Cloudflare deployment & self-hosting
|
|
47
107
|
|
|
48
|
-
|
|
108
|
+
The Worker source is in `worker/index.mjs` and `worker/auth.mjs`. Infrastructure is described in `wrangler.toml`.
|
|
49
109
|
|
|
50
|
-
|
|
110
|
+
1. Configure a Cloudflare Access self-hosted application protecting `/mcp` and `/admin/*` with an Owner-only policy. Never protect `/relay/*` with Access.
|
|
111
|
+
2. Configure cryptographic Access JWT verification on the Worker before deploying:
|
|
51
112
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
`worker/index.mjs` currently supports the legacy qqking.top host for rollback. The free workers.dev endpoint is the canonical address.
|
|
59
|
-
|
|
60
|
-
## Releases
|
|
61
|
-
|
|
62
|
-
- CI executes syntax tests and package validation.
|
|
63
|
-
- Immutable versioned npm packages carry the authoritative `latest` dist-tag.
|
|
64
|
-
- Release workflow uses **GitHub Actions OIDC npm trusted publishing** for this repository and release.yml; no long-lived npm publish token is needed.
|
|
65
|
-
- GitHub Releases preserves the same immutable `.tgz` as a backup.
|
|
66
|
-
- Secrets, local `device.json`, `.env`, `node_modules` and existing Cloudflare Access policies are not stored in Git.
|
|
113
|
+
```bash
|
|
114
|
+
wrangler secret put CF_ACCESS_TEAM_DOMAIN # e.g. https://your-team.cloudflareaccess.com
|
|
115
|
+
wrangler secret put CF_ACCESS_AUD # Access application AUD tag
|
|
116
|
+
wrangler deploy
|
|
117
|
+
```
|
|
67
118
|
|
|
68
119
|
## Security
|
|
69
120
|
|
|
70
|
-
This tool
|
|
121
|
+
This tool provides remote filesystem and command-execution capabilities. Restrict Cloudflare Access to your own identity, configure `CF_ACCESS_TEAM_DOMAIN` + `CF_ACCESS_AUD`, approve only devices you control, and consider running `--readonly` or `--allow-dir` for day-to-day workflows. See [SECURITY.md](SECURITY.md) and [AGENTS.md](AGENTS.md).
|