Skip to main content
Glama
Ahrefs MCP Server

Ahrefs MCP Server

Official
by ahrefs
WARNING

This repository is no longer maintained! We have released aremote Ahrefs MCP server, which doesn't require local setup and works directly in popular AI tools. Learn more here: Remote MCP server documentation

This repository is for the local Ahrefs MCP server which works with API v3 keys only. It DOES NOT work with MCP keys. It IS NOT maintained. It is OUTDATED. And we do not recommend using it.

Ahrefs MCP

A Model Context Protocol server to connect Claude desktop and other compatible AI assistants to Ahrefs.

Installation

npm commands need to be executed in a terminal:

  • macOS: open the Terminal from your Applications folder

  • Windows: press Windows + R, type cmd, and press Enter

Install Node.js and npm

  1. Download Node.js from nodejs.org

  2. Follow the installation instructions for your operating system

  3. Verify installation by running:

npm -v
  1. A version number will be printed if installation was successful

Windows Users

  • When installing Node.js, use the official installer and make sure the folder is added to PATH when selecting installation options.

Install Ahrefs MCP Server

npm install --prefix=~/.global-node-modules @ahrefs/mcp -g

Upgrading versions

If you've installed our MCP server before, and just want to upgrade, run this command:

npm install --prefix=~/.global-node-modules @ahrefs/mcp@latest -g

Related MCP server: MCP Deep Web Research Server

Configuration

You can now add the Ahrefs MCP to your favourite AI assistant app by adding the ahrefs part to your app's configuration file:

{
    "mcpServers": {
        "ahrefs": {
            "command": "npx",
            "args": [
                "--prefix=~/.global-node-modules",
                "@ahrefs/mcp"
            ],
            "env": {
                "API_KEY": "YOUR_API_KEY_HERE"
            }
        }
    }
}

Specific for Windows OS

{
    "mcpServers": {
        "ahrefs": {
            "command": "npx",
            "args": [
                "--prefix=C:\\Users\\YOUR_USERNAME_HERE\\.global-node-modules\\node_modules",
                "@ahrefs/mcp"
            ],
            "env": {
                "API_KEY": "YOUR_API_KEY_HERE"
            }
        }
    }
}
  1. Take note of the double escape backslashes

  2. Take note that the prefix directory is slightly different

  3. Take note of the forward slash for @ahrefs/mcp

  4. If you are working with Claude Desktop, run Ctrl-Alt-Del to open Task Manager and kill Claude Desktop. Otherwise, your newly changed config will not be loaded.

To learn more about creating or controlling API keys, refer to the official documentation.

Where to find the configuration file

Claude Desktop

  1. Download Claude for Desktop

  2. Select Settings...

  1. Click on Developer in the left panel, then Edit Config

  1. Paste the configuration above into the open file

  2. Restart the Claude app! If the installation is successful, it should look like this:

If you prefer directly navigating to the file, the paths are:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

If there are any issues, please refer to the official documentation

Cursor

Cursor supports configurations that are either project-specific or global: the MCP configuration file will be at .cursor/mcp.json or ~/.cursor/mcp.json respectively. For more details, read the official documentation.

Common Installation Issues & Fixes

1. Node.js or npm Not Installed / Recognized

Symptoms:

  • Running npm -v shows an error like command not found or 'npm' is not recognized.

Fix:

  • Ensure you've installed Node.js from nodejs.org.

  • Restart your terminal after installation.

  • On Windows, make sure the Node.js installer added npm to your PATH.

Platform-Specific Checks:

  • Windows: Open Command Prompt (Win + R → cmd) and run:

    node -v
    npm -v
  • macOS/Linux: Open Terminal and run:

    which node && which npm

If it returns nothing, Node.js may not be in your $PATH.


2. Permission Errors During Global Installation

Symptoms:

  • Errors like EACCES: permission denied, especially on macOS or Linux.

Fix:

  • Install using a user-scoped global prefix as shown in the installation guide:

    npm install --prefix=~/.global-node-modules @ahrefs/mcp -g
  • This avoids requiring elevated privileges (sudo).

Extra Tip: If you used sudo previously and created permission issues, reset folder ownership:

sudo chown -R $(whoami) ~/.global-node-modules

2a. macOS Terminal Permissions

Symptoms:

  • Terminal shows "Operation not permitted" errors

  • Unable to create folders or files

  • Permission denied messages when running npm commands

Fix: Check if Terminal has Full Disk Access:

  • Open System Settings (or System Preferences)

  • Go to Privacy & Security → Full Disk Access

  • Make sure Terminal.app is in the list and checked

  • If not present, click '+', navigate to Applications → Utilities → Terminal.app

Note: Modern macOS versions require explicit permissions for Terminal access. Without proper permissions, npm installations and other file operations may fail silently or with permission errors.


3. npx Cannot Find the Ahrefs MCP Command

Symptoms:

  • Error: Cannot find package '@ahrefs/mcp'

Fix: Ensure your config uses the same prefix used during install:

"command": "npx",
"args": [
  "--prefix=~/.global-node-modules",
  "@ahrefs/mcp"
]

Note: Do not omit the --prefix unless you're installing globally system-wide (not recommended).


4. Configuration File Not Detected

Symptoms:

  • Claude does not list the MCP under “tools”.

Fix:

  • Make sure the config file path is correct:

    • Windows: %APPDATA%\Claude\claude_desktop_config.json

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

    • Linux: (Rare, but if applicable) ~/.config/Claude/claude_desktop_config.json

  • Double-check you pasted the configuration inside the correct section and restarted Claude after saving.


5. API Key Problems

Symptoms:

  • MCP fails silently or throws an error about API_KEY.

  • Claude responds with a message that it ran into authentication issues.

Fix: Ensure this line is present in the MCP config:

"env": {
  "API_KEY": "YOUR_API_KEY_HERE"
}

Replace YOUR_API_KEY_HERE with your actual key. Ensure that your API key settings give you the necessary permissions.

For more help, refer to Ahrefs API key docs.


6. Path Expansion Issues

Symptoms:

  • Error messages containing ENOENT or "no such file or directory"

  • npm commands fail with path-related errors

  • ~ or environment variables not being expanded correctly

Fix: Use absolute paths instead of relying on path expansion:

Windows:

C:\Users\<username>\.global-node-modules

Replace <username> with your actual Windows username.

macOS:

/Users/<username>/.global-node-modules

Replace <username> with your macOS username.

Linux:

/home/<username>/.global-node-modules

Replace <username> with your Linux username.

Example Configuration:

{
    "mcpServers": {
        "ahrefs": {
            "command": "npx",
            "args": [
                "--prefix=/Users/username/.global-node-modules",  // Replace with your absolute path
                "@ahrefs/mcp"
            ],
            "env": {
                "API_KEY": "YOUR_API_KEY_HERE"
            }
        }
    }
}

How to Find Your Absolute Path:

Windows:

  1. Open Command Prompt

  2. Type echo %USERPROFILE%

macOS/Linux:

  1. Open Terminal

  2. Type echo $HOME

Note: Using absolute paths eliminates issues with path expansion and ensures the configuration works regardless of environment variables or shell configurations.


🧪 Diagnostic Commands Per Platform

Issue

Windows Command

macOS/Linux Command

Check Node version

node -v && npm -v

node -v && npm -v

Check if MCP is installed

npm list -g --prefix=%USERPROFILE%\.global-node-modules @ahrefs/mcp

npm list -g --prefix=~/.global-node-modules @ahrefs/mcp

Clear corrupted install

Delete folder manually

rm -rf ~/.global-node-modules


📍 Summary of Key Paths

Purpose

Windows

macOS

Linux

Claude config file

%APPDATA%\Claude\claude_desktop_config.json

~/Library/Application Support/Claude/claude_desktop_config.json

~/.config/Claude/claude_desktop_config.json (if applicable)

Global MCP install location

%USERPROFILE%\.global-node-modules

~/.global-node-modules

~/.global-node-modules


📘 Still Having Issues?

Let us know what errors you're seeing, along with your OS and the output of:

npm list -g --prefix=~/.global-node-modules @ahrefs/mcp

Available Tools

42 tools
batch-analysis-batch-analysisC

Performs a batch analysis of multiple URLs, domains, or subdomains to retrieve selected SEO, backlink, organic, and paid traffic metrics. Use doc tool first to get the real input schema.

Inputs: select (required), targets (required), country, order_by, +1 more.

docA

Full documentation for Ahrefs tools. You must use this tool to get the input schema for any other tool.

Inputs: tool.

keywords-explorer-matching-termsC

Retrieves keyword ideas and their associated SEO metrics by matching input terms or phrases in a specified country, with extensive support for filtering, sorting, and metric selection. Use doc tool first to get the real input schema.

Inputs: country (required), select (required), keyword_list_id, keywords, +6 more.

keywords-explorer-overviewC

Provides an overview of keyword metrics—including search volume, CPC, ranking difficulty, traffic potential, and intent—for specified keywords, domains, or URLs within a given country. Use doc tool first to get the real input schema.

Inputs: country (required), select (required), keyword_list_id, keywords, +7 more.

keywords-explorer-search-suggestionsC

Provides keyword search suggestions and related keyword metrics (e.g., search volume, difficulty, CPC) for specified queries or keyword lists, with options to filter, sort, and customize returned fields by country. Use doc tool first to get the real input schema.

Inputs: country (required), select (required), keyword_list_id, keywords, +4 more.

keywords-explorer-volume-by-countryC

Retrieves search volume metrics for a specified keyword broken down by country. Use doc tool first to get the real input schema.

Inputs: keyword (required), limit.

keywords-explorer-volume-historyC

Retrieves historical search volume data for a specified keyword within a given country and date range. Use doc tool first to get the real input schema.

Inputs: country (required), keyword (required), date_from, date_to.

management-locationsC

Retrieves a list of management locations filtered by country code and optionally by US state. Use doc tool first to get the real input schema.

Inputs: country_code (required), us_state.

management-project-competitorsC

Retrieves the list of competitors associated with a specific Rank Tracker project in Ahrefs, using the project's unique identifier. Use doc tool first to get the real input schema.

Inputs: project_id (required).

management-project-keywordsB

Retrieves keywords associated with a specific project in Ahrefs' Rank Tracker by project ID. Use doc tool first to get the real input schema.

Inputs: project_id (required).

management-projectsC

Retrieves information about existing projects, including ownership, access type, presence of Rank Tracker keywords, and project ID. Use doc tool first to get the real input schema.

Inputs: access, has_keywords, owned_by, project_id.

rank-tracker-competitors-overviewC

Provides an overview of competitor rankings and keyword metrics for a specified project and date in Ahrefs Rank Tracker, allowing comparison between current and previous data. Use doc tool first to get the real input schema.

Inputs: date (required), device (required), project_id (required), select (required), +6 more.

rank-tracker-overviewC

Provides an overview of tracked keyword rankings and related search metrics for a specified project and date, with support for historical comparison, filtering, column selection, and device type. Use doc tool first to get the real input schema.

Inputs: date (required), device (required), project_id (required), select (required), +6 more.

serp-overview-serp-overviewC

Returns an overview of the top search results (SERP) for a specified keyword and country, including detailed metrics about each result like position, backlinks, traffic, domain rating, and related keywords. Use doc tool first to get the real input schema.

Inputs: country (required), keyword (required), select (required), date, +1 more.

site-audit-projectsA

Retrieves a list of site audit projects available in the system. Use doc tool first to get the real input schema.

Inputs: no named parameters.

site-explorer-anchorsC

Retrieves anchor text and associated backlink metrics for a specified domain or URL, with filtering and selection options. Use doc tool first to get the real input schema.

Inputs: select (required), target (required), history, limit, +5 more.

site-explorer-domain-ratingC

Retrieves the domain rating and related metrics for a specified domain or URL as of a specific date. Use doc tool first to get the real input schema.

Inputs: date (required), target (required), protocol.

site-explorer-domain-rating-historyC

Retrieves the historical domain rating data for a specified domain or URL over a defined date range and grouping interval. Use doc tool first to get the real input schema.

Inputs: date_from (required), target (required), date_to, history_grouping.

site-explorer-keywords-historyC

Retrieves historical data on the number of organic keywords a specified website or URL has ranked for, segmented by various search position ranges and grouped by a chosen time interval. Use doc tool first to get the real input schema.

Inputs: date_from (required), target (required), country, date_to, +4 more.

site-explorer-linked-anchors-externalC

Retrieves data about external anchor text (the clickable words in outbound links) used on a specified domain, subdomain, or URL, including metrics like dofollow link counts, distinct linked domains, and other attributes about the links. Use doc tool first to get the real input schema.

Inputs: select (required), target (required), limit, mode, +4 more.

site-explorer-linked-anchors-internalC

Retrieves internal anchor text data for a given website or URL, detailing how anchor texts are used in links between pages on the same site. Use doc tool first to get the real input schema.

Inputs: select (required), target (required), limit, mode, +4 more.

site-explorer-linkeddomainsC

Retrieves information about external domains that are linked from a specified target domain or URL, allowing for filtering, field selection, and various scopes of analysis. Use doc tool first to get the real input schema.

Inputs: select (required), target (required), limit, mode, +4 more.

site-explorer-metricsC

Provides SEO performance metrics for a specified domain, URL, or site section as of a given date, with options to customize search scope, protocol, country, and search volume mode. Use doc tool first to get the real input schema.

Inputs: date (required), target (required), country, mode, +2 more.

site-explorer-metrics-by-countryC

Provides organic and paid search performance metrics for a specified website, broken down by country, for a specific date. Use doc tool first to get the real input schema.

Inputs: date (required), target (required), mode, protocol, +2 more.

site-explorer-metrics-historyC

Retrieves historical data on key organic and paid search traffic and cost metrics for a specified domain, URL, or path over a selectable date range and grouping interval. Use doc tool first to get the real input schema.

Inputs: date_from (required), target (required), country, date_to, +5 more.

site-explorer-organic-competitorsC

Retrieves a list of organic search competitors for a specified website or URL, providing comparative SEO metrics such as common keywords, traffic estimations, and domain strength for a chosen country and date. Use doc tool first to get the real input schema.

Inputs: country (required), date (required), select (required), target (required), +8 more.

site-explorer-organic-keywordsC

Retrieves detailed organic keyword data for a given domain, URL, or path, including rankings, search intent, SERP features, traffic and CPC metrics, with the ability to filter, sort, and compare metrics across dates and regions. Use doc tool first to get the real input schema.

Inputs: date (required), select (required), target (required), country, +8 more.

site-explorer-pages-by-trafficC

Retrieves pages from a specified domain, subdomain, path, or exact URL, ranked by their estimated organic search traffic for a selected country and protocol. Use doc tool first to get the real input schema.

Inputs: target (required), country, mode, protocol, +1 more.

site-explorer-pages-historyC

Retrieves historical data about pages from a specified domain, URL, or section of a site, grouped by a chosen time interval. Use doc tool first to get the real input schema.

Inputs: date_from (required), target (required), country, date_to, +3 more.

site-explorer-paid-pagesC

Returns detailed metrics about pages on a specified site or URL that are ranking in paid search results, including traffic, keyword data, ad presence, and changes over time, with powerful filtering and comparison capabilities. Use doc tool first to get the real input schema.

Inputs: date (required), select (required), target (required), country, +8 more.

site-explorer-refdomainsC

Retrieves detailed information about referring domains that link to a specified target domain or URL, with flexible filtering, selection, and sorting of backlink-related metrics. Use doc tool first to get the real input schema.

Inputs: select (required), target (required), history, limit, +5 more.

site-explorer-refdomains-historyC

Provides historical data on referring domains linking to a specified target (domain or URL) over a defined date range, with customizable grouping and analysis scope. Use doc tool first to get the real input schema.

Inputs: date_from (required), target (required), date_to, history_grouping, +2 more.

site-explorer-top-pagesC

Returns a list of the top-performing pages for a specified website or URL, including detailed SEO metrics (such as organic rankings, traffic, top keyword, and changes over time), with support for comparison between two dates and flexible filtering. Use doc tool first to get the real input schema.

Inputs: date (required), select (required), target (required), country, +8 more.

site-explorer-total-search-volume-historyC

Retrieves the historical total organic search volume, traffic, and traffic value for a given site or URL over a specified time period and grouping. Use doc tool first to get the real input schema.

Inputs: date_from (required), target (required), country, date_to, +5 more.

site-explorer-url-rating-historyC

Retrieves the historical URL rating data for a specified domain or URL over a defined date range, grouped by a chosen time interval. Use doc tool first to get the real input schema.

Inputs: date_from (required), target (required), date_to, history_grouping.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.8/5.0

    Scored across 42 tools

    Disambiguation3/5

    The tools are organized into clear categories (keywords-explorer, site-explorer, management, etc.), which helps differentiate them, but within categories there is significant overlap. For example, site-explorer-metrics, site-explorer-metrics-by-country, and site-explorer-metrics-history all retrieve metrics with slight variations, which could cause confusion. The descriptions are detailed but many tools share similar purposes with minor scope differences.

    Naming Consistency4/5

    Tool names follow a consistent hyphen-separated pattern with a clear category-action structure (e.g., keywords-explorer-overview, site-explorer-metrics). However, there are minor deviations like 'batch-analysis-batch-analysis' (redundant) and 'serp-overview-serp-overview' (redundant), and some names are lengthy but generally predictable.

    Tool Count2/5

    With 42 tools, this server is overly large for a single MCP server, making it cumbersome for agents to navigate. While Ahrefs is a comprehensive SEO platform, the tool count could be reduced by consolidating overlapping functionalities (e.g., multiple metrics tools) or splitting into focused sub-servers for better manageability.

    Completeness5/5

    The tool set provides extensive coverage of Ahrefs' SEO capabilities, including keyword research, site analysis, backlink tracking, rank tracking, and management features. It supports CRUD-like operations (e.g., retrieval, analysis, historical data) across all major domains, with no obvious gaps for typical SEO workflows.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers