MCP server for Grok X.com search integration using xAI API
Project description
Grok X.com Search MCP Server
A Model Context Protocol (MCP) server that integrates xAI's Grok API for X.com search functionality. This server enables Claude Desktop and Claude Code users to search and analyze X/Twitter content with real-time data access.
Features
- Real-time X.com Search: Search posts, users, conversation threads, and trending topics
- Advanced Analysis: Basic and comprehensive analysis modes with sentiment analysis
- Robust Error Handling: Retry logic, rate limiting, and graceful degradation
- Claude Integration: Works with both Claude Desktop and Claude Code via MCP protocol
- Comprehensive Filtering: Date ranges, user handles, engagement metrics
Quick Start
Prerequisites
- Python 3.12+
- xAI API key from console.x.ai
Install from PyPI
# Using uvx (recommended)
uvx grok-mcp
# Or using pip
pip install grok-mcp
Configuration
Claude Code
Add to your Claude Code MCP settings:
Project scope (.mcp.json in your project root):
{
"mcpServers": {
"grok-search": {
"command": "uvx",
"args": ["grok-mcp"],
"env": {
"XAI_API_KEY": "your-xai-api-key"
}
}
}
}
User scope (global settings):
claude mcp add grok-search --command "uvx grok-mcp" --env XAI_API_KEY=your-xai-api-key
Claude Desktop
Add to your Claude Desktop configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"grok-search": {
"command": "uvx",
"args": ["grok-mcp"],
"env": {
"XAI_API_KEY": "your-xai-api-key"
}
}
}
}
Restart Claude Desktop after adding the configuration.
Available Tools
search_posts
Search X.com posts with advanced filtering and analysis options.
| Parameter | Required | Description |
|---|---|---|
query |
Yes | Search query for X.com posts |
max_results |
No | Maximum results (1-100, default: 20) |
handles |
No | Filter by user handles (without @) |
start_date |
No | Start date (YYYY-MM-DD) |
end_date |
No | End date (YYYY-MM-DD) |
analysis_mode |
No | "basic" or "comprehensive" |
search_users
Search for X.com users and profiles.
| Parameter | Required | Description |
|---|---|---|
query |
Yes | Search query for users |
max_results |
No | Maximum results (1-50, default: 20) |
search_threads
Search X.com conversation threads and replies.
| Parameter | Required | Description |
|---|---|---|
query |
Yes | Search query for threads |
max_results |
No | Maximum threads (1-20, default: 10) |
get_trends
Get trending topics and hashtags on X.com.
| Parameter | Required | Description |
|---|---|---|
location |
No | Location (e.g., "United States", "Global") |
max_results |
No | Maximum trends (1-50, default: 20) |
health_check
Check the health and status of the Grok API connection.
Development
Setup for Development
git clone https://github.com/guzus/grok-mcp.git
cd grok-mcp
uv sync --dev
Run Tests
uv run pytest
uv run pytest --cov=src/grok_mcp
Validate Configuration
uv run python scripts/validate_config.py
Architecture
grok-mcp/
├── src/grok_mcp/
│ ├── server.py # Main MCP server
│ ├── config.py # Configuration management
│ ├── grok_client.py # Grok API client with retry/rate limiting
│ ├── search_tools.py # Search tool implementations
│ ├── response_formatter.py # Response formatting
│ └── exceptions.py # Custom exceptions
├── tests/ # Test suite
└── scripts/ # Utility scripts
Publishing
This server is available on:
- PyPI:
pip install grok-mcporuvx grok-mcp - MCP Registry: Listed as
io.github.guzus/grok-mcp - Smithery: Available at smithery.ai
Publish to PyPI
uv build
uv publish
Publish to MCP Registry
mcp-publisher login github
mcp-publisher publish
Troubleshooting
"API key not configured"
- Ensure
XAI_API_KEYis set in your MCP configuration - Verify the API key is valid at console.x.ai
"Tool not found"
- Restart Claude Desktop/Code after configuration changes
- Check that
uvxorpipis available in your PATH
Rate limit errors
- The server implements automatic retry with exponential backoff
- Check your xAI API usage limits
License
MIT License - see LICENSE for details.
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grok_mcp-0.1.2.tar.gz.
File metadata
- Download URL: grok_mcp-0.1.2.tar.gz
- Upload date:
- Size: 69.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9e6ce88cbecaa8b5e6636059d1d9528aa0ef453ac7a0f289d42944bb7ab6623
|
|
| MD5 |
d315fa6ffb35883ae225f6e27e5b5c9f
|
|
| BLAKE2b-256 |
36d9daed5ec89edbd26243e9d77bb750167f9b5dd01b72668b9b8f6b67a3747a
|
File details
Details for the file grok_mcp-0.1.2-py3-none-any.whl.
File metadata
- Download URL: grok_mcp-0.1.2-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c88f78d1bc4e1c25f1723ca74f1a4a198161a0b9d0dc9b7b5f353f34a67e8143
|
|
| MD5 |
ee558ee9d04a2cae8a5c418c071ab77b
|
|
| BLAKE2b-256 |
7bf6a12d3caa6460e03ebfab1247a9faa6dbee28339acb0b5c4c88a4f1a10807
|