Information
# 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](https://nodejs.org/en/download/)
2. Follow the installation instructions for your operating system
3. Verify installation by running:
\`\`\`sh
npm -v
\`\`\`
4. 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
\`\`\`sh
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:
\`\`\`sh
npm install --prefix=~/.global-node-modules @ahrefs/mcp@latest -g
\`\`\`
## 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:
\`\`\`json
\{
"mcpServers": \{
"ahrefs": \{
"command": "npx",
"args": [
"--prefix=~/.global-node-modules",
"@ahrefs/mcp"
],
"env": \{
"API_KEY": "YOUR_API_KEY_HERE"
\}
\}
\}
\}
\`\`\`
### Specific for Windows OS
\`\`\`json
\{
"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](https://docs.ahrefs.com/docs/api/reference/api-keys-creation-and-management).
### Where to find the configuration file
#### Claude Desktop
1. Download Claude for Desktop
2. Select \`Settings...\`
\.global-node-modules
\`\`\`
Replace \`\` with your actual Windows username.
**macOS:**
\`\`\`sh
/Users//.global-node-modules
\`\`\`
Replace \`\` with your macOS username.
**Linux:**
\`\`\`sh
/home//.global-node-modules
\`\`\`
Replace \`\` with your Linux username.
**Example Configuration:**
\`\`\`json
\{
"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?
- Check the [official MCP documentation](https://modelcontextprotocol.io/quickstart/user)
- Or reach out to internal support at Ahrefs through your usual engineering support channel.
Let us know what errors you're seeing, along with your OS and the output of:
\`\`\`sh
npm list -g --prefix=~/.global-node-modules @ahrefs/mcp
\`\`\`