Skip to content

fix(mcp): keep briefs and Improve actions to admins and managers - #1770

Merged
gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:fix/mcp-costly-managers
Oct 29, 2026
Merged

gkhngyk merged 5 commits into
ansvisor:mainfrom
cihan-gyk:fix/mcp-costly-managers

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The MCP tools that generate at a cost now check the key owner's role first, as the web app does after #1763's follow-up.

  • generate_content_brief and create_improve_action call requireManager before reading anything.
  • Their REST twins, POST /api/mcp/content-opportunities/:id/brief and /api/mcp/prompts/:id/improve-action, answer 403 role_required.
  • docs/guides/mcp-server.mdx: both are marked "(admin, manager)", and the Roles section is updated.

Related issue

None.

Stacked on #1764 (MCP shopping plan gate, itself on #1762, the MCP role gate). 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/role-gate.test.ts 'src/app/api/mcp/content-opportunities/[id]/brief/route.test.ts'

  • Analysts and agency partners are refused, with nothing read or fetched.
  • Managers pass.

Checklist

🤖 Generated with Claude Code

cihan-gyk and others added 4 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]>
Generating with AI is for admins and managers (2026-10-29), as in the
dashboard. generate_content_brief and create_improve_action now check the
key's role before anything is read or generated, and so do their REST
mirrors (POST /api/mcp/content-opportunities/:id/brief and
/api/mcp/prompts/:id/improve-action, 403 role_required). The MCP guide
marks both as admin and manager writes and lists AI work among what the
roles keep.

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

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 d23ef1dd: rebased onto main (docs conflict only)

Reviewed this PR's own change (#1764's head 7a4a30e → 1273892), read on main 3b7611c.

What I changed (branch take-1770, built on main 3b7611c: this PR's commit cherry-picked onto it)

  • The base. As it stands, the branch doesn't merge with main. Its old copies of #1762 and #1764 conflict with main in docs/guides/mcp-server.mdx, web/src/lib/mcp/data.ts and role-gate.test.ts.
  • The docs conflict. The PR's own commit conflicts only in docs/guides/mcp-server.mdx, against #1713's task review tools. I kept both:
    • The create_improve_action row is now marked "(admin, manager)", below the three task review rows.
    • The Roles paragraph lists reviewing tasks, dismissing, and work that costs AI (briefs and Improve actions) as admin/manager work.
  • No code changes.

What I checked

  • Order of checks. generateBriefFor and createImproveActionFor call requireManager before the ownership read, the subscription check and the internal call.
    • The role is the key's own, so checking it first reveals nothing about another organization's ids.
    • A refused call never reaches the LLM.
  • The REST twins. POST /api/mcp/content-opportunities/:id/brief and /api/mcp/prompts/:id/improve-action already pass errors through failedCallResponse, which answers RoleRequiredError with 403 role_required.
  • The internal routes. The internal brief route on the API has no user, so this check is the brief's only role gate over a key. The internal Improve route also checks the role on the API once #1769 is in.
  • Tool descriptions and docs say "Needs an admin or a manager" and match the behaviour.
  • Each gate is tested. Removing either requireManager makes the role-gate tests fail, for analysts and for agency partners. The new brief route test checks the 403 mapping, which was already on main.
  • Embeds: none added. The two existing !inner reads are unchanged.
  • Read-only workspace. No new write route. subscription-guard-coverage.test.ts passes.
  • Tests (on main with this PR and #1769). Web tsc is clean. lib/mcp, api/mcp, lib/agent and the touched component tests pass: 61 files, 408 tests. The full web suite gives 598 of 600 files; the two timing tests that failed under load (shopping categories, Library paging) pass when re-run.

Follow-up (not blocking)

  1. web/src/lib/mcp/role-gate.ts's header comment still lists briefs as day-to-day work open to every member. Worth one line in a later change.

Before merging

  • Merge take-1770, not this branch: this branch conflicts with main.
  • It is independent of #1769: the two merge together cleanly, in either order.

@gkhngyk
gkhngyk merged commit 7e0765f 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