grok-mcp
grok-mcp
封装 xAI Grok API 的 MCP 服务器。允许 Claude 和其他 AI 智能体将思考、规划和实时搜索任务委托给 Grok。
快速开始
在任何设备上添加到 Claude Code 的一行命令:
claude mcp add grok -e XAI_API_KEY=your-key -- npx -y @pkwadsy/grok-mcp你需要从 console.x.ai 获取 xAI API 密钥。
替代方案:项目配置
添加到你项目的 .mcp.json 中:
{
"mcpServers": {
"grok": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@pkwadsy/grok-mcp"],
"env": {
"XAI_API_KEY": "your-xai-api-key"
}
}
}
}Related MCP server: grok-search-mcp
工具
ask_grok
向 Grok 提问,支持可选的文件上下文、网页搜索和 X/Twitter 搜索。
参数 | 类型 | 必需 | 描述 |
| string | 是 | 给 Grok 的问题或任务 |
| string[] | 否 | 包含在上下文中的文件(见下文文件语法) |
| number | 否 | 覆盖最大文件数(默认 50) |
| number | 否 | 覆盖每个文件的最大大小(KB,默认 32) |
| string | 否 | 自定义系统提示词 |
| string | 否 | 使用的模型(默认: |
| boolean | 否 | 网页搜索,默认开启 |
| boolean | 否 | 启用 X/Twitter 搜索 |
check_files
文件解析试运行。验证所有文件并显示大小,而不调用 Grok。如果 check_files 通过,ask_grok 也会通过。
参数 | 类型 | 必需 | 描述 |
| string[] | 是 | 要检查的文件(语法与 |
| number | 否 | 覆盖最大文件数(默认 50) |
| number | 否 | 覆盖每个文件的最大大小(KB,默认 32) |
文件语法
文件以字符串数组形式传递,语法简洁:
语法 | 描述 |
| 整个文件 |
| 第 10 到 30 行 |
| 仅第 10 行 |
| Glob 模式 |
| 绕过单文件大小限制 |
| 结合行范围与强制模式 |
安全限制
限制 | 默认值 | 覆盖方式 |
单次调用文件数 | 50 |
|
单文件大小 | 32 KB |
|
总上下文 | 256 KB | 硬性上限,不可覆盖 |
可用模型
grok-4.20-multi-agent— 多智能体模式,非常适合架构和规划(默认)grok-4.20-reasoning— 旗舰推理模型grok-4.20-non-reasoning— 快速,无推理grok-4.1-fast-reasoning— 更便宜的推理模型grok-4.1-fast-non-reasoning— 最便宜、快速
示例
带文件上下文提问:
prompt: "Review this code for bugs"
files: ["src/index.ts", "src/utils.ts:20-50"]搜索网页:
prompt: "What happened in tech news today?"搜索 X/Twitter:
prompt: "What are people saying about the new React release?"
x_search: true提问前检查文件:
files: ["src/**/*.ts"]许可证
MIT
Available Tools
2 toolsask_grokA
Ask Grok a question. Grok is great for thinking, planning, architecture, and real-time search via web and X/Twitter. Use web_search for current information from the internet. Use x_search to find and analyze posts on X/Twitter. IMPORTANT: Grok has no context about your conversation or codebase. Always include all relevant context directly in the prompt — file contents, error messages, architecture details, constraints, and goals. The more context you provide, the better Grok's response will be. Do not assume Grok knows anything about the current project. Use the files parameter to automatically include file contents with line numbers — this is preferred over pasting code into the prompt. File paths are resolved relative to the server working directory: /app. Responses include a response_id — pass it back as previous_response_id to continue a conversation without resending context.
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The question or task for Grok. Include all relevant context — constraints, background, and goals — since Grok has no access to your conversation or files. Use the files parameter to attach source code rather than pasting it inline | |
| previous_response_id | No | Response ID from a previous ask_grok call. Continues the conversation — Grok remembers all prior context so you don't need to resend files or repeat background. Not supported by multi-agent model (beta limitation) | |
| files | No | Files to include in context. Compact syntax: "path/to/file" (whole file), "path/to/file:10-30" (lines 10-30), "path/to/file:10" (just line 10), "src/**/*.ts" (glob pattern), "large-file.ts:force" (bypass per-file size limit). Paths resolve relative to server cwd. | |
| max_files | No | Override max file count (default 50). Useful when a glob legitimately matches many files | |
| max_file_size | No | Override max per-file size in KB (default 32). Applies to all files without :force suffix | |
| system_prompt | No | Custom system prompt to guide Grok's behavior | |
| model | No | Model to use. Defaults to grok-4.20-multi-agent. Options: grok-4.20-multi-agent, grok-4.20-reasoning, grok-4.20-non-reasoning, grok-4.1-fast-reasoning, grok-4.1-fast-non-reasoning | |
| web_search | No | Web search is enabled by default. Set to false to disable | |
| x_search | No | Enable X/Twitter search to find and analyze posts |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Despite no annotations, the description fully discloses behavioral traits: Grok has no context about conversation or codebase, responses include a response_id for continuation, file inclusion syntax, model options, and search defaults. The limitation of previous_response_id in multi-agent mode is also noted.
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 fairly long but well-organized, using bold for emphasis and clear sections. Every sentence contributes essential information. Could be slightly more concise, but overall efficient for the complexity covered.
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?
For a tool with 9 parameters and no output schema, the description is comprehensive: covers all input aspects, explains the output (response_id), gives continuation guidance, and addresses the critical context limitation. Complete and actionable.
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%, but the description adds substantial value: explains the rationale for using files, provides detailed file path syntax, clarifies the purpose of previous_response_id, and describes model options and search behavior. It enriches the parameter meanings significantly beyond the schema.
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 'Ask Grok a question' and outlines what Grok excels at (thinking, planning, architecture, real-time search). It distinguishes from related tools like web_search and x_search, though they are not listed as siblings on this server. The purpose is specific and 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?
Explicitly provides when to use this tool vs alternatives: 'Use web_search for current information... Use x_search to find and analyze posts.' Also gives critical usage guidance: include full context, use files parameter, how to continue conversations with previous_response_id. No ambiguity.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
check_filesA
Dry-run file resolution. Use this before ask_grok to verify files will resolve correctly and check context size. Uses the same validation as ask_grok — if check_files passes, ask_grok will too. File paths resolve relative to: /app
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | Files to check. Same syntax as ask_grok: "path/to/file", "path/to/file:10-30", "src/**/*.ts", "large-file.ts:force" | |
| max_files | No | Override max file count (default 50) | |
| max_file_size | No | Override max per-file size in KB (default 32) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries full burden. It discloses the tool is a dry-run (non-destructive), verifies file resolution, checks context size, and states that file paths resolve relative to /app. It doesn't detail error behavior or rate limits, but for a simple check tool this is adequate.
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 extremely concise at three sentences, with the primary purpose front-loaded. Every sentence adds essential 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 simplicity, no output schema, and a single sibling, the description covers the core functionality and relationship well. It explains validation equivalence and file resolution. It does not describe the return format, but the overall completeness is sufficient for an agent to use the tool correctly.
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?
The input schema has 100% coverage with detailed descriptions for all three parameters. The description adds an important context note about file paths resolving relative to /app, which is not in the schema. However, this is environmental context rather than parameter semantics, so the baseline 3 is appropriate.
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 the tool performs a 'dry-run file resolution' and explicitly differentiates it from its sibling 'ask_grok' by positioning it as a preparatory verification step. The verb 'check' and noun 'files' are specific.
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?
The description provides explicit usage guidance: 'Use this before ask_grok' and explains that if check_files passes, ask_grok will too. It also notes the same validation logic, giving clear context for when to use this tool versus the alternative.
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.
2 tool updates
v1.4.0- First observed
ask_grok - First observed
check_files
TDQS
Scored across 2 tools
ask_grok and check_files serve clearly distinct purposes: one is for querying Grok, the other is a dry-run validator for file resolution. No overlap or ambiguity.
Both tool names follow a consistent verb_noun pattern (ask_grok, check_files), using underscores and clear verbs.
Only 2 tools feels thin for a server that provides access to Grok, which could benefit from additional tools for conversation management or specialized searches.
The tool set lacks basic conversational features like retrieving history or managing context, and the promised web_search/x_search capabilities are not exposed as separate tools, limiting functionality.
Maintenance
Related MCP Connectors
MCP server for progressive tool usage at any scale (see https://klavis.ai)
MCP server for building and testing AI agents with multi-model experimentation and insights.
The Remote MCP server acts as a standardized bridge between LLM applications (like Claude, ChatGPT, and Cursor) and external services, enabling AI agents to access external tools and resources. Its primary capability is providing a centralized search tool to discover other MCP servers and their respective tools. Unlike local implementations, it runs remotely with OAuth authentication and permission controls for security.
Hosted MCP with 91 agent tools: X, domains, SEO, Maps, Trends, Search, YouTube, TikTok, and more.
Related MCP Servers
- AlicenseAqualityAmaintenanceUse XAI's latest api functionalities with Grok MCP. It supports image understanding and generation, live search, latest models and more.2252MIT
- AlicenseNot gradedqualityCmaintenanceMCP server that enables coding agents to search X/Twitter and the web through the local Grok CLI, providing better search results than default Codex or Claude search without requiring an API key.17 npm6MIT
- AlicenseNot gradedqualityAmaintenanceMCP server for xAI Grok API with 19 tools for chat, web and X search, session management, tool chaining, image and video generation, and documentation.2MIT
- AlicenseNot gradedqualityDmaintenanceA single-file MCP server that enhances Claude Desktop with real-time web and X search, multi-tool agent, and image/video generation via xAI's Grok.MIT