grok-web-search-mcp
It runs an MCP server that lets any MCP host (e.g. Grok, Cursor, Claude Desktop) perform live Grok/xAI-powered web and X searches through a single web_search tool and receive concise, cited answers.
Live web search with Grok-synthesized answers and source citations
X (Twitter) post/account search, optionally restricted with handle filters and date ranges
Combine web and X results in one call, or search only web or only X
Optional image input (URL, data URI, or local file path) for visual questions while searching
Image/video understanding for content on browsed pages and X posts
Domain allowlist/denylist to constrain web sources
Optional per-request model override, reasoning effort, and system prompt
Configurable API key, base URL, model, timeouts, retries, and logging via environment variables
Works with the official xAI API or OpenAI-compatible proxies
Returns a lean JSON result: query, text, citations, and sources_used; failures are surfaced as MCP protocol errors
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@grok-web-search-mcp search the web for the latest AI breakthroughs"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Language: English | 中文
About The Project
Agents need live web and X access with citations, not just a chat completion. This project wraps xAI’s server-side web_search and x_search tools as a single MCP tool, so hosts like Grok, Cursor, or Claude Desktop can call them without embedding xAI client logic.
Repository: https://github.com/NakanoSanku/grok-web-search-mcp
Upstream call (simplified):
POST {base_url}/responses
Authorization: Bearer <api_key>
Content-Type: application/json
{
"model": "grok-4.5",
"input": [{"role": "user", "content": "<query>"}],
"tools": [
{"type": "web_search", "enable_image_understanding": true},
{
"type": "x_search",
"allowed_x_handles": ["xai"],
"from_date": "2025-10-01",
"to_date": "2025-10-10",
"enable_image_understanding": true,
"enable_video_understanding": true
}
]
}Design goals:
One MCP tool, one calling contract — models may only pass
query/scope/recency/imagesLean results —
query/text/citations/sources_used(no raw upstream dump)Custom base URL — official
https://api.x.ai/v1or OpenAI-compatible proxiesOptional vision input — attach https URLs or data URIs (local paths are opt-in)
No PyPI required — run directly from GitHub with
uvx --from git+...
Features
Capability | Notes |
Live web search | Grok synthesizes an answer with source URLs |
Live X search | Included by default; set |
X filters | Handle allow/deny lists (max 20, |
Domain filters | Allowlist or denylist (max 5, mutually exclusive; scheme/path stripped) |
Search media understanding | Images on web pages and X posts; videos on X posts |
Client image input | Optional |
Lean JSON output | No |
Protocol errors | Upstream/validation failures set MCP |
Retries | 429 / 502 / 503 / 504 and transport timeouts, with backoff |
Proxy-friendly |
|
GitHub install |
|
Not included: enable_image_search (web image gallery embedding). Use images when you provide a picture; use enable_image_understanding for images on browsed pages and X posts.
Built With
Related MCP server: WebQuest MCP
Getting Started
Prerequisites
Python 3.10+
An xAI API key (or a key for a compatible gateway)
uv (recommended for
uvxfrom GitHub)
# optional: install uv
curl -LsSf https://astral.sh/uv/install.sh | shQuick start (uvx from GitHub)
No local clone required for day-to-day MCP use:
export GROK_API_KEY=xai-...
uvx --from git+https://github.com/NakanoSanku/grok-web-search-mcp.git grok-web-search-mcpPin a branch, tag, or commit when you need reproducibility:
uvx --from git+https://github.com/NakanoSanku/grok-web-search-mcp.git@main grok-web-search-mcp
# uvx --from git+https://github.com/NakanoSanku/grok-web-search-mcp.git@v0.3.0 grok-web-search-mcpLocal development install
Clone the repository:
git clone https://github.com/NakanoSanku/grok-web-search-mcp.git cd grok-web-search-mcpInstall dependencies:
uv sync # or: pip install -e ".[dev]"Create a local env file:
cp .env.example .envEdit
.envand set at leastGROK_API_KEY(see Configuration).
Configuration
Variable | Required | Default | Description |
| Yes | — | Also accepts |
| No |
| Also |
| No |
| Also |
| No |
| Request timeout in seconds (1–3600). High reasoning + search can need minutes |
| No |
| TCP/TLS connect timeout (capped by |
| No |
| Analyze images on browsed pages and X posts |
| No |
| Default thinking length: |
| No |
| Allow |
| No | cwd | Directory jail for local images when enabled |
| No |
| Retries for 429/5xx/timeouts (0–8) |
| No |
|
|
| No |
| Analyze videos in X posts (operator-only; not a tool argument) |
| No | — | Operator web allowlist (max 5). Callers cannot set this |
| No | — | Operator web denylist (max 5) |
| No | — | Operator X handle allowlist (max 20) |
| No | — | Operator X handle denylist (max 20) |
| No | — | Extra rules appended to the server-owned system prompt |
Keep secrets out of git. Prefer host-injected env for MCP configs when possible.
Usage
Run the Server
Recommended (from GitHub):
export GROK_API_KEY=xai-...
uvx --from git+https://github.com/NakanoSanku/grok-web-search-mcp.git grok-web-search-mcpFrom a local checkout:
export GROK_API_KEY=xai-...
# Windows PowerShell: $env:GROK_API_KEY="xai-..."
uv run grok-web-search-mcp
# or
uv run python -m grok_web_search_mcpCompatible proxy example:
export GROK_API_KEY=sk-xxx
export GROK_BASE_URL=http://127.0.0.1:8317/v1
export GROK_MODEL=grok-4.5
uvx --from git+https://github.com/NakanoSanku/grok-web-search-mcp.git grok-web-search-mcpMCP Host Config
Preferred: run from GitHub with uvx (no local path).
JSON-style hosts (Cursor / Claude Desktop, etc.):
{
"mcpServers": {
"grok-web-search": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/NakanoSanku/grok-web-search-mcp.git",
"grok-web-search-mcp"
],
"env": {
"GROK_API_KEY": "xai-your-key",
"GROK_BASE_URL": "https://api.x.ai/v1",
"GROK_MODEL": "grok-4.5"
}
}
}
}Grok user config (~/.grok/config.toml):
[mcp_servers.grok-web-search]
command = "uvx"
args = [
"--from",
"git+https://github.com/NakanoSanku/grok-web-search-mcp.git",
"grok-web-search-mcp",
]
enabled = true
[mcp_servers.grok-web-search.env]
GROK_API_KEY = "xai-your-key"
GROK_BASE_URL = "https://api.x.ai/v1"
GROK_MODEL = "grok-4.5"Pin a ref (branch / tag / commit):
args = [
"--from",
"git+https://github.com/NakanoSanku/grok-web-search-mcp.git@main",
"grok-web-search-mcp",
]Local development only (absolute path to a checkout):
[mcp_servers.grok-web-search]
command = "uv"
args = [
"run",
"--directory",
"/absolute/path/to/grok-web-search-mcp",
"grok-web-search-mcp",
]
enabled = trueTool: web_search
Every host model must use the same four-key contract. Extra arguments (model, reasoning_effort, system_prompt, domain/handle filters) are rejected. Quality knobs live in environment variables so search behavior does not drift between models.
Parameter | Type | Description |
| string | Required. A natural-language question, 2–600 characters. Not a keyword list ( |
|
| Default |
|
| Default |
| string[]? | Optional picture URLs (http(s) / data URI, max 5). Only if the user provided a picture. |
Canonical example:
{ "query": "What is xAI's latest valuation?" }The server then: normalizes query, injects a fixed system prompt, applies operator filters from env, maps recency to X date bounds, and always uses the configured model / reasoning effort.
images are Responses API input_image parts. Local filesystem paths are disabled by default. This is not “search the web for stock images.”
Response Shape
Success (MCP isError: false, structured content):
{
"query": "What is xAI?",
"text": "...",
"citations": [{"url": "https://x.ai", "title": "xAI"}],
"sources_used": ["web", "x"],
"scope": "all",
"recency": "any"
}Failure is a protocol-level tool error (isError: true) with a short message, for example Grok API error (401): Invalid API key. Incomplete or empty upstream responses are also errors, not silent success.
Intentionally not returned: API key, model, base_url, raw upstream JSON, or annotation blobs (URLs are mined into citations only). Diagnose config outside the tool result (env / host MCP settings / stderr logs).
Python Client Example
import asyncio
from grok_web_search_mcp.client import GrokWebSearchClient
from grok_web_search_mcp.config import Settings
async def main():
async with GrokWebSearchClient(Settings.from_env()) as client:
result = await client.web_search("What is xAI?")
print(result.to_dict())
asyncio.run(main())Real calls consume model + server-side search quota. Unit tests use mocks and do not hit the network.
Development
git clone https://github.com/NakanoSanku/grok-web-search-mcp.git
cd grok-web-search-mcp
uv sync --extra dev
uv run pytest
# live API (optional): GROK_LIVE=1 uv run pytest -m liveProject layout:
src/grok_web_search_mcp/
server.py # MCP tool surface
client.py # Responses API client + image helpers
config.py # Environment settings
tests/Roadmap
Single lean
web_searchMCP toolEnable upstream
web_searchandx_searchby defaultX handle/date filters and image/video understanding
Custom
base_url/ proxy supportDomain allow/deny filters
Optional multimodal image input
Install / run from GitHub via
uvxProtocol-level errors, retries, timeout/reasoning defaults
Local-image jail (disabled by default)
Canonical MCP calling contract (
query/scope/recency/images)Optional Streamable HTTP transport docs/examples
Golden-set evaluation harness for search quality
See the open issues.
Contributing
Contributions are welcome.
Fork the project
Create your feature branch (
git checkout -b feature/AmazingFeature)Commit your changes (
git commit -m 'Add some AmazingFeature')Push to the branch (
git push origin feature/AmazingFeature)Open a Pull Request
Please keep the tool surface lean: prefer one well-documented tool over many thin wrappers.
License
Distributed under the MIT License. See LICENSE for more information.
Acknowledgments
Available Tools
1 toolweb_searchA
Live web and X search via Grok. Returns ok, text (answer), citations (URL list). Optional images: public URL, data:image/...;base64,..., or local file path (max 5) to ask about a picture while searching. Supports web domain filters, X handle/date filters, and reasoning_effort (low/medium/high). Image understanding applies to browsed pages and X posts; video understanding applies to X posts only.
Inputs: query (required), model, images, to_date, +10 more. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 1 tool
Only one tool exists, so there is no possibility of confusion or overlap with other tools.
With a single tool, naming consistency is inherently perfect as there is no pattern to break.
A single tool is slightly minimal but reasonably scoped for a focused web search server, as the tool itself is comprehensive.
The tool covers web search, X search, image understanding, domain and date filters, and reasoning effort, leaving no obvious gaps for its stated purpose.
Related MCP Connectors
Web search API and MCP server for developers building AI agents.
Live AI-native web search with citations. One tool for every MCP client. Flat per-request pricing.
Docs: https://docs.keenable.ai/mcp-server Keenable is a free, remote MCP server that gives agents access to the web index. Search the web with ranked results and date/site filters, then fetch any indexed page as clean markdown. Works out of the box with no account or API key.
Search, read, and act on the web. The Stophy MCP server for agents.
Related MCP Servers
- AlicenseAqualityBmaintenanceAn MCP server that provides real-time web search and X (Twitter) search capabilities via the xAI API.239 npmMIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that exposes powerful web search and scraping tools to AI agents and MCP-compatible clients.Apache 2.0
- AlicenseAqualityCmaintenanceMCP server for live X/Twitter and web search, driven by your locally logged-in Grok CLI and leveraging your X Premium or SuperGrok subscription quota.31MIT
- FlicenseNot gradedqualityDmaintenanceMCP server providing web search, news search, and X/Twitter search capabilities via HTTP or stdio.-