Skip to content

feat(mcp): turn on app sign-in for MCP, with Help and docs - #2291

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/mcp-oauth-launch
Nov 11, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/mcp-oauth-launch

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Do not merge until migrations 00510 and 00511 are applied to the production database. This PR switches app sign-in on as soon as it merges. Ops steps are below under "What ops sets".

Summary

PR 7 of the MCP over OAuth plan (#2141), the launch PR. PRs 1 to 6 are merged: #2260, #2261, #2262, #2272, #2273 and #2274. upstream/main is merged into this branch, including #2287 and #2288, so the diff is this PR alone.

Merge order: after #2274 (merged) and after migrations 00510 and 00511 are applied to the production database.

What changes for customers when it merges

  • On Ansvisor Cloud, Claude and ChatGPT can connect to https://app.ansvisor.com/api/mcp by signing in. Claude here means claude.ai, the desktop and mobile apps, and Claude Code. There is no key to copy.
  • This works on every paid plan (Starter, Growth, Enterprise), but not in the free trial or on an ended plan (owner decision, 2026-11-09).
  • What an app may do depends on the plan, as it does for an API key: on Starter it reads, and changes need Growth.
  • People see and disconnect their apps in Settings › MCP & API Keys › Connected apps (feat(settings): list and disconnect connected apps #2273). An app unused for 30 days is disconnected on its own.
  • API keys work exactly as before, on every plan.
  • On a self-hosted install, app sign-in turns on by itself wherever NEXT_PUBLIC_APP_URL is https:// with no path. On plain http, it stays off and nothing changes.

1. On by default (web/src/lib/mcp-oauth/config.ts)

  • mcpOAuthEnabled() is true unless MCP_OAUTH_ENABLED=false. Before, it was on only with =true.
  • It still needs an issuer: oauthIssuer() takes only https:// with no path, or http:// on localhost for development. So a self-hosted http install stays off.
  • MCP_OAUTH_ENABLED=false is the kill switch, in any case and with surrounding spaces. 0, off and no also switch it off. When it is off:
    • the /.well-known OAuth documents and /api/oauth/* answer 404;
    • the MCP endpoint's 401 no longer starts a sign-in;
    • ans_oat_ tokens are refused;
    • Connected apps is hidden.
  • Connections stay stored while it is off. When it is back on, an app reconnects with its refresh token, as long as that token's 30 days have not passed.
  • Comments in mcp-auth.ts, http.ts and api/mcp/route.ts now describe the new default.

2. OpenAI's domain check (web/src/app/api/well-known/openai-apps-challenge/route.ts)

  • GET /.well-known/openai-apps-challenge returns OPENAI_APPS_CHALLENGE as text/plain; charset=utf-8, with Cache-Control: no-store.
  • The value is read on each request and trimmed, so a pasted newline or spaces are not served.
  • It answers 404 when the variable is unset or blank.
  • It is served at the root only, through a next.config.ts rewrite, like the OAuth discovery documents. The proxy's matcher skips any path with a dot, so locale routing never redirects it.
  • I checked it against next start on this branch's production build, with OPENAI_APPS_CHALLENGE=' oai-check-token-42\n':
    • /.well-known/openai-apps-challenge answered 200 with content-type: text/plain; charset=utf-8 and cache-control: no-store. The body was exactly the 18 bytes oai-check-token-42, with no redirect.
    • /en/.well-known/openai-apps-challenge answered 404.
  • The unset case (404) is covered by the route's unit tests.

3. Copy (web/messages/en.json, api-keys-section.tsx)

  • feat(settings): list and disconnect connected apps #2273 already shows this endpoint box line while sign-in is on: "Claude and ChatGPT: add this address as a connector and sign in. Other clients: create a key…". The plan note shows too.
  • The one gap was the Claude Desktop setup line in the new key's dialog. With sign-in on, it now reads: "In Claude, open Settings → Connectors → Add custom connector and fill in these fields. Or enter only the name and URL, and sign in to Ansvisor instead of using a key." The key is settings.apiKeys_connectWhereClaudeDesktopSignIn.
  • With sign-in off, the line is unchanged.

4. Wording that assumed an API key

  • These tool descriptions said a change is logged under "the API key's user": update_task_status, create_improve_action, override_mention_sentiment and approve_task_review. They now say "the user this connection acts as (the API key's owner, or the person who connected the app)".
  • get_site_audit_quota's error over MCP now says "No organization found for this connection".
  • The role refusal (RoleRequiredError, for MCP tools and the REST routes) now says "This connection acts as an analyst" instead of "This API key acts as…".
  • The MCP coach skill (skills/ansvisor-aeo-coach/SKILL.md) now says a change is logged under "the person the API key or the app's sign-in acts as".
  • Messages that really are about API keys are kept. Examples: the REST /api/mcp/site-audits/quota route, which takes keys only, and the standalone (REST) coach skill.
  • The first line of MCP_INSTRUCTIONS (the engine list) is not touched here. fix(mcp): name only the engines Ansvisor tracks in the server instructions #2287 changed it, and that change came in through the merge from main.

5. Gemini CLI setup (checked against Gemini CLI 0.67.0)

  • Both the in-app snippet (web/src/lib/mcp/client-setup.ts) and the docs now use gemini mcp add --scope user.
    • Without it, Gemini CLI writes to its default scope, project: the current folder's .gemini/settings.json, with the key. That file can end up committed.
  • The docs' header is now in single quotes ('Authorization: Bearer $ANSVISOR_TOKEN').
    • The shell no longer expands the variable, so the file stores the reference and not the key.
    • Gemini CLI resolves $VAR and ${VAR} in its settings each time it loads them.
  • The docs now say the command writes "url" with "type": "http". Before, they said httpUrl.
  • The docs add that, with sign-in on, Gemini CLI can sign in instead with /mcp auth ansvisor. It registers itself through dynamic registration, with a localhost redirect.
  • The Gemini CLI extension page (docs/guides/gemini-cli.mdx, feat(integrations): add a Gemini CLI extension for the MCP server #2289) is not touched.

6. Help (help/settings/mcp-server.md, approved; web/src/lib/help/approved-articles.json regenerated)

  • New and updated sections:
    • connecting Claude or ChatGPT by signing in, and the consent page's choices;
    • what each plan includes: sign-in on paid plans, not in the trial or on an ended plan; Starter reads, and changes need Growth;
    • Connected apps, Disconnect, and the 30-day idle end;
    • what an app that only reads is told;
    • self-hosted needs https.
  • Every section is 150 words or fewer. The longest has 136.

7. What's new (whats-new/mcp-app-sign-in.md)

  • approved: false, plans: [starter, growth, enterprise], plan_mode: show_upgrade.
  • It stays out of entries.json until it is approved.

8. Docs

  • docs/guides/mcp-server.mdx:
    • Connect by signing in: Claude, Claude Code, ChatGPT and other spec clients, and the consent page.
    • App sign-in (OAuth):
      • discovery: the 401 challenge, and the protected resource and authorization server metadata;
      • the endpoints, PKCE S256, resource, iss, client authentication, redirect URI rules and rate limits;
      • registration with Client ID Metadata Documents, from feat(mcp): accept Client ID Metadata Documents (00511) #2274's final code: a host name on port 443 (an IP-address host is refused), public addresses only, no redirects, 5 s for the whole fetch, 10 KB, JSON, and a cache of 5 minutes to a day;
      • dynamic client registration;
      • scopes mcp:read / mcp:write and the 403 step-up;
      • token lifetimes from config.ts: request 10 min, code 5 min, access 1 h, refresh 30 days rotating, with a 30 s reuse grace;
      • plans, the oauth_plan_required error, and disconnect and revoke.
    • "There is no OAuth sign-in" is gone.
    • Role and tool rows now say "the key or the app sign-in".
    • The Gemini CLI fix from section 5.
  • docs/api-reference/authentication.mdx: a short App sign-in (OAuth) for the MCP server section. App tokens work only at /api/mcp.
  • docs/self-host/env-variables.mdx:
    • MCP_OAUTH_ENABLED: on by default, and false is the kill switch;
    • OPENAI_APPS_CHALLENGE;
    • NEXT_PUBLIC_APP_URL must be https:// with no path for app sign-in.
    • web/.env.example matches.
  • docs/faq.mdx: disconnecting connected apps works on a read-only workspace.
  • docs/guides/mentions.mdx: the override_mention_sentiment row.

Tests

  • The flag (helpers.test.ts):
    • on by default with an https or localhost issuer;
    • off on plain http or with no address;
    • switched off by false, FALSE, " false\n", 0, off or no;
    • on with true, 1 or an empty value.
  • Every OAuth suite now runs with the flag unset: oauth.test.ts, authorize, connections, consent, cimd, mcp-auth.oauth and api/mcp/route. The kill-switch tests set false.
  • openai-apps-challenge/route.test.ts (6 tests): the token as plain text, exact and never cached; trimmed; 404 when unset, empty or blank; served at the root by the rewrite only.
  • api-keys-section.test.tsx: the endpoint box and the Claude Desktop line, with sign-in on and off.
  • client-setup.test.ts: the Gemini CLI snippet.
  • role-gate.test.ts and the content-opportunity status route test pin the new refusal text.
  • Help validation: yarn test -u src/lib/help.

Related issue

Part of #2141. This is PR 7 of 8; PR 8 links the directory listings once they are live.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

What ops sets (Vercel, production and preview)

  • Check that NEXT_PUBLIC_APP_URL=https://app.ansvisor.com, with no path. It is the issuer, and app sign-in stays off without it.
  • MCP_OAUTH_ENABLED: nothing to set. To switch app sign-in off, set MCP_OAUTH_ENABLED=false and redeploy. API keys keep working.
  • OPENAI_APPS_CHALLENGE=<token> once OpenAI's portal gives the domain verification token. Then redeploy and check that https://app.ansvisor.com/.well-known/openai-apps-challenge shows it.
  • Apply 00510 and 00511 to production before merging (needs-migration), then run supabase/check-drift.sh.
  • Vercel Firewall (plan, section 6):
    • make sure bot protection and the WAF don't block Anthropic (160.79.104.0/21) or OpenAI on /.well-known/*, /api/oauth/* and /api/mcp;
    • optionally, add a rate-limit rule on /api/oauth/register and /api/oauth/token.

What ops must confirm in OpenAI's portal

OpenAI's pages (developers.openai.com) can't be read from the build session. So the code follows the plan's research, not the current page (plan, section 8). Before submitting, confirm in the portal:

  • that the domain check is still a plain-text token at the root's /.well-known/openai-apps-challenge;
  • which redirect URI ChatGPT uses. The code sends RFC 9207 iss in every authorization response, and lets dynamic registration and Client ID Metadata Documents register https://chatgpt.com/… redirects;
  • that a tools-only server, with no Apps SDK widgets, is accepted;
  • the per-tool hint reasons (from PR 1), the test account (no MFA) and the test cases.

How to test

  1. From web/: npx vitest run src/lib/mcp-oauth src/app/api/oauth src/app/api/mcp src/app/api/well-known src/lib/mcp src/lib/mcp-auth src/components/settings/api-keys-section src/lib/help.
  2. Run the app with NEXT_PUBLIC_APP_URL=http://localhost:3000 and no MCP_OAUTH_ENABLED:
    • curl -i localhost:3000/.well-known/oauth-authorization-server answers 200 with the metadata;
    • curl -i -X POST localhost:3000/api/mcp answers 401 with WWW-Authenticate: Bearer … resource_metadata=….
  3. With MCP_OAUTH_ENABLED=false, both answer as before: 404, and a 401 without the challenge. Settings › MCP & API Keys shows no Connected apps.
  4. With OPENAI_APPS_CHALLENGE=abc123:
    • curl -i localhost:3000/.well-known/openai-apps-challenge answers 200, text/plain; charset=utf-8, no-store, with body abc123 and no redirect to /en/….
    • Without the variable, it answers 404.
  5. Use a deployment whose NEXT_PUBLIC_APP_URL is its own https:// address, with no path.
    • Add <that address>/api/mcp in Claude as a custom connector with no key. Claude opens Ansvisor's sign-in and the consent page.
    • After Allow, list_brands works, and the app is listed under Connected apps.
    • On a preview whose NEXT_PUBLIC_APP_URL is another host, the resource doesn't match the address you typed, so Claude can't connect.
  6. Go to Settings › MCP & API Keys → New key.
    • Claude Desktop: the line under the picker says you can sign in instead.
    • Gemini CLI: the snippet has --scope user.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors, 12 warnings, all in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR: launching app sign-in, meaning the switch, its copy, Help and docs, and the wording that assumed a key
  • Help article updated under help/ (or no user-visible change) — see help/README.md: help/settings/mcp-server.md (approved, approved-articles.json regenerated); what's-new entry added with approved: false

Also checked:


Generated by Claude Code

PR 7 of the MCP over OAuth plan (ansvisor#2141). Merge after ansvisor#2274 and after
00510 and 00511 are applied in production.

- App sign-in is on unless MCP_OAUTH_ENABLED=false (the kill switch;
  0, off and no too). It still needs an https issuer, so a self-hosted
  install on plain http stays off.
- GET /.well-known/openai-apps-challenge serves OPENAI_APPS_CHALLENGE as
  text/plain, no-store, trimmed; 404 while unset.
- The new key's Claude Desktop line says Claude can sign in instead.
- Tool descriptions, the role refusal and get_site_audit_quota's error
  no longer assume an API key; the MCP coach skill likewise.
- Gemini CLI: --scope user, so the key isn't written into the project's
  .gemini/settings.json; the docs keep $ANSVISOR_TOKEN a reference and
  say it writes url with type http, and how Gemini CLI can sign in.
- Help (approved, regenerated), a what's-new entry (not approved), and
  docs: the MCP guide's app sign-in section, authentication, env vars.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
@mintlify

mintlify Bot commented Nov 11, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit c69f1b1.

Approve preview

@gkhngyk gkhngyk 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.

LGTM.

@gkhngyk
gkhngyk merged commit 52475cb into ansvisor:main Nov 11, 2026
14 checks passed
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.

3 participants