Skip to content

feat(mcp): keep MCP writes to Growth and above, reads on every plan - #1850

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/mcp-plan-gate
Oct 30, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/mcp-plan-gate

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

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:
    • New mcpWriteAccess(orgId) returns ok, inactive or plan. It reads the plan, subscription and contract overrides once (ORG_PLAN_COLUMNS).
    • It reuses the plan card's lock (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.
    • Self-hosted, and a key without an organization, are always ok.
  • gateWriteTools checks in this order, reading the plan at most once per server:
    1. the demo brand;
    2. subscription_inactive;
    3. plan_required.
  • Refusal: a tool error with { error: 'plan_limit', code: 'plan_required', required_plan: 'growth', message }.
    • Write tools stay listed, so the host model can tell the person why. This knowingly departs from CHAT-22's acceptance line "a Starter connection lists READ tools only", because a hidden tool can't explain itself.
  • REST (lib/mcp-auth.ts): every POST, PUT, PATCH or DELETE on /api/mcp/* gets the same check. The answer is 402 subscription_inactive or 402 plan_required.
    • The MCP endpoint keeps gateWrites: false and gates its tools instead.
    • In-app routes (assertSubscriptionActive) are unchanged.

Web

  • Plan card (planCardOf):
    • MCP is read in the trial and on Starter, locked to Growth for writes; read_write from Growth, paid.
    • After the trial, the card lists "make changes from Claude, ChatGPT or Cursor" for Growth. The unused mcp benefit is removed.
  • Settings › API Keys: a cloud-only note: "On Starter and in the free trial, MCP tools and the API can read. Changes need Growth."
  • Docs:
    • help/settings/mcp-server.md gets "What your plan includes".
    • docs/guides/mcp-server.mdx gets "Reading and writing per plan", with the plan_required body.

Heads-up: Starter workspaces that write through MCP today will get plan_required after this ships.

Follow-up, not in this PR: a docs PR for skills/ansvisor-aeo-coach*/SKILL.md, which mention subscription_inactive but not plan_required yet.

Merge note: this PR and #1851 touch neighbouring lines of planCardOf's chips in lib/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 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

How to test

  1. With NEXT_PUBLIC_IS_CLOUD=true, put the workspace on Starter and create an API key.
  2. From an MCP client:
    • a list_/get_ tool works;
    • a write tool (e.g. create_improve_action) answers the plan_required tool error;
    • a POST to an /api/mcp/* write route answers 402 plan_required.
  3. Repeat in a Growth trial (subscription_status = trialing): the same as Starter.
  4. On paid Growth or Enterprise, writes work.
  5. On a canceled plan, subscription_inactive comes first.
  6. Settings › API Keys shows the plan note on the cloud only. Settings › Chat › Your plan shows MCP read on Starter and in the trial, and MCP read + write on Growth.
  7. Unit tests: 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:

  • the API Keys note;
  • the plan card on Growth, Starter and the Growth trial.

Full web suite: 656 files / 6,474 tests passed.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (0 errors; 7 old warnings in files this PR doesn't touch)
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR

🤖 Generated with Claude Code

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]>
@mintlify

mintlify Bot commented Oct 30, 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 f9a4bd7.

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.

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.ts through server.registerTool, after gateWriteTools wraps the server. Registering a tool any other way throws (an existing test covers this). There are 48 list_/get_ reads and 17 gated tools. server.test.ts already checks that each tool's readOnlyHint matches the list_/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. mcpWriteAccess reads plan, subscription_status, plan_overrides from 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, then plan_required. A canceled Starter workspace still gets subscription_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 isTrial is 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 402 subscription_inactive or 402 plan_required. I listed all 15 write handlers that use authenticateMcpRequest, and each one is a real write, so no read gets refused by mistake. GET routes are untouched. /api/mcp itself keeps gateWrites: 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 has api_access in config/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_plan and 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.mdx and help/settings/mcp-server.md match 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-level plan_limit refusals elsewhere (shopping) use 403. Both count as plans in api-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_required to the ansvisor-aeo-coach skills.

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.json merge 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 (including plan-row.test.ts) and subscription-guard-coverage.test.ts all pass.
  • tsc --noEmit is clean. eslint and prettier are clean on the touched files.

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

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.

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.

2 participants