Repository navigation
feat(mcp): keep MCP writes to Growth and above, reads on every plan - #1850
Conversation
The owner's decision of 2026-10-30 (CHAT-22 feature 3 item 13, DECISIONS
S): MCP reads (list_/get_ tools) work on every plan, the free trial
included; writing, running and spending need Growth or above, paid, and
the MCP server enforces it, not only the plan card.
- gateWriteTools refuses a write tool on Starter and in a free trial with a
tool error carrying plan_required, required_plan growth and a short
reason. The order: the demo brand first, then a plan that isn't active
(subscription_inactive), then the plan. Plan and subscription come from
one read per server (mcpWriteAccess, the plan card's planGateLock).
- The tools stay listed, so the host model can tell the person why.
- The /api/mcp REST routes answer a write on such a plan with 402 and the
same body (authenticateMcpRequest).
- Plan card: MCP reads in the trial ("MCP read"), locked for writes at
Growth; after the trial, paying for Growth adds MCP writes.
- Settings > API Keys says so on the cloud; help and the MCP guide explain
the rule and the refusal.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
gkhngyk
left a comment
There was a problem hiding this comment.
PR #1850 — feat(mcp): keep MCP writes to Growth and above, reads on every plan
Verdict: approve. No blocking issues. One optional test commit is offered below.
Head b112e325090540dd03a9ef7aedf9573ad3ef1ddf sits directly on the current main (a8121a6c8), so it merges clean.
What I checked
- Every write tool is gated. All 65 tools are registered in
lib/mcp/server.tsthroughserver.registerTool, aftergateWriteToolswraps the server. Registering a tool any other way throws (an existing test covers this). There are 48list_/get_reads and 17 gated tools.server.test.tsalready checks that each tool'sreadOnlyHintmatches thelist_/get_rule, so a write tool can't slip in under a read name without failing CI. - The plan is read when each call is made.
mcpWriteAccessreadsplan, subscription_status, plan_overridesfrom the organization row. It reads once per server, which means once per request, and only when a gated tool is called. API keys carry no plan, so a key made on any plan follows the workspace's current plan. - Order of refusals. First the demo brand, then
subscription_inactive, thenplan_required. A canceled Starter workspace still getssubscription_inactive, as before. A plan that can't be read still refuses the call. - Trials. The Growth trial gets reads only. The Enterprise trial writes, because
isTrialis false for Enterprise, matching the AI budget. Paid Growth and Enterprise write. Self-hosted, and a key with no organization, are never gated. - REST. Every POST, PUT, PATCH or DELETE under
/api/mcp/*answers 402subscription_inactiveor 402plan_required. I listed all 15 write handlers that useauthenticateMcpRequest, and each one is a real write, so no read gets refused by mistake. GET routes are untouched./api/mcpitself keepsgateWrites: false./api/v1/*has only GET handlers. - One rule for the server and the card. The server and the plan card both use
planFactsFromOrgRow+planGateLock({ minPlan: 'growth' }). Starter already hasapi_accessinconfig/plans.ts, so "reads on every plan" agrees with the config. - Error for the client. It's a tool error whose JSON gives
error,code,required_planand a message that names Settings › Billing. Write tools stay listed, so the assistant can explain the refusal. - Docs and help. The new sections in
docs/guides/mcp-server.mdxandhelp/settings/mcp-server.mdmatch the code and the exact body. The API Keys note shows on the cloud only.
Notes (non-blocking)
- REST uses 402 for
plan_required. Feature-levelplan_limitrefusals elsewhere (shopping) use 403. Both count as plans inapi-failure.ts, and the docs state 402, so this is just worth knowing. - The new docs section says "every plan reads". A few reads are still feature-gated on Starter (the shopping tools answer
plan_limit), as explained further up the same page. You could add "(the Growth-only reads above aside)". - As you noted, a follow-up should add
plan_requiredto theansvisor-aeo-coachskills.
Optional test
Offered as one commit: a walk over every registered tool on Starter (active) and in the Growth trial. It checks that each tool's read-only hint matches the gate's rule, and that every gated tool answers plan_required with required_plan: growth before it runs. It fails if the plan branch is removed from the gate.
Merge with other open PRs
- #1851 conflicts in
web/src/lib/chat/access.ts, as the description says. #1857 inherits the same conflict through #1851. - #1805, #1807, #1808, #1818, #1800 and the other Chat PRs that touch
en.jsonmerge clean against this one. - #1805 renames the section to "MCP & API Keys". The new text in this PR doesn't use the old name, so nothing goes stale.
Tests run
On the PR head, which is the same tree as merged with main:
src/lib/mcp,mcp-auth.test.ts,src/lib/chat,src/components/settings,src/components/chat-access,src/lib/guards(includingplan-row.test.ts) andsubscription-guard-coverage.test.tsall pass.tsc --noEmitis clean. eslint and prettier are clean on the touched files.
gkhngyk
left a comment
There was a problem hiding this comment.
Merging in order with the other approved PRs. This head merges current main; its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build.
Summary
Product owner's decision, 2026-10-30 (CHAT-22 feature 3 item 13, DECISIONS S): MCP and the API read on every plan, the free trial included; writing, running and spending through them need Growth or above, paid. Until now, the plan card showed the rule but nothing enforced it, so a Starter key could write. The trial was also shown as having no MCP at all.
Server
lib/mcp/subscription-gate.ts:mcpWriteAccess(orgId)returnsok,inactiveorplan. It reads the plan, subscription and contract overrides once (ORG_PLAN_COLUMNS).planFactsFromOrgRow+planGateLock({ minPlan: 'growth' })), so the server and the card can't disagree. Allowed: Enterprise (trial included) and Growth paid. Refused: the Growth trial and Starter.ok.gateWriteToolschecks in this order, reading the plan at most once per server:subscription_inactive;plan_required.{ error: 'plan_limit', code: 'plan_required', required_plan: 'growth', message }.lib/mcp-auth.ts): every POST, PUT, PATCH or DELETE on/api/mcp/*gets the same check. The answer is 402subscription_inactiveor 402plan_required.gateWrites: falseand gates its tools instead.assertSubscriptionActive) are unchanged.Web
planCardOf):readin the trial and on Starter, locked to Growth for writes;read_writefrom Growth, paid.mcpbenefit is removed.help/settings/mcp-server.mdgets "What your plan includes".docs/guides/mcp-server.mdxgets "Reading and writing per plan", with theplan_requiredbody.Heads-up: Starter workspaces that write through MCP today will get
plan_requiredafter this ships.Follow-up, not in this PR: a docs PR for
skills/ansvisor-aeo-coach*/SKILL.md, which mentionsubscription_inactivebut notplan_requiredyet.Merge note: this PR and #1851 touch neighbouring lines of
planCardOf's chips inlib/chat/access.ts. Whichever merges second needs a small conflict fix; I'll merge main forward myself.Related issue
None. Product owner's decision.
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 testsHow to test
NEXT_PUBLIC_IS_CLOUD=true, put the workspace on Starter and create an API key.list_/get_tool works;create_improve_action) answers theplan_requiredtool error;/api/mcp/*write route answers 402plan_required.subscription_status = trialing): the same as Starter.subscription_inactivecomes first.lib/mcp/subscription-gate.test.ts,lib/mcp-auth.test.ts,lib/mcp/demo-gate.test.ts,lib/chat/access.test.ts,api-keys-section.test.tsx.Checked in the browser:
Full web suite: 656 files / 6,474 tests passed.
Checklist
yarn lintpasses (0 errors; 7 old warnings in files this PR doesn't touch)yarn typecheckpassesyarn format:checkpasses🤖 Generated with Claude Code