grok-imagine-mcp
Click on "Deploy 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., "@grok-imagine-mcpGenerate a 16:9 cyberpunk city image and save it to /Users/me/images"
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.
grok-imagine-mcp
An MCP (Model Context Protocol) server that generates images using Grok Imagine. It automates a headless Chromium browser to submit prompts, wait for generation, and save the resulting images to disk.
Features
Image generation via text prompts with configurable aspect ratios
Cookie-based authentication -- paste a cURL command from your browser to log in
Concurrent generation -- up to 4 parallel tabs with automatic queuing for additional requests
Auto-closing browser -- closes Chromium after 1 minute of inactivity, reopens on next request
Error handling -- detects rate limits, expired sessions, and sign-in redirects with clear messages
Stealth mode -- uses
playwright-extrawith stealth plugin to avoid bot detection
Related MCP server: Grok Image MCP
Prerequisites
Bun v1.3+
A Grok account (free tier works)
Installation
bun installMCP Configuration
Add the server to your MCP client config (e.g. .cursor/mcp.json):
{
"mcpServers": {
"grok-imagine-mcp": {
"command": "bun",
"args": ["run", "/path/to/grok-imagine-mcp/src/index.ts"]
}
}
}Set "env": { "DEV": "true" } to run the browser in visible (non-headless) mode for debugging.
Tools
auth
Authenticate with Grok by providing cookies from your browser session.
Open https://grok.com in your browser (make sure you're logged in)
Open Developer Tools (F12 or Cmd+Option+I)
Go to the Network tab
Refresh the page
Click on any request to grok.com
Right-click -> "Copy as cURL"
Pass the entire curl command to the
authtool
The tool extracts and saves the essential cookies (sso, sso-rw, cf_clearance, x-userid). Cookies persist in data/storage-state.json.
generate_images
Generate images using Grok Imagine.
Parameter | Type | Required | Description |
| string | yes | Text prompt describing the image(s) to generate |
| number | no | Number of images to save (1-6, default: 1). Each batch produces ~3 images. |
| string | yes | Absolute path to the folder where images will be saved |
| string | no |
|
Images are saved as grok-{timestamp}-{index}.jpg (or .png).
Development
# Run in dev mode (visible browser, file watching)
bun run dev
# Type check
bun run typecheck
# Lint & format
bun run fixProject Structure
src/
index.ts MCP server entry point and tool registration
browser.ts Browser lifecycle, tab pool, and idle timeout
generate.ts Image generation logic (prompt submission, polling, saving)
chromium.ts Playwright + stealth plugin setup
cookies.ts Cookie parsing, saving, and loading
console.ts Browser console log capture
constants.ts Configuration constants
data/
profile/ Chromium persistent user data
storage-state.json Saved cookies and storage stateThis server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for Grok Imagine AI video generation
MCP server for Qwen Image 3 AI image generation
MCP server for Flux AI image generation
MCP server for Google Veo AI video generation
Related MCP Servers
- AlicenseNot gradedqualityNot gradedmaintenanceAn MCP server that enables high-quality image generation using OpenAI's GPT-Image-1 model with support for style variations and HD quality. It automatically downloads and saves generated images to a local directory as PNG files while managing metadata and batch processing.-
- AlicenseAqualityCmaintenanceMCP server for generating and editing images using xAI's Grok image model, supporting text prompts, batch generation, local files, and optional proxy configurations.215 npm29MIT
- AlicenseAqualityDmaintenanceMCP server for generating images using OpenRouter API, supporting models like Gemini 2.5 Flash. Enables image generation with flexible options like saving to local files.2Do What The F*ck You Want To Public
- FlicenseCqualityBmaintenanceCookie-based MCP server for Grok Imagine experiments, enabling image generation and media post creation using your own Grok.com cookies.351-