Ahrefs MCP is a Model Context Protocol server that connects AI assistants like Claude Desktop to Ahrefs data and functionality. This local server works with API v3 keys and allows your AI assistant to access Ahrefs capabilities directly from your conversations.
npm -v
When installing Node.js on Windows, use the official installer and ensure the folder is added to PATH during installation.
Run this command in your terminal:
npm install --prefix=~/.global-node-modules @ahrefs/mcp -g
If you've already installed the MCP server and want to upgrade:
npm install --prefix=~/.global-node-modules @ahrefs/mcp@latest -g
Add the Ahrefs MCP to your AI assistant app by adding this configuration:
{
"mcpServers": {
"ahrefs": {
"command": "npx",
"args": [
"--prefix=~/.global-node-modules",
"@ahrefs/mcp"
],
"env": {
"API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}
For Windows users, the configuration requires a slightly different format:
{
"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"
}
}
}
}
Important Windows notes:
@ahrefs/mcp
To learn more about API keys, see the official documentation.
Configuration file locations:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
Cursor supports either project-specific or global configuration:
.cursor/mcp.json
~/.cursor/mcp.json
For more details, see the official Cursor documentation.
Symptoms:
npm -v
shows an error like command not found
or 'npm' is not recognized
Fix:
Verification commands:
node -v && npm -v
which node && which npm
Symptoms:
EACCES: permission denied
Fix:
sudo
previously and created permission issues:
sudo chown -R $(whoami) ~/.global-node-modules
Symptoms:
Fix:
Symptoms:
Cannot find package '@ahrefs/mcp'
Fix:
Symptoms:
Fix:
Symptoms:
Fix:
Symptoms:
ENOENT
or "no such file or directory"Fix:
C:\Users\<username>\.global-node-modules
/Users/<username>/.global-node-modules
node -v && npm -v
Windows:
npm list -g --prefix=%USERPROFILE%\.global-node-modules @ahrefs/mcp
macOS/Linux:
npm list -g --prefix=~/.global-node-modules @ahrefs/mcp
If you continue experiencing issues, check the official MCP documentation or contact Ahrefs support.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "ahrefs" '{"command":"npx","args":["--prefix=~/.global-node-modules","@ahrefs/mcp"],"env":{"API_KEY":"YOUR_API_KEY_HERE"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"ahrefs": {
"command": "npx",
"args": [
"--prefix=~/.global-node-modules",
"@ahrefs/mcp"
],
"env": {
"API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"ahrefs": {
"command": "npx",
"args": [
"--prefix=~/.global-node-modules",
"@ahrefs/mcp"
],
"env": {
"API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect