ZUSHENG Studio
中 ← All Notes

Field Note · 001

Connect Plain ChatGPT to a Local Workspace via MCP, OAuth & SSH Reverse Tunnel.

A straightforward goal: without switching to Work mode, let an ordinary web chat read files, patch code, and run commands directly inside my local workspace—fewer context switches, and fewer wasted tokens.

Sep 15, 2026 MCP · OAuth · DevSpace · SSH Reverse Tunnel Verified in production

The Goal

What I wanted was simple: a plain ChatGPT web chat talking directly to my Mac mini.

Not remote desktop, not spinning up another cloud container, and not jumping out into Work mode. Whenever an active conversation needs to check the real environment, it should read, edit, and run commands straight on my machine.

  • Open real local Git repositories and workspaces
  • Read files, search code, and apply patches
  • Run shell, Git, build, and test commands
  • Keep the current conversation context instead of bootstrapping a new session
Why bother?

I live in ChatGPT every day, and plenty of tasks are just quick file checks, small patches, or test runs. Switching to Work mode forces me to rebuild all context from scratch—slower, and double the tokens. Saving tokens was half the motivation.

Constraints

Before touching any config, I drew five hard boundaries:

  • DevSpace stays bound strictly to 127.0.0.1
  • Zero public inbound ports opened on the workstation
  • No Docker, VM, sandbox, or duplicate worktrees
  • No syncing projects out to a separate environment
  • Operate inside the existing macOS/Windows toolchain as the local user
  • Zero disruption to services already running on the public edge host

What Plain Chat Actually Gets

Once wired end to end, tools/list exposes 6 tools. Note that tool mode must be set to codex to unlock all six—otherwise two tools silently disappear (see Pitfall 1).

open_workspace

Open an allowed local workspace.

read

Read file contents.

apply_patch

Patch files inside the real workspace.

show_changes

Inspect local diffs and changes.

exec_command

Run shell, Git, build, and test commands.

write_stdin

Interact with long-running processes.

Live Demo

Both machines connect the same way: add a connector in ChatGPT, approve the OAuth consent page once, and explicitly select it inside any conversation. Each machine has its own connector and stays completely independent.

OAuth consent screen in ChatGPT when adding the DevSpace Home PC connector
Adding a connector. Approve the OAuth consent once and name it per machine—here, DevSpace Home PC.

Mac mini. Below is a real plain ChatGPT session with DevSpace Mac Mini attached—reaching straight into the Mac mini without switching to Work.

Plain ChatGPT session connected to DevSpace Mac Mini inspecting a local git repository and live PCB DRC via EasyEDA bridge
Real session: plain ChatGPT attached to DevSpace Mac Mini reading the local repository and querying live PCB, DRC, and netlist state through the local EasyEDA bridge—all without leaving regular chat.

Here I asked it to cross-check a PCB layout: first reading commit status and audit notes from the git repo, then pulling live DRC results and the netlist via the EasyEDA bridge, and comparing every discrepancy line by line.

Nothing moved off the machine.

Git, EasyEDA, Node, and the files never left the Mac mini—ChatGPT simply calls them over MCP.

win-pc. The exact same setup repeated on my Windows workstation under DevSpace Home PC.

Plain ChatGPT listing active processes on the Windows PC including ZCode, EasyEDA, blender-mcp, node, python, and ToDesk
Live process inspection on Windows: ZCode, EasyEDA, blender-mcp, node, python, and ToDesk, each annotated by the model.

One Architecture, Two Machines

The pipeline came up on the Mac mini first and was later cloned onto the Windows box. Both machines share a single overseas edge host. Adding the second site was purely additive—not a single line of the original config changed.

ChatGPT Web · Plain Chat
        ↓
https://mcp.<domain>
        ↓
Overseas Edge · Caddy
        ↓
127.0.0.1:<tunnel-port>
        ↓
SSH Reverse Tunnel
        ↓
Localhost · 127.0.0.1:7676
        ↓
DevSpace
        ↓
Real Workspace
Why an SSH reverse tunnel?

I also had FRP and Tailscale on hand, but both require installing extra daemons on the server, and FRP needs additional inbound firewall ports. An SSH reverse tunnel works out of the box with zero extra server software or open ports.

Because that edge host already serves live traffic, I enforced a strict "append-only" rule: each Caddy site sits in its own file, imported via one line in the main Caddyfile, and changes roll out with reload rather than restart.

Path & Config

Host · Port
mcp.example.com · 17676
Local Bind
DevSpace listens strictly on 127.0.0.1:7676
Tunnel
ssh -N -R 17676:127.0.0.1:7676 initiated outbound by the Mac
Public Edge
Overseas Caddy terminates HTTPS and proxies to loopback port 17676
Site Config
/etc/caddy/devspace.caddy
Persistence
Two LaunchAgents (DevSpace & SSH tunnel), both with KeepAlive
Allowed Roots
/Volumes/PSSD/Dev (42 git repos) + one desktop project directory
ChatGPT URL
MCP + OAuth endpoint at https://mcp.example.com/mcp

The key invariant is that the Mac dials out. Nothing external ever connects directly to the Mac, and DevSpace stays bound to loopback.

Debugging Trail

The initial symptom looked simple: ChatGPT failed to add the connector with "Error fetching OAuth configuration / Request timeout" and never showed the consent screen. Behind that one message were several completely independent issues.

01 · First Suspect
Did the edge WAF drop requests with status 444?

444 looks identical from the outside: abrupt connection drop, client timeout, and empty access logs. But "looks like" is not proof—it needed a controlled test.

02 · Controlled Test
Disable only the WAF, leave everything else untouched.

End-to-end OAuth + MCP tests passed locally, proving OpenResty, the tunnel, and DevSpace were healthy. Yet ChatGPT Cloud still failed to deliver a single subsequent request to the origin.

03 · Root Cause
WAF cleared; the OpenAI Cloud → Mainland IP leg was dropping multi-step handshakes.

Correlating both ends proved it: ChatGPT’s first probe to /.well-known/oauth-protected-resource/mcp returned 200, and the second request vanished before ever reaching the server. Moving the edge to Singapore brought up the OAuth screen immediately—the migration itself was the fix.

04 · Separate Bug
/.well-known/openid-configuration returned 404.

The MCP SDK router did not expose this path, yet ChatGPT probes it. Adding explicit rewrites on the edge completed discovery.

05 · Final Switch
Dynamic Client Registration (DCR) must be selected in ChatGPT.

Choosing custom OAuth client with an empty client ID skips POST /register and guarantees failure.

Why DNS was not the culprit. Google, Cloudflare, and authoritative NS records all matched. From 40 overseas probes, 39 reached discovery cleanly and 25/25 hit oauth-authorization-server. Resolution was never broken.

The real difference was request sequence: isolated probes succeeded, while a multi-request OAuth handshake back-to-back did not survive the cross-border path.

End-to-End Verification

Once healthy, the full handshake sequence looks like this:

GET  /.well-known/oauth-protected-resource/mcp → 200
GET  /.well-known/oauth-authorization-server   → 200
GET  /.well-known/openid-configuration         → 200
POST /register                                 → 201
GET  /authorize                                → 200
POST /authorize                                → 302
POST /token                                    → 200
POST /mcp                                      → 200
tools/list                                     → 6 tools
Check Outcome
ChatGPT OAuth discovery Passed
DCR registration POST /register → 201
Token exchange POST /token → 200
MCP session POST /mcp → 200
Tool list 6 tools
Live local access Plain chat read real workspaces on the Mac mini

The final row is what matters. Health checks and tools/list only prove the server is alive—not that a real conversation can actually read your files.

Path & Config

Host · Port
mcp.win.example.com · 17677
Local Bind
DevSpace listens strictly on 127.0.0.1:7676
Tunnel
ssh -N -R 17677:127.0.0.1:7676 initiated outbound by Windows
Public Edge
Second Caddy site on the same overseas node proxying to port 17677
Site Config
/etc/caddy/win.caddy
Persistence
Task Scheduler: trigger at logon, interactive session, restart on failure
Allowed Roots
C:\Users\Zusheng + D:\luma-render
ChatGPT URL
Same MCP + OAuth flow with DCR enabled

Same invariant: this machine dials out, with zero inbound ports exposed.

Windows-Specific Pitfalls

Non-interactive SSH sessions skip user PATH.

Even with nvm-windows installed, node -v fails as unknown and npm i -g breaks when node-gyp cannot locate node. Launch scripts must prepend set PATH=C:\env\nvm\v24.21.0;%PATH% explicitly.

Task Scheduler kills long-running tasks after 72 hours by default.

ExecutionTimeLimit must be explicitly disabled, and LogonType set to Interactive when desktop context is needed.

open_workspace responses include SSE : keepalive comments.

Especially noticeable on large folders. Test scripts must parse multi-frame SSE streams rather than assuming a single data event—my first verifier flagged real successes as failures because of this.

Verification

Public E2E passed register 201 → authorize 302 → token 200 → initialize 200 → tools/list 200 with all 6 tools. Access logs recorded 46 openai-mcp/1.0.0 requests in five minutes (all 200/202), and the chat read the live process list on the workstation.

Field Pitfalls

1. DEVSPACE_TOOL_MODE is ignored inside config.json

DEVSPACE_TOOL_MODE and DEVSPACE_WIDGETS are read exclusively from environment variables; putting them in config.json does nothing. Running bare devspace serve silently drops back to minimal mode—no errors, yet apply_patch and show_changes vanish.

DEVSPACE_TOOL_MODE=codex
DEVSPACE_WIDGETS=changes
devspace serve

On macOS, LaunchAgent therefore invokes a thin wrapper script that exports both variables before starting DevSpace.

2. OAuth discovery needs four well-known routes

Ensure all four routes respond cleanly on the public edge:

/.well-known/oauth-protected-resource
/.well-known/oauth-protected-resource/mcp
/.well-known/oauth-authorization-server
/.well-known/openid-configuration

Note that ChatGPT probes the bare root without the /mcp suffix, whereas the MCP SDK only registers the suffixed variant—rewrite both.

3. Local TUN proxies can spoof network diagnostics

With mihomo TUN active locally, curl --resolve, nc, and even dig @1.1.1.1 get hijacked through fake-IP routes (198.18.x.x). I once thought I was probing an overseas edge while actually hitting a mainland server.

Never trust local-only probes for cross-border debugging.

Always test from an independent remote node so local proxy rules do not masquerade as server bugs.

4. Stale DNS caches fake TLS errors

Right after switching DNS to the new edge, browsers threw ERR_SSL_PROTOCOL_ERROR. The cert was fine—the browser still cached the old IP, whose server no longer held that SNI site and returned TLS alert 80. Flushing cache cleared it immediately.

5. POST /mcp → 400 No valid MCP session can be normal

Observed during session negotiation; the immediate retry carrying the negotiated session ID returns 200. Do not mistake an isolated 400 log line for a broken setup.

Security Boundary: Wider Than Expected

allowedRoots only constrains open_workspace. Once any allowed workspace is open, exec_command runs a full shell under the local OS user.

In testing, it could read outside the allowlist as well as ~/.devspace. Therefore:

allowedRoots is not a security sandbox.

It prevents opening the wrong directory by accident, not shell traversal. The real security boundaries are OS user permissions, loopback binding, OAuth consent, and action approval.

Reuse Checklist for Machine #3

Updated after bringing up both macOS and Windows. Items marked "Windows" were discovered on the second machine:

  • Keep DevSpace bound strictly to 127.0.0.1
  • Match Node version to DevSpace’s package.json (>=22.19 <27), not devspace doctor’s outdated hint
  • Export DEVSPACE_TOOL_MODE / DEVSPACE_WIDGETS in the launcher script, not config.json
  • Windows: explicitly set PATH inside launcher scripts since non-interactive SSH skips user env vars
  • Run both DevSpace and ssh -R under OS service supervision with auto-restart
  • Windows: disable Task Scheduler’s 72-hour execution timeout and use interactive LogonType
  • Place the public HTTPS ingress on an overseas node
  • Give each machine its own hostname: ChatGPT caches OAuth metadata and failures per URL
  • Assign a dedicated loopback tunnel port per machine (Mac 17676, win-pc 17677)
  • Expose all 4 well-known discovery endpoints
  • Select DCR when registering the connector in ChatGPT
  • Verify public E2E before wiring ChatGPT
  • Windows: tolerate SSE : keepalive lines when parsing open_workspace
  • Start a fresh ChatGPT conversation and select the new connector explicitly after adding it
  • Always verify with a real file read in plain chat—not just health or tools/list

Current Status

Verified: plain ChatGPT web conversations access real local workspaces over MCP and invoke open_workspace, read, apply_patch, show_changes, exec_command, and write_stdin. The exact same architecture now runs independently on two machines sharing one overseas ingress.

Everyday payoff: small coding and hardware verification tasks stay in the active chat, saving both context switches and tokens.