All posts

How to Connect Claude or Any AI Agent to Ahrefs (Ahrefs MCP and API Guide)

By Harsh Vats, Founder, DigiVats · Published 31 October 2026 · 16 min read

If you use Ahrefs daily, you know the routine: open a report, apply filters, export a CSV, paste it somewhere, then work out what it means. An AI agent can skip most of that. Connect Claude to Ahrefs and you can ask for a competitor gap or a backlink check in plain English, with answers built on live Ahrefs data.

This guide covers Ahrefs MCP setup for Claude, Claude Code, ChatGPT and Cursor, plus the Ahrefs API for your own agents. It also covers prompts that work, how to keep API units from disappearing, and what to do when something breaks. We work from Faridabad, so examples lean towards Indian city and service searches. The method works in any market.

The short version: Ahrefs runs a hosted MCP server at https://api.ahrefs.com/mcp/mcp. Add it as a connector in Claude, sign in with Ahrefs, and start asking questions. You need a paid Ahrefs plan that includes MCP, and you should always cap rows and fields so one prompt cannot burn your monthly units.

Why connect AI to Ahrefs

An AI model on its own does not know your rankings, your backlinks or what your competitors rank for. It can guess, and the guess sounds confident. That is the weak point of most “Claude SEO” advice.

Connecting Ahrefs fixes that. The AI calls Ahrefs, reads real numbers, then does what it is good at: sorting, comparing, summarising and writing. This is what people mean by Ahrefs AI workflows: your own data, with a model doing the legwork.

  • Faster research. Ask for “keywords a competitor ranks for that we do not” and the agent runs the right reports.
  • No copy and paste. No exports, no spreadsheets.
  • Data and writing in one chat. The same conversation that finds a keyword can draft the brief.

The AI is not an SEO strategist. It can oversimplify, repeat what you already know or misread a table. Ahrefs says the same in its 15 MCP use cases: the MCP supplements manual analysis, it does not replace judgment. If you want a person to run this for you, our SEO services in Faridabad team uses these tools with a human checking every output.

What MCP is

MCP stands for Model Context Protocol. Anthropic introduced it as an open standard on 25 November 2024 in its announcement. The official site, modelcontextprotocol.io, compares it to a USB-C port for AI apps: one standard way to connect them to data sources, tools and workflows. The same connector approach works for other tools too, for example connecting Claude to Notion over MCP.

There are three parts. The host is the AI app (Claude, ChatGPT, Cursor). The client is the connector the host creates. The server exposes the tools, and here that is Ahrefs.

The Ahrefs MCP server is hosted by Ahrefs at https://api.ahrefs.com/mcp/mcp and uses streamable HTTP. You install nothing. You point your AI app at that address and sign in. An old local “ahrefs-mcp-server” repository exists on GitHub, but it is unmaintained and does not work with MCP keys, so ignore it.

The tools cover the reports you already know:

  • Site Explorer: Domain Rating, backlinks, referring domains, anchors, top pages, organic keywords, competitors, broken backlinks, history.
  • Keywords Explorer: overview, matching and related terms, suggestions, volume by country and history.
  • SERP Overview, Rank Tracker and Site Audit.
  • Brand Radar (some features may need an add-on), Google Search Console data, Web Analytics and management tools.

If your AI app caps the number of tools, add a tools parameter to the URL, such as tools=essentials. See Ahrefs’ tool categories page for group names. A wrong name makes the connection fail.

What you need first

  • A plan with MCP. Ahrefs says MCP is available on Lite and higher paid plans. Check Ahrefs’ pricing page for what your plan includes.
  • Know your limits. Each plan caps rows per request (at the time of writing 100 on Lite, 250 on Standard, 500 on Advanced) and gives a monthly pool of API units. Calls from AI apps use the same pool as direct API calls. See Account settings, then Limits and usage.
  • The right person. Workspace owners and admins manage API keys.
  • A client that supports remote MCP. Claude, ChatGPT on the web, Cursor, Copilot Studio and n8n all do.

There are two ways to sign in:

  • OAuth (recommended). You approve access on an Ahrefs screen, and Ahrefs creates a dedicated key with the MCP scope. OAuth-created keys default to 200,000 units a month at the time of writing, and admins can change that.
  • Manual MCP key. Generate one in Account Settings, then API Keys, with Generate MCP key. Manual keys have no per-key limit by default.

MCP keys and API keys are not interchangeable

An MCP key works with the MCP server. A normal API v3 key works with the public API. Mixing them up is a common cause of 401 errors.

Set up Claude.ai and the Claude desktop app

Steps from Ahrefs’ Claude Desktop/Web guide:

  1. Open Claude, go to Customize, then Connectors, and click +.
  2. Search for Ahrefs in the approved connectors list and open its card.
  3. Click Connect, choose your Ahrefs workspace and account, then click Allow.
  4. Check that Ahrefs appears in your connector list.

In a chat, enable the Ahrefs connector and make sure the tools you need are switched on. If the connector is set to ask permission, Claude pauses for approval on each query. Ahrefs notes Allow unsupervised skips these prompts. I suggest keeping them on until you trust your workflow.

MCP key alternative. If the connector card is not available, open Claude’s Settings, go to the Developer section, edit the config file and add this, as Ahrefs documents:

claude_desktop_config.json
{
  "mcpServers": {
    "Ahrefs": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://api.ahrefs.com/mcp/mcp",
        "--header",
        "Authorization:${AUTH_HEADER}"
      ],
      "env": {
        "AUTH_HEADER": "Bearer YOUR_MCP_KEY"
      }
    }
  }
}

Replace the placeholder with a key from Ahrefs, save, and restart the app. This needs Node.js. On the phone, you cannot add a custom connector. Add Ahrefs on web or desktop first and it appears in your mobile Connectors settings.

Set up Claude Code

Claude Code is Anthropic’s command-line coding agent. It can pull Ahrefs data and then edit your site files in the same session. This is the strongest Claude MCP SEO setup if you are comfortable in a terminal. Following Ahrefs’ Claude Code guide:

Terminal
claude mcp add ahrefs https://api.ahrefs.com/mcp/mcp -t http

Then start Claude Code, run /mcp, choose Ahrefs, log in, pick your workspace and click Allow. Confirm it shows as connected, then run a small test query.

Handy commands from the Claude Code MCP docs: claude mcp list, claude mcp get ahrefs, and --scope user to use the server in every project. To use an MCP key instead of OAuth:

Terminal, MCP key
claude mcp add --transport http ahrefs https://api.ahrefs.com/mcp/mcp \
  --header "Authorization: Bearer YOUR_MCP_KEY"

Claude Code does not validate the key when you add it, so check /mcp. The command can also land in your shell history, so prefer OAuth.

Set up ChatGPT

Ahrefs supports ChatGPT with a warning: its guide says MCP client access is in beta, in developer mode, for Pro and Plus accounts on the web. Menu names change often, so if your screen differs, follow the current Ahrefs ChatGPT guide and OpenAI’s custom MCP server docs. At the time of writing, Ahrefs says:

  1. Open Settings, then Apps, then Advanced settings, and turn on Developer mode.
  2. Click Create app.
  3. Enter the server URL https://api.ahrefs.com/mcp/mcp, set authentication to OAuth, and leave client ID and secret blank.
  4. Tick that you trust the app, click Create, pick your workspace and click Allow.
  5. In each new chat, enable the connector from the + menu.

Be explicit in prompts. Name the Ahrefs MCP, name the tool, say which fields to return and tell ChatGPT not to use web search. Ahrefs’ own tester found Claude more reliable for tool use. ChatGPT also asks you to confirm actions by default, and Ahrefs includes management tools that can create or change things, so read each approval.

Set up Cursor

Ahrefs does not publish a Cursor-specific guide that I could find. This setup relies on Cursor’s generic remote MCP support, described in Cursor’s MCP docs, combined with the Ahrefs endpoint. Confirm the connection with a simple query first, such as the Domain Rating of your own site, before you rely on it.

Cursor reads .cursor/mcp.json in a project or ~/.cursor/mcp.json for all projects. Remote servers use url and headers, and the ${env:NAME} form keeps the key out of the file:

mcp.json
{
  "mcpServers": {
    "ahrefs": {
      "url": "https://api.ahrefs.com/mcp/mcp",
      "headers": {
        "Authorization": "Bearer ${env:AHREFS_MCP_KEY}"
      }
    }
  }
}

Generate an MCP key in Ahrefs, set AHREFS_MCP_KEY in your shell profile, restart Cursor, and check the server status in Cursor’s Customize area. Cursor asks before running MCP tools by default. Leave that on.

Other AI agents and the Ahrefs API v3

Some agents do not speak MCP, or you want a scheduled script. Use the Ahrefs API (v3) with an API key. One rule first: Ahrefs’ terms do not permit calling the MCP endpoint from your own scripts or standalone HTTP clients. For code, use the public API. Documented clients such as n8n and Copilot Studio are fine.

From the API docs: you need an eligible paid plan, owners and admins create keys (with an expiry date and optional monthly unit cap), the key goes in the Authorization: Bearer header, and the default rate limit is 60 requests a minute. The full list of endpoints is in the OpenAPI spec.

A first call in Python reads Domain Rating. Ahrefs documents ahrefs.com as a free test target, so use it while testing. For background on the metric, see our domain rating guide.

Python
import os
import requests

key = os.environ["AHREFS_API_KEY"]  # never hard-code this

r = requests.get(
    "https://api.ahrefs.com/v3/site-explorer/domain-rating",
    headers={"Authorization": f"Bearer {key}", "Accept": "application/json"},
    params={"target": "ahrefs.com", "date": "2026-11-28"},
    timeout=30,
)
r.raise_for_status()
print(r.json())
print("Units used:", r.headers.get("x-api-units-cost-total-actual"))

The same idea in JavaScript, for Keywords Explorer. Note select and limit:

JavaScript
const params = new URLSearchParams({
  country: "in",
  keywords: "ahrefs",
  select: "keyword,volume,difficulty",
  limit: "5",
});

const res = await fetch(
  `https://api.ahrefs.com/v3/keywords-explorer/overview?${params}`,
  { headers: { Authorization: `Bearer ${process.env.AHREFS_API_KEY}` } }
);
if (!res.ok) throw new Error(`Ahrefs API error ${res.status}`);
console.log(await res.json());

Check the Keywords Explorer reference for field names before using your own keywords.

To plug this into any agent that supports function calling, wrap each call as a tool, such as get_domain_rating(domain). Make the wrapper enforce limit and select and keep a daily spend cap, so the agent cannot request thousands of rows by accident.

Claude MCP SEO prompts that work

Ahrefs advises naming the MCP in the prompt, being specific about numbers and countries, and splitting big jobs into steps. Replace the brackets with your own details.

Keyword research

Prompt
Use the Ahrefs MCP. For country India, find 30 keywords related to "[your service]" with monthly volume above 100 and keyword difficulty below 25. Return keyword, volume, difficulty and traffic potential in a table, sorted by traffic potential. Use only Ahrefs data and tell me if any field is missing.

Competitor gaps

Prompt
Use the Ahrefs MCP. Find the organic competitors of [yourdomain.com] in India and pick the top 3. List up to 40 keywords where at least one of them ranks in the top 10 and [yourdomain.com] is not in the top 100. Return keyword, volume, difficulty and the competitor URL.

Backlink audit

Prompt
Use the Ahrefs MCP. For [yourdomain.com], list the 25 most recent referring domains with Domain Rating, and the most used anchor texts. Flag anything unnatural, such as one exact-match anchor repeated many times.

Finding spam links

Prompt
Use the Ahrefs MCP. List backlinks to [yourdomain.com] from referring domains with Domain Rating below 5. Limit to 100 rows. Group by referring domain and flag the ones that look spammy, such as random foreign-language pages or link-farm style URLs. Explain each flag. Do not suggest any action yet.

Check flagged domains yourself before you disavow anything.

Tracking DR

Prompt
Use the Ahrefs MCP. Show the Domain Rating history of [yourdomain.com], [competitor1.com] and [competitor2.com] for the last 12 months, by month. Which site grew fastest, and in which months?

Follow up with “which referring domains were gained or lost in the month our DR changed most?” Our domain rating guide explains how to read the answer.

Content brief

Prompt
Use the Ahrefs MCP. I want to rank for "[keyword]" in India. Show the SERP overview, list the top 5 pages with traffic and referring domains, and note common subtopics and page types. Then write a brief: working title, headings, questions to answer, and internal links to add. Use only the data you pulled.

Local SEO for a city

Prompt
Use the Ahrefs MCP. I run a [service] business in [city]. Find India keywords containing "[service]" with "[city]" or "near me", with volume and difficulty. Show which pages from the top 3 competitors rank for them. Ahrefs volume is country level, so label city numbers as estimates.

Keyword tools are weaker for local pack and Google Business Profile work. Our digital marketing agency in Faridabad page explains how we split website SEO from local profile work, and the same approach applies in Gurgaon and Noida.

Worked example: keywords for city service pages, then draft the pages

Say you offer a service in several cities and want one landing page per city. Here is a workflow for Claude or Claude Code with Ahrefs connected.

  1. Set the scope. Write down the service, the cities and the country. Cap it, for example 10 cities and 5 keywords each.
  2. Pull cheap seed data. Ask for volume and difficulty only, one row per keyword (prompt below).
  3. Expand the winners. For the three cities with the most demand, ask for 20 matching terms each (“best”, “company”, “near me”) with volume and difficulty.
  4. Study the results. Ask for the SERP overview of each target keyword. For the top 5 results, note page type (service page, directory, blog), referring domains and traffic, and whether a newer site could compete.
  5. Plan the pages. Ask for a URL, title tag, H1 and primary keyword per city, with no two pages targeting the same keyword. You review and edit. This is where judgment matters most.
  6. Draft. Ask for a draft per approved city, with a unique intro, a short FAQ and internal links. You supply the local facts: areas served, real projects, real addresses. Do not let the AI invent local details or reviews. Claude Code can write the page files straight into your project.
  7. Review and publish. Check every claim. Thin copy-and-swap city pages are what search engines try to filter out, so each page needs something useful the others lack.
  8. Track. Add the keywords to Rank Tracker (Ahrefs says Rank Tracker endpoints do not consume units) and check again in a month.
Prompt for step 2
Use the Ahrefs MCP, Keywords Explorer, country India. For "[service] in [city]" for each of these cities: [city 1], [city 2], [city 3], return volume and keyword difficulty only, one row per keyword.

We run this process for clients across Delhi, Jaipur and Udaipur as well. If the pages need a proper site underneath, see website design in Faridabad, or mobile app development if you are building an app.

Keeping API unit costs down

The AI does not know what a query costs, so it will happily ask for thousands of rows. Per Ahrefs’ limits docs, a request costs the larger of a 50-unit base or the per-row cost times the rows. The per-row cost adds up each unique field returned, plus fields used in where and order_by. Most fields cost 1 unit, some cost 5 or 10. Cached responses cost nothing.

  • Always set a limit. Write “limit 20” or “top 50 only” in the prompt.
  • Select only the fields you need. Every extra field is charged on every row. Keywords Explorer fields like volume and difficulty cost more than basic ones.
  • Filter at the source. “Volume above 100 and difficulty below 30” is cheaper than fetching everything and filtering later.
  • Check the cost. On the API, read the x-api-units-cost-total response header. In chat, ask the agent to describe its planned call and wait for your OK.
  • Use free endpoints. Free test queries exist for Ahrefs’ own domains and keywords, and Rank Tracker, Management and Public endpoints (including free Domain Rating) do not use units.
  • Split big jobs. “Audit my whole site” can trigger dozens of calls. Run steps, and stop at the first useful result.
  • Batch where possible. With a 50-unit floor per request, many tiny requests waste units.
  • Set caps. Give each key a monthly cap, and watch Limits and usage weekly.

Troubleshooting

Auth errors (401, 403, sign-in loops)

  • Check the key type: MCP key for MCP, API key for API v3.
  • Check the key has not expired and your subscription is active.
  • With OAuth, remove the connector, add it again and choose the right workspace.
  • In Claude Code, run /mcp to see status and re-authenticate.
  • Make sure the header is exactly Authorization: Bearer YOUR_KEY with no extra quotes.
  • If you are not an admin, you may lack permission to approve or create keys.

Units running out

  • A 429 on the API usually means more than 60 requests a minute. Slow down and retry.
  • Check Limits and usage, and any per-key cap. OAuth keys have a default monthly cap that an admin can raise.
  • Review the cost tips above for prompts that asked for too many rows or fields.

Tools not showing

  • Start a new chat after adding the connector.
  • Make sure the connector is enabled for this chat, and the individual tools are on.
  • If your app limits tool count, use the tools parameter, and spell group names exactly.
  • After editing a config file, restart the app and check the JSON for missing commas.
  • In Cursor, make sure the environment variable is set in the session that launched the editor.

The AI answers without calling Ahrefs

Say “Use the Ahrefs MCP” in the prompt, and ask “which Ahrefs tools did you call, and with what parameters?” Ahrefs also reminds users that traffic numbers are estimates, so compare the first few rows with the report in Ahrefs.

Security tips

  • Least privilege. Prefer read-only work and switch off tools you do not need, especially management tools that create or delete things. Ahrefs advises giving custom servers only the permissions they need.
  • One key per tool. If one leaks, you can cut it off without breaking the rest.
  • Set expiry and caps. A leaked key with a small cap does limited damage.
  • Never paste a key into a chat. Keep keys in environment variables or a secrets manager, and use the ${env:NAME} form in config files.
  • Keep keys out of Git. Do not commit mcp.json, .mcp.json or .env files holding a real key.
  • Keep approval prompts on until you have watched the tool calls for a while.
  • Beware prompt injection. Text in a web page or document can try to steer an agent. Do not give an agent that reads untrusted content powerful write tools.
  • Revoke what you do not use. Delete old keys in Ahrefs. In Claude Code, run claude mcp logout ahrefs then claude mcp remove ahrefs. Ahrefs invalidates a user’s keys when they are removed from the workspace.
  • Rotate after any doubt. If a key may have shown up in a chat, screenshot or repository, delete it and make a new one.

Want this set up for your business, or SEO work with a person accountable for the result? Contact DigiVats. We are a small agency in Sector 49, Faridabad.

Frequently asked questions

What is the Ahrefs MCP server?

A hosted Model Context Protocol server run by Ahrefs at https://api.ahrefs.com/mcp/mcp. It lets AI apps such as Claude, ChatGPT and Cursor call Ahrefs reports and use the live results in their answers. You install nothing: connect your AI app and sign in with Ahrefs.

Which Ahrefs plans include MCP and API access?

Ahrefs says MCP is available on Lite and higher plans. API v3 needs an eligible paid plan, and other plans only get limited free test queries. Plans change, so check Ahrefs' pricing page.

How do I connect Ahrefs to Claude?

In Claude on web or desktop, open Customize, choose Connectors, click the plus button, search for Ahrefs, click Connect, pick your workspace and click Allow. In Claude Code, run claude mcp add ahrefs https://api.ahrefs.com/mcp/mcp -t http, then /mcp to sign in.

Can I use Ahrefs with ChatGPT?

Yes, with limits. Ahrefs says ChatGPT MCP access is a beta feature in developer mode for Pro and Plus accounts on the web. Add the server URL as a custom app with OAuth, enable it in each chat, and tell ChatGPT to use the Ahrefs MCP rather than web search.

What is the difference between an MCP key and an API key?

They are separate. An MCP key (from Generate MCP key, or created when you sign in with OAuth) works with the MCP server. An API v3 key works with the public API. Using the wrong one often causes 401 errors.

Does using Ahrefs through AI cost extra?

AI calls use the same monthly API units as direct API calls, so there is no separate meter, but heavy prompts can drain the pool. Each billed request costs at least 50 units. Ask for limited rows and only the fields you need.

Can Claude do SEO on its own with Ahrefs data?

It can do much of the research and first-draft work, such as keyword gaps, backlink summaries and briefs. It cannot replace judgment. Traffic figures are estimates, and the AI should not invent local facts for your pages. Review its output.

Is it safe to give an AI agent access to my Ahrefs account?

It can be if you limit the risk. Use OAuth or a dedicated key, switch off tools you do not need, set expiry and unit caps, keep keys out of chats and Git, and keep approval prompts on.