MCP Hub
Back to servers

xai-mcp-server

MCP server for xAI Grok APIs - image generation, chat, vision, search, and video for Claude Code

glama
Updated
Jan 31, 2026

xAI MCP Server

A Model Context Protocol (MCP) server that brings xAI's Grok APIs to Claude Code. Generate images, chat with Grok, analyze images, search the web, and create videos—all from natural language prompts in your Claude Code session.

Features

ToolDescription
generate_imageGenerate images using Grok Imagine
chatChat with Grok models (grok-3, grok-4, grok-3-mini)
analyze_imageAnalyze and describe images with Grok Vision
live_searchReal-time web, news, and X/Twitter search
generate_videoGenerate videos from text prompts

Prerequisites

  • Node.js 18.0.0 or higher
  • xAI API Key from x.ai/api
  • Claude Code installed

Installation

Option 1: Clone and Build

# Clone the repository
git clone https://github.com/joemccann/xai-mcp-server.git
cd xai-mcp-server

# Install dependencies
npm install

# Build
npm run build

Option 2: Install from npm (coming soon)

npm install -g xai-mcp-server

Configuration for Claude Code

Step 1: Get Your xAI API Key

  1. Go to x.ai/api
  2. Sign up or log in
  3. Create an API key
  4. Copy the key (starts with xai-)

Step 2: Configure Claude Code

Add the MCP server to your Claude Code settings file:

Location: ~/.claude/settings.json

{
  "mcpServers": {
    "xai": {
      "command": "node",
      "args": ["/absolute/path/to/xai-mcp-server/dist/index.js"],
      "env": {
        "XAI_API_KEY": "xai-your-api-key-here"
      }
    }
  }
}

Important: Replace /absolute/path/to/xai-mcp-server with the actual path where you cloned the repository.

Step 3: Restart Claude Code

Restart Claude Code to load the new MCP server. You should see the xAI tools available.

Usage

Once configured, you can use natural language to invoke xAI capabilities:

Image Generation

Generate an image of a cyberpunk cityscape at night with neon lights.
Using grok imagine, create a watercolor painting of a mountain landscape.
Generate 3 variations of a logo for a coffee shop called "Bean There".

Chat with Grok

Ask Grok to explain the theory of relativity in simple terms.
Have Grok write a haiku about programming.

Image Analysis

Analyze this image and describe what you see: https://example.com/photo.jpg
What text is visible in this screenshot: [image URL]

Live Search

Search for the latest news about SpaceX launches.
Find recent tweets about the new iPhone release.
Search the web for Python best practices 2024.

Video Generation

Generate a 5-second video of clouds moving across a blue sky.
Create a video animation of a bouncing ball.

Tool Reference

generate_image

Generate images from text descriptions using Grok Imagine.

ParameterTypeRequiredDefaultDescription
promptstringYes-Text description of the image
nnumberNo1Number of images (1-10)
modelstringNogrok-2-imageImage generation model
aspect_ratiostringNo-Aspect ratio (e.g., "16:9", "1:1", "4:3")
response_formatstringNourlOutput format: "url" or "b64_json"

Example Response:

{
  "success": true,
  "images": [
    {
      "index": 1,
      "url": "https://api.x.ai/images/generated/abc123.png",
      "revised_prompt": "A detailed cyberpunk cityscape..."
    }
  ]
}

chat

Chat with Grok language models.

ParameterTypeRequiredDefaultDescription
messagestringYes-Message to send to Grok
modelstringNogrok-3Model: grok-3, grok-4, grok-3-mini
system_promptstringNo-System context/instructions
temperaturenumberNo0.7Sampling temperature (0-2)
max_tokensnumberNo-Maximum response tokens

analyze_image

Analyze images using Grok's vision capabilities.

ParameterTypeRequiredDefaultDescription
image_urlstringYes-Image URL or base64 data URL
promptstringNo"Describe this image"Question or instruction
detailstringNoautoDetail level: "low", "high", "auto"
modelstringNogrok-2-vision-1212Vision model

live_search

Perform real-time web searches using Grok.

ParameterTypeRequiredDefaultDescription
querystringYes-Search query
sourcesarrayNo["web"]Sources: "web", "news", "x"
date_rangeobjectNo-Date filter: { start, end } (YYYY-MM-DD)
max_resultsnumberNo10Maximum results (1-20)

generate_video

Generate videos from text descriptions.

ParameterTypeRequiredDefaultDescription
promptstringYes-Video description
modelstringNogrok-2-videoVideo generation model
durationnumberNo5Duration in seconds (1-15)
imagestringNo-Input image URL to animate
videostringNo-Input video URL to edit
aspect_ratiostringNo-Aspect ratio (e.g., "16:9")
wait_for_completionbooleanNotrueWait for video to finish

Development

# Install dependencies
npm install

# Build TypeScript
npm run build

# Watch mode (rebuild on changes)
npm run dev

# Run the server directly
npm start

Project Structure

xai-mcp-server/
├── src/
│   ├── index.ts           # MCP server entry point
│   ├── xai-client.ts      # xAI API client with types
│   └── tools/
│       ├── generate-image.ts
│       ├── chat.ts
│       ├── vision.ts
│       ├── live-search.ts
│       └── generate-video.ts
├── dist/                  # Compiled JavaScript
├── package.json
├── tsconfig.json
└── README.md

Troubleshooting

"XAI_API_KEY environment variable is required"

Ensure your ~/.claude/settings.json includes the env block with your API key:

"env": {
  "XAI_API_KEY": "xai-your-key-here"
}

Tools not appearing in Claude Code

  1. Verify the path in args is absolute and correct
  2. Ensure the project is built (npm run build)
  3. Restart Claude Code completely
  4. Check Claude Code logs for MCP connection errors

API errors

  • Verify your API key is valid at x.ai
  • Check you have sufficient API credits
  • Some features may require specific API tier access

API Reference

This server uses the xAI API. For full API documentation, see:

License

MIT

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Acknowledgments

Reviews

No reviews yet

Sign in to write a review