How to Set Up an MCP Server for SEO (Step-by-Step 2026 Guide)
The Model Context Protocol (MCP) is an open standard developed by Anthropic that allows AI models to interact with external tools and data sources through a...
- The Model Context Protocol MCP is an open standard developed by Anthropic that allows AI models to interact with external tools and data sources...
- Python 3.12+ or Node.js 18+ API keys for your SEO tools Ahrefs, Semrush, Google Search Console A server to host the MCP server can run locally for...
- pip install mcp httpx python-dotenv The mcp package provides the server framework.
- python server.py The server listens on STDIO.
- Once running, an AI assistant can execute complex SEO workflows with a single prompt: 'Check the ranking for 'technical SEO guide' on example.com...
- Never expose your MCP server directly to the internet without authentication.
- Install MCP SDK and dependencies Create the server with 2-3 SEO tool functions Store all API keys in environment variables Test locally with...
The Model Context Protocol (MCP) is an open standard developed by Anthropic that allows AI models to interact with external tools and data sources through a standardized server interface. An MCP server for SEO acts as a bridge between AI assistants and your SEO tooling, enabling automated data...
What is an MCP server
The Model Context Protocol (MCP) is an open standard developed by Anthropic that allows AI models to interact with external tools and data sources through a standardized server interface. An MCP server for SEO acts as a bridge between AI assistants and your SEO tooling, enabling automated data collection, analysis, and reporting.
In 2026, MCP servers are essential for SEO teams that want to automate repetitive tasks: checking rankings, auditing pages, monitoring Core Web Vitals, and generating structured reports. By setting up an MCP server, you give AI assistants direct access to your SEO data stack without manual copy-paste.
Prerequisites
- Python 3.12+ or Node.js 18+ (this guide uses Python)
- API keys for your SEO tools (Ahrefs, Semrush, Google Search Console)
- A server to host the MCP server (can run locally for testing)
- Basic familiarity with Python async programming
Step 1: Install the MCP SDK
pip install mcp httpx python-dotenv
The mcp package provides the server framework. httpx handles async HTTP requests.
Step 2: Set up project structure
mkdir seo-mcp-server
cd seo-mcp-server
touch server.py .env
Add your API keys to .env:
AHRFS_API_KEY=your_a## Step 3: Build the MCP server
Here is a complete MCP server exposing SEO tools as AI-accessible functions:
```python
import os
import httpx
from mcp.server import Server, stdio_server
from mcp.types import Tool, TextContent
from dotenv import load_dotenv
load_dotenv()
app = Server("seo-tools")
@app.list_tools()
async def list_tools() -> list[Tool]:
return [
Tool(
name="check_ranking",
description="Check keyword ranking position",
inputSchema={
"type": "object",
"properties": {
"keyword": {"type": "string"},
"domain": {"type": "string"}
},
"required": ["keyword", "domain"]
}
),
Tool(
name="analyze_url",
description="Analyze a URL for SEO issues",
inputSchema={
"type": "object",
"properties": {"url": {"type": "string"}},
"required": ["url"]
}
),
Tool(
name="check_core_web_vitals",
description="Fetch Core Web Vitals from CrUX API",
inputSchema={
"type": "object",
"properties": {"url": {"type": "string"}},
"required": ["url"]
}
),
Tool(
name="backlink_profile",
description="Get backlink profile for a domain",
inputSchema={
"type": "object",
"properties": {"domain": {"type": "string"}},
"required": ["domain"]
}
)
]
@app.call_tool()
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
if name == "check_ranking":
async with httpx.AsyncClient() as client:
response = await client.get(
"https://api.semrush.com/v3/rankings/organic",
params={
"key": os.getenv("SEMRUSH_API_KEY"),
"keyword": arguments["keyword"],
"domain": arguments["domain"],
"database": "us"
}
)
data = response.json()
return [TextContent(
type="text",
text=f"Keyword: {arguments['keyword']}\n"
f"Position: {data.get('position', 'Not found')}\n"
f"Volume: {data.get('volume', 'N/A')}"
)]
elif name == "check_core_web_vitals":
async with httpx.AsyncClient() as client:
response = await client.post(
"https://chromeuxreport.googleapis.com/v1/records:queryRecord",
json={"url": arguments["url"]},
headers={"Authorization": f"Bearer {os.getenv('GSC_API_KEY')}"}
)
data = response.json()
lcp = data.get("record", {}).get("metrics", {}).get("largest_contentful_paint", {})
return [TextContent(
type="text",
text=f"LCP (p75): {lcp.get('percentiles', {}).get('p75', 'N/A')}ms"
)]
return [TextContent(type="text", text=f"Unknown tool: {name}")]
if __name__ == "__main__":
import asyncio
asyncio.run(stdio_server(app))
Step 4: Run the MCP server
python server.py
The server listens on STDIO. Register it with your AI assistant:
mcp install server.py --name "SEO Tools"
For Claude Desktop, add to claude_desktop_config.json:
{
"mcpServers": {
"seo-tools": {
"command": "python",
"args": ["/path/to/seo-mcp-server/server.py"]
}
}
}
Step 5: Use the MCP server for SEO workflows
Once running, an AI assistant can execute complex SEO workflows with a single prompt:
"Check the ranking for 'technical SEO guide' on example.com, analyze the top result, and suggest improvements."
The AI calls check_ranking, then analyze_url, and synthesizes results into recommendations.
Security considerations
Never expose your MCP server directly to the internet without authentication. The STDIO transport is local only. Store API keys in environment variables. Do not hardcode keys in the server code.
Audit: MCP server setup checklist
- [ ] Install MCP SDK and dependencies
- [ ] Create the server with 2-3 SEO tool functions
- [ ] Store all API keys in environment variables
- [ ] Test locally with
python server.py - [ ] Register the server in your AI assistant config
- [ ] Verify the AI can call each tool and return results
- [ ] Add error handling for failed API requests
- [ ] Set up logging for MCP server requests
- [ ] Document available tools for team use
MCP servers represent the future of SEO automation. By connecting AI assistants directly to your tooling, you eliminate manual data gathering and accelerate analysis. Build your first MCP server with the tools you use most and iterate from there.
Citations
- Anthropic. "Model Context Protocol (MCP) Documentation." Anthropic, 2025. https://modelcontextprotocol.io/
- MCP GitHub. "MCP Specification and SDKs." GitHub, 2025. https://github.com/modelcontextprotocol
- Search Engine Land. "How to Use MCP for SEO Automation." Search Engine Land, 2026. https://searchengineland.com/mcp-server-seo-automation-guide
- Ahrefs. "Ahrefs API Documentation." Ahrefs, 2026. https://ahrefs.com/api/documentation