Grok2 Image Generator MCP server

Enables AI assistants to generate images through the Grok2 model using stdio transport for seamless integration into existing workflows.
Back to servers
Provider
fl0w1nd
Release date
Apr 04, 2025
Language
TypeScript
Package
Stats
1.2K downloads
19 stars

This MCP server enables chat assistants to generate images using the Grok-2 model through the Model Context Protocol (MCP). It acts as a bridge between chat applications and xAI's image generation capabilities.

Installation

Using npx (Recommended)

You can quickly start the server using npx:

npx -y grok2-image-mcp-server

To configure your MCP client application, add the following to your MCP configuration:

{
    "mcpServers": {
        "grok2_image": {
            "command": "npx",
            "args": [
                "grok2-image-mcp-server"
            ],
            "env": {
                "XAIAPI_KEY": "xAI Key"
            }
        }
    }
}

Environment Variables

The server can be configured using the following environment variables:

  • XAIAPI_KEY (required): Your xAI API key

  • XAIAPI_BASE_URL (optional): API proxy URL if the default endpoint (https://api.x.ai/v1) is inaccessible. Must end with /v1

    Example:

    XAIAPI_BASE_URL=https://api-proxy.me/xai/v1
    
  • IMAGE_PROXY_DOMAIN (optional): Image proxy domain if the default image server (imgen.x.ai) is inaccessible

    Example:

    IMAGE_PROXY_DOMAIN=https://image.proxy.workers.dev
    

Creating an Image Proxy with Cloudflare Workers

If you encounter issues accessing the generated images, you can set up a Cloudflare Workers proxy:

  1. Copy the following code to your Cloudflare Workers:
addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

const TARGET_DOMAIN = 'imgen.x.ai'

async function handleRequest(request) {
  const url = new URL(request.url)
  const targetUrl = `https://${TARGET_DOMAIN}${url.pathname}${url.search}`

  const init = {
    method: request.method,
    headers: request.headers,
    body: request.method === 'GET' || request.method === 'HEAD' ? undefined : request.body,
    redirect: 'follow'
  }

  const response = await fetch(targetUrl, init)

  const newHeaders = new Headers(response.headers)
  newHeaders.set('Access-Control-Allow-Origin', '*')

  return new Response(response.body, {
    status: response.status,
    statusText: response.statusText,
    headers: newHeaders
  })
}
  1. Deploy the worker
  2. Set up a custom domain (e.g., https://image.proxy.workers.dev)
  3. Configure the IMAGE_PROXY_DOMAIN environment variable with your custom domain

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later