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 (~/.claude.json):

claude mcp add grok-search -s user -- uvx grok-mcp

Then edit ~/.claude.json to add the env variable:

{
  "mcpServers": {
    "grok-search": {
      "command": "uvx",
      "args": ["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.2.0.tar.gz (69.5 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.2.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: grok_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 69.5 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.2.0.tar.gz
Algorithm Hash digest
SHA256 baa74aaba210d968ab2dc475a20e7c3807cb760054d05db6e6e04eeaaac11cc0
MD5 5a121ac9e1b157b46caa8317e915da0c
BLAKE2b-256 af4f5e9d25872036c363000923d167657ed759d0dda394a1cd5d43d13b0e3677

See more details on using hashes here.

File details

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

File metadata

  • Download URL: grok_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7e9dd352e367461b27e66383935d5a384a9ff5b12d89db40fc6bfc4428ac9a4
MD5 90af08bfe9989b3d3ece7f9b24eca57a
BLAKE2b-256 27c229f5c874b13830e5170b9083ea9a3170ad7055ad32126761841181ed28c7

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