The Ahrefs MCP server allows you to connect Claude desktop and other compatible AI assistants to Ahrefs data and functionality through the Model Context Protocol standard. This integration empowers your AI assistant to directly access Ahrefs features when you need them.
npm -v
When installing Node.js on Windows, use the official installer and ensure the folder is added to PATH when selecting installation options.
Run this command in your terminal:
npm install --prefix=~/.global-node-modules @ahrefs/mcp -g
If you've previously installed the MCP server and want to upgrade:
npm install --prefix=~/.global-node-modules @ahrefs/mcp@latest -g
Add the following to your AI assistant's configuration file:
{
"mcpServers": {
"ahrefs": {
"command": "npx",
"args": [
"--prefix=~/.global-node-modules",
"@ahrefs/mcp"
],
"env": {
"API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}
For Windows users, use this configuration instead:
{
"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
For information about creating or managing API keys, refer to the official Ahrefs API documentation.
Direct file paths:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
For additional help, see the official MCP documentation.
Cursor supports both project-specific and global configurations:
.cursor/mcp.json
~/.cursor/mcp.json
For more details, see Cursor's documentation.
Symptoms:
npm -v
shows errors like command not found
or 'npm' is not recognized
Fix:
Windows:
node -v
npm -v
macOS/Linux:
which node && which npm
Symptoms:
EACCES: permission denied
Fix:
npm install --prefix=~/.global-node-modules @ahrefs/mcp -g
If you previously used sudo
and created permission issues:
sudo chown -R $(whoami) ~/.global-node-modules
Symptoms:
Fix:
Symptoms:
Cannot find package '@ahrefs/mcp'
Fix:
"command": "npx",
"args": [
"--prefix=~/.global-node-modules",
"@ahrefs/mcp"
]
Symptoms:
Fix:
Symptoms:
Fix:
"env": {
"API_KEY": "YOUR_API_KEY_HERE"
}
Symptoms:
ENOENT
or "no such file or directory"Fix:
Windows:
C:\Users\<username>\.global-node-modules
macOS:
/Users/<username>/.global-node-modules
Linux:
/home/<username>/.global-node-modules
To find your absolute path:
Windows: Run echo %USERPROFILE%
in Command Prompt
macOS/Linux: Run echo $HOME
in Terminal
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