TL;DR:
- Manual citation tracking is unreliable: LLMs return different results with every query due to sampling variation, making spreadsheet-based audits an indefensible baseline.
- Claude Code and public MCP servers make programmatic querying possible: Query ChatGPT, Claude, Perplexity, and Gemini in batches from a single CLI workflow, without building custom integrations.
- Citation rate, mention rate, and AI share of voice calculate automatically: Your monthly output feeds directly into a CSV that maps to HubSpot or Salesforce custom properties via API.
- This guide covers the full stack: System architecture, Claude Code prompts, CRM integration steps, and how to present AI visibility data in board reporting.
B2B buyers are increasingly using AI assistants to evaluate vendors before visiting websites. If your brand is absent from those answers, you may be missing opportunities the sales team never sees, and a spreadsheet of manual screenshots is not a defensible answer to the CEO who keeps forwarding ChatGPT results showing your competitors. This guide shows you how to build a repeatable Claude Code for AEO workflows using Claude Code and public MCP servers so you can measure AI visibility programmatically instead of manually.
The hidden cost of manual auditing
Most marketing teams start the same way: a junior marketer opens ChatGPT, types in ten queries, screenshots the results, and pastes them into a spreadsheet. The result is data you cannot trust and hours of work that tells you almost nothing.
The problem is method, not effort. As our AI tracking platform analysis documented, LLM outputs vary with every call due to sampling temperature and nucleus sampling (top-p). One query run from a marketer's desktop in New York does not represent what a buyer in London sees. You need programmatic, multi-session averaging to build a defensible baseline.
Commercial tools address some of this, but they vary significantly in scope and cost:
Tool | Key features | Pricing |
|---|
Discovered Labs tracker | Programmatic citation audits, CRM pipeline integration | Custom, part of retainer |
Amplitude AI visibility | User path analysis, LLM mention tracking | Free for all Amplitude customers |
SE Ranking | Keyword tracking, AI Overview monitoring | See website for current pricing |
Averi.ai | Share of voice tracking, competitor alerts | See website for current pricing |
Siftly.ai | Real-time alerts, sentiment analysis | See website for current pricing |
For teams wanting a custom, low-cost alternative, the Claude Code and MCP path delivers programmatic accuracy without managed-service overhead.
Why AI output timelines vary
AI assistants that use retrieval-augmented generation (RAG) systems often prioritize fresher content. A page published recently with a visible timestamp may outperform older content when both are semantically relevant to the query. A static, one-time audit decays in value fast. Your citation rate may shift if competitors publish new optimized content or if you let your own pages age without updates. This makes baseline measurement now a key starting position for the next round of optimization.
System architecture: CLI to MCP to LLM endpoints
The next three steps cover the technical build. If you are a marketing leader rather than a developer, the decisions that belong to you are: which queries to track (Step 1), which metrics go into board reporting (Step 4), and how AI-sourced pipeline surfaces in your CRM (Step 5). Steps 2 and 3 are written for the technical specialist or agency engineer building and maintaining the workflow.
Mapping the Claude Code data flow
Claude Code can orchestrate this workflow by reading a local query file, connecting to an MCP server, and making structured API calls to each LLM endpoint. The measurement challenges vary across different aspects of AI visibility including web search and citations.
[Claude Code CLI] ---> [MCP Server] ---> [LLM APIs]
|---> OpenAI (ChatGPT)
|---> Anthropic (Claude)
|---> Perplexity
|---> Google (Gemini)
Claude Code communicates with MCP servers via JSON-RPC (a lightweight protocol that exchanges structured commands and responses). The current MCP specification supports stdio and Streamable HTTP transport layers. When you invoke a tool in natural language, Claude Code formats the call, executes it, and returns structured results you can parse or pipe directly into a CSV.
Connecting Claude Code to MCP servers
Model Context Protocol (MCP) is an open standard that lets Claude Code securely connect to external tools, databases, and APIs without custom integration code. For citation tracking, you can use servers like Brave Search MCP for live web access and source verification, and the filesystem server to read your local query list stored as a JSON file.
npxnpm install @modelcontextprotocol/server-brave-searchclaude mcp.search
Then register it with Claude Code:
claude mcp add
MCP servers typically install as npm or Python packages, making setup relatively straightforward.
Step 1: Identify high-value buyer intent queries
Focus on commercial and transactional queries rather than informational head terms. A query like "best incident management platform for Site Reliability Engineering (SRE) teams" maps directly to a buying conversation. A query like "what is incident management" does not, even if it pulls more volume. Our competitor content gap analysis guide covers how to extract these queries from Ahrefs and Google Search Console using Claude Code.
Build a JSON file of priority queries grouped by pipeline stage:
{
"consideration": [
"best incident management software for enterprise",
"PagerDuty alternatives for SRE teams"
],
"evaluation": [
"incident.io vs PagerDuty comparison",
"incident management platform pricing 2026"
]
}
Prioritize by deal value, not search volume. The queries tied to active buying decisions are typically the ones that matter most for tracking.
The prompt patterns below are written for the developer running the workflow. Marketing leaders can skip to Step 4 to see the metric definitions and what the output CSV will contain.
Two core prompt patterns for Claude Code
1. Pure CLI invocation (headless mode)
claude -p "Read queries.json. For each query, call the LLM API endpoints via MCP to retrieve responses from each platform. Parse each result for brand mentions and citation links. Write output to citations_$(date +%Y-%m).csv." --output-format json
2. Multi-step interactive task
In a Claude Code session, provide the following prompt:
Step 1: Read queries.json and confirm the query count.
Step 2: Query OpenAI, Anthropic, Perplexity, and Gemini for each query using the MCP server endpoints.
Step 3: For each response, extract brand mentions, citation URLs, and competitor mentions.
Step 4: Calculate citation rate (cited / total queries), mention rate (mentioned / total queries), and AI share of voice per brand.
Step 5: Write a summary table to report.md and commit to a Git repository.
Consider using --output-format json on headless runs to get structured output. The output can include token cost and turn count, which helps monitor API spend over time. A typical 100-query monthly audit across multiple platforms will incur API costs from each provider, with per-token charges varying by model.
Managing API limits and data errors
Build basic error handling into your Claude Code script to catch HTTP 429 rate-limit responses and retry after a configurable delay. Consider structuring your query list in smaller batches rather than running the full set in one call. Different platforms also return citations in different formats: Perplexity includes source links in the majority of its responses, while ChatGPT's citation rate is significantly lower, and some platforms use text-only mentions alongside linked citations. Your parser will need to handle multiple citation formats including numbered reference notation, inline URLs, and markdown hyperlinks.
Step 3: Audit citation frequency across LLMs
Once your query file and MCP configuration are ready, trigger the monthly audit with the CLI command from Step 2. To automate the cadence, you could schedule it as a cron job or use a GitHub Actions workflow with a schedule trigger set to run on the first of each month.
Step 4: Calculate citation rate and mention rate
These metrics belong in your board reporting stack, and each measures something distinct:
- Citation rate: The percentage of queries where your website is explicitly linked. If 100 queries return 28 responses with a link to your domain, your citation rate is 28%.
- Mention rate: The percentage of queries where your brand is named but not linked. Our Reddit and ChatGPT research, covering 144,000 AI citations, shows mention tracking is essential for comprehensive visibility measurement.
- AI share of voice: Your brand's citation count divided by total brand citations across all competitors for the same query set.
- AI-referred pipeline: Revenue directly attributed to sessions that arrived via an AI platform referral URL, tracked with UTM parameters and confirmed in HubSpot or Salesforce. In our client work, unoptimized B2B SaaS brands typically come in below 10% citation rate on their core buyer queries. Brands using content built to the CITABLE framework for passage retrieval have reached 40% or above within three to four months across our book of work. The framework's block structure (200 to 400-word sections with answer-first openings) is designed to improve how well sections function as standalone retrievable passages for RAG systems that use semantic embeddings and similarity matching to select content.
Step 5: Operationalize and integrate with CRM
The CRM configuration below is for your technical or RevOps specialist. Hand them the CSV schema from Step 4 and the UTM conventions you already use for paid campaigns.
Pipe your monthly CSV output into HubSpot using the CRM /crm/v3/importsAPI, mapping your citation columns to custom contact or company properties. For Salesforce, the native HubSpot connector supports bidirectional sync, so any AI-referred MQL tagged with a UTM source of chatgpt or perplexity can flow into your Salesforce pipeline automatically. Check HubSpot's current connector documentation for the plan tier that includes bidirectional sync, as availability may have changed.
Add a "how did you hear about us" field to your demo request form. It captures attribution that no UTM tag reaches: the buyer who started research in Claude and ended up booking a call after a Google search. Your board reporting can then include AI-referred sessions (GA4), AI-sourced MQLs (HubSpot), and AI-attributed pipeline (Salesforce), with honest caveats about cross-platform discrepancy noted inline.
Without a programmatic tracking system, it is difficult to prove that optimization work is moving citation rates. Tom Wentworth, CMO at incident.io, described the starting point before systematic tracking was in place:
"Before Discovered Labs, we were using homegrown LLM prompts, without a clear strategy for what to optimize for or exactly how best to structure content." - Tom Wentworth, CMO at incident.io, incident.io case study
After moving to a structured, programmatic approach, incident.io's AI visibility climbed from 38% to 64% and organic meetings booked grew 22%. An anonymous B2B SaaS client using the same infrastructure went from 550 to over 3,500 AI-referred trials in seven weeks.
Building this workflow in-house is achievable for a technically capable team. For most B2B SaaS marketing leaders, the gap is not the tooling but knowing which queries to track, what citation rates to target, and how to structure content to move those numbers month over month. A dedicated agency typically delivers faster time to first citation data. Our AEO agency vs in-house cost breakdown covers the true first-year cost comparison if you are modeling the build-vs-buy decision for your CFO.
If you want to see how this infrastructure applies to your query set, our AI visibility tracker runs across 100,000+ clicks per month and feeds directly into client reporting. The AEO content evaluator is a free self-serve diagnostic tool.
Discovered Labs is an organic search agency for B2B SaaS. We work across web search, AI citations, and training data, with a full-time AI/ML engineering team building the proprietary tooling that powers our audits. Pricing is public and retainers are month-to-month. Book a call and we will tell you honestly whether we are a fit.
FAQs
What is the difference between a brand mention and an AI citation?
A mention is a text reference to your brand in an LLM response. A citation is a reference that an LLM includes alongside its generated response, linking or attributing the answer to a specific source. This can be a clickable link back to your website, a footnote, source pin, or inline reference. The gap between text-only mentions and linked citations varies significantly by platform: Perplexity includes source links in the majority of its responses, while some platforms use text-only mentions with no outbound links, making mention tracking essential alongside citation tracking.
How often should we run citation audits?
Monthly audits are common for B2B SaaS brands actively optimizing for AI visibility, though standard comprehensive content audits in B2B SaaS typically run quarterly or biannually. The frequency should balance API token costs against how quickly you need to detect changes in citation behavior. For high-velocity campaigns, more frequent checks may be warranted.
What is a good baseline citation rate for a B2B SaaS brand?
In our client work, unoptimized brands typically come in below 10% citation rate on their core 50 buyer-intent queries. After three to four months of structured optimization using the CITABLE framework, clients have reached 40% or above. These figures reflect our book of work and won't apply uniformly across every market or query set.
Can we track competitor AI citations in the same workflow?
Yes. Add competitor domains to your parsing logic so the script flags any response that cites them. This gives you AI share of voice data: your brand's citation count divided by total brand citations across all competitors for the same query set, expressed as a percentage.
Key terms glossary
Answer Engine Optimization (AEO): The process of structuring and optimizing web content so that large language models retrieve and cite it in user answers, as distinct from ranking for traditional keyword searches.
Model Context Protocol (MCP): An open standard that enables Claude Code to securely connect to external data sources, tools, and APIs using a JSON-RPC transport layer.
Passage retrieval: The technical process where an LLM searches a database for specific, semantically relevant text blocks rather than ranking entire web pages. Dense retrieval models, as documented in Karpukhin et al., outperform traditional keyword-based retrieval by 9 to 19 points on top-20 passage selection.
Citation rate: The percentage of tracked queries in which your website URL appears as an explicit link in the LLM response.
Mention rate: The percentage of tracked queries in which your brand name appears in the LLM response, regardless of whether a link is included.
AI share of voice: Your brand's citation count divided by total brand citations across all competitors for the same tracked query set, expressed as a percentage.