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.1.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.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: grok_mcp-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d430801e4a703bf9715a92461024465459d0ad380207bedb432e11f0a7b87390
MD5 76cc5e9b5ffe19a62971793f95a4e805
BLAKE2b-256 10677fd3a5ca6acf52910d61c18556df86ed575505e91e4e40c6a39d1b6c2ccf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: grok_mcp-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c4ce8de57fe242879960b5d5d42a125c2233d7e1a7639cc98f0974241227f78
MD5 fe875e0eb65019586948229607590cd3
BLAKE2b-256 67dd4b2cfab95f318694fa3dae775dcfad17d05457d6b7f9682c5bd1f288479c

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