Skip to content

fix(den): explain redirect-URI refusals and open provider sign-in in a real tab - #4678

Merged
benjaminshafii merged 2 commits into
devfrom
fix/connect-signin-tab-errors
Sep 9, 2026
Merged

benjaminshafii merged 2 commits into
devfrom
fix/connect-signin-tab-errors

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

Why

Clicking Connect on an external MCP connection could end in a generic "OpenWork could not read the answer from its API… try again" screen inside an about:blank popup window, even though den-api had a precise diagnosis. Root cause chain:

  1. Some providers' authorization servers only approve allowlisted redirect URIs; they refuse OpenWork's dynamic client registration with HTTP 400 (invalid_redirect_uri, or invalid_request naming the redirect URI). den-api classified this generically (MCP_HTTP_400).
  2. den-api answered connect/start handshake failures with HTTP 502.
  3. The API is served behind an edge that replaces an origin's 502/504 with its own CORS-less error page, so the browser on the web origin could never read the body. den-web's fix(den-web): explain OAuth-start answers the browser cannot read #4666 wrapper then showed the readability message and told the member to retry — which cannot help for this class of failure.

What changed

den-api

  • New diagnostic MCP_OAUTH_REDIRECT_URI_NOT_ALLOWED (phase AUTH_CLIENT_REGISTRATION, not retryable, provider_admin owns it) with a plain-language message and operator action; providerCode carries the provider's error.
  • connect/start handshake failures return 424 instead of 502 so the diagnostic reaches the browser; the body includes callbackUrl for the new code. Route schema updated; SDK regenerated.
  • Other 502 sites in mcp-connections.ts (validation, requirements discovery, tool catalog) have the same edge exposure and are left for a follow-up.

den-web

  • Connect opens a same-window tab at /connect/oauth (rendered with the shared DenStatusScreen OpenWork shell) instead of an about:blank popup window filled by document.write.
  • The failure screen explains what happened in the member's words; advice is driven by retryable/actionOwner (never "try again" when retrying cannot help). A provider refusing the redirect URI gets: "{provider} hasn't approved OpenWork yet", the redirect URI to allowlist and the reference (copyable), and technical details on demand. The unreadable-response wording from fix(den-web): explain OAuth-start answers the browser cannot read #4666 is kept.

Test tooling

  • scripts/mock-oauth-mcp-server.mjs + mcpMock({ rejectDynamicRedirectUris }) reproduce the provider refusal deterministically.

Proof

Coverage decision: extend the two existing journeys (no new spec files).

  • pnpm evals:pr specs/mcp-oauth-start-browser-readable-errors.test.ts — placement: local (PR lane resolved by testkit) — Passed (1/1). Asserts 424 with exactly one readable Access-Control-Allow-Origin, MCP_OAUTH_REDIRECT_URI_NOT_ALLOWED for both provider error shapes with callbackUrl, the vanishing-provider failure keeping a different code and no callbackUrl, no secrets in bodies, and no CORS allowance for untrusted origins.
  • pnpm evals:e2e mcp-oauth-start-unreadable-response --local — placement: local (--local); the journey declares local placement because the fault proxy must sit in front of den-api before Den boots — Passed (1/1, 0 skipped). Asserts the sign-in tab is a same-window /connect/oauth page (no about:blank target) for a readable 424, an unreadable injected answer, and a provider refusing the redirect URI (named provider, redirect URI, reference, no retry advice and no readability message, zero provider authorize requests), then the same button starts provider sign-in once the provider accepts.
  • den-api tsc clean; test/external-mcp-diagnostics.test.ts 89/89; den-web typecheck clean; den-web unit suite 228/229 — the one failure (cloud-super-admins-role-hierarchy) reproduces on origin/dev with this branch's den-web changes stashed, so it is pre-existing; pnpm --filter @openwork/sdk generate:check clean.

Evidence report is published as the sticky test-evidence comment below.

…a real tab

When a member clicks Connect on an external MCP connection, den-api's
OAuth-start route answered handshake failures with HTTP 502. The API sits
behind an edge that replaces origin 502/504 responses with its own
CORS-less error page, so the browser on the web origin could never read
den-api's diagnostic: the member saw a generic "could not read the
answer, try again" even when the provider's authorization server had
refused OpenWork's redirect URI and retrying could not help.

den-api
- Classify a dynamic-client-registration 400 that rejects the redirect
  URI (provider error invalid_redirect_uri, or invalid_request /
  invalid_client_metadata naming the redirect URI) as
  MCP_OAUTH_REDIRECT_URI_NOT_ALLOWED: not retryable, provider_admin owns
  it, plain-language message and operator action.
- Answer connect/start handshake failures with 424 instead of 502 so the
  diagnostic reaches the browser; include callbackUrl for the new code so
  the UI can show what the provider must allowlist. SDK regenerated.

den-web
- Connect opens a same-window tab at /connect/oauth (rendered with the
  shared OpenWork status shell) instead of an about:blank popup window
  filled by document.write.
- The failure screen explains what happened in the member's words, with
  advice driven by retryable/actionOwner (never "try again" when retrying
  cannot help), copyable redirect URI and reference, and technical
  details on demand. The unreadable-response wording from #4666 is kept.

Proof
- evals/specs/mcp-oauth-start-browser-readable-errors.test.ts: 424 with
  readable CORS, the new diagnostic for both provider error shapes,
  callbackUrl, and the untrusted-origin negative.
- evals/specs/mcp-oauth-start-unreadable-response.e2e.test.ts: the tab
  is a same-window /connect/oauth page (no about:blank target) for a
  readable 424, an unreadable answer, and a provider refusing the
  redirect URI (named provider, redirect URI, reference, no retry
  advice), then the same button starts provider sign-in.
- scripts/mock-oauth-mcp-server.mjs: MOCK_REJECT_DCR_REDIRECT_URIS
  reproduces the provider refusal deterministically.
@vercel

vercel Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 9, 2026 3:36pm UTC
openwork-den Ready Ready Preview Sep 9, 2026 3:36pm UTC
openwork-diagnostics Ready Ready Preview Sep 9, 2026 3:36pm UTC
openwork-landing Ready Ready Preview, v0 Sep 9, 2026 3:36pm UTC

@benjaminshafii

benjaminshafii commented Sep 9, 2026 •

Copy link
Copy Markdown
Member Author

Test evidence (PR lane, companion to the sticky journey report) — specs/mcp-oauth-start-browser-readable-errors.test.ts

Command: pnpm evals:pr specs/mcp-oauth-start-browser-readable-errors.test.ts · placement: local (PR lane resolved by testkit) · exit 0 · 1 passed / 0 failed / 0 skipped → Passed

SHA f937901 · engine v1

✅ passed · 7 expectations passed · 0 failed · 0 pending

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. Preflight for OAuth start is answered for the trusted web origin

OPTIONS returned HTTP 204 with allow-origin http://127.0.0.1:60152, credentials, Authorization and X-OpenWork-Org-Id allowed.

ℹ️ ASSERTION — 2. Successful OAuth start is readable from the browser

HTTP 200 needs_auth carried one allow-origin http://127.0.0.1:60152 and allow-credentials true.

ℹ️ ASSERTION — 3. OAuth invalid_redirect_uri redirect rejection is actionable and browser-readable

HTTP 424 carried MCP_OAUTH_REDIRECT_URI_NOT_ALLOWED, the shared callback URL, one allow-origin http://127.0.0.1:60152, and no secrets.

ℹ️ ASSERTION — 4. OAuth invalid_request redirect rejection is actionable and browser-readable

HTTP 424 carried MCP_OAUTH_REDIRECT_URI_NOT_ALLOWED, the shared callback URL, one allow-origin http://127.0.0.1:60152, and no secrets.

ℹ️ ASSERTION — 5. Unrelated OAuth handshake failure stays distinct and browser-readable

HTTP 424 oauth_handshake_failed carried a different diagnostic, no callback URL, one allow-origin http://127.0.0.1:60152, and no secrets.

ℹ️ ASSERTION — 6. Unauthenticated OAuth start is readable from the browser

HTTP 401 carried allow-origin http://127.0.0.1:60152 and allow-credentials true.

ℹ️ ASSERTION — 7. Untrusted origins never receive CORS allowance

Preflight and HTTP 424 for https://untrusted.example.test carried no allow-origin header.


Test run created 2026-09-09T15:31:41.066Z · Source: evals/results/test-runs/2026-09-09T15-31-41-065Z-den-oauth-start-answers-browser-preflights-successes-and-handshake-failures-with/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4678 --test-run 2026-09-09T15-31-41-065Z-den-oauth-start-answers-browser-preflights-successes-and-handshake-failures-with

…-errors

# Conflicts:
#	evals/packages/labs/src/mock-mcp.ts
@benjaminshafii

benjaminshafii commented Sep 9, 2026 •

Copy link
Copy Markdown
Member Author

Passed · 1/1 tests · 2/2 assertions · 0 images

Commit f9379011c7fbe8e6a70166f53b83b6c3583a3a81 · selected evidence

Open review report

@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 (f9379011c7fbe8e6a70166f53b83b6c3583a3a81). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@benjaminshafii
benjaminshafii merged commit 865e348 into dev Sep 9, 2026
36 checks passed

This branch was successfully deployed

4 active deployments
Preview – openwork-landing — f9379011 Deployed Sep 9, 2026 by vercel[bot]
Preview – openwork-den — f9379011 Deployed Sep 9, 2026 by vercel[bot]
Preview – openwork-app — f9379011 Deployed Sep 9, 2026 by vercel[bot]
Preview – openwork-diagnostics — f9379011 Deployed Sep 9, 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