Skip to content

feat(mcp): add OpenWork-managed local OAuth gateway - #3652

Merged
reachjalil merged 4 commits into
devfrom
codex/local-mcp-oauth-gateway
Aug 10, 2026
Merged

reachjalil merged 4 commits into
devfrom
codex/local-mcp-oauth-gateway

Conversation

@reachjalil

@reachjalil reachjalil commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add an opt-in OpenWork-managed OAuth path for custom remote MCPs in local desktop workspaces
  • reuse the provider-neutral enterprise MCP client for discovery, DCR or pre-registered clients, PKCE, token exchange, refresh, and authenticated tool verification
  • expose provider tools to the bundled OpenCode engine through a scoped loopback MCP gateway with oauth: false, so OpenCode never receives provider OAuth credentials
  • persist OAuth state in an AES-256-GCM encrypted local vault whose key is held by desktop OS secure storage or an explicitly configured standalone-server secret
  • handle reconnect, logout, enable/disable, and removal through the existing MCP settings surface
  • guard managed-provider egress with public-HTTPS checks, private/reserved and unsafe IANA special-use address blocking, DNS answers bound to the socket connection, and redirect revalidation
  • restrict Electron external navigation to HTTP(S) URLs before opening provider authorization pages

Why

Some MCP providers can complete OAuth through OpenWork's enterprise MCP client but still fail when the bundled OpenCode client owns the direct connection. This adds a compatibility path entirely on the OpenWork side: OpenWork owns OAuth and token lifecycle, while OpenCode continues to consume a normal MCP tool surface.

The path is opt-in per connection and desktop-local only. Existing direct remote MCPs and local command MCPs are unchanged.

Security boundary

Provider access tokens, refresh tokens, OAuth client secrets, registrations, discovery state, and PKCE transactions stay in the encrypted OpenWork vault. OpenWork Desktop lazily protects the random vault key with the operating system's secure-storage service and persists only the protected key blob, separately from the vault. The standalone server requires OPENWORK_ENCRYPTION_KEY and has no plaintext key-file fallback; that server-only value is removed from the managed OpenCode child environment.

The runtime OpenCode config contains only the loopback gateway URL and a connection-scoped bearer derived from a process-only secret. That bearer rotates on restart.

Outside explicit local development, provider URLs must use HTTPS and resolve only to public addresses; private, reserved, documentation, and other unsafe special-use blocks are rejected. DNS validation runs inside the outbound socket connector, and the exact validated answer is passed to TCP/TLS so a hostname cannot rebind between validation and connection. Redirects use the same protected transport, HTTPS downgrade is blocked, credential-bearing request bodies cannot cross origins, and provider authorization pages cannot invoke custom external protocols.

Verification

  • pnpm -C apps/server test src/local-managed-mcp-url-guard.test.ts src/local-managed-mcp.e2e.test.ts src/embedded-lifecycle.test.ts — 16 tests passed, 96 assertions
  • pnpm -C apps/desktop test — 185 passed, 1 skipped
  • pnpm -C apps/app exec bun test tests/desktop-web-url.test.ts — 2 tests passed, 5 assertions
  • pnpm -C apps/server typecheck
  • pnpm -C apps/desktop typecheck:electron
  • pnpm -C apps/app typecheck
  • pnpm -C apps/server build
  • pnpm install --frozen-lockfile
  • compiled embedded server import verified with the desktop production dependency links

The focused end-to-end test covers discovery/DCR, PKCE callback, encrypted persistence without a colocated plaintext key, OS-protected desktop key restoration, fail-closed secure-storage behavior, OpenCode runtime registration, unauthorized gateway rejection, tool listing and calls, provider tool errors without false reauthentication, silent token refresh, terminal revocation, restart reconciliation with bearer rotation, disconnect, and reconnect.

An opt-in testkit tape and voiceover were added. The repository-wide eval TypeScript check is currently blocked by the pre-existing connectors-quick-add.slow.test.ts MockMcpHandle.handshakes type error.

@vercel

vercel Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview Aug 10, 2026 10:29am
openwork-den Ready Ready Preview Aug 10, 2026 10:29am
openwork-den-worker-proxy Ready Ready Preview Aug 10, 2026 10:29am
openwork-diagnostics Ready Ready Preview Aug 10, 2026 10:29am
openwork-landing Ready Ready Preview, v0 Aug 10, 2026 10:29am

@reachjalil
reachjalil enabled auto-merge (squash) August 10, 2026 10:06
Comment thread apps/server/src/local-managed-mcp.ts Resolved

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (712ef8ddbe1818a39a6c705834d52ed2183c7932). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

This branch was successfully deployed

5 active deployments
Preview – openwork-den-worker-proxy — 712ef8dd Deployed Aug 10, 2026 by vercel[bot]
Preview – openwork-landing — 712ef8dd Deployed Aug 10, 2026 by vercel[bot]
Preview – openwork-den — 712ef8dd Deployed Aug 10, 2026 by vercel[bot]
Preview – openwork-app — 712ef8dd Deployed Aug 10, 2026 by vercel[bot]
Preview – openwork-diagnostics — 712ef8dd Deployed Aug 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant