xAI MCP Server

xAI MCP Server

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.

Category
访问服务器

README

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_image Generate images using Grok Imagine
chat Chat with Grok models (grok-3, grok-4, grok-3-mini)
analyze_image Analyze and describe images with Grok Vision
live_search Real-time web, news, and X/Twitter search
generate_video 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: Quick Install (Recommended)

curl -fsSL https://raw.githubusercontent.com/joemccann/xai-mcp-server/main/install.sh | bash

This installs the server and automatically configures Claude Code. You'll be prompted for your xAI API key.

Option 2: npx from GitHub

No installation needed - runs directly from GitHub:

npx github:joemccann/xai-mcp-server

Option 3: npm Global Install

npm install -g @joemccann/xai-mcp-server

Option 4: Clone and Build

git clone https://github.com/joemccann/xai-mcp-server.git
cd xai-mcp-server
npm install

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

Note: If you used the Quick Install (Option 1), this is already done for you.

Add the MCP server to your Claude Code settings file:

Location: ~/.claude/settings.json

Using npx from npm (no install needed):

{
  "mcpServers": {
    "xai": {
      "command": "npx",
      "args": ["-y", "@joemccann/xai-mcp-server"],
      "env": {
        "XAI_API_KEY": "xai-your-api-key-here"
      }
    }
  }
}

Using npx from GitHub:

{
  "mcpServers": {
    "xai": {
      "command": "npx",
      "args": ["-y", "github:joemccann/xai-mcp-server"],
      "env": {
        "XAI_API_KEY": "xai-your-api-key-here"
      }
    }
  }
}

If installed globally via npm:

{
  "mcpServers": {
    "xai": {
      "command": "xai-mcp-server",
      "env": {
        "XAI_API_KEY": "xai-your-api-key-here"
      }
    }
  }
}

If cloned/installed locally:

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

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.

Parameter Type Required Default Description
prompt string Yes - Text description of the image
n number No 1 Number of images (1-10)
model string No grok-2-image Image generation model
aspect_ratio string No - Aspect ratio (e.g., "16:9", "1:1", "4:3")
response_format string No url Output 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.

Parameter Type Required Default Description
message string Yes - Message to send to Grok
model string No grok-3 Model: grok-3, grok-4, grok-3-mini
system_prompt string No - System context/instructions
temperature number No 0.7 Sampling temperature (0-2)
max_tokens number No - Maximum response tokens

analyze_image

Analyze images using Grok's vision capabilities.

Parameter Type Required Default Description
image_url string Yes - Image URL or base64 data URL
prompt string No "Describe this image" Question or instruction
detail string No auto Detail level: "low", "high", "auto"
model string No grok-2-vision-1212 Vision model

live_search

Perform real-time web searches using Grok.

Parameter Type Required Default Description
query string Yes - Search query
sources array No ["web"] Sources: "web", "news", "x"
date_range object No - Date filter: { start, end } (YYYY-MM-DD)
max_results number No 10 Maximum results (1-20)

generate_video

Generate videos from text descriptions.

Parameter Type Required Default Description
prompt string Yes - Video description
model string No grok-2-video Video generation model
duration number No 5 Duration in seconds (1-15)
image string No - Input image URL to animate
video string No - Input video URL to edit
aspect_ratio string No - Aspect ratio (e.g., "16:9")
wait_for_completion boolean No true Wait 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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选