Repository navigation
Description
What
Let the in-product AI assistant (/dashboard/agent) run and read Site Audits in chat — e.g. "audit my homepage" → it triggers an audit, then summarizes the score, weak categories, and the top AI-written fixes.
Why
The Agent is already "grounded in the MCP read tools"; Site Audit + its AI fix recommendations are the most actionable surface to expose there. A user shouldn't have to leave the chat to audit a page.
Approach
The Agent keeps its own tool registry in web/src/lib/agent/tools.ts (buildAgentTools(auth)) that wraps the shared data functions in web/src/lib/mcp/data.ts, with names matching the MCP tool ids. So:
- Depends on feat(mcp): run a Site Audit via MCP (run_site_audit + get_site_audit), quota-charged #269 / feat(mcp): list_site_audits + get_site_audit_quota read tools #270 — those add the in-process audit data functions (
runSiteAuditFor,getSiteAuditFor,listSiteAuditsFor) scoped byMcpAuthContext. The agent tools should reuse those, the same wayget_visibility_summaryreusesgetVisibilitySummaryFor. (The currentweb/src/lib/actions/audits.tsactions auth with the user token, which doesn't fit the agent'sMcpAuthContextpath — landing the data layer in feat(mcp): run a Site Audit via MCP (run_site_audit + get_site_audit), quota-charged #269 resolves this once.) - Add tool entries to
buildAgentTools:get_site_audit+list_site_audits(reads) andrun_site_audit(trigger — consumes a monthly audit credit). - Update
web/src/lib/agent/system-prompt.ts: add the new tools to the "Tools available" list and a rule thatrun_site_auditis a write that costs a credit — only fire on explicit user intent (mirror theupdate_opportunity_status/generate_content_briefguidance). The chat loop already multi-steps (stepCountIs(20)), so trigger→pollget_site_audit→summarize works in one turn.
Quota is enforced server-side (shared pool with the dashboard), so a credit-exhausted run surfaces the limit message to the user.
Acceptance
- Asking the assistant to audit a URL triggers an audit for the active/owned brand and reports the result (score, weak categories, top fixes)
-
run_site_auditonly fires on explicit user intent; the assistant doesn't audit unprompted - A credit-exhausted run is reported to the user as the limit/upgrade message
- Reads (
get_site_audit,list_site_audits) work without consuming credits
Pairs with #270; inline rendering of the result is tracked separately.
Activity
feat(agent): use Site Audit from the in-product assistant (#307)