grok-web-search-mcp
语言: 英文 | 中文
关于项目
智能体需要带引用的实时网页和 X 访问,而不仅仅是聊天补全。本项目将 xAI 服务端的 web_search 和 x_search 工具封装为一个 MCP 工具,因此 Grok、Cursor 或 Claude Desktop 等主机无需嵌入 xAI 客户端逻辑即可调用它们。
仓库: https://github.com/NakanoSanku/grok-web-search-mcp
上游调用(简化):
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
}
]
}设计目标:
一个 MCP 工具,一个调用契约 — 模型只能传递
query/scope/recency/images精简结果 —
query/text/citations/sources_used(无原始上游转储)自定义基础 URL — 官方
https://api.x.ai/v1或 OpenAI 兼容代理可选视觉输入 — 附加 https URL 或 data URI(本地路径为可选)
无需 PyPI — 直接通过
uvx --from git+...从 GitHub 运行
特性
能力 | 说明 |
实时网页搜索 | Grok 综合答案并附上来源 URL |
实时 X 搜索 | 默认包含;设置 |
X 过滤器 | 处理允许/拒绝列表(最多 20 个, |
域名过滤器 | 允许列表或拒绝列表(最多 5 个,互斥;去除 scheme/path) |
搜索媒体理解 | 网页和 X 帖子上的图片;X 帖子上的视频 |
客户端图片输入 | 可选 |
精简 JSON 输出 | 工具结果中不包含 |
协议错误 | 上游/验证失败会设置 MCP |
重试 | 429 / 502 / 503 / 504 和传输超时,带退避 |
代理友好 |
|
GitHub 安装 |
|
不包含: enable_image_search(网页图片库嵌入)。当你提供图片时使用 images;对浏览页面和 X 帖子上的图片使用 enable_image_understanding。
构建工具
Related MCP server: WebQuest MCP
快速开始
前置要求
Python 3.10+
xAI API 密钥(或兼容网关的密钥)
uv(推荐用于从 GitHub 使用
uvx)
# optional: install uv
curl -LsSf https://astral.sh/uv/install.sh | sh快速启动(从 GitHub 使用 uvx)
日常 MCP 使用无需本地克隆:
export GROK_API_KEY=xai-...
uvx --from git+https://github.com/NakanoSanku/grok-web-search-mcp.git grok-web-search-mcp需要可复现性时,固定分支、标签或提交:
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-mcp本地开发安装
克隆仓库:
git clone https://github.com/NakanoSanku/grok-web-search-mcp.git cd grok-web-search-mcp安装依赖:
uv sync # or: pip install -e ".[dev]"创建本地环境文件:
cp .env.example .env编辑
.env并至少设置GROK_API_KEY(参见 配置)。
配置
变量 | 必需 | 默认值 | 说明 |
| 是 | — | 也接受 |
| 否 |
| 也接受 |
| 否 |
| 也接受 |
| 否 |
| 请求超时(秒,1–3600)。高推理 + 搜索可能需要几分钟 |
| 否 |
| TCP/TLS 连接超时(受 |
| 否 |
| 分析浏览页面和 X 帖子上的图片 |
| 否 |
| 默认思考长度: |
| 否 |
| 允许 |
| 否 | cwd | 启用时本地图片的目录限制 |
| 否 |
| 429/5xx/超时的重试次数(0–8) |
| 否 |
|
|
| 否 |
| 分析 X 帖子中的视频(仅操作员;不是工具参数) |
| 否 | — | 操作员网页允许列表(最多 5 个)。调用者不能设置此选项 |
| 否 | — | 操作员网页拒绝列表(最多 5 个) |
| 否 | — | 操作员 X 句柄允许列表(最多 20 个) |
| 否 | — | 操作员 X 句柄拒绝列表(最多 20 个) |
| 否 | — | 附加到服务器拥有的系统提示词中的额外规则 |
将密钥保留在 git 之外。尽可能优先使用主机注入的环境变量来配置 MCP。
用法
运行服务器
推荐(从 GitHub):
export GROK_API_KEY=xai-...
uvx --from git+https://github.com/NakanoSanku/grok-web-search-mcp.git grok-web-search-mcp从本地检出:
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_mcp兼容代理示例:
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 主机配置
首选:使用 uvx 从 GitHub 运行(无需本地路径)。
JSON 风格主机(Cursor / Claude Desktop 等):
{
"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 用户配置(~/.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"固定引用(分支 / 标签 / 提交):
args = [
"--from",
"git+https://github.com/NakanoSanku/grok-web-search-mcp.git@main",
"grok-web-search-mcp",
]仅限本地开发(检出的绝对路径):
[mcp_servers.grok-web-search]
command = "uv"
args = [
"run",
"--directory",
"/absolute/path/to/grok-web-search-mcp",
"grok-web-search-mcp",
]
enabled = true工具:web_search
每个主机模型必须使用相同的四键契约。额外参数(model、reasoning_effort、system_prompt、域名/句柄过滤器)会被拒绝。质量旋钮位于环境变量中,因此搜索行为不会在模型之间漂移。
参数 | 类型 | 说明 |
| string | 必需。 自然语言问题,2–600 个字符。不是关键词列表( |
|
| 默认 |
|
| 默认 |
| string[]? | 可选的图片 URL(http(s) / data URI,最多 5 个)。仅当用户提供了图片时使用。 |
规范示例:
{ "query": "What is xAI's latest valuation?" }服务器随后:规范化 query,注入固定系统提示词,应用来自环境变量的操作员过滤器,将 recency 映射到 X 日期范围,并始终使用配置的模型 / 推理努力。
images 是 Responses API 的 input_image 部分。本地文件系统路径默认禁用。这不是“搜索网页获取库存图片”。
响应结构
成功(MCP isError: false,结构化内容):
{
"query": "What is xAI?",
"text": "...",
"citations": [{"url": "https://x.ai", "title": "xAI"}],
"sources_used": ["web", "x"],
"scope": "all",
"recency": "any"
}失败是协议级别的工具错误(isError: true),带有简短消息,例如 Grok API error (401): Invalid API key。不完整或为空的上游响应同样属于错误,而非静默成功。
有意不返回:API key、model、base_url、原始上游 JSON 或注释数据块(URL 仅被提取到 citations 中)。请在工具结果之外诊断配置(环境变量 / 宿主 MCP 设置 / stderr 日志)。
Python 客户端示例
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())真实调用会消耗模型和服务端搜索配额。单元测试使用 mock,不会访问网络。
开发
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 live项目结构:
src/grok_web_search_mcp/
server.py # MCP tool surface
client.py # Responses API client + image helpers
config.py # Environment settings
tests/路线图
单一精简的
web_searchMCP 工具默认启用上游
web_search和x_searchX 账号/日期过滤以及图像/视频理解
自定义
base_url/ 代理支持域名允许/拒绝过滤器
可选的多模态图像输入
通过
uvx从 GitHub 安装 / 运行协议级错误、重试、超时/推理默认值
本地图像 jail(默认禁用)
规范的 MCP 调用约定(
query/scope/recency/images)可选的 Streamable HTTP 传输文档/示例
用于搜索质量的黄金集评估框架
参见开放问题。
贡献
欢迎贡献。
Fork 本项目
创建你的功能分支(
git checkout -b feature/AmazingFeature)提交你的更改(
git commit -m 'Add some AmazingFeature')推送到分支(
git push origin feature/AmazingFeature)打开一个 Pull Request
请保持工具表面精简:优先选择一个文档完善的工具,而不是许多薄封装。
许可证
基于 MIT 许可证分发。更多信息请参阅 LICENSE。
致谢
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.
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | Optional model override (default from GROK_MODEL / grok-4.5). | |
| query | Yes | Natural-language search question or topic. | |
| images | No | Optional image input(s) for visual questions: URL / data-URI / local path (comma or newline separated, max 5). Not an image-search API. | |
| to_date | No | Optional inclusive X search end date (YYYY-MM-DD). | |
| from_date | No | Optional inclusive X search start date (YYYY-MM-DD). | |
| image_detail | No | Vision detail for input images: low | high | auto (default high). | |
| system_prompt | No | Optional system instruction prepended to the request. | |
| allowed_domains | No | Optional comma-separated allowlist (max 5). Mutually exclusive with excluded_domains. | |
| excluded_domains | No | Optional comma-separated denylist (max 5). | |
| reasoning_effort | No | Optional thinking length for reasoning models: low | medium | high. | |
| allowed_x_handles | No | Optional comma-separated X handle allowlist (max 20). Mutually exclusive with excluded_x_handles. | |
| excluded_x_handles | No | Optional comma-separated X handle denylist (max 20). | |
| enable_image_understanding | No | Analyze images found on browsed pages and X posts (default on). | |
| enable_video_understanding | No | Analyze videos found in X posts (default off). |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries full burden. It discloses return format, image handling constraints (max 5, types), and scoping of image/video understanding. It lacks explicit mention of read-only nature but is otherwise transparent.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is concise (6 sentences), front-loaded with core purpose, and every sentence adds meaningful information without redundancy.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's complexity (14 parameters, optional features) and the presence of an output schema, the description covers most behavioral aspects. Minor gaps exist (e.g., rate limits, indexing scope), but overall it is thorough.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so baseline is 3. The description adds value by summarizing key parameters (domain filters, reasoning_effort) and clarifying behavior of image/video understanding fields, which are not detailed in schema descriptions.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states it performs 'Live web and X search via Grok' and details return values. It uses a specific verb (search) and resource (web and X), and the purpose is unambiguous.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
While no sibling tools exist for comparison, the description provides clear context on features and filters, sufficiently guiding usage. It could benefit from explicit when-not-to-use, but the absence of alternatives makes this less critical.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
1 tool update
v0.1.0- First observed
web_search
TDQS
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.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
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.
Scrape, crawl and search the web for AI agents via MCP.
Related MCP Servers
- AlicenseAqualityDmaintenanceAn MCP server that provides real-time web search and X (Twitter) search capabilities via the xAI API.228MIT
- AlicenseNot gradedqualityCmaintenanceA Model Context Protocol server that exposes powerful web search and scraping tools to AI agents and MCP-compatible clients.Apache 2.0
- AlicenseAqualityBmaintenanceMCP 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 gradedqualityCmaintenanceMCP server providing web search, news search, and X/Twitter search capabilities via HTTP or stdio.-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/NakanoSanku/grok-web-search-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server