Skip to main content

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.

PyPI version License: MIT

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

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-mcp or uvx 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_KEY is 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 uvx or pip is 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

grok_mcp-0.1.0.tar.gz (69.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grok_mcp-0.1.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file grok_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: grok_mcp-0.1.0.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

Hashes for grok_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aa436d593da6da59a94f510cc5ec60afa814ae0ecce5d2022d51811cc6330aea
MD5 5fa40fc9e643d62ebf81ace1912df4e6
BLAKE2b-256 0eb47047351401f05cb7eee65807ca90942dab650489f48283c7098bcf0ecc92

See more details on using hashes here.

File details

Details for the file grok_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: grok_mcp-0.1.0-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

Hashes for grok_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7198ab21780e47c908c2fe1f10a4f0c93bed2874787a9f86e4d3e77eb5ffdb87
MD5 2aa23caf5d69fd824ac9fd86f32f0482
BLAKE2b-256 31ccfa0120d6a6393a3e7ed71355d53c13e7edd40bfb84570f5f7cfcabae3e10

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page