grok-mcp
Connects Claude Code to xAI's Grok for real-time web and X (Twitter) search with multi-agent architecture and 2M token context.
README
Grok MCP Server
Give Claude Code the power of Grok 4.20
An MCP server that connects Claude Code to xAI's Grok, unlocking real-time web search and X (Twitter) search capabilities.
Why Grok + Claude?
| Grok's Strengths | Use Case |
|---|---|
| Web + X Search | Real-time information with transparent source URLs |
| X/Twitter Search | Track social media trends, public opinion, breaking news |
| 4-Agent Architecture | Harper (research) + Benjamin (logic) + Lucas (creative) collaboration |
| 2M Token Context | Massive context window for comprehensive analysis |
Philosophy: Claude is the commander, Grok is the specialist for real-time search and social media intelligence.
Quick Start
1. Get API Key
Visit xAI Console and create an API key.
2. Configure Claude Code
Add to your MCP config file:
- Mac:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"grok-mcp": {
"command": "npx",
"args": ["-y", "@lkbaba/grok-mcp@latest"],
"env": {
"XAI_API_KEY": "your_xai_api_key_here"
}
}
}
}
@latestensures you always get the newest version when Claude Code restarts.
3. Restart Claude Code
Tools (2)
grok_agent_search - Smart Search
Real-time web and X (Twitter) search powered by Grok. Grok automatically analyzes queries, executes searches (potentially multiple rounds), synthesizes information, and provides cited answers.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
query |
string | Yes | - | Search query |
search_type |
enum | No | mixed |
web / x / mixed (recommended) |
model |
enum | No | grok-4.20-multi-agent-beta-0309 |
See model table below |
output_format |
enum | No | text |
text (Markdown) / json (native JSON Schema enforced) |
web_search_config |
object | No | - | Domain filters (allowed/excluded are mutually exclusive) |
x_search_config |
object | No | - | Date range, handle filters (allowed/excluded are mutually exclusive), video understanding |
Output includes: Search results with inline citations, search queries Grok used, titled source links, and usage statistics.
Example:
"Search for the latest Claude Code updates on X and the web"
grok_brainstorm - Creative Brainstorming
Multi-perspective idea generation with project context support.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
topic |
string | Yes | - | Brainstorming topic |
context |
string | No | - | Additional context |
context_files |
string[] | No | - | Project files to read as context (max 10) |
count |
number | No | 5 |
Number of ideas (1-10) |
style |
enum | No | balanced |
innovative / practical / radical / balanced |
model |
enum | No | grok-4.20-multi-agent-beta-0309 |
Model selection |
output_format |
enum | No | text |
text (Markdown) / json (native JSON Schema with pros/cons/feasibility) |
Style temperature mapping: practical=0.5, balanced=0.7, innovative=0.95, radical=1.0
Example:
"Brainstorm 3 practical ideas for improving user onboarding, read ./README.md for context"
Model Selection
| Model | Architecture | Price (input/output per M) | Context | Best For |
|---|---|---|---|---|
grok-4.20-multi-agent-beta-0309 |
4-Agent collaboration | $2.00 / $6.00 | 2M | Default — lowest hallucination rate (~4.2%) |
grok-4.20-beta-0309-reasoning |
Chain-of-thought | $2.00 / $6.00 | 2M | Deep technical analysis |
grok-4.20-beta-0309-non-reasoning |
Standard | $2.00 / $6.00 | 2M | Fastest speed, quick creative divergence |
Performance
Tested on 2026-03-12:
| Operation | Model | Time | Tokens |
|---|---|---|---|
| Web Search | multi-agent | ~29s | ~70K |
| X Search | multi-agent | ~28s | ~48K |
| Brainstorm (3 ideas) | multi-agent | ~16s | ~3.6K |
| Brainstorm (5 ideas) | non-reasoning | ~7s | ~2.2K |
Proxy Configuration
<details> <summary>For users behind proxy/VPN</summary>
Add proxy environment variable to your config:
{
"mcpServers": {
"grok-mcp": {
"command": "npx",
"args": ["-y", "@lkbaba/grok-mcp@latest"],
"env": {
"XAI_API_KEY": "your_xai_api_key_here",
"HTTPS_PROXY": "http://127.0.0.1:7897"
}
}
}
}
Native fetch (undici) automatically reads proxy environment variables.
</details>
Local Development
<details> <summary>Build from source</summary>
git clone https://github.com/LKbaba/Grok-mcp.git
cd Grok-mcp
npm install
npm run build
export XAI_API_KEY="your_xai_api_key_here"
npm start
</details>
Project Structure
src/
├── config/
│ └── index.ts # Configuration (zod validation)
├── types/
│ └── index.ts # TypeScript type definitions
├── tools/
│ ├── definitions.ts # MCP tool JSON Schema definitions
│ ├── agent-search.ts # grok_agent_search implementation
│ └── brainstorm.ts # grok_brainstorm implementation
├── utils/
│ ├── grok-client.ts # xAI API client (native fetch)
│ ├── tool-builder.ts # Search tool parameter builder
│ └── logger.ts # Logging and performance monitoring
└── index.ts # MCP server entry point
Comparison with Gemini MCP
| Feature | Gemini MCP | Grok MCP |
|---|---|---|
| Web Search | Google Search (grounding) | Grok Web Search |
| X/Twitter Search | Not available | Native support |
| Citation URLs | Google redirect (opaque) | Direct URLs with titles (transparent) |
| Search Speed | ~8-10s (flash) | ~16-29s (grok-4.20) |
| Agent Architecture | Single model | 4-Agent collaboration |
| Structured Output | text/json | text/json (native JSON Schema enforced) |
| Brainstorm | Structured JSON | Structured JSON + style/count/context_files |
Best strategy: Use both! Gemini for speed and code analysis, Grok for deep search and X/Twitter intelligence.
Security
- Path traversal protection:
context_filesare sandboxed to the working directory — paths like../../etc/passwdare blocked - Sensitive file blocking:
.env,.pem,.key, credentials, and database files are automatically excluded - Input validation: Domain filters, date ranges, handle filters, and file counts are validated with strict schemas
- Mutual exclusivity:
allowed_domains/excluded_domainsandallowed_x_handles/excluded_x_handlescannot be set simultaneously - No hardcoded secrets: API keys are loaded from environment variables only
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。