askgrokmcp
Click on "Deploy 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., "@askgrokmcp what are the latest AI news?"
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.
Grok MCP Server
A Model Context Protocol (MCP) server that brings Grok into Claude Code as native tools.
Two backends:
Backend | Meter | Set with |
xAI API | Prepaid API credits |
|
| The Grok subscription, including Imagine |
|
Ask Grok questions, generate images, run multi-round consensus analysis, and explore available models — directly from your terminal. The CLI backend generates images with Imagine. It does not generate video.
Tools
Tool | Description |
| Send a prompt to Grok with optional system prompt and sampling parameters |
| Generate images and save them locally. The API backend calls Aurora. The CLI backend calls Imagine |
| List all xAI models available to your account |
| Run a full Consensus Validation Protocol (CVP) for deep, multi-round analysis |
| Run a rigorous multi-round Validation Protocol on any artifact (code, plan, prompt, PR) with scorecard + improved version |
Related MCP server: xAI MCP Server
Built-in Protocols
Consensus Validation Protocol (CVP)
The grok_consensus tool implements a structured, multi-round analysis protocol. Instead of a single prompt-and-response, it runs 3-10 iterative rounds where Grok progressively deepens its analysis — challenging its own assumptions, evaluating evidence strength, and synthesizing a balanced conclusion.
> Run CVP on whether large language models can reason
> Ask Grok to validate the claim that sleep deprivation affects decision-making — use 5 rounds
> Consensus check with Grok on the future of nuclear energyThe entire protocol executes server-side in a single tool call. Each round builds on the full conversation history for genuine iterative refinement.
Default: 3 rounds | Max: 10 rounds | Full protocol documentation
Validation Protocol
The grok_validate tool runs a rigorous, multi-round quality gate on any artifact — code, plans, research, prompts, PR descriptions, architectures. Grok produces a scored scorecard (correctness, completeness, innovation/risk, clarity, best practices), identifies critical issues, and returns an improved version ready to copy-paste.
> grok_validate with artifact is [paste your plan or code here]
> grok_validate with artifact is [auth module] criteria is security, input validation rubric is security-focused
> grok_validate with artifact is [your plan] reference is [original output] rounds is 6 rubric is strictSupports four rubric presets: balanced (default), strict, innovative, and security-focused. An optional reference argument enables side-by-side comparison with another model's output.
Default: 5 rounds | Max: 10 rounds
Prerequisites
Node.js >= 18
Claude Code CLI installed
API backend: an xAI API key from console.x.ai
CLI backend: the grok CLI and a completed
grok login
Setup
Option A: Install from npm
npm install -g askgrokmcpThen register with Claude Code:
claude mcp add grok -e XAI_API_KEY=your_api_key_here -- grok-mcpOption B: Clone from source
git clone https://github.com/marceloceccon/askgrokmcp.git
cd askgrokmcp
npm installThen register with Claude Code:
claude mcp add grok -e XAI_API_KEY=your_api_key_here -- node /path/to/askgrokmcp/grok-mcp.mjsReplace /path/to/askgrokmcp with the actual path where you cloned the repository.
Replace your_api_key_here with your xAI API key in either option. That's it — the tools are now available in Claude Code and bill API credits.
Option C: Claude Code plugin (subscription)
Use this when you want text and Imagine images to draw from the Grok subscription instead of API credits.
git clone https://github.com/marceloceccon/askgrokmcp.git
cd askgrokmcp
npm install
grok loginFrom Claude Code, add this repository as a marketplace and install the plugin:
/plugin marketplace add /path/to/askgrokmcp
/plugin install askgrok@askgrokmcpThe plugin starts bin/plugin-start.mjs with GROK_BACKEND=cli. On a fresh checkout that has no node_modules, the launcher runs npm install once. Its output stays on stderr.
XAI_API_KEY in the environment is removed from the grok child process, so a key used by other tools does not switch these calls onto API credits.
temperature, max_tokens, and top_p belong to the API backend. The CLI backend rejects them. Imagine chooses the image model. Pass model to ask_grok to select a chat model from list_models.
Usage
Once registered, you can use the tools naturally in Claude Code:
Ask Grok a question
> ask grok what the latest news in AI areUse a system prompt
> ask grok to review this code, using a system prompt that says "You are a senior security auditor"Control sampling parameters
> ask grok to generate test data with temperature 0 and max_tokens 500Use a specific model for one call
> ask grok to summarize this document using grok-3Generate an image
> ask grok to generate an image of a sunset over mountains and save it as images/sunset.pngGenerate multiple variations
> ask grok to generate 4 variations of a logo for a coffee shop and save them as images/logo.pngWhen generating multiple images, files are automatically numbered (e.g., logo-1.png, logo-2.png, ...).
Run a consensus analysis
> run CVP on the effectiveness of carbon capture technology
> ask grok to validate whether quantum computers will break RSA by 2030 — use 5 roundsList available models
> list the available grok models
> list grok chat models only
> list grok image modelsModel Selection
The server uses a three-level priority system for model selection:
Priority | Mechanism | Scope |
1st (highest) |
| Single request |
2nd |
| Server lifetime |
3rd (default) | Built-in defaults (see below) | Fallback |
Built-in defaults
At startup the server probes the xAI /models endpoint and selects the best available model:
Purpose | Frontier (preferred) | Fallback |
Chat |
|
|
Image generation |
|
|
If the frontier model is not available on your account, the server automatically falls back to the safe default.
Change defaults via environment variable
claude mcp add grok \
-e XAI_API_KEY=your_api_key_here \
-e GROK_CHAT_MODEL=grok-3 \
-e GROK_IMAGE_MODEL=grok-2-image \
-- grok-mcpOverride per call
Just tell Claude which model to use:
> ask grok to explain quantum computing using model grok-3Or use list_models first to discover what's available, then pick one.
File write safety
By default the server only writes images inside the current working directory (the directory Claude Code was launched from) and its subdirectories. Any path that resolves outside that directory is rejected with a clear error.
To allow writes to a different location, set the SAFE_WRITE_BASE_DIR environment variable to an absolute path:
export SAFE_WRITE_BASE_DIR=/tmp/my-imagesOr pass it directly when registering the server:
claude mcp add grok \
-e XAI_API_KEY=your_api_key_here \
-e SAFE_WRITE_BASE_DIR=/tmp/my-images \
-- grok-mcpNote: Absolute paths that resolve outside the allowed base directory are rejected. Use relative paths (e.g.
images/output.png) or setSAFE_WRITE_BASE_DIRexplicitly.
Configuration
Variable | Default | Description |
|
|
|
| (required for | xAI API key. Ignored for |
|
| CLI binary used when |
|
| Default model for |
|
| Image model for the API backend. The CLI backend uses Imagine |
|
| Timeout for a text or |
|
| Base timeout for Imagine. Each extra image adds 60 seconds, up to 15 minutes |
|
| Turn cap for text CLI calls |
|
| Base directory for image writes |
|
| Timeout per xAI API request in milliseconds |
|
| Number of retries for transient errors (429/5xx/network/timeout) |
|
| Base delay for exponential retry backoff |
|
| Logs tool and backend request metadata to stderr |
|
| Includes full request payloads in logs (use carefully) |
Request logging
Request logging is optional and disabled by default.
Enable metadata-only logs:
export LOG_REQUESTS=trueTo also log full request payloads (including prompts), explicitly enable:
export LOG_REQUESTS=true
export LOG_REQUEST_PAYLOADS=trueImportant: Logs are written to stderr (not stdout) so MCP protocol communication remains safe.
Project Structure
askgrokmcp/
grok-mcp.mjs Server entry point, config, HTTP client
bin/plugin-start.mjs Claude Code plugin launcher (GROK_BACKEND=cli)
.claude-plugin/plugin.json Plugin manifest
.claude-plugin/marketplace.json
skills/ask-grok/SKILL.md When to call ask, consensus, validate, or Imagine
src/tools.js Tool definitions and handlers
src/cli-backend.js grok CLI subscription backend
protocols/ Protocol documentation
consensus-validation.md
grok-mcp.test.mjs API-path test suite
src/cli-backend.test.mjs CLI backend test suiteHow it works
This server implements the MCP protocol over stdio. When Claude Code starts, it launches the server as a subprocess and communicates with it via JSON-RPC over stdin/stdout. The server translates MCP tool calls into either xAI API requests or a headless grok CLI run.
flowchart LR
A[Claude Code] -- stdio --> B[grok-mcp.mjs]
B -- HTTPS --> C[xAI API]
B -- grok CLI --> D[Grok subscription]On the CLI backend, text tools run grok with tools denied and a one-directory scratch pad, so the coding agent does not edit the project. generate_image runs grok with only the image_gen tool inside a temporary directory, then copies the image through the same path sandbox as the API backend. Multi-round tools send the transcript so far on each turn.
For the grok_consensus tool, the server manages a multi-round conversation loop with Grok internally, returning the complete analysis in a single response:
sequenceDiagram
participant C as Claude Code
participant S as grok-mcp
participant G as xAI API
C->>S: grok_consensus(topic, rounds)
loop Each round
S->>G: chat/completions (with full history)
G-->>S: Round analysis
end
S-->>C: Structured CVP resultsLicense
Available Tools
5 toolsask_grokB
Ask Grok a question and get a response. Default model: grok-4.3. Supports system prompts and sampling parameters (temperature, max_tokens, top_p). Run list_models to see all available model options.
Inputs: prompt (required), model, top_p, max_tokens, +2 more.
generate_imageB
Generate an image using Grok's Aurora image model and save it to a local file. Default model: grok-imagine-image-quality. Use the optional 'model' parameter to use a different image model.
Inputs: prompt (required), file_path (required), n, model.
grok_consensusB
Runs a full iterative Consensus Validation Protocol (CVP) between Claude and Grok. Returns a structured final summary. Default 3 rounds, maximum 10. Supports custom round count via the 'rounds' argument.
Inputs: topic (required), rounds.
grok_validateA
Runs a rigorous Validation Protocol on any artifact (code, plan, research, prompt, PR, architecture, etc.). Produces a scored scorecard, identifies weaknesses, and returns an improved version. Use this as your mandatory quality gate before shipping complex work. Default model: grok-4.3.
Inputs: artifact (required), rounds, rubric, criteria, +1 more.
list_modelsA
List all xAI models available to your account, including their IDs and capabilities. Use this to discover which models you can pass to ask_grok or generate_image. You can also filter by type: 'chat' for language models or 'image' for image generation.
Inputs: filter.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
The three Grok-query tools (ask_grok, grok_consensus, grok_validate) all ultimately call Grok, but their descriptions carve out distinct roles: single question, multi-round consensus, and scored validation scorecard. The boundary between ask_grok with a review-style prompt and grok_validate is the only real point of confusion, and generate_image/list_models are unambiguous.
Most names are verb_noun snake_case (generate_image, ask_grok, list_models), but grok_consensus and grok_validate invert the pattern with a resource prefix, and the 'grok_' prefix is applied inconsistently. Readable overall, but the convention is mixed.
Five tools is a tight, well-scoped surface for a Grok API wrapper: chat, image generation, model discovery, and two higher-level workflow tools. Each tool has a clear reason to exist and nothing feels padded or missing at the count level.
Core lifecycle for the domain is covered: discover models, ask questions, generate images, and run validation/consensus workflows. Minor gaps remain — no multi-turn conversation continuation, no image/vision input, no streaming or token/usage inspection — but agents can work around these.
Maintenance
Related MCP Connectors
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.
Agent personas for Claude. 16 tools, 13 personas, 3 workflows. Zero extra API cost. Free.
Live SEO workflow tools for Claude Code, Codex, and AI agents.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceIntegrates Google Gemini API capabilities into Claude Code, supporting text generation, image analysis, and AI image creation. It features specialized tools for creative brainstorming and managing multi-turn chat sessions.-
- AlicenseAqualityDmaintenanceIntegrates xAI's Grok APIs into Claude Code to enable image and video generation, real-time web searches, and multi-modal image analysis. It provides a suite of tools for interacting with Grok models directly through natural language prompts during a Claude session.555 npm1MIT
- AlicenseNot gradedqualityNot gradedmaintenanceEnables Claude to query Grok as a peer for collaborative reasoning, code reviews, and architecture debates. It provides access to real-time web research and multiple specialized reasoning modes through the xAI API.-
- FlicenseBqualityNot gradedmaintenanceIntegrates Grok AI into Claude Code to enable real-time X/Twitter search and deep analysis of social media links. It supports a dual-mode architecture featuring a browser-based free mode for SuperGrok subscribers and a cost-controlled API mode.216 npm1-