Grok2API MCP Server
Enables real-time web and Twitter/X search via Grok, returning structured results with source URLs, confidence scores, and key points. Supports multiple output modes, language options, and time range filtering.
README
<div align="center">
Grok2API MCP Server
English · 中文
</div>
An MCP (Model Context Protocol) server that provides real-time web search via Grok. Returns structured results with source URLs, confidence scores, key points, and multi-language support.
How It Works
Claude / Cursor / etc. ──MCP──> grok-mcp-server ──HTTP──> grok2api ──> Grok
This server bridges MCP clients to a grok2api-compatible backend, exposing Grok's real-time web search through an OpenAI-compatible API.
Features
- Real-time web & Twitter/X search via Grok
- Structured JSON output — summary, key points with citations, source list, confidence score
- Multiple output modes —
brief,analyst,raw - Multi-language support — respond in any language
- Time range filtering —
24h,7d,30d,all - Source freshness control — prefer recent sources
- Domain allowlist preference — prioritize trusted domains (best-effort)
- Automatic retries with exponential backoff
- Runtime metrics via
grok_statstool
Prerequisites
You need a running grok2api instance (or any OpenAI-compatible API endpoint backed by a Grok model with web search).
Setting Up the grok2api Backend
It is strongly recommended to use a secondary/alt Grok account for this, not your primary account.
1. Deploy grok2api
Choose the method that fits your environment:
<details> <summary><b>VPS / Server (Docker Compose — recommended)</b></summary>
Requires Docker and Docker Compose installed on your server.
git clone https://github.com/chenyme/grok2api
cd grok2api
docker compose up -d
The admin panel will be available at http://your-server-ip:8000/admin (default password: grok2api).
</details>
<details> <summary><b>macOS (local)</b></summary>
Requires Python 3.11+ and uv.
# Install uv if you don't have it
brew install uv
# Clone and run
git clone https://github.com/chenyme/grok2api
cd grok2api
uv sync
uv run main.py
The admin panel will be at http://localhost:8000/admin (default password: grok2api).
</details>
<details> <summary><b>Windows (local)</b></summary>
Requires Python 3.11+ and uv.
# Install uv (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Clone and run
git clone https://github.com/chenyme/grok2api
cd grok2api
uv sync
uv run main.py
The admin panel will be at http://localhost:8000/admin (default password: grok2api).
</details>
<details> <summary><b>Linux (local, without Docker)</b></summary>
Requires Python 3.11+ and uv.
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone and run
git clone https://github.com/chenyme/grok2api
cd grok2api
uv sync
uv run main.py
The admin panel will be at http://localhost:8000/admin (default password: grok2api).
</details>
For cloud deployments (Vercel, Render), see the grok2api README.
2. Get Your Grok Cookie
- Log into grok.com with your Grok account
- Open browser DevTools (
F12orCmd+Opt+I) - Go to the Application tab
- In the left sidebar, expand Storage → Cookies
- Find the cookie named
ssoorsso-rw - Copy its value
3. Add Token to grok2api
- Open the grok2api admin panel (
http://your-server:8000/admin) - Click Add to add a new token
- Paste the cookie value you just copied
- Select your account type based on your Grok subscription:
- Basic — 80 requests per 20 hours
- Super — 140 requests per 2 hours
The GROK_API_KEY in your .env is the admin key configured in grok2api (the app.app_key value, default: grok2api).
Installation
Option A: Global install (recommended)
git clone https://github.com/wousp112/grok2api-mcp-server.git
cd grok-mcp-server
cp .env.example .env
# Edit .env with your API URL and key
npm install
npm link
Option B: Local install
git clone https://github.com/wousp112/grok2api-mcp-server.git
cd grok-mcp-server
cp .env.example .env
# Edit .env with your API URL and key
npm install
Configuration
Copy .env.example to .env and fill in your values:
| Variable | Required | Default | Description |
|---|---|---|---|
GROK_API_URL |
Yes | — | Your grok2api endpoint (e.g. http://your-server:8000/v1) |
GROK_API_KEY |
Yes | — | API key for authentication |
GROK_MODEL |
No | grok-3 |
Grok model name |
GROK_REQUEST_TIMEOUT_MS |
No | 60000 |
Request timeout (ms) |
GROK_MAX_RETRIES |
No | 2 |
Max retry attempts |
GROK_BACKOFF_BASE_MS |
No | 800 |
Base backoff delay for retries (ms) |
GROK_READ_TIMEOUT_MS |
No | Same as request timeout | Axios timeout (ms) |
MCP Client Configuration
<details> <summary><b>Claude Desktop</b></summary>
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"grok-search": {
"command": "grok-mcp-server",
"args": [],
"env": {
"PATH": "/usr/local/bin:/usr/bin:/bin"
}
}
}
}
</details>
<details> <summary><b>Claude Code</b></summary>
{
"mcpServers": {
"grok-search": {
"command": "grok-mcp-server",
"args": []
}
}
}
</details>
<details> <summary><b>Cursor</b></summary>
Add to .cursor/mcp.json:
{
"mcpServers": {
"grok-search": {
"command": "grok-mcp-server",
"args": []
}
}
}
</details>
Note: If you skipped
npm link, use the full path instead:"command": "/path/to/grok-mcp-server/index.js"
Tools
grok_web_search
Search the web or Twitter/X via Grok with structured output.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
query |
string | Yes | — | The question or topic to search for |
output_mode |
brief|analyst|raw |
No | analyst |
Response detail level |
language |
string | No | en |
Response language code |
time_range |
24h|7d|30d|all |
No | all |
Search lookback window |
freshness_days |
integer | No | — | Prefer sources within N days |
max_sources |
integer | No | 8 |
Max sources in output (1–20) |
domains_allowlist |
string[] | No | — | Preferred source domains, best-effort (max 30) |
Response structure:
{
"summary": "Concise factual summary",
"key_points": [
{ "point": "Key finding", "source_urls": ["https://..."] }
],
"sources": [
{
"title": "Article Title",
"url": "https://...",
"publisher": "Publisher Name",
"published_at": "2025-01-01T00:00:00Z",
"relevance_note": "Why this source matters"
}
],
"confidence": 0.85,
"as_of": "2025-01-01T12:00:00Z",
"notes": "Additional context or caveats"
}
grok_stats
Returns runtime metrics: call counts, error distribution, uptime.
Acknowledgements
- grok2api by chenyme — the backend that makes Grok accessible via OpenAI-compatible API
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 模型以安全和受控的方式获取实时的网络信息。