xAI Grok MCP Bridge
This server bridges the local grok CLI to an MCP host (e.g., Claude Code), allowing you to use Grok as a sub-agent for AI-powered tasks directly from your MCP environment.
grok_ask: Start a new headless Grok session with a prompt. Supports model selection, workspace, session ID, max turns, reasoning effort, custom rules, timeout, and raw output.grok_continue: Resume a previous or most-recent Grok session with a follow-up prompt, by explicit session ID or automatic continuation.grok_code_review: Submit code or diffs for a strict second-opinion review targeting correctness, security, and regression risks. Uses tuned offline-review rules (web search disabled), supports optional prior analysis, configurablemax_findings(1–10), and aself_checkextra verification loop.grok_version: Retrieve the version of the locally installedgrokCLI.
Additional features across tools:
Specify a workspace/project directory for Grok to inspect (defaults to server's current directory).
Use
raw_outputmode to get debug payloads including stdout, stderr, return codes, and parsed JSON.Inject custom run-scoped rules into Grok's system prompt.
Set the
XAI_MCP_DEBUGenvironment variable to diagnose bridge startup or CLI invocation issues.
Click on "Install 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., "@xAI Grok MCP BridgeReview this TypeScript function for potential null pointer errors"
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.
x.ai Grok CLI MCP Bridge
Use the local grok CLI as an MCP sub-agent from Claude Code or any MCP host.
This server wraps the documented x.ai headless scripting mode. The generic tools use JSON output,
while grok_code_review uses plain output because it produced better review results in practice.
grok --no-auto-update --prompt-file /tmp/prompt.md --cwd /path/to/project --output-format jsonRequirements
Python 3.10+
grokonPATHAuth already configured with
grok login, or an environment supported by the CLI such asXAI_API_KEYOptional:
GROK_CLI_PATHifgrokis not onPATH
GROK_CLI_PATH is strict: bare commands resolve through PATH, while path values must point to an
executable file. Directories and non-executable files are rejected.
Related MCP server: peer-agents-mcp
Install
cd /Users/zvisegal/devlope/XAIMsp
/opt/homebrew/bin/python3.12 -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip
pip install -e ".[dev]"
pytest -q -p no:cacheprovider
ruff check --no-cache .MCP Host Config
Add this server to the MCP host config. Prefer the project venv Python:
{
"mcpServers": {
"xai": {
"command": "/Users/zvisegal/devlope/XAIMsp/.venv/bin/python",
"args": ["/Users/zvisegal/devlope/XAIMsp/server.py"]
}
}
}Tools
grok_ask(prompt, workspace?, timeout_s?, model?, session_id?, max_turns?, reasoning_effort?, rules?, raw_output?)grok_continue(prompt, workspace?, timeout_s?, model?, resume?, max_turns?, reasoning_effort?, rules?, raw_output?)grok_code_review(code_or_diff, question?, primary_analysis?, workspace?, timeout_s?, model?, max_findings?, reasoning_effort?, self_check?, raw_output?)grok_version()
workspace defaults to the MCP server's current directory. Pass the project path explicitly when
you want Grok to inspect a specific repo.
Use grok_code_review as a second-opinion reviewer after CodeHelper or manual analysis. It embeds
strict offline-review rules in the prompt, disables web search, and uses --prompt-file.
Advanced parameters:
self_check=true: Passes--checkfor an extra Grok verification loop. Use sparingly because it costs more time and quota.raw_output=true: Returns a debug payload with extracted text, stdout, stderr, return code, and parsed JSON when available.session_idandresume: Useful for explicit Grok session control.session_idshould be a valid UUID for new sessions.rules: Available on generic ask/continue calls. Prefergrok_code_reviewfor second-opinion code review because it already uses the tuned offline-review prompt.
Set XAI_MCP_DEBUG=true only when diagnosing bridge startup or CLI invocation issues.
See CLAUDE_CODE_USAGE.md for the recommended Claude Code workflow and CLAUDE_CODE_UPDATE_GROK_PATH.md for the latest path-handling update.
Security
Grok is an agentic CLI. workspace is a working directory, not a security boundary. The bridge
does not expose --always-approve through MCP tools. Use grok_code_review with focused snippets
or diffs, and verify findings before editing code.
Smoke Test
This makes a real Grok call and may use quota:
python test_smoke.pyAvailable Tools
4 toolsgrok_askB
Ask Grok a prompt in a new headless CLI session.
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | Optional Grok model id passed to `--model`. | grok-4.5 |
| rules | No | Optional run-scoped rules appended to Grok's system prompt. | |
| prompt | Yes | The question or task for Grok. | |
| max_turns | No | Optional limit for agent turns. | |
| timeout_s | No | Maximum seconds to wait. Default 300, capped at 600. | |
| workspace | No | Working directory for Grok. Defaults to this server's cwd. | |
| raw_output | No | Return text plus raw stdout/stderr and parsed JSON when true. | |
| session_id | No | Optional UUID for a new named headless session. | |
| reasoning_effort | No | Optional reasoning effort string passed through. |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations provided, so description bears full responsibility. It only mentions a 'new headless CLI session' but omits behavioral traits like session handling, timeout behavior, authentication needs, or raw output characteristics.
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?
A single sentence that is concise but lacks structure. It could be expanded with a brief example or key options without losing conciseness.
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 complexity (9 parameters) and presence of output schema, the description is minimally adequate. It doesn't highlight common use cases or important parameters, but combined with schema it is acceptable for a straightforward prompting tool.
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 description coverage is 100%, so baseline is 3. The description adds no extra meaning beyond the input schema; it does not explain parameters like model, rules, or raw_output.
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 verb 'Ask', the resource 'Grok', and the context 'new headless CLI session'. It effectively distinguishes from sibling tools like grok_continue (which implies continuation) and grok_code_review.
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?
No explicit guidance on when to use this tool vs alternatives like grok_continue or grok_code_review. The phrase 'new headless CLI session' hints at one-shot usage, but lacks clear when-to-use or when-not-to-use instructions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
grok_code_reviewA
Ask Grok for a strict second-opinion code review.
This tool is intended to run after CodeHelper or manual analysis. It sends
strict run-scoped review rules, disables web search, and passes large
prompts via --prompt-file.
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | Optional Grok model id passed to `--model`. | grok-4.5 |
| question | No | Review focus. | Find concrete correctness, security, and regression risks. |
| timeout_s | No | Maximum seconds to wait. Default 300, capped at 600. | |
| workspace | No | Working directory for Grok. Defaults to this server's cwd. | |
| raw_output | No | Return text plus raw stdout/stderr when true. | |
| self_check | No | Pass `--check` for an extra verification loop. Costs more time/quota. | |
| code_or_diff | Yes | Code, diff, or focused snippets to review. | |
| max_findings | No | Maximum findings to request. Must be 1-10. | |
| primary_analysis | No | Optional CodeHelper/manual findings to challenge. | |
| reasoning_effort | No | Optional reasoning effort string passed through. | high |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Without annotations, the description discloses key behaviors: sends strict rules, disables web search, uses `--prompt-file` for large prompts. This adds value beyond a simple verb definition and helps the agent understand the tool's operation.
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?
Two sentences with no wasted words. Front-loaded with purpose and context, every sentence serves a purpose.
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 10 parameters (1 required) and an output schema, the description covers core purpose, usage order, and behavioral quirks. It could mention error handling or quotas, but the schema and output schema compensate well.
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 description coverage is 100%, so baseline is 3. Description adds some context (e.g., 'passes large prompts via `--prompt-file`'), but does not significantly enhance understanding beyond the schema's detailed parameter 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?
Description clearly states it is a strict second-opinion code review tool, distinguishing it from siblings like general Q&A (grok_ask) or continuation (grok_continue). It specifies verb 'Ask Grok for... code review' and resource 'code_or_diff'.
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 says 'intended to run after CodeHelper or manual analysis', providing clear context for when to use it. Does not explicitly state when not to use, but sibling tools imply alternatives (e.g., grok_ask for general questions).
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
grok_continueC
Continue a Grok headless session.
If resume is provided, resumes that session id. Otherwise passes
--continue, which continues the most recent session in the workspace.
| Name | Required | Description | Default |
|---|---|---|---|
| model | No | grok-4.5 | |
| rules | No | ||
| prompt | Yes | ||
| resume | No | ||
| max_turns | No | ||
| timeout_s | No | ||
| workspace | No | ||
| raw_output | No | ||
| reasoning_effort | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
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 explains the two continuation modes but does not disclose behavioral traits like session state mutation, rate limits, or data persistence. It lacks details on side effects of continuing a session.
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 with two sentences. The first sentence states the purpose, and the second explains two modes. Zero wasted words, and it is well-structured for quick parsing.
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 complexity (9 parameters, no annotations) and presence of an output schema, the description lacks essential context. It does not define what a 'headless session' is, how to obtain a session ID, or what the output contains. It assumes prior knowledge, leaving the agent underinformed.
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 description coverage is 0%, so the description must compensate. It only explains the 'resume' parameter and implies a '--continue' behavior, but fails to describe the other 8 parameters including the required 'prompt'. This is insufficient for a 9-parameter tool.
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's purpose: continuing a Grok headless session. It specifies two modes (resume or --continue), providing a specific verb and resource. However, it does not explicitly distinguish from siblings like grok_ask, but the purpose is clear enough.
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 explains two usage scenarios (resume a specific session or continue the most recent) but offers no guidance on when to use this tool compared to alternatives like grok_ask. There is no mention of prerequisites or when not to use it.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
grok_versionA
Return the installed Grok CLI version.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Description fully discloses the tool's behavior: it returns the installed version. No annotations are present, but the description covers all relevant aspects (read-only, no side effects). For a tool of this simplicity, transparency is complete.
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?
A single, clear sentence that is front-loaded and avoids any unnecessary words. Every part of the description is meaningful and concise.
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 has an output schema (not shown but indicated) and zero parameters, the description is complete. It suffices for an agent to understand the tool's purpose and usage without ambiguity.
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?
Input schema has zero parameters with 100% coverage, so no parameter descriptions are needed. Description does not add anything beyond the schema, but baseline for 0 params is 4.
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?
Tool name 'grok_version' and description 'Return the installed Grok CLI version' clearly identify the verb (Return) and resource (Grok CLI version). It is distinct from sibling tools like grok_ask, grok_code_review, and grok_continue.
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 explicit when-to-use or when-not-to-use guidance is provided, the simple nature of a version check and the sibling tools' different purposes make usage obvious. Could be improved by mentioning that it requires no arguments and is safe to call anytime.
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.
4 tool updates
v0.1.0- First observed
grok_ask - First observed
grok_code_review - First observed
grok_continue - First observed
grok_version
TDQS
Each tool has a distinct purpose: general prompting, code review, session continuation, and version checking. No overlap in functionality.
All tools follow a consistent pattern: 'grok_' prefix with snake_case verb or noun suffixes (ask, code_review, continue, version).
4 tools is on the lower end but still appropriate for a focused bridge to a CLI tool. Could be expanded slightly but not under-scoped.
Core operations are covered: prompting, code review, session continuation, and version info. Missing session management or configuration tools but minimal for the domain.
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
- QuallaaOAuthcom.quallaa
Talk to your public-facing AI from any MCP client — Claude, ChatGPT, Cursor, Cline, Windsurf.
Source-checked CLI guides and model-aware planning for Claude Code, Codex, and Grok Build.
Use AI models for chat, image, and video generation from Claude Code and other MCP hosts.
Shared memory and actions for Claude, Kiro, OpenAI, Cursor, and other MCP-compatible AI clients.
1
Related MCP Servers
- AlicenseAqualityCmaintenanceMCP server that wraps the Grok CLI to enable code review, adversarial testing, and chat with xAI's Grok model, integrating into any MCP host as a peer reviewer, adversary, and consultant.49111MIT
- FlicenseBqualityBmaintenanceEnables AI coding tools to call Grok and Antigravity CLIs as peer reviewers for code review, planning, debugging, and collaborative sessions.13-
- AlicenseNot gradedqualityAmaintenanceEnables Codex to use Grok Build CLI as a controlled subagent via MCP tools for independent investigation, review, and isolated implementation tasks.4MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to generate text, images, and videos via Grok's web UI using MCP tools (grok_chat, grok_generate_image, grok_generate_video) without an API key.MIT
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/segalz/XAIMsp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server