Repository navigation
Description
What's wrong
The Settings → API Keys page shows the MCP endpoint URL that users
copy into their Claude / Cursor / Zed config. It builds the URL from
window.location.origin, which causes two problems:
- SSR + hydration drift. The page is server-rendered first with
nowindowavailable, then re-rendered on the client. With browser
caching, service workers, or a slow hydration, the URL the user
ends up seeing can be wrong — including a stalehttp://localhost:3000
if they ever opened the same page during local development. - Inconsistent with the rest of the codebase. Other places that
need the canonical app URL read it from
process.env.NEXT_PUBLIC_APP_URL(see references below). This one
spot drifted towindow.location.originand now shows a different
value than every other URL-aware feature in the app.
End result: the user can copy the wrong URL into their MCP client
config and nothing connects.
Expected
The MCP endpoint URL should be built from
process.env.NEXT_PUBLIC_APP_URL, falling back to
window.location.origin only when the env var isn't set (graceful
fallback for setups where it's been left blank).
Where to fix
web/src/components/settings/api-keys-section.tsx — two spots use
window.location.origin:
- Around line 144: the
<code>element that displays the URL - Around line 152: the
copy()button'sonClick(same string)
Both should switch to the env-var-first pattern.
Reference pattern
The rest of the codebase already does it this way:
web/src/app/api/stripe/checkout/route.ts(~line 69)web/src/app/api/stripe/success/route.ts(~line 8)web/src/lib/actions/team.ts(~lines 208, 273)web/src/app/layout.tsx(~line 30)
All do roughly:
const appUrl = process.env.NEXT_PUBLIC_APP_URL || /* fallback */;A small helper or a useMemo inside the component is fine. Keep it
small.
How to verify
Open /dashboard/settings → API Keys tab. The MCP endpoint URL
shown should match whatever NEXT_PUBLIC_APP_URL resolves to in your
environment. Click the copy button — clipboard should contain the same
URL.
Contribution guide
See CONTRIBUTING.md for branch naming, commit
conventions, and PR workflow.
Activity