@juexibobi/private-desktop-mcp 0.3.3 → 0.3.4

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/README.md CHANGED
@@ -22,6 +22,12 @@ For more details, use `--debug`:
22
22
  npx.cmd --yes --prefer-online --package=@juexibobi/private-desktop-mcp@latest -- private-desktop-mcp connect --debug
23
23
  ```
24
24
 
25
+ ### Windows system proxy detection (v0.3.4)
26
+
27
+ PCC automatically uses the current Windows user's **effective system proxy** (WinINET), including static HTTP/Mixed proxies, Windows proxy bypass rules, and supported PAC/WPAD configurations. It uses the same detected proxy for the HTTPS device-pairing API and for the secure WebSocket relay. No manual `HTTPS_PROXY` configuration is required for normal Windows system proxy settings.
28
+
29
+ Explicit `HTTPS_PROXY`, `HTTP_PROXY` or `ALL_PROXY` settings take precedence over Windows settings; `NO_PROXY` exclusions are respected for an explicitly configured environment proxy. Supported proxy transport is HTTP/HTTPS CONNECT. SOCKS-only proxy endpoints must be exposed through an HTTP/Mixed port. The detected proxy is re-checked periodically when retrying a lost connection. If system lookup fails or times out, PCC reports a warning and tries a direct connection.
30
+
25
31
  Debug mode prints **redacted parameter metadata and response size/type**, not command contents, file contents or raw tool results. Sensitive fields and inline tokens are masked, but local paths and other non-sensitive metadata may still appear, so avoid sharing debug logs publicly. The child gateway's detailed stderr/stdout is still stored at `%TEMP%\private-desktop-mcp-device.log`. Neither logging mode changes device pairing, OAuth or startup behavior.
26
32
 
27
33
  ## Current independent endpoint
package/bin/cli.mjs CHANGED
@@ -5,20 +5,40 @@ import os from "node:os";
5
5
  import {spawn,spawnSync} from "node:child_process";
6
6
  import {fileURLToPath} from "node:url";
7
7
  import WebSocket from "ws";
8
- import { EnvHttpProxyAgent, setGlobalDispatcher } from "undici";
9
- import { getProxyForUrl } from "proxy-from-env";
8
+ import { ProxyAgent } from "undici";
9
+ import { resolveProxyForUrl } from "./proxy.mjs";
10
10
  import { HttpsProxyAgent } from "https-proxy-agent";
11
11
  import { logLine, rpcDescription, rpcOutcome, sanitizeText } from "./logging.mjs";
12
- setGlobalDispatcher(new EnvHttpProxyAgent());
12
+
13
13
  const root=path.dirname(path.dirname(fileURLToPath(import.meta.url)));
14
14
  const command=process.argv.slice(2).find(a=>!a.startsWith("--"))||"connect",debug=process.argv.includes("--debug"),relay="https://private-desktop-device-relay.ljx2043979076.workers.dev";
15
15
  const config=path.join(process.env.APPDATA||path.join(os.homedir(),".config"),"PrivateDesktopMCP","device.json");
16
16
  const sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms));
17
+ let currentProxy=null,proxyCheckedAt=0,lastProxyNotice="";
18
+ const agents=new Map();
19
+ function remoteTransport(){
20
+ if(!currentProxy||Date.now()-proxyCheckedAt>10000){
21
+ currentProxy=resolveProxyForUrl(relay);
22
+ proxyCheckedAt=Date.now();
23
+ if(currentProxy.mode==="unsupported")throw Error(currentProxy.reason+" (use an HTTP/Mixed port via system settings or HTTPS_PROXY)");
24
+ const notice=currentProxy.mode==="proxy"?"🌐 Proxy: "+currentProxy.source+" ("+currentProxy.description+")":
25
+ currentProxy.mode==="unavailable"?"⚠️ Proxy detection unavailable: "+currentProxy.reason+"; trying direct":
26
+ "🌐 Direct connection ("+currentProxy.source+")";
27
+ if(notice!==lastProxyNotice){logLine(currentProxy.mode==="unavailable"?"warn":"info",notice);lastProxyNotice=notice}
28
+ }
29
+ if(currentProxy.mode!=="proxy")return {};
30
+ let transport=agents.get(currentProxy.url);
31
+ if(!transport){
32
+ transport={dispatcher:new ProxyAgent(currentProxy.url),wsAgent:new HttpsProxyAgent(currentProxy.url)};
33
+ agents.set(currentProxy.url,transport);
34
+ }
35
+ return transport;
36
+ }
17
37
  let stopping=false,child=null,socket=null;
18
38
  function saved(){try{return JSON.parse(fs.readFileSync(config,"utf8"))}catch{return null}}
19
39
  function store(x){fs.mkdirSync(path.dirname(config),{recursive:true,mode:0o700});fs.writeFileSync(config,JSON.stringify(x,null,2),{mode:0o600});}
20
40
  function forget(){try{fs.unlinkSync(config)}catch{}}
21
- 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;}
41
+ async function post(route,data){const {dispatcher}=remoteTransport();const r=await fetch(relay+route,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(data),signal:AbortSignal.timeout(12000),...(dispatcher?{dispatcher}:{})});const j=await r.json();if(!r.ok)throw Error(j.error||"HTTP "+r.status);return j;}
22
42
  async function pair(){
23
43
  const v=await post("/relay/pair/start",{name:os.hostname()});
24
44
  logLine("info","🔑 New device pairing requested");
@@ -59,9 +79,9 @@ async function respond(ws,msg){
59
79
  if(ws.readyState===WebSocket.OPEN)ws.send(JSON.stringify(response));
60
80
  }
61
81
  async function connect(creds){return new Promise(resolve=>{
62
- const proxyUrl=getProxyForUrl(relay);
82
+ const {wsAgent}=remoteTransport();
63
83
  logLine("info","🌐 Connecting to Cloudflare relay...");
64
- 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;
84
+ const ws=new WebSocket(relay.replace(/^https:/,"wss:")+"/relay/ws",{headers:{"Authorization":"Bearer "+creds.token,"X-Device-ID":creds.deviceId},handshakeTimeout:15000,...(wsAgent?{agent:wsAgent}:{})});socket=ws;
65
85
  let status=0;
66
86
  ws.on("open",()=>{logLine("info","✅ Connected to Cloudflare relay");logLine("info","🟢 Device online: "+os.hostname());console.log("CONNECTED. ChatGPT can now use this device. Ctrl+C to disconnect.");});
67
87
  ws.on("unexpected-response",(req,res)=>{status=res.statusCode;res.resume();logLine("error","Relay refused: HTTP "+status)});
@@ -75,7 +95,7 @@ if(["help","--help","-h"].includes(command)){console.log("Private Desktop MCP: c
75
95
  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")}}
76
96
  else if(command==="reset"){forget();console.log("Local credentials cleared. Revoke old credentials in the admin page too.");}
77
97
  else if(command==="connect"){
78
- logLine("info","PCC v0.3.3 starting ("+(debug?"debug":"normal")+" logging)");
98
+ logLine("info","PCC v0.3.4 starting ("+(debug?"debug":"normal")+" logging)");
79
99
  try{const credentials=saved()||await pair();if(saved())logLine("info","💾 Stored device pairing found");await startGateway();let retries=0;
80
100
  while(!stopping){const r=await connect(credentials);if(r.unauthorized){forget();logLine("error","Credentials revoked; run again to pair.");break}if(stopping)break;retries++;const ms=Math.min(30000,1500*2**Math.min(5,retries));logLine("warn","Reconnecting in "+Math.ceil(ms/1000)+"s");await sleep(ms);}
81
101
  }catch(e){logLine("error","ERROR: "+sanitizeText(e.message,250));process.exitCode=1}finally{stopGateway()}
package/bin/proxy.mjs ADDED
@@ -0,0 +1,53 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { getProxyForUrl } from "proxy-from-env";
3
+
4
+ const proxyEnvironmentKeys=[
5
+ "https_proxy","http_proxy","all_proxy",
6
+ "npm_config_https_proxy","npm_config_http_proxy","npm_config_proxy"
7
+ ];
8
+ export function hasEnvironmentProxy(env=process.env){
9
+ const names=new Set(Object.keys(env).filter(k=>proxyEnvironmentKeys.includes(k.toLowerCase())));
10
+ return [...names].some(k=>String(env[k]??"").trim().length>0);
11
+ }
12
+ export function normalizeProxy(value,source){
13
+ const raw=String(value||"").trim();
14
+ if(!raw)return {mode:"direct",source};
15
+ const uri=/^[a-z][a-z0-9+.-]*:\/\//i.test(raw)?raw:"http://"+raw;
16
+ let parsed;
17
+ try{parsed=new URL(uri)}catch{return {mode:"unsupported",source,reason:"Invalid proxy address"}}
18
+ if(!["http:","https:"].includes(parsed.protocol)){
19
+ return {mode:"unsupported",source,reason:"Proxy protocol "+parsed.protocol+" is not HTTP CONNECT; use an HTTP/Mixed proxy port"};
20
+ }
21
+ if(!parsed.hostname)return {mode:"unsupported",source,reason:"Missing proxy hostname"};
22
+ return {mode:"proxy",source,url:parsed.href,description:parsed.protocol.slice(0,-1).toUpperCase()+" CONNECT via "+parsed.hostname+":"+(parsed.port||(["https:"].includes(parsed.protocol)?"443":"80"))};
23
+ }
24
+ export function queryWindowsProxy(url,{spawn=spawnSync}={}){
25
+ // Windows WinINET system proxy, including static proxy, exclusions, PAC and WPAD.
26
+ // Use the Windows user's configuration instead of guessing a Clash/v2rayN port.
27
+ const target=String(url).replace(/'/g,"''");
28
+ const script="$ErrorActionPreference='Stop';"
29
+ +"$u=[Uri]'"+target+"';"
30
+ +"$p=[System.Net.WebRequest]::GetSystemWebProxy();"
31
+ +"if($p.IsBypassed($u)){[Console]::Out.Write('DIRECT')}"
32
+ +"else{$v=$p.GetProxy($u);if($v.AbsoluteUri -eq $u.AbsoluteUri){[Console]::Out.Write('DIRECT')}else{[Console]::Out.Write($v.AbsoluteUri)}}";
33
+ const result=spawn("powershell.exe",["-NoLogo","-NoProfile","-NonInteractive","-Command",script],{
34
+ encoding:"utf8",timeout:6000,windowsHide:true,maxBuffer:4096
35
+ });
36
+ if(result.error||result.status!==0){
37
+ return {mode:"unavailable",source:"windows",reason:result.error?.code==="ETIMEDOUT"?"Windows proxy lookup timed out":"Windows proxy lookup failed"};
38
+ }
39
+ const output=String(result.stdout||"").trim();
40
+ if(output==="DIRECT")return {mode:"direct",source:"windows"};
41
+ if(!output)return {mode:"unavailable",source:"windows",reason:"Windows proxy lookup returned no result"};
42
+ return normalizeProxy(output,"windows");
43
+ }
44
+ export function resolveProxyForUrl(url,{
45
+ platform=process.platform,env=process.env,envLookup=getProxyForUrl,windowsLookup=queryWindowsProxy
46
+ }={}){
47
+ if(hasEnvironmentProxy(env)){
48
+ const chosen=envLookup(url);
49
+ return chosen?normalizeProxy(chosen,"environment"):{mode:"direct",source:"environment-bypass"};
50
+ }
51
+ if(platform==="win32")return windowsLookup(url);
52
+ return {mode:"direct",source:"system"};
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juexibobi/private-desktop-mcp",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Private multi-device Desktop Commander MCP connector for Cloudflare Workers with paired WebSocket relays",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,6 +12,7 @@
12
12
  },
13
13
  "files": [
14
14
  "bin/cli.mjs",
15
+ "bin/proxy.mjs",
15
16
  "bin/logging.mjs",
16
17
  "gateway.mjs",
17
18
  "README.md",