@juexibobi/private-desktop-mcp 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +55 -2
- package/bin/cli.mjs +69 -0
- package/gateway.mjs +44 -0
- package/package.json +33 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 KFCheems
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Private Desktop MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Self-hosted multi-device [Model Context Protocol](https://modelcontextprotocol.io/) bridge for Desktop Commander using Cloudflare Workers, Durable Objects and a one-command Windows connector.
|
|
4
|
+
|
|
5
|
+
**Transport:** Streamable HTTP to ChatGPT; outgoing WebSocket from the device to the relay.
|
|
6
|
+
|
|
7
|
+
## Public release (after npm owner authorizes publishing)
|
|
8
|
+
|
|
9
|
+
```powershell
|
|
10
|
+
npx.cmd --yes --prefer-online @juexibobi/private-desktop-mcp@latest connect
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
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
|
+
|
|
15
|
+
## Current independent endpoint
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
https://private-desktop-device-relay.ljx2043979076.workers.dev/mcp
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
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.
|
|
22
|
+
|
|
23
|
+
## Pairing devices
|
|
24
|
+
|
|
25
|
+
1. On a Windows machine with Node.js 20.18.1+ run `private-desktop-mcp connect` after installation (or the npx command above).
|
|
26
|
+
2. The first run prints an expiring pairing code and an Access-protected approval URL.
|
|
27
|
+
3. Sign into Cloudflare Access and approve the **matching code** in the admin page.
|
|
28
|
+
4. The device saves a locally scoped credential in the user's AppData and connects via WebSocket. Never commit or share that credential.
|
|
29
|
+
5. Leave the terminal open while using tools. Press **Ctrl+C** to disconnect. No startup tasks or Windows services are installed.
|
|
30
|
+
6. Reconnecting the same paired device needs no further approval. Revoke old devices from the admin page.
|
|
31
|
+
|
|
32
|
+
If multiple devices are online, select the intended one at the admin page. The relay must never route to an arbitrary device when the target is ambiguous.
|
|
33
|
+
|
|
34
|
+
## Running without npm publication
|
|
35
|
+
|
|
36
|
+
Install from your own checked-out repository with `npm install` then `node bin/cli.mjs connect`. To install globally from the project: `npm install -g .`.
|
|
37
|
+
|
|
38
|
+
## Cloudflare deployment
|
|
39
|
+
|
|
40
|
+
The Worker source is in `worker/index.mjs`. The infrastructure is described by `wrangler.toml`. Production has a **separate Cloudflare Access self-hosted application** protecting exactly `/mcp` and `/admin/*`, with Owner-only policy. Device pairing paths `/relay/*` remain reachable but device WebSocket access is protected by a bearer token issued only after pairing approval.
|
|
41
|
+
|
|
42
|
+
Never protect the **entire Worker** with Worker-level Access: this would prevent WebSocket connections. Never deploy the Worker without first configuring path-based Access for the MCP and admin endpoints. Use Wrangler or Cloudflare API credentials provided directly in your own secure environment.
|
|
43
|
+
|
|
44
|
+
`worker/index.mjs` currently supports the legacy qqking.top host for rollback. The free workers.dev endpoint is the canonical address.
|
|
45
|
+
|
|
46
|
+
## Releases
|
|
47
|
+
|
|
48
|
+
- CI executes syntax tests and package validation.
|
|
49
|
+
- Immutable versioned npm packages carry the authoritative `latest` dist-tag.
|
|
50
|
+
- Release workflow supports **GitHub Actions OIDC npm trusted publishing**, after an npm owner manually configures this repository as a trusted publisher on npmjs.com.
|
|
51
|
+
- GitHub Releases preserves the same immutable `.tgz` as a backup.
|
|
52
|
+
- Secrets, local `device.json`, `.env`, `node_modules` and existing Cloudflare Access policies are not stored in Git.
|
|
53
|
+
|
|
54
|
+
## Security
|
|
55
|
+
|
|
56
|
+
This tool has Windows filesystem and command-execution capabilities. Restrict Cloudflare Access to your own identity, approve only devices you control and never expose a naked HTTP MCP endpoint. See [SECURITY.md](SECURITY.md).
|
package/bin/cli.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import {spawn,spawnSync} from "node:child_process";
|
|
6
|
+
import {fileURLToPath} from "node:url";
|
|
7
|
+
import WebSocket from "ws";
|
|
8
|
+
import { EnvHttpProxyAgent, setGlobalDispatcher } from "undici";
|
|
9
|
+
import { getProxyForUrl } from "proxy-from-env";
|
|
10
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
11
|
+
setGlobalDispatcher(new EnvHttpProxyAgent());
|
|
12
|
+
const root=path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
13
|
+
const command=process.argv[2]||"connect",relay="https://private-desktop-device-relay.ljx2043979076.workers.dev";
|
|
14
|
+
const config=path.join(process.env.APPDATA||path.join(os.homedir(),".config"),"PrivateDesktopMCP","device.json");
|
|
15
|
+
const sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms));
|
|
16
|
+
let stopping=false,child=null,socket=null;
|
|
17
|
+
function saved(){try{return JSON.parse(fs.readFileSync(config,"utf8"))}catch{return null}}
|
|
18
|
+
function store(x){fs.mkdirSync(path.dirname(config),{recursive:true,mode:0o700});fs.writeFileSync(config,JSON.stringify(x,null,2),{mode:0o600});}
|
|
19
|
+
function forget(){try{fs.unlinkSync(config)}catch{}}
|
|
20
|
+
async function post(route,data){const r=await fetch(relay+route,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(data),signal:AbortSignal.timeout(12000)});const j=await r.json();if(!r.ok)throw Error(j.error||"HTTP "+r.status);return j;}
|
|
21
|
+
async function pair(){
|
|
22
|
+
const v=await post("/relay/pair/start",{name:os.hostname()});
|
|
23
|
+
console.log("\nNEW DEVICE: "+os.hostname()+"\nPAIRING CODE: "+v.code+"\nPlease visit "+v.approvalUrl+" and approve the matching code.\nWaiting for approval (60 minutes)...\n");
|
|
24
|
+
for(let i=0;i<720&&!stopping;i++){
|
|
25
|
+
await sleep(5000);let r;try{r=await post("/relay/pair/poll",{pairId:v.pairId,proof:v.proof})}catch(e){if(/expired|invalid/i.test(e.message))throw e;continue}
|
|
26
|
+
if(r.status==="approved"){const credentials={deviceId:r.deviceId,token:r.token};store(credentials);console.log("Device approved and credentials saved.");return credentials}
|
|
27
|
+
}
|
|
28
|
+
throw Error("Pairing timed out. Re-run the command.");
|
|
29
|
+
}
|
|
30
|
+
async function portOpen(){const r=await fetch("http://127.0.0.1:8717/mcp",{signal:AbortSignal.timeout(1500)});return r.status>0;}
|
|
31
|
+
async function startGateway(){
|
|
32
|
+
try{if(await portOpen())throw Error("Port 8717 is already occupied. Stop the other MCP gateway before connecting.")}catch(e){if(/occupied/.test(e.message))throw e}
|
|
33
|
+
const fd=fs.openSync(path.join(process.env.TEMP||os.tmpdir(),"private-desktop-mcp-device.log"),"a");
|
|
34
|
+
child=spawn(process.execPath,[path.join(root,"gateway.mjs")],{cwd:root,stdio:["ignore",fd,fd],windowsHide:true});fs.closeSync(fd);
|
|
35
|
+
for(let i=0;i<40;i++){if(child.exitCode!==null)throw Error("Gateway exited unexpectedly. See private-desktop-mcp-device.log");try{if(await portOpen())return}catch{}await sleep(500)}
|
|
36
|
+
throw Error("Gateway failed to listen on port 8717.");
|
|
37
|
+
}
|
|
38
|
+
function stopGateway(){if(child?.pid){if(process.platform==="win32")spawnSync("taskkill.exe",["/PID",String(child.pid),"/T","/F"],{windowsHide:true,timeout:8000});else child.kill("SIGTERM");child=null;}}
|
|
39
|
+
async function respond(ws,msg){
|
|
40
|
+
const headers={};for(const k of ["accept","content-type","mcp-session-id","mcp-protocol-version","last-event-id","mcp-method","mcp-name"])if(msg.headers?.[k])headers[k]=msg.headers[k];
|
|
41
|
+
try{const rpc=JSON.parse(String(msg.body||""));if(typeof rpc.method==="string"){headers["mcp-method"]=rpc.method;if(rpc.method==="tools/call"&&typeof rpc.params?.name==="string")headers["mcp-name"]=rpc.params.name;}}catch{}
|
|
42
|
+
let response;
|
|
43
|
+
try{
|
|
44
|
+
const r=await fetch("http://127.0.0.1:8717/mcp",{method:msg.method||"POST",headers,body:msg.body,signal:AbortSignal.timeout(70000)});
|
|
45
|
+
const body=await r.text(),forward={};for(const k of ["content-type","mcp-session-id","mcp-protocol-version"])if(r.headers.has(k))forward[k]=r.headers.get(k);
|
|
46
|
+
response={kind:"response",id:msg.id,status:r.status,headers:forward,body:body.slice(0,8*1024*1024)};
|
|
47
|
+
}catch(e){response={kind:"response",id:msg.id,status:502,headers:{"content-type":"application/json"},body:JSON.stringify({error:"Local gateway error",message:String(e.message).slice(0,180)})}}
|
|
48
|
+
if(ws.readyState===WebSocket.OPEN)ws.send(JSON.stringify(response));
|
|
49
|
+
}
|
|
50
|
+
async function connect(creds){return new Promise(resolve=>{
|
|
51
|
+
const proxyUrl=getProxyForUrl(relay);
|
|
52
|
+
const ws=new WebSocket(relay.replace(/^https:/,"wss:")+"/relay/ws",{headers:{"Authorization":"Bearer "+creds.token,"X-Device-ID":creds.deviceId},handshakeTimeout:15000,...(proxyUrl?{agent:new HttpsProxyAgent(proxyUrl)}:{})});socket=ws;
|
|
53
|
+
let status=0;
|
|
54
|
+
ws.on("open",()=>console.log("CONNECTED. ChatGPT can now use this device. Ctrl+C to disconnect."));
|
|
55
|
+
ws.on("unexpected-response",(req,res)=>{status=res.statusCode;res.resume();console.error("Relay refused:",status)});
|
|
56
|
+
ws.on("message",data=>{let m;try{m=JSON.parse(String(data))}catch{return}if(m.kind==="request")respond(ws,m).catch(e=>console.error(e.message))});
|
|
57
|
+
ws.on("error",e=>console.error("Relay:",e.message));
|
|
58
|
+
ws.on("close",()=>{socket=null;resolve({unauthorized:status===401})});
|
|
59
|
+
})}
|
|
60
|
+
function stop(){if(stopping)return;stopping=true;try{socket?.close(1000,"Manual disconnect")}catch{}stopGateway();setTimeout(()=>process.exit(0),200).unref();}
|
|
61
|
+
process.on("SIGINT",stop);process.on("SIGTERM",stop);
|
|
62
|
+
if(["help","--help","-h"].includes(command)){console.log("Private Desktop MCP: connect | status | reset\nFirst connect requires approval at https://private-desktop-device-relay.ljx2043979076.workers.dev/admin/devices\nCtrl+C to disconnect. No automatic startup.");}
|
|
63
|
+
else if(command==="status"){console.log("Paired:",!!saved());try{console.log("Local HTTP:",(await fetch("http://127.0.0.1:8717/mcp",{signal:AbortSignal.timeout(2000)})).status)}catch{console.log("Local MCP offline")}}
|
|
64
|
+
else if(command==="reset"){forget();console.log("Local credentials cleared. Revoke old credentials in the admin page too.");}
|
|
65
|
+
else if(command==="connect"){
|
|
66
|
+
try{const credentials=saved()||await pair();await startGateway();let retries=0;
|
|
67
|
+
while(!stopping){const r=await connect(credentials);if(r.unauthorized){forget();console.error("Credentials revoked; run again to pair.");break}if(stopping)break;retries++;const ms=Math.min(30000,1500*2**Math.min(5,retries));console.log("Reconnecting in "+Math.ceil(ms/1000)+"s");await sleep(ms);}
|
|
68
|
+
}catch(e){console.error("ERROR:",e.message);process.exitCode=1}finally{stopGateway()}
|
|
69
|
+
}else{console.error("Unknown command. Use help");process.exitCode=2}
|
package/gateway.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { Client } from "@modelcontextprotocol/client";
|
|
6
|
+
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
7
|
+
import { Server } from "@modelcontextprotocol/server";
|
|
8
|
+
import { proxyServer, startHTTPServer } from "mcp-proxy";
|
|
9
|
+
|
|
10
|
+
const root = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
if (process.platform === "win32" && !process.env.PUPPETEER_EXECUTABLE_PATH) {
|
|
12
|
+
const edge = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";
|
|
13
|
+
if (fs.existsSync(edge)) process.env.PUPPETEER_EXECUTABLE_PATH = edge;
|
|
14
|
+
}
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
const pkgFile = require.resolve("@wonderwhy-er/desktop-commander/package.json");
|
|
17
|
+
const exe = path.join(path.dirname(pkgFile), "dist", "index.js");
|
|
18
|
+
const transport = new StdioClientTransport({ command: process.execPath, args: [exe], stderr: "inherit" });
|
|
19
|
+
const upstream = new Client({ name: "private-mcp-gateway", version: "0.1.0" }, { capabilities: {} });
|
|
20
|
+
await upstream.connect(transport);
|
|
21
|
+
const serverCapabilities = upstream.getServerCapabilities();
|
|
22
|
+
const serverInfo = upstream.getServerVersion();
|
|
23
|
+
const tools = await upstream.listTools();
|
|
24
|
+
const port = Number(process.env.MCP_PORT || 8717);
|
|
25
|
+
if (!Number.isInteger(port) || port < 1024 || port > 65535) throw Error("Invalid MCP_PORT");
|
|
26
|
+
console.log("MCP upstream ready:", serverInfo?.name, "tools:", tools.tools?.length);
|
|
27
|
+
const { close } = await startHTTPServer({
|
|
28
|
+
host: "127.0.0.1",
|
|
29
|
+
port,
|
|
30
|
+
streamEndpoint: "/mcp",
|
|
31
|
+
sseEndpoint: null,
|
|
32
|
+
cors: false,
|
|
33
|
+
maxBodySize: 1048576,
|
|
34
|
+
eventStoreMaxEvents: 100,
|
|
35
|
+
createServer: async () => {
|
|
36
|
+
const downstream = new Server(serverInfo, { capabilities: serverCapabilities });
|
|
37
|
+
await proxyServer({ client: upstream, server: downstream, serverCapabilities });
|
|
38
|
+
return downstream;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
console.log(`Local MCP gateway listening at http://127.0.0.1:${port}/mcp`);
|
|
42
|
+
const stop = async () => { await close(); await upstream.close(); process.exit(0); };
|
|
43
|
+
process.on("SIGINT", stop);
|
|
44
|
+
process.on("SIGTERM", stop);
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juexibobi/private-desktop-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Private multi-device Desktop Commander MCP connector for Cloudflare Workers with paired WebSocket relays",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20.18.1"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"private-desktop-mcp": "bin/cli.mjs"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/cli.mjs",
|
|
15
|
+
"gateway.mjs",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/KFCheems/private-desktop-mcp.git"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/KFCheems/private-desktop-mcp",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "node --check bin/cli.mjs && node --check gateway.mjs && node --test tests/*.test.mjs"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@wonderwhy-er/desktop-commander": "0.2.52",
|
|
29
|
+
"mcp-proxy": "6.7.19",
|
|
30
|
+
"ws": "8.18.3",
|
|
31
|
+
"undici": "7.30.0",
|
|
32
|
+
"https-proxy-agent": "9.1.0",
|
|
33
|
+
"proxy-from-env": "2.1.0"
|
|
34
|
+
}
|
|
35
|
+
}
|