Skip to content

fix(ui): use NEXT_PUBLIC_APP_URL for the MCP endpoint shown in Settings → API Keys #27

Closed

Description

@gkhngyk

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:

  1. SSR + hydration drift. The page is server-rendered first with
    no window available, 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 stale http://localhost:3000
    if they ever opened the same page during local development.
  2. 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 to window.location.origin and 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's onClick (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

  1. added
    bug
    good first issue
    help wanted
    on May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions