Skip to main content
Glama

Grok MCP Server

npm version Node.js License: MIT

A Model Context Protocol (MCP) server that brings xAI's Grok API into Claude Code as native tools.

Ask Grok questions, generate images with Aurora, run multi-round consensus analysis, and explore available models — directly from your terminal.


Tools

Tool

Description

ask_grok

Send a prompt to Grok with optional system prompt and sampling parameters

generate_image

Generate images using Grok's Aurora model and save them locally

list_models

List all xAI models available to your account

grok_consensus

Run a full Consensus Validation Protocol (CVP) for deep, multi-round analysis

grok_validate

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 energy

The 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 strict

Supports 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

  • xAI API key — get one at console.x.ai

Setup

Option A: Install from npm

npm install -g askgrokmcp

Then register with Claude Code:

claude mcp add grok -e XAI_API_KEY=your_api_key_here -- grok-mcp

Option B: Clone from source

git clone https://github.com/marceloceccon/askgrokmcp.git
cd askgrokmcp
npm install

Then register with Claude Code:

claude mcp add grok -e XAI_API_KEY=your_api_key_here -- node /path/to/askgrokmcp/grok-mcp.mjs

Replace /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.

Usage

Once registered, you can use the tools naturally in Claude Code:

Ask Grok a question

> ask grok what the latest news in AI are

Use 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 500

Use a specific model for one call

> ask grok to summarize this document using grok-3

Generate an image

> ask grok to generate an image of a sunset over mountains and save it as images/sunset.png

Generate multiple variations

> ask grok to generate 4 variations of a logo for a coffee shop and save them as images/logo.png

When 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 rounds

List available models

> list the available grok models
> list grok chat models only
> list grok image models

Model Selection

The server uses a three-level priority system for model selection:

Priority

Mechanism

Scope

1st (highest)

model argument in the tool call

Single request

2nd

GROK_CHAT_MODEL / GROK_IMAGE_MODEL env vars

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

grok-4.3

grok-4.3

Image generation

grok-imagine-image-quality

grok-imagine-image-quality

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-mcp

Override per call

Just tell Claude which model to use:

> ask grok to explain quantum computing using model grok-3

Or 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-images

Or 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-mcp

Note: Absolute paths that resolve outside the allowed base directory are rejected. Use relative paths (e.g. images/output.png) or set SAFE_WRITE_BASE_DIR explicitly.

Configuration

Variable

Default

Description

XAI_API_KEY

(required)

Your xAI API key

GROK_CHAT_MODEL

grok-4.3

Default model for ask_grok, grok_consensus, and grok_validate

GROK_IMAGE_MODEL

grok-imagine-image-quality

Default model for generate_image

SAFE_WRITE_BASE_DIR

process.cwd()

Base directory for image writes

XAI_REQUEST_TIMEOUT_MS

30000

Timeout per xAI API request in milliseconds

XAI_MAX_RETRIES

2

Number of retries for transient errors (429/5xx/network/timeout)

XAI_RETRY_BASE_DELAY_MS

500

Base delay for exponential retry backoff

LOG_REQUESTS

false

Logs tool/xAI request metadata to stderr

LOG_REQUEST_PAYLOADS

false

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=true

To also log full request payloads (including prompts), explicitly enable:

export LOG_REQUESTS=true
export LOG_REQUEST_PAYLOADS=true

Important: 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
  src/tools.js           Tool definitions and handler implementations
  protocols/             Protocol documentation
    consensus-validation.md
  grok-mcp.test.mjs     Test suite

How 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 xAI API requests and returns the results.

flowchart LR
    A[Claude Code] -- stdio --> B[grok-mcp.mjs]
    B -- HTTPS --> C[xAI API]

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 results

License

MIT

Available Tools

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

ParametersJSON Schema
NameRequiredDescriptionDefault
promptYesThe question or prompt to send to Grok
system_promptNoOptional system prompt to set Grok's behavior and persona for this request.
modelNoChat model to use for this request. Defaults to "grok-4.3". Use list_models to see available chat models.
temperatureNoSampling temperature (0-2). Lower values make output more deterministic. Default: model-dependent.
max_tokensNoMaximum number of tokens to generate in the response.
top_pNoNucleus sampling: only consider tokens with cumulative probability up to this value (0-1).

TDQS

B3.3/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description bears full responsibility. It discloses that the tool supports system prompts and sampling parameters, but does not describe response format, rate limits, authentication needs, or any behavioral traits beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is three concise sentences with no wasted words. It front-loads the core purpose and efficiently lists supported parameters and additional guidance.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 6 parameters, no output schema, and no annotations, the description is adequate but incomplete. It covers default model and parameter types, but lacks details on output format, error handling, or behavioral constraints for a chat tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

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 minimal extra meaning: it mentions the default model 'grok-4.3' and that system prompt is optional, but otherwise does not enhance understanding of temperature, max_tokens, or top_p beyond their schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool asks Grok a question and gets a response, and mentions default model and supported parameters. However, it does not differentiate from siblings like grok_consensus or grok_validate, which limits clarity on when to use this specific tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage is implied: ask a question and get a response. It suggests using list_models for model options, but provides no explicit guidance on when to use this tool versus alternatives like grok_consensus, nor any exclusion criteria.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
promptYesText description of the image to generate
file_pathYesPath where the image file should be saved. Relative paths resolve from cwd; absolute paths must be within SAFE_WRITE_BASE_DIR (or cwd if unset). Example: images/output.png
nNoNumber of image variations to generate (1-10, default 1)
modelNoImage model to use for this request. Defaults to "grok-imagine-image-quality". Use list_models to see available image models.

TDQS

B3.4/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so the description must carry the behavioral disclosure burden. It mentions saving to local file and default model, but omits critical details like file overwrite behavior, supported formats, permissions, rate limits, or error handling.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences with no unnecessary words. The most important action ('generate an image... and save to a local file') is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema and the description does not mention return value. Given the tool creates and saves a file, missing info on what is returned (e.g., saved path, success status) reduces completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema covers 100% of parameters with clear descriptions. The description adds useful context about default model and linking to list_models, but does not provide significant additional meaning beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it generates an image using Grok's Aurora model and saves to file. It distinguishes from sibling tools (ask_grok, grok_consensus, grok_validate, list_models) which serve different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives guidance on using the 'model' parameter to switch image models, but does not provide explicit when-to-use or when-not-to-use instructions relative to siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

grok_consensusA

Runs a full iterative Consensus Validation Protocol (CVP) between Claude and Grok. Returns a structured final summary. Default 3-5 rounds. Supports custom round count via the 'rounds' argument.

ParametersJSON Schema
NameRequiredDescriptionDefault
topicYesThe topic, claim, or question to analyze through the consensus protocol.
roundsNoNumber of analysis rounds to run. Omit for the default (3 rounds). Higher values (up to 10) yield deeper analysis at the cost of latency.

TDQS

A3.9/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description discloses the iterative nature, default round count, and customizable rounds, but lacks details on costs (latency), model participation specifics, and limitations. With no annotations, the description carries full burden but falls short of full transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences long, front-loads the core function and return type, and avoids redundancy. Every sentence provides essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a multi-round consensus protocol between two models, the description provides basic understanding but omits details on output structure, round mechanics, and use case scenarios. Adequate but not comprehensive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds value beyond the schema by clarifying default rounds (3-5) and explaining the trade-off for higher round counts (deeper analysis vs. latency). Both parameters are covered in schema, so this additional context is beneficial.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool runs an iterative Consensus Validation Protocol between two models, which distinguishes it from siblings like ask_grok (simple Q&A) and generate_image (image generation). It specifies the return type (structured final summary) and key parameters.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is for deep analysis requiring consensus but does not explicitly state when to use it over alternatives or provide exclusions. Siblings are named but no comparative guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
artifactYesThe artifact to validate (code, plan, research output, prompt, PR description, etc.)
criteriaNoOptional focus areas or custom evaluation criteria (e.g. 'security, performance, maintainability')
referenceNoOptional reference output from another model for side-by-side comparison
roundsNoNumber of validation rounds (1-10, default 5). Higher = deeper analysis.
rubricNoEvaluation style preset (default: balanced)

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It adequately describes outcomes (scored scorecard, identifies weaknesses, returns improved version) and mentions the default model. It could be more explicit about side effects (e.g., does not modify the original artifact), but overall it provides sufficient behavioral disclosure for a non-destructive analysis tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise: three sentences covering function, outputs, and usage recommendation. It front-loads the core action and avoids any fluff. Every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given there is no output schema, the description adequately explains return value (scored scorecard, identified weaknesses, improved version). With 5 parameters (1 required) and no nested objects, the description covers the essential context. It could benefit from mentioning the output format or that the artifact is not mutated, but it is sufficient for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly. The description adds no additional semantic detail beyond the schema (e.g., it doesn't elaborate on valid values for 'rounds' or 'rubric'), making it merely adequate. The default model mention is not a parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it runs a validation protocol on any artifact, produces a scorecard, identifies weaknesses, and returns an improved version. The verb 'validate' and resource 'artifact' are specific, and it distinguishes from siblings like 'ask_grok' (Q&A) and 'generate_image' (image generation).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly recommends use as a 'mandatory quality gate before shipping complex work,' providing clear when-to-use guidance. It does not explicitly state when not to use, but the sibling tool list (ask_grok, generate_image, etc.) implies alternatives. The default model mention adds useful context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
filterNoFilter models by capability. 'chat' returns language/reasoning models, 'image' returns image generation models, 'all' returns everything (default).

TDQS

A4.1/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries the burden. It discloses listing with IDs and capabilities and filtering, but does not mention permissions, rate limits, or side effects. For a read-only listing, this is adequate but not exceptional.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, front-loaded with main purpose, no redundant information. Efficient and clear.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple tool (one optional parameter, no output schema, siblings that are consumers), the description fully covers what an agent needs: purpose, filter usage, and integration with other tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% and the description adds context by linking filter values to model types ('chat' for language models, 'image' for image generation). This adds value beyond the schema description but is minor, so baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool 'List all xAI models available to your account', specifying the verb 'List' and the resource 'xAI models'. It distinguishes from siblings by mentioning they consume the model IDs (ask_grok, generate_image).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use: 'to discover which models you can pass to ask_grok or generate_image'. Provides filter options but does not explicitly state when not to use, though context is clear.

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.

  1. 5 tool updatesv1.5.0
    • First observedask_grok
    • First observedgenerate_image
    • First observedgrok_consensus
    • First observedgrok_validate
    • First observedlist_models

TDQS

A4/5.0
Disambiguation5/5

Each tool has a clearly distinct purpose: Q&A, image generation, consensus validation, artifact validation, and model listing. No overlap or ambiguity.

Naming Consistency4/5

All names use lowercase with underscores, but there is a slight inconsistency: most tools follow verb_noun (ask_grok, generate_image, list_models) while two start with the product prefix 'grok_' (grok_consensus, grok_validate), breaking the verb-first pattern.

Tool Count5/5

5 tools is well-scoped for a server that wraps Grok API functionality—enough to cover key interactions without bloat.

Completeness5/5

The tool surface covers core Grok capabilities: query, image generation, consensus, validation, and model discovery. No obvious missing operations for the intended scope.

Maintenance

ActivityMaintained
ResponsivenessNo issues

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

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Integrates 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.
    5
    40
    1
    MIT
  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    Enables 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.
    -
  • F
    license
    B
    quality
    Not graded
    maintenance
    Integrates 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.
    2
    48
    1
    -

Latest Blog Posts

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/entropyvortex/askgrokmcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server