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 MCP ServerSearch for the latest news about SpaceX launches"
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.
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
Tool | Description |
| Generate images using Grok Imagine |
| Chat with Grok models (grok-3, grok-4, grok-3-mini) |
| Analyze and describe images with Grok Vision |
| Real-time web, news, and X/Twitter search |
| Generate 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
Option 2: Install from npm (coming soon)
Configuration for Claude Code
Step 1: Get Your xAI API Key
Go to x.ai/api
Sign up or log in
Create an API key
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
Important: Replace
/absolute/path/to/xai-mcp-serverwith 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
Chat with Grok
Image Analysis
Live Search
Video Generation
Tool Reference
generate_image
Generate images from text descriptions using Grok Imagine.
Parameter | Type | Required | Default | Description |
| string | Yes | - | Text description of the image |
| number | No | 1 | Number of images (1-10) |
| string | No |
| Image generation model |
| string | No | - | Aspect ratio (e.g., "16:9", "1:1", "4:3") |
| string | No |
| Output format: "url" or "b64_json" |
Example Response:
chat
Chat with Grok language models.
Parameter | Type | Required | Default | Description |
| string | Yes | - | Message to send to Grok |
| string | No |
| Model: grok-3, grok-4, grok-3-mini |
| string | No | - | System context/instructions |
| number | No | 0.7 | Sampling temperature (0-2) |
| number | No | - | Maximum response tokens |
analyze_image
Analyze images using Grok's vision capabilities.
Parameter | Type | Required | Default | Description |
| string | Yes | - | Image URL or base64 data URL |
| string | No | "Describe this image" | Question or instruction |
| string | No |
| Detail level: "low", "high", "auto" |
| string | No |
| Vision model |
live_search
Perform real-time web searches using Grok.
Parameter | Type | Required | Default | Description |
| string | Yes | - | Search query |
| array | No |
| Sources: "web", "news", "x" |
| object | No | - | Date filter: |
| number | No | 10 | Maximum results (1-20) |
generate_video
Generate videos from text descriptions.
Parameter | Type | Required | Default | Description |
| string | Yes | - | Video description |
| string | No |
| Video generation model |
| number | No | 5 | Duration in seconds (1-15) |
| string | No | - | Input image URL to animate |
| string | No | - | Input video URL to edit |
| string | No | - | Aspect ratio (e.g., "16:9") |
| boolean | No | true | Wait for video to finish |
Development
Project Structure
Troubleshooting
"XAI_API_KEY environment variable is required"
Ensure your ~/.claude/settings.json includes the env block with your API key:
Tools not appearing in Claude Code
Verify the path in
argsis absolute and correctEnsure the project is built (
npm run build)Restart Claude Code completely
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
xAI for the Grok API
Model Context Protocol for the MCP specification
Anthropic for Claude Code