Skip to content

feat(mcp): run a Site Audit via MCP (run_site_audit + get_site_audit), quota-charged #269

Closed

Description

@gkhngyk

What

Expose Site Audit through the MCP server so an AI assistant (Claude Desktop / Code / Cursor) can audit a page and read the result — charging the same monthly Site Audit quota as the dashboard.

Two tools:

  • run_site_audit (write/trigger) — inputs brand_id + url. Starts an audit and returns the new audit's id + status: "running" (the audit runs async, ~30s). Charges the monthly quota.
  • get_site_audit (read) — input audit_id. Returns the full result (total score, category scores, signals, AI recommendations) once status is completed (or failed). The assistant polls this after run_site_audit.

Why

The audit + AI fix recommendations are the most actionable output of the product; letting an agent trigger and read them (then act on the drafted fixes) is a natural extension of the existing MCP toolkit.

Approach (mirror the existing generate_content_brief pattern)

  • Auth / ownership: MCP requests authenticate via ans_ API key → org (see web/src/lib/mcp-auth.ts). Verify the caller's org owns brand_id in the web data layer before any outbound call (return null → 404 on mismatch, so probing ids costs nothing) — same guard as listContentOpportunitiesFor.
  • Trigger path: add a data fn runSiteAuditFor(auth, brandId, url) in web/src/lib/mcp/data.ts that, after the ownership check, calls a new internal server endpoint (POST /api/internal/site-audits, CRON_SECRET-auth) — exactly how generateBriefFor calls /api/internal/content/:id/brief. The internal endpoint reuses the existing audit pipeline in server/src/routes/audits.js (create running row → runAuditJob → quota charged on completion).
  • Quota: the internal endpoint enforces enforceSiteAuditQuota(orgId) (already in server/src/lib/plan-guard.js). On exhaustion it returns 402/429; surface that message to the agent. MCP-triggered audits count against the same site_audit_usage pool, so dashboard + MCP share the limit.
  • Tools: register run_site_audit + get_site_audit in web/src/lib/mcp/server.ts (write-tool description should warn it consumes a monthly audit credit, like the generate_content_brief warning).
  • REST parity: POST /api/mcp/site-audits + GET /api/mcp/site-audits/[id] under web/src/app/api/mcp/, mirroring the data fns.

Acceptance

  • run_site_audit starts an audit for an owned brand + URL and returns its id; a foreign/unknown brand returns not-found with no audit created
  • get_site_audit returns the running→completed result with score, categories, signals, and recommendations
  • A run charges the monthly quota; when the quota is exhausted the tool returns the upgrade/limit message (no audit created)
  • REST endpoints under /api/mcp/site-audits behave identically
  • Tool descriptions make the credit cost + async (poll get_site_audit) behavior explicit

Activity

  1. added
    enhancement
    on Jun 17, 2026
  2. gkhngyk commented on Jun 26, 2026

    @gkhngyk
    ContributorAuthor

    Picking this up — implementing the two MCP tools (run_site_audit + get_site_audit) mirroring the generate_content_brief pattern, sharing the existing site_audit_usage quota pool. PR to follow.

  3. added a commit that references this issue on Jun 26, 2026
    7b31088
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions