grok-mcp
A minimal local MCP server that lets Claude Desktop or Claude Code delegate coding tasks to Grok Build running headless as a subagent.
README
grok-mcp
A minimal local MCP server (stdio) that lets Claude Desktop or Claude Code delegate coding tasks to Grok Build running headless as a subagent.
Built for supervising agents: results are ground-truthed against git (no phantom
"files modified"), failures are honest failures, long tasks run as background jobs,
and every result carries a machine-readable structuredContent payload.
Tools
grok_task
| Input | Required | Description |
|---|---|---|
prompt |
yes | The coding task for Grok Build |
cwd |
yes | Absolute path to the target repo/directory |
model |
no | Grok model ID, validated up front. Default: grok-composer-2.5-fast |
permission_mode |
no | See permissions below |
session_id |
no | Session UUID from a previous result — resumes that session with context intact |
background |
no | true → return immediately with a job_id; poll grok_task_result |
timeout_ms |
no | Per-task timeout (default 15 min, clamped 10 s – 2 h) |
effort |
no | low / medium / high (maps to grok's --effort) |
Runs grok --no-auto-update -p "<prompt>" -m <model> -s <uuid> --output-format json
(-r <uuid> when resuming) with the process cwd set to your target repo and your
full user environment, so grok uses your existing OAuth login cached in ~/.grok
(no XAI_API_KEY needed or used).
For anything non-trivial, pass background: true. MCP clients time out long
synchronous requests (typically ~60 s); a timed-out request looks like an error while
the task keeps running and editing files. Background mode sidesteps that entirely. If
a synchronous call does get cancelled mid-run, the job keeps running and the response
tells you the job_id to fetch later — and synchronous runs send MCP progress
notifications, which keeps clients that support them from timing out at all.
grok_task_result
Fetch the outcome of a job: job_id (required), max_wait_ms (default 25 s, max 50 s
per call — call repeatedly while it reports running).
grok_task_status
Non-blocking status. Pass job_id for one job, omit to list all known jobs.
grok_task_cancel
Kill a queued or running job (SIGTERM, then SIGKILL). Returns the git-verified
partial changes the run left on disk. Finished jobs are unaffected.
Job records persist to ~/.grok-mcp/jobs/ (last 100), so grok_task_result
still works after a server restart — including the Claude Desktop restart that a
server upgrade requires. A job that was mid-run when the server died is reported as
failed with stop reason ServerRestart and instructions to verify via git or resume
the session; its outcome was not captured.
Concurrency: jobs in the same cwd run strictly serially. The git snapshot-diff
that makes files_changed trustworthy assumes one writer per working tree, and
parallel grok runs in one repo would conflict anyway. A second job dispatched into
the same directory is queued (the dispatch response says so, and behind which job);
different directories run in parallel freely.
grok_models
Lists valid model IDs from grok's local model cache. grok_task also validates the
model up front and puts the valid IDs in the error message, with a "did you mean"
suggestion for near-misses (composer-2.5 → grok-composer-2.5-fast).
Result payload
Every result includes human-readable text plus structuredContent:
{
"v": 2,
"success": true,
"stop_reason": "EndTurn",
"job_id": "6c8a1268-…",
"session_id": "068253b9-…",
"files_changed": ["a.txt", "b.txt", "c.txt"],
"files_changed_source": "git",
"diff_stat": " 2 files changed, 2 insertions(+), 2 deletions(-)",
"commands_run": ["npm test"],
"duration_ms": 28699,
"model": "grok-composer-2.5-fast",
"context_tokens_used": 21871,
"tool_call_count": 4,
"final_response": "…grok's own summary…",
"response_truncated": false,
"warnings": []
}
v is the payload schema version — check it before parsing if you depend on the
shape. final_response is capped at 16 000 chars (response_truncated: true when
cut). context_tokens_used / tool_call_count come from grok's session signals,
best effort — for budgeting when dispatching many jobs.
files_changedis ground truth, not narration: the server snapshotsgit status --porcelain -uallbefore and after the run and diffs the two (plusgit diff --name-onlyacross any commits the task made). A dirty tree before the run is fine — only new changes are listed.diff_statis scoped to those files. In non-git directories it falls back to parsing grok's session transcript and says so viafiles_changed_source: "transcript".- One deliberate blind spot:
git status --porcelain -ualldoesn't see edits to gitignored files (.env.local, build output, …). If a task only touches ignored files,files_changedis empty — by design, but worth knowing. success: falsemeans it: any run ending with grok'sstopReasonother thanEndTurn(Cancelled, or anything grok adds later) returnsisError: true— even though grok exits 0 in those cases. Changes listed on that path are explicitly labeled partial work: the run stopped before grok considered the task done, and a cancel can land after some edits persisted.commands_runis best-effort transcript parsing (grok's headless output has no tool-call events), scoped to the current turn for resumed sessions.
Prerequisites
- Grok Build CLI installed (
grokbinary, default location~/.grok/bin/grok) - Logged in via OAuth: run
grok loginonce in a terminal - Node.js 18+
Install & build
git clone https://github.com/maikunari/grok-mcp.git
cd grok-mcp
npm install
npm run build
Register in Claude Desktop
Add this to your Claude Desktop config (macOS:
~/Library/Application Support/Claude/claude_desktop_config.json), merging into an
existing mcpServers block if you have one, then fully quit and reopen Claude Desktop:
{
"mcpServers": {
"grok": {
"command": "node",
"args": ["/absolute/path/to/grok-mcp/dist/index.js"]
}
}
}
Tip: Claude Desktop launches MCP servers with a minimal
PATH. If yournodecomes from nvm, Homebrew, or another version manager, use the absolute path to the node binary (find it withwhich node) as thecommandvalue instead of"node".
Register in Claude Code
claude mcp add --scope user grok -- node /absolute/path/to/grok-mcp/dist/index.js
(--scope user makes it available in every project; omit it to register for the
current project only. Takes effect in new sessions.)
Configuration
Optional environment variables (add an "env": { ... } object to the server entry):
| Variable | Default | Purpose |
|---|---|---|
GROK_TASK_TIMEOUT_MS |
900000 (15 min) |
Default per-task timeout (timeout_ms overrides per call) |
GROK_BIN |
~/.grok/bin/grok (falls back to grok on PATH) |
Path to the grok binary |
Headless permissions (verified behavior)
Headless grok has no TTY to answer approval prompts. Verified on Grok Build 0.2.87:
when a tool needs an approval nothing can grant, grok cancels the run — exit code
0, stopReason: "Cancelled", no changes persisted. This server reports that as a
failure, never as a result.
Mode cheat-sheet for coding tasks:
permission_mode |
Headless behavior |
|---|---|
auto |
Recommended. Edits + shell commands complete (verified) |
bypassPermissions |
Everything auto-approved |
acceptEdits |
Edits only — the first shell command cancels the whole run (verified) |
default / omitted |
Uses the user's global config; cancels on any unapproved tool |
Alternative to per-call modes: enable global auto-approve in ~/.grok/config.toml
(applies to all grok sessions, including interactive ones):
[ui]
permission_mode = "always-approve"
Note: a project-scoped <repo>/.grok/config.toml cannot carry permission
settings — grok only reads [mcp_servers] from project config (verified against
0.2.87 docs). The server never creates or modifies any config file; if no
auto-approval is detected, the result includes a warning instead.
Auth
Uses your existing Grok Build OAuth login (token cached in ~/.grok/auth.json). If a
task fails with the auth-expired message, run grok login in a terminal and retry.
Development
npm run test:cli pins the grok CLI behavior this server depends on (3 short real
grok calls): -s creates new sessions and errors already in use on existing ones,
-r resumes with context. Grok's own README claims -s resumes — its --help is
correct and this server follows it. If grok ever changes -s to resume, this test
fails loudly instead of the server breaking quietly.
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 模型以安全和受控的方式获取实时的网络信息。