Skip to content

fix(mcp): gate the shopping reads on the plan's shopping analytics - #1764

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:fix/mcp-shopping-plan-gate
Oct 29, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:fix/mcp-shopping-plan-gate

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The Product Visibility page is for plans with shopping_analytics (Growth and up). It checks that only in the browser. The MCP tools list_shopping_cards and get_product_visibility, and /api/v1/shopping-cards, didn't check it at all.

Both data functions now read the organization's plan (ORG_PLAN_COLUMNS + hasFeature) after the brand check and answer NOT_IN_PLAN without it:

  • Starter: the MCP tool returns plan_limit, and REST answers 403.
  • A Growth plan that ended keeps reading, as the read-only dashboard does.
  • Self-hosted has no gate.

Docs: mcp-server.mdx and api-reference/metrics.mdx say "Growth and up".

Related issue

None.

Stacked on #1762 (MCP keys carry the caller's role). This branch's test gives its key a role. The diff against it holds only this change.

Type of change

  • fix — Bug fix

How to test

cd web && yarn vitest run src/lib/mcp/shopping-plan.test.ts (6 tests): Starter is refused, Growth passes, an ended Growth plan reads, self-hosted has no gate, and REST answers 403.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: lint (0 errors, 7 warnings), typecheck, 558 test files / 5,336 tests and build pass

🤖 Generated with Claude Code

cihan-gyk and others added 3 commits October 29, 2026 14:09
…smissing

The MCP tools write with the service role, so the row rules that keep
analysts from adding prompts never reached them: an analyst's key could
accept a prompt suggestion and add a tracked prompt. The key's role now
comes with the auth context and the data layer checks it, for the tool and
its REST route alike:

- accept_prompt_suggestion, accept_topic_suggestion and
  dismiss_topic_suggestion: admins and managers only.
- dismiss_prompt_suggestion: not agency partners, as the table's rule.
- update_opportunity_status: any member records progress; dismissing, or
  moving a dismissed one back, needs an admin or a manager.

Drafts, briefs, Site Audits, tasks and Improve actions stay open to every
member. A refused tool answers with the reason; the REST routes answer 403
role_required. The MCP guide names the role each write needs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Shopping page is locked on Starter, but only in the browser: over an
API key, list_shopping_cards, get_product_visibility and their REST routes
(/api/v1/shopping-cards included) read the cards on any plan. They now
check shopping_analytics on the organization's plan after the brand check
and answer plan_limit without reading a card: a tool error with the reason,
and 403 on the REST routes, as the API's requireFeature answers.

A plan that has ended keeps reading what it had, as the read-only dashboard
does; self-hosted has no gate. The MCP guide and the metrics reference say
the endpoints need Growth or above.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 29, 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 fe34672.

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.

Looks good, with follow-ups

Reviewed 7a4a30e. It is stacked on #1762 (9e11860), from ce9a3dc, and I reviewed its own diff (9e11860..7a4a30e). Web and docs, no migration.

What I checked

  • The gate. listShoppingCards and getProductVisibility check the brand first, then the plan:
    • planIncludes reads ORG_PLAN_COLUMNS and checks hasFeature(usagePlanFromOrgRow(…).plan, 'shopping_analytics').
    • A Growth plan that has ended keeps reading, as the API's requireFeature(…, { readOnly: true }) and the dashboard do.
    • Self-hosted skips the read.
    • Another organization's brand still answers "not found" before any plan read.
  • Every surface. The gate is in the data functions, so it covers:
    • the tools list_shopping_cards and get_product_visibility;
    • /api/mcp/shopping-cards, plus /api/v1/shopping-cards, which re-exports it;
    • /api/mcp/product-visibility, which has no /v1 path.
  • Refusal body. { error: 'plan_limit', message } with 403 is what the API's requireFeature answers. The plan name comes from getMinimumPlanForFeature, so it follows plans.ts. The tools return the same JSON as an error result.
  • Embeds. None added. planIncludes reads organizations directly.
  • The tests catch it. I put #1762's data.ts, server.ts and both routes back under the PR's shopping-plan.test.ts. Both Starter cases fail: the tool answers, and REST says 200. With the PR, the 6 tests pass. The lib/mcp, api/mcp, api/v1 and lib/agent tests and subscription-guard-coverage.test.ts pass at this head: 31 files, 194 tests. Web tsc is clean, and so is Prettier on the touched files.
  • Docs. mcp-server.mdx and api-reference/metrics.mdx say Growth and up and give the 403 body.
  • It merges cleanly on ce9a3dc and alongside #1763 and #1733.

Follow-ups

  1. #1733 adds its own plan check for Product Visibility (PLAN_LOCKED, the same hasFeature(usagePlanFromOrgRow(…)) read). Whichever lands second could reuse the other's helper and refusal text, so the shopping tools answer the same way.
  2. Merge after #1762, since this branch contains it.

@gkhngyk
gkhngyk merged commit ca64e05 into ansvisor:main Oct 29, 2026
5 of 6 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.

2 participants