Automate AEO improvements with an autonomous audit-fix-verify loop using the REST API or MCP tools.
Overview
The agent fix loop is a pattern where an AI agent audits a website, identifies weak criteria, applies fixes, and re-audits to verify improvement. This can run autonomously or with human-in-the-loop checkpoints.
The Loop
1
Audit
2
Analyze
3
Fix
4
Re-audit
5
Compare
Repeat if score < target
Audit - Submit domain or fetch existing audit
Analyze - Get fix prompts sorted by score impact
Fix - Apply changes to your website (schema, content, config)
Re-audit - Request fresh audit after changes
Compare - Check new score vs previous, identify remaining gaps
REST API Approach
The full loop can be implemented as a script that runs end-to-end. Here is a complete TypeScript example:
agent-fix-loop.ts
const API = class="code-string">"https:class="code-commentclass="code-string">">//www.aeocontent.ai/api/v1";
const headers = {
class="code-string">"Authorization": class="code-string">`Bearer ${process.env.AEO_API_KEY}`,
class="code-string">"Content-Type": class="code-string">"application/json",
};
class=class="code-string">"code-comment">// Step 1: Get current audit with fix prompts
const audit = await fetch(
class="code-string">`${API}/audits/your-domain-com?include=fix_prompts`,
{ headers }
).then(r => r.json());
console.log(class="code-string">`Current score: ${audit.data.audit.overall_score}`);
console.log(class="code-string">`Fix prompts: ${audit.data.fix_prompts.length}`);
class=class="code-string">"code-comment">// Step 2: Review top fix prompts (sorted by impact)
for (const fix of audit.data.fix_prompts.slice(0, 3)) {
console.log(class="code-string">`[${fix.criterion}] Score: ${fix.current_score}/10`);
console.log(class="code-string">` Prompt: ${fix.prompt}`);
}
class=class="code-string">"code-comment">// Step 3: Apply fixes to your site...
class=class="code-string">"code-comment">// (implement changes based on fix prompts)
class=class="code-string">"code-comment">// Step 4: Request re-audit
const reaudit = await fetch(
class="code-string">`${API}/audits/your-domain-com/reaudit`,
{ method: class="code-string">"POST", headers }
).then(r => r.json());
class=class="code-string">"code-comment">// Step 5: Poll until complete
let status = class="code-string">"pending";
while (![class="code-string">"completed", class="code-string">"failed"].includes(status)) {
awaitnew Promise(r => setTimeout(r, 30000)); class=class="code-string">"code-comment">// 30s intervals
const check = await fetch(
class="code-string">`${API}/audits/your-domain-com/status`,
{ headers }
).then(r => r.json());
status = check.data.status;
console.log(class="code-string">`Status: ${status}`);
}
class=class="code-string">"code-comment">// Step 6: Compare scores
const newAudit = await fetch(
class="code-string">`${API}/audits/your-domain-com?include=fix_prompts`,
{ headers }
).then(r => r.json());
console.log(class="code-string">`New score: ${newAudit.data.audit.overall_score}`);
MCP Approach
With MCP tools, your AI agent can run the same loop interactively in Claude Code or Cursor. Instead of writing code, you describe what you want in natural language:
1
"Check the AEO audit for my-domain.com with fix prompts"
Fix prompts are returned as part of the audit response when you include the fix_prompts parameter. Each prompt targets a specific criterion and includes actionable instructions:
fix_prompts response
{
class="code-string">"fix_prompts": [
{
class="code-string">"criterion_id": 1,
class="code-string">"criterion": class="code-string">"llms.txt",
class="code-string">"current_score": 0,
class="code-string">"potential_impact": 10,
class="code-string">"prompt": class="code-string">"Create a /llms.txt file at the root of your domain...",
class="code-string">"webflow_prompt": class="code-string">"In Webflow, go to Site Settings > Hosting > Custom Code..."
}
],
class="code-string">"fix_summary": {
class="code-string">"total_fixable": 8,
class="code-string">"potential_score_gain": 23,
class="code-string">"top_3_impact": [class="code-string">"llms.txt", class="code-string">"Schema.org Markup", class="code-string">"FAQ Section"]
}
}
Fix prompts include both general instructions and Webflow-specific instructions when applicable. The prompts are sorted by potential_impact so you fix the highest-value items first.
Best Practices
Start with the top 3 highest-impact fixes
Wait for re-audit to complete before making more changes (avoid stacking)
Set a target score (e.g., 80) and loop until reached
Use version comparison to track progress over time
Combine with visibility reports for a complete picture
Re-audits are rate-limited. You can request one re-audit at a time per domain. Wait for the current audit to complete before requesting another.