Skip to main content
Glama

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 搜索。

参数

类型

必需

描述

prompt

string

是

给 Grok 的问题或任务

files

string[]

否

包含在上下文中的文件(见下文文件语法)

max_files

number

否

覆盖最大文件数(默认 50)

max_file_size

number

否

覆盖每个文件的最大大小(KB,默认 32)

system_prompt

string

否

自定义系统提示词

model

string

否

使用的模型(默认:grok-4.20-multi-agent)

web_search

boolean

否

网页搜索,默认开启

x_search

boolean

否

启用 X/Twitter 搜索

check_files

文件解析试运行。验证所有文件并显示大小,而不调用 Grok。如果 check_files 通过,ask_grok 也会通过。

参数

类型

必需

描述

files

string[]

是

要检查的文件(语法与 ask_grok 相同)

max_files

number

否

覆盖最大文件数(默认 50)

max_file_size

number

否

覆盖每个文件的最大大小(KB,默认 32)

文件语法

文件以字符串数组形式传递,语法简洁:

语法

描述

"src/index.ts"

整个文件

"src/index.ts:10-30"

第 10 到 30 行

"src/index.ts:10"

仅第 10 行

"src/**/*.ts"

Glob 模式

"large-file.ts:force"

绕过单文件大小限制

"large-file.ts:1-100:force"

结合行范围与强制模式

安全限制

限制

默认值

覆盖方式

单次调用文件数

50

max_files 参数

单文件大小

32 KB

max_file_size 参数或 :force 后缀

总上下文

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 tools
ask_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.

Inputs: prompt (required), previous_response_id, files, max_files, +5 more.

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

Inputs: files (required), max_files, max_file_size.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 2 tools

    Disambiguation5/5

    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.

    Naming Consistency5/5

    Both tool names follow a consistent verb_noun pattern (ask_grok, check_files), using underscores and clear verbs.

    Tool Count3/5

    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.

    Completeness2/5

    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

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers