Repository navigation
feat(mcp): turn on app sign-in for MCP, with Help and docs - #2291
Merged
Merged
Conversation
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
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
6 of 13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/mainis 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.
00510_mcp_oauth.sql(feat(mcp): accept OAuth access tokens at /api/mcp, behind MCP_OAUTH_ENABLED (00510) #2261); 00511 is00511_mcp_oauth_cimd.sql(feat(mcp): accept Client ID Metadata Documents (00511) #2274).oauth_clients,oauth_grantsand the other OAuth tables. Without 00510 and 00511, connecting fails with a server error.What changes for customers when it merges
https://app.ansvisor.com/api/mcpby signing in. Claude here means claude.ai, the desktop and mobile apps, and Claude Code. There is no key to copy.NEXT_PUBLIC_APP_URLishttps://with no path. On plainhttp, it stays off and nothing changes.1. On by default (
web/src/lib/mcp-oauth/config.ts)mcpOAuthEnabled()is true unlessMCP_OAUTH_ENABLED=false. Before, it was on only with=true.oauthIssuer()takes onlyhttps://with no path, orhttp://on localhost for development. So a self-hostedhttpinstall stays off.MCP_OAUTH_ENABLED=falseis the kill switch, in any case and with surrounding spaces.0,offandnoalso switch it off. When it is off:/.well-knownOAuth documents and/api/oauth/*answer 404;ans_oat_tokens are refused;mcp-auth.ts,http.tsandapi/mcp/route.tsnow 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-challengereturnsOPENAI_APPS_CHALLENGEastext/plain; charset=utf-8, withCache-Control: no-store.next.config.tsrewrite, like the OAuth discovery documents. The proxy's matcher skips any path with a dot, so locale routing never redirects it.next starton this branch's production build, withOPENAI_APPS_CHALLENGE=' oai-check-token-42\n':/.well-known/openai-apps-challengeanswered200withcontent-type: text/plain; charset=utf-8andcache-control: no-store. The body was exactly the 18 bytesoai-check-token-42, with no redirect./en/.well-known/openai-apps-challengeanswered 404.3. Copy (
web/messages/en.json,api-keys-section.tsx)settings.apiKeys_connectWhereClaudeDesktopSignIn.4. Wording that assumed an API key
update_task_status,create_improve_action,override_mention_sentimentandapprove_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".RoleRequiredError, for MCP tools and the REST routes) now says "This connection acts as an analyst" instead of "This API key acts as…".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"./api/mcp/site-audits/quotaroute, which takes keys only, and the standalone (REST) coach skill.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 frommain.5. Gemini CLI setup (checked against Gemini CLI 0.67.0)
web/src/lib/mcp/client-setup.ts) and the docs now usegemini mcp add --scope user.project: the current folder's.gemini/settings.json, with the key. That file can end up committed.'Authorization: Bearer $ANSVISOR_TOKEN').$VARand${VAR}in its settings each time it loads them."url"with"type": "http". Before, they saidhttpUrl./mcp auth ansvisor. It registers itself through dynamic registration, with alocalhostredirect.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.jsonregenerated)https.7. What's new (
whats-new/mcp-app-sign-in.md)approved: false,plans: [starter, growth, enterprise],plan_mode: show_upgrade.entries.jsonuntil it is approved.8. Docs
docs/guides/mcp-server.mdx:resource,iss, client authentication, redirect URI rules and rate limits;mcp:read/mcp:writeand the 403 step-up;config.ts: request 10 min, code 5 min, access 1 h, refresh 30 days rotating, with a 30 s reuse grace;oauth_plan_requirederror, and disconnect and revoke.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, andfalseis the kill switch;OPENAI_APPS_CHALLENGE;NEXT_PUBLIC_APP_URLmust behttps://with no path for app sign-in.web/.env.examplematches.docs/faq.mdx: disconnecting connected apps works on a read-only workspace.docs/guides/mentions.mdx: theoverride_mention_sentimentrow.Tests
helpers.test.ts):false,FALSE," false\n",0,offorno;true,1or an empty value.oauth.test.ts,authorize,connections,consent,cimd,mcp-auth.oauthandapi/mcp/route. The kill-switch tests setfalse.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.tsand the content-opportunity status route test pin the new refusal text.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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsWhat ops sets (Vercel, production and preview)
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, setMCP_OAUTH_ENABLED=falseand redeploy. API keys keep working.OPENAI_APPS_CHALLENGE=<token>once OpenAI's portal gives the domain verification token. Then redeploy and check thathttps://app.ansvisor.com/.well-known/openai-apps-challengeshows it.needs-migration), then runsupabase/check-drift.sh.160.79.104.0/21) or OpenAI on/.well-known/*,/api/oauth/*and/api/mcp;/api/oauth/registerand/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:
/.well-known/openai-apps-challenge;issin every authorization response, and lets dynamic registration and Client ID Metadata Documents registerhttps://chatgpt.com/…redirects;How to test
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.NEXT_PUBLIC_APP_URL=http://localhost:3000and noMCP_OAUTH_ENABLED:curl -i localhost:3000/.well-known/oauth-authorization-serveranswers 200 with the metadata;curl -i -X POST localhost:3000/api/mcpanswers 401 withWWW-Authenticate: Bearer … resource_metadata=….MCP_OAUTH_ENABLED=false, both answer as before: 404, and a 401 without the challenge. Settings › MCP & API Keys shows no Connected apps.OPENAI_APPS_CHALLENGE=abc123:curl -i localhost:3000/.well-known/openai-apps-challengeanswers200,text/plain; charset=utf-8,no-store, with bodyabc123and no redirect to/en/….NEXT_PUBLIC_APP_URLis its ownhttps://address, with no path.<that address>/api/mcpin Claude as a custom connector with no key. Claude opens Ansvisor's sign-in and the consent page.list_brandsworks, and the app is listed under Connected apps.NEXT_PUBLIC_APP_URLis another host, the resource doesn't match the address you typed, so Claude can't connect.--scope user.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors, 12 warnings, all in files this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)help/(or no user-visible change) — see help/README.md:help/settings/mcp-server.md(approved,approved-articles.jsonregenerated); what's-new entry added withapproved: falseAlso checked:
yarn buildpasses with CI's placeholder env, and/api/well-known/openai-apps-challengeis in the route list.main: 93 files, 942 tests passed. They coveredsrc/lib/help,src/lib/mcp-oauth,src/app/api/oauth,src/app/api/mcp,src/app/api/well-known,src/lib/mcp, bothmcp-authtests,api-keys-section,connected-apps,src/lib/chat/whats-newandsrc/lib/chat/skills.yarn test, before the merge of fix(mcp): name only the engines Ansvisor tracks in the server instructions #2287/fix(web): show the Ansvisor clover as the favicon, on light and dark tabs #2288: 1,085 files, 11,965 tests passed, 1 skipped.Generated by Claude Code