Self-hosted 4.86.1: MCP OAuth consent fails with 403 "Invalid request origin"

We run self-hosted Retool 4.86.1 on Kubernetes behind nginx (TLS termination) → Kubernetes ingress. We connect Claude Code to the Retool MCP server. Below, PUBLIC_HOST is our public Retool hostname, served over HTTPS.

Discovery works, dynamic client registration works, the consent screen opens. Clicking Authorize fails:

POST /api/oauth2/authorize on PUBLIC_HOST
→ 403 {"error":"invalid_request","error_description":"Invalid request origin."}

The backend log shows "requestOriginValid": false and no headers.

Request headers from the browser (same tab, user signed in, XSRF cookies present):

  • :authority is PUBLIC_HOST
  • origin is PUBLIC_HOST with the https scheme
  • referer is PUBLIC_HOST with the https scheme, path "/"
  • sec-fetch-site: same-origin

What we already checked:

  • BASE_DOMAIN is PUBLIC_HOST with the https scheme, no trailing slash, on the backend and MCP pods
  • OAUTH_MAIN_DOMAIN is PUBLIC_HOST without a scheme; MCP_SERVICE_EXTERNAL_URL is PUBLIC_HOST with the https scheme
  • COOKIE_INSECURE is not set; HOST_HEADER_NAME is not set (we removed it, same 403)
  • POST /mcp returns 401 with the Bearer challenge; both /.well-known discovery URLs return PUBLIC_HOST, as in the self-hosted MCP guide
  • The proxy passes Host and X-Forwarded-Host with PUBLIC_HOST

Questions:

  1. What does this origin check compare the Origin header against (Host, X-Forwarded-Host, X-Forwarded-Proto, BASE_DOMAIN, something else)?
  2. The retool-helm chart PR 392 mentions env.MCP_TRUSTED_PROXY_CIDRS for proxies that terminate TLS. Is it supported in 4.86.1, and is it related?

This follows my earlier topic "Self-hosted 4.34.x: MCP OAuth metadata returns internal ingress host as issuer". That one is fixed in 4.86.0.

Thanks!

Summary

On self-hosted Retool 4.86.1 (Kubernetes, nginx TLS termination → ingress), the MCP OAuth flow completes discovery and dynamic client registration and shows the consent screen, but clicking Authorize fails with POST /api/oauth2/authorize returning 403 {"error":"invalid_request","error_description":"Invalid request origin."} and backend logs showing "requestOriginValid": false.

AI Response

This origin check validates the request's Origin/Referer against Retool's configured public origin, so the backend must receive the original public Host header and HTTPS protocol from the proxy — not the internal ingress host. Because TLS is terminated at nginx, confirm the proxy forwards the public Host and X-Forwarded-Proto: https all the way through to the main Retool service on port 3000, and ensure the /mcp, /.well-known, and /api/oauth2/ routes are all served under the exact same public origin as required by the self-hosted MCP guide. Also verify OAUTH_MAIN_DOMAIN and MCP_SERVICE_EXTERNAL_URL resolve to that identical public origin, and that any SSO gateway lets the consent POST reach the backend with the authorization query parameters and user session intact. The documented origin/Host-forwarding and same-origin routing requirements are the direct, affirmative cause to check here; there is no separate trusted-proxy CIDR setting called out for this validation in the official self-hosted MCP configuration.*

Sources

:bookmark: Enable the MCP server | Retool Docs
The self-hosted MCP setup guide requires all /mcp and OAuth endpoints to share one public origin and instructs proxies to preserve the original public Host header and HTTPS protocol — the exact conditions the authorize origin check validates.
:bookmark: Use Retool's MCP server | Retool Docs
Confirms the self-hosted MCP server uses OAuth 2.0 against your own instance origin (https:///mcp) and requires version 4.0.0+, framing the browser consent/authorize step that is being rejected.

The Community Team is testing out a new automation. Let us know if it's helpful (or not) by leaving a :heart:, :+1:, or :-1:. Or by marking this post as the "Solution"! Let us know if you have any feedback here. :rocket: