BeClaude

grok-mcp

New
Community RegistryGeneralby Morten

Integrate xAI's Grok models into Claude Code for multi-model collaboration

First seen 6/6/2026

Summary

Grok-MCP integrates xAI's Grok models directly into Claude Code, enabling multi-model collaboration for enhanced reasoning, debugging, and code generation.

  • Developers can leverage Grok's specialized models for faster or more accurate responses, with built-in cost tracking and caching to optimize usage.

Overview

A Claude Code plugin that integrates xAI's Grok models for multi-model collaboration.

Features

  • Natural language triggers: "Ask Grok...", "What does Grok think..."
  • Direct commands: /query, /review, /debug, /design for quick Grok queries
  • Model selection: Choose from fast, smartest, code-optimized, or reasoning models
  • Model-aware timeouts: 90s for slow grok-4, 30s for fast models
  • Smart streaming: Auto-enables streaming for complex queries
  • Cost tracking: See token usage and cost estimates for every query
  • Response caching: Reduce costs with intelligent caching

Installation

Prerequisites

  1. xAI API Key: Get one from console.x.ai
  2. Claude Code: Version with plugin support

Install from GitHub

bash
# Add the plugin marketplace
/plugin marketplace add mortenbrudvik/ClaudeGrokMcp

# Install the plugin
/plugin install grok-mcp@grok-mcp-dev

# Restart Claude Code

Set API Key

Add to your environment or Claude Code settings:

macOS/Linux (bash/zsh):

bash
export XAI_API_KEY=xai-your-key-here

Windows PowerShell:

powershell
$env:XAI_API_KEY = "xai-your-key-here"

Windows Command Prompt:

cmd
set XAI_API_KEY=xai-your-key-here

Or configure in Claude Code (works on all platforms):

bash
/config set PLUGIN_ENV_XAI_API_KEY=xai-your-key-here

Usage

Natural Language

Just ask Claude to use Grok:

code
"Ask Grok what the best practices are for error handling in TypeScript"

"Have Grok analyze this function for bugs"

"What does Grok think about this architecture?"

/grok Command

bash
# Simple query
/grok What is the time complexity of merge sort?

# Specify model
/grok --model fast Explain what a mutex is

# Code analysis
/grok --model code Review this function: function add(a,b) { return a-b }

# Extended reasoning
/grok --model reasoning Think through microservices vs monolith trade-offs

Model Aliases

AliasModelBest ForPricing (per 1M tokens)
autogrok-4General queries$3.00 / $15.00
fastgrok-4-fastQuick responses$0.20 / $0.50
smartestgrok-4Complex analysis$3.00 / $15.00
codegrok-code-fast-1Programming tasks$0.20 / $1.50
reasoninggrok-4-1-fast-reasoningMulti-step thinking (2M context)$0.20 / $0.50
cheapgrok-4-fastBudget-conscious$0.20 / $0.50
visiongrok-4Image/vision analysis$3.00 / $15.00

MCP Tools

grok_query

Query Grok with a question or prompt. Supports vision/image analysis.

typescript
{
  query: string,           // Required: The question to ask
  model?: string,          // Model alias or ID (default: "auto")
  context?: string,        // System context to guide response
  max_tokens?: number,     // Max response tokens (default: 4096)
  temperature?: number,    // Sampling temperature 0-2 (default: 0.7)
  image_url?: string,      // Image URL or base64 data URI for vision
  image_detail?: string    // Detail level: "auto", "low", "high"
}

grok_analyze_code

Analyze code for bugs, performance issues, security vulnerabilities, and style problems.

typescript
{
  code: string,            // Required: The code to analyze
  language?: string,       // Programming language (auto-detected)
  analysis_type?: string,  // "performance", "bugs", "security", "style", "all"
  context?: string,        // Additional context about the code
  model?: string           // Model to use (default: grok-code-fast-1)
}

grok_reason

Perform extended reasoning and deep thinking on complex problems.

typescript
{
  query: string,           // Required: The problem to reason through
  effort?: string,         // "low", "medium", "high" (default: "medium")
  show_thinking?: boolean, // Include reasoning trace (default: true)
  context?: string,        // Additional context
  model?: string           // Model to use (default: grok-4-1-fast-reasoning)
}

grok_estimate_cost

Estimate the cost of a Grok query before execution.

typescript
{
  query: string,           // Required: The query to estimate
  model?: string,          // Model to use (default: auto)
  context?: string,        // Additional context
  max_tokens?: number      // Expected output tokens
}

grok_execute_code

Execute Python code server-side for calculations and testing.

typescript
{
  code: string,            // Required: Python code to execute
  description?: string,    // What the code should accomplish
  include_output?: boolean,// Include stdout/stderr (default: true)
  max_turns?: number,      // Max iterations 1-10 (default: 3)
  model?: string           // Model to use (default: grok-4-1-fast)
}

grok_search_x

Search X/Twitter and web using Grok agentic search.

typescript
{
  query: string,              // Required: Search query
  enable_x_search?: boolean,  // Search X/Twitter (default: true)
  enable_web_search?: boolean,// Search web (default: false)
  x_handles?: string[],       // Filter by X handles
  from_date?: string,         // Start date filter
  to_date?: string,           // End date filter
  include_citations?: boolean // Include source citations (default: true)
}

grok_with_file

Query Grok with file content as context.

typescript
{
  query: string,           // Required: Question about the file
  file_content: string,    // Required: File content as text
  filename?: string,       // Original filename for format detection
  file_type?: string,      // "code", "text", "markdown", "json", "csv", "xml", "yaml"
  context?: string,        // Additional context
  model?: string,          // Model to use
  max_tokens?: number,     // Max response tokens (default: 4096)
  temperature?: number     // Sampling temperature (default: 0.7)
}

grok_models

List available models with capabilities and pricing.

typescript
{
  refresh?: boolean  // Force refresh from API (default: false)
}

grok_status

Get current status of the Grok MCP plugin.

typescript
{
  include_details?: boolean  // Include detailed breakdown (default: false)
}

grok_generate_image

Generate images from text descriptions.

typescript
{
  prompt: string,            // Required: Text description of image to generate
  n?: number,                // Number of images 1-10 (default: 1)
  model?: string,            // Model to use (default: grok-2-image-1212)
  response_format?: string   // "url" or "b64_json" (default: "url")
}

Configuration

Environment Variables

VariableDefaultDescription
XAI_API_KEYRequiredYour xAI API key
XAI_BASE_URLhttps://api.x.ai/v1API base URL
XAI_TIMEOUTModel-awareDefault timeout (90s for grok-4, 30s for fast models)
GROK_CACHE_ENABLEDtrueEnable response caching
GROK_COST_LIMIT_USD10Session cost limit
GROK_API_TIERstandardAPI tier (standard/enterprise)

Rate Limits

TierTokens/MinuteRequests/Minute
Standard500,000500
Enterprise10,000,00010,000

Response Format

Every query returns:

code
[Grok's response]

---
Model: grok-4-fast
Tokens: 150 in / 342 out (492 total)
Cost: $0.0002
Response time: 1234ms

Examples

Code Review

code
/grok --model code Review this function:

function fibonacci(n) {
  if (n <= 1) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}

Architecture Discussion

code
Ask Grok to analyze the trade-offs between using Redis vs Memcached for session storage

Multi-Model Collaboration

code
I want both your perspective and Grok's on whether to use TypeScript strict mode

Development

Build

bash
cd mcp
npm install
npm run build

Project Structure

code
grok-mcp/
├── .claude-plugin/
│   ├── plugin.json        # Plugin manifest
│   └── marketplace.json   # Dev marketplace
├── skills/
│   └── using-grok/
│       └── SKILL.md       # Natural language skill
├── commands/
│   ├── query.md           # /grok-mcp:query command
│   ├── review-with-grok.md # /grok-mcp:review-with-grok
│   ├── debug-with-grok.md  # /grok-mcp:debug-with-grok
│   └── design-review.md    # /grok-mcp:design-review
├── mcp/
│   ├── package.json
│   ├── tsconfig.json
│   └── src/
│       ├── index.ts       # MCP server entry
│       ├── client/
│       │   └── xai-client.ts
│       ├── services/      # Cache, cost tracking, rate limiting
│       ├── tools/
│       │   ├── query.ts   # grok_query tool
│       │   ├── models.ts  # grok_models tool
│       │   ├── analyze-code.ts
│       │   ├── reason.ts
│       │   └── ...        # 10 tools total
│       └── types/
│           └── index.ts
└── README.md

Troubleshooting

"XAI_API_KEY is required"

Set your API key (see Set API Key above for platform-specific commands), or use:

bash
/config set PLUGIN_ENV_XAI_API_KEY=xai-your-key-here

"Rate limit exceeded"

The plugin automatically retries with exponential backoff. For heavy usage, consider enterprise tier.

"Model not found"

Use grok_models to see current available models. Model IDs change periodically.

Plugin not loading

  1. Verify installation: /plugin list
  2. Check MCP status: /mcp
  3. Restart Claude Code

License

MIT

Links

Install & Usage

1
Open your MCP config
~/.claude.json
2
Add the server config

Add the configuration to "mcpServers": { "grok-mcp": { "command": "...", "args": [] } }

3
Restart Claude Code
/mcp

Use Cases

Ask Grok for best practices on a specific programming language or framework during development.
Use Grok to review and debug complex code snippets, leveraging its reasoning model for deeper analysis.
Generate alternative design patterns or architecture suggestions by querying Grok alongside Claude.
Quickly fetch up-to-date technical documentation or API references using Grok's fast model.
Compare code outputs from Claude and Grok to identify potential improvements or edge cases.
Optimize token usage and monitor costs when running frequent Grok queries in large projects.

Usage Examples

1

/grok-mcp query 'What are the best practices for error handling in Python async code?'

2

/grok-mcp review --model grok-4 'Review this function for potential race conditions: [code snippet]'

3

Ask Grok to design a REST API endpoint for user authentication with JWT tokens.

View source on GitHub
mcp

Security Audits

LicenseUnknownSourceWarnRepositoryPass

Frequently Asked Questions

What is grok-mcp?

Grok-MCP integrates xAI's Grok models directly into Claude Code, enabling multi-model collaboration for enhanced reasoning, debugging, and code generation. Developers can leverage Grok's specialized models for faster or more accurate responses, with built-in cost tracking and caching to optimize usage.

How to install grok-mcp?

To install grok-mcp: open your mcp config (~/.claude.json), then add the config to "mcpServers": { "grok-mcp": { "command": "...", "args": [] } }. Finally, /mcp in Claude Code.

What is grok-mcp best for?

grok-mcp is a mcp categorized under General. It is designed for: mcp. Created by Morten.

What can I use grok-mcp for?

grok-mcp is useful for: Ask Grok for best practices on a specific programming language or framework during development.; Use Grok to review and debug complex code snippets, leveraging its reasoning model for deeper analysis.; Generate alternative design patterns or architecture suggestions by querying Grok alongside Claude.; Quickly fetch up-to-date technical documentation or API references using Grok's fast model.; Compare code outputs from Claude and Grok to identify potential improvements or edge cases.; Optimize token usage and monitor costs when running frequent Grok queries in large projects..