grok-imagine-mcp

grok-imagine-mcp

An MCP server that automates a headless Chromium browser to generate images using Grok Imagine via text prompts. It supports configurable aspect ratios and saves images directly to disk using cookie-based authentication.

Category
Visit Server

README

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-extra with stealth plugin to avoid bot detection

Prerequisites

  • Bun v1.3+
  • A Grok account (free tier works)

Installation

bun install

MCP 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.

  1. Open https://grok.com in your browser (make sure you're logged in)
  2. Open Developer Tools (F12 or Cmd+Option+I)
  3. Go to the Network tab
  4. Refresh the page
  5. Click on any request to grok.com
  6. Right-click -> "Copy as cURL"
  7. Pass the entire curl command to the auth tool

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
prompt string yes Text prompt describing the image(s) to generate
quantity number no Number of images to save (1-6, default: 1). Each batch produces ~3 images.
saveFolderFullPath string yes Absolute path to the folder where images will be saved
aspectRatio string no 2:3, 3:2, 1:1, 9:16, or 16:9 (default: 1:1)

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 fix

Project 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 state

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured