Grok MCP

A MCP server for xAI's Grok API, providing access to capabilities including image understanding, image generation, live web search, and reasoning models.

Grok-MCP

MCP server for xAI's Grok API with agentic tool calling, image and video generation, vision, and file support.

Features

  • Agentic Tool Calling: Web search, X search, and code execution with multi-step reasoning
  • Multiple Grok Models: Access to Grok-4.1-Fast-Reasoning, Grok-4.1-Fast-Non-Reasoning, Grok-4-Fast, 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

Installation

  1. Clone the repository:
git clone https://github.com/merterbak/Grok-MCP.git
cd Grok-MCP
  1. Create a venv environment:
uv venv
source .venv/bin/activate # macOS/Linux or .venv\Scripts\activate on Windows
  1. 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

Note: For using images and files, you must provide paths to chat. See Filesystem MCP (Optional) for setup.

list_models

List all available Grok models.


chat

Standard chat completion with optional persistent history.

ParameterTypeDefaultDescription
promptstrrequiredYour message
sessionstrNoneSession name to save/load history
modelstrgrok-4Model to use
system_promptstrNoneSystem instruction

chat_with_vision

Analyze images with text.

ParameterTypeDefaultDescription
promptstrrequiredQuestion about the image
sessionstrNoneSession name to save/load history
modelstrgrok-4Vision model
image_pathsList[str]NoneLocal image file paths
image_urlsList[str]NoneImage URLs
detailstrautoauto, low, or high

Returns: Content + usage with prompt_image_tokens


generate_image

Create or edit images from text.

ParameterTypeDefaultDescription
promptstrrequiredImage description or edit instruction
modelstrgrok-imagine-imageImage model
image_pathstrNoneLocal image path to edit
image_urlstrNoneImage URL to edit
nint1Number of images (1-10)
aspect_ratiostrNonelike "16:9", "1:1"

generate_video

Create or edit videos from text, images, or existing videos.

ParameterTypeDefaultDescription
promptstrrequiredVideo description or edit instruction
modelstrgrok-imagine-videoVideo model
image_pathstrNoneLocal image path to animate
image_urlstrNoneImage URL to animate
video_pathstrNoneLocal video path to edit (max 20MB)
video_urlstrNoneVideo URL to edit
durationintNoneDuration in seconds (1-15)
aspect_ratiostrNonelike "16:9", "4:3"
resolutionstrNone"720p" or "480p"

web_search

Agentic web search with autonomous research.

ParameterTypeDefaultDescription
promptstrrequiredSearch query
modelstrgrok-4-1-fastModel
allowed_domainsList[str]NoneRestrict to domains (max 5)
excluded_domainsList[str]NoneExclude domains (max 5)
enable_image_understandingboolFalseAnalyze images in results
include_inline_citationsboolFalseEmbed citations in text
max_turnsintNoneLimit reasoning turns

Returns: Content, citations, tool_calls, usage


x_search

Agentic X (Twitter) search.

ParameterTypeDefaultDescription
promptstrrequiredSearch query
modelstrgrok-4-1-fastModel
allowed_x_handlesList[str]NoneOnly these handles (max 10)
excluded_x_handlesList[str]NoneExclude handles (max 10)
from_datestrNoneStart date (DD-MM-YYYY)
to_datestrNoneEnd date (DD-MM-YYYY)
enable_image_understandingboolFalseAnalyze images
enable_video_understandingboolFalseAnalyze videos
include_inline_citationsboolFalseEmbed citations
max_turnsintNoneLimit turns

Returns: Content, citations, tool_calls, usage


grok_agent

Unified agent combining files, images, and all agentic tools (web search, X search, code execution).

ParameterTypeDefaultDescription
promptstrrequiredYour query
sessionstrNoneSession name to save/load history
modelstrgrok-4-1-fastModel
file_idsList[str]NoneUploaded file IDs to search
image_urlsList[str]NoneImage URLs to analyze
image_pathsList[str]NoneLocal image paths
use_web_searchboolFalseEnable web search
use_x_searchboolFalseEnable X search
use_code_executionboolFalseEnable code execution
+ all web_search and x_search params

Returns: Content, citations, tool_calls, code_outputs, uploaded_file_ids, usage


code_executor

Execute Python code for calculations and analysis.

ParameterTypeDefaultDescription
promptstrrequiredTask description
modelstrgrok-4-1-fastModel
max_turnsintNoneLimit turns

Returns: Content, tool_calls, code_outputs, usage


stateful_chat

Maintain conversation state across requests.

ParameterTypeDefaultDescription
promptstrrequiredYour message
modelstrgrok-4Model
response_idstrNonePrevious response ID to continue a conversation
system_promptstrNoneSystem instruction

Returns: Content, response_id, usage


retrieve_stateful_response

Retrieve a stored conversation.


delete_stateful_response

Delete a stored conversation.

upload_file

Upload a document (max 48 MB).

ParameterTypeDefaultDescription
file_pathstrrequiredLocal file path

Supported formats: .txt, .md, .py, .js, .csv, .json, .pdf, and more


list_files

List uploaded files with sorting.

ParameterTypeDefaultDescription
limitint100Max files to return
orderstrdescasc or desc
sort_bystrcreated_atcreated_at, filename, or size

get_file

Get file metadata by ID.


get_file_content

Download file content by ID.

ParameterTypeDefaultDescription
file_idstrrequiredFile ID
max_bytesint500000Max bytes to return

delete_file

Delete a file by ID.


chat_with_files

Chat with uploaded documents using agentic document search.

ParameterTypeDefaultDescription
promptstrrequiredQuestion about docs
sessionstrNoneSession name to save/load history
modelstrgrok-4-1-fastModel
file_idsList[str]NoneFile IDs to search
system_promptstrNoneSystem instruction

Returns: Content, citations, usage


list_chat_sessions

List all saved chat sessions in chats/.


get_chat_history

Get the full message history for a session.

ParameterTypeDefaultDescription
sessionstrdefaultSession name

clear_chat_history

Delete the history file for a session.

ParameterTypeDefaultDescription
sessionstrdefaultSession name

License

This project is open source and available under the MIT License.

Related Servers