Access Grok API for Image, Search, and Reasoning
Grok-MCP is an MCP server for xAI's Grok API: web/X search, vision, image and video generation, and file support.
1.0.3Add to Favorites
Why it matters
Integrate with the xAI Grok API to leverage advanced capabilities including image understanding, image generation, real-time search, and sophisticated reasoning models.
Outcomes
What it gets done
Analyze images using natural language queries.
Generate images from text descriptions.
Perform real-time internet searches with source citations.
Engage in stateful conversations with reasoning models.
Source
Get it from source
Spark does not host a copy of it.
Open sourceReports
Agent outcome reports
No reports yet
Capabilities
Tools your agent gets
List all available Grok models with creation dates and owner information
Standard chat completion with extensive customization capabilities
Get detailed reasoning along with the response
Analyze images using natural language queries
Create images from text descriptions
Real-time internet search with source citations
Maintain conversation state across multiple requests on xAI servers
Retrieve previously saved conversation response
Delete saved conversation from xAI servers
Overview
Grok MCP Server
Grok-MCP is an MCP server that exposes xAI's Grok API - web and X search, vision, Grok Imagine image and video generation, and a Files API - as callable tools. It supports agentic tool calls that combine search, code execution, and image generation in one request, plus stateful conversations and local chat history. Use it when an MCP client needs Grok specifically, for its web/X research, vision, or Grok Imagine generation tools. Claude Desktop cannot pass local images to an MCP tool directly, so pair it with the Filesystem MCP server for that case.
What it does
Grok-MCP is an MCP server for xAI's Grok API, exposing web and X (Twitter) search, vision, image and video generation, and file handling as tools an MCP client can call. It supports agentic tool calling - multi-step reasoning that mixes web search, X search, code execution, and image generation in one request - plus access to Grok's current model lineup (grok-4.6, grok-4.5, grok-build-0.1, and others).
When to use - and when NOT to
Use it when an MCP client such as Claude Desktop or Claude Code needs to reach Grok specifically: for autonomous web/X research with citations, running Python in a sandbox, generating or editing images and video with Grok Imagine, or chatting over uploaded documents with stateful, server-stored conversation history. It is not a fit if the client is Claude Desktop and you need to hand it local images or files directly in chat - Claude Desktop cannot pass uploaded images to an MCP tool, so file paths on disk must be supplied instead (the optional Filesystem MCP server bridges that gap).
Capabilities
Chat tools cover a standard chat completion, chat_with_vision for local or remote images, chat_with_files grounded on uploaded documents, and a stateful trio (stateful_chat, retrieve_stateful_response, delete_stateful_response) keyed by response_id. Agentic tools add web_search, x_search, a sandboxed code_executor, and grok_agent, a unified agent that combines files, images, web/X search, and code execution with server-side image generation. Image and video tools (generate_image, generate_video, extend_video) run on Grok Imagine, with multi-reference editing and an option to save results to images/ instead of returning temporary URLs. File tools (upload_file, list_files, get_file, get_file_content, delete_file) manage the Files API, and local tools (list_chat_sessions, get_chat_history, clear_chat_history) manage JSON chat history saved in chats/. list_models returns all available Grok language and image models with live pricing.
How to install
Requires Python 3.11+, an xAI API key, and Astral UV.
claude mcp add grok-mcp -e XAI_API_KEY=your_api_key_here -- uv run --directory /path/to/Grok-MCP python main.py
For Claude Desktop, point the server command at uv run --directory /path/to/Grok-MCP python main.py with XAI_API_KEY set in the config's env block instead. It also runs over stdio directly (uv run python main.py), in Docker (docker compose up --build), or under the MCP Inspector (mcp dev main.py) for debugging.
Who it's for
Developers using an MCP-compatible client who specifically want Grok's agentic web/X research, vision, and Grok Imagine image and video generation available as tools, rather than a generic multi-provider chat connector. It is MIT-licensed.
Source README
Grok-MCP
MCP server for xAI’s Grok API with Web/X search, vision, image/video generation and file support.
Features
- Agentic Tool Calling: Web search, X search, code execution, and image generation with multi-step reasoning
- Multiple Grok Models: Access to latest models such as grok-4.6, grok-4.5, grok-build-0.1 and more
- Image and Video Generation: Create images and videos using Grok Imagine
- Vision Capabilities: Analyze images with Grok's vision models
- Files API: Upload, manage, and chat with documents
- Stateful Conversations: Maintain conversation context as id across multiple requests
- Local Chat History: Option to save persistent client side chat history as JSON files in chats/
Prerequisites
- Python 3.11 or higher
- xAI API key (Get one here)
- Astral UV
Installation
- Clone the repository:
git clone https://github.com/merterbak/Grok-MCP.git
cd Grok-MCP
- Create a venv environment:
uv venv
source .venv/bin/activate # macOS/Linux or .venv\Scripts\activate on Windows
- Install dependencies:
uv sync
Configuration
Claude Desktop Integration
Add this to your Claude Desktop configuration file:
{
"mcpServers": {
"grok": {
"command": "uv",
"args": [
"--directory",
"/path/to/Grok-MCP",
"run",
"python",
"main.py"
],
"env": {
"XAI_API_KEY": "your_api_key_here"
}
}
}
}
Claude Code Integration
Run this command from inside the project directory:
claude mcp add grok-mcp -e XAI_API_KEY=your_api_key_here -- uv run --directory /path/to/Grok-MCP python main.py
Or if you have a .env file with your key:
claude mcp add grok-mcp -- uv run --directory /path/to/Grok-MCP python main.py
Verify it's registered:
claude mcp list
Filesystem MCP (Optional)
Claude Desktop can't send uploaded images in the chat to an MCP tool.
The easiest way to give access to files directly from your computer is official Filesystem MCP server.
After setting it up you’ll be able to just write the image’s file path (such as /Users/mert/Desktop/image.png) in chat and Claude can use it with any vision chat tool.
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/<your-username>/Desktop",
"/Users/<your-username>/Downloads"
]
}
}
}
For stdio:
uv run python main.py
Docker:
docker compose up --build
Mcp Inspector:
mcp dev main.py
Available Tools
Each tool has a full docstring in src/server.py with its arguments and return format. MCP client surfaces those directly, so this list is just a quick map of what's available.
Note: For using images and files, you must provide paths to chat. See Filesystem MCP (Optional) for setup.
Chat and reasoning
chat- standard chat completion with optional persistent history, multi-agent support,
and a per requestservice_tier.chat_with_vision- analyze local or remote images with a Grok vision model.chat_with_files- chat grounded on previously uploaded documents.stateful_chat- continue a server-side stored conversation viaresponse_id.retrieve_stateful_response- fetch a stored response by ID.delete_stateful_response- delete a stored response by ID.
Agentic tools
web_search- autonomous web research with domain filters and citations.x_search- autonomous search over X (Twitter) posts, with handle and date filters.code_executor- solve tasks by running Python in a sandbox.grok_agent- unified agent that mixes files, images, web search, X search, code execution,
and server-side image generation. Generated images are written toimages/.
Image and video
generate_image- create or edit images with Grok Imagine (multi-reference editing supported).
Passsave=trueto write the results toimages/instead of returning temporary URLs.generate_video- text-to-video, image-to-video, or video editing with Grok Imagine.extend_video- extend an existing generated video with a follow-up prompt.
Files
upload_file- upload a local document.list_files- list uploaded files with sorting.get_file- fetch file metadata by ID.get_file_content- download file content as text.delete_file- delete a file by ID.
Local chat history
list_chat_sessions- list saved sessions inchats/.get_chat_history- get a session's full transcript.clear_chat_history- delete a session's local history file.
Models
list_models- list all Grok language and image models with live pricing.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.