Skip to main content
Glama

Grok Image MCP

English | 中文


An MCP (Model Context Protocol) server for image generation and editing using the Grok image model from xAI.

Note: This package was previously published as grok2-image-mcp-server. That package is now deprecated — please use grok-image-mcp instead.

Features

  • Image Generation — Generate images from text prompts with configurable aspect ratio, resolution, and batch count

  • Image Editing — Edit existing images with natural language instructions, supporting 1–3 source images

  • Local File Support — Provide local image paths for editing; the server reads and encodes them automatically

  • Image Proxy — Optional proxy domain for imgen.x.ai to handle network restrictions

  • HTTP Proxy — Optional network proxy for API requests

Related MCP server: image-studio-mcp

Installation

{
  "mcpServers": {
    "grok_image": {
      "command": "npx",
      "args": ["grok-image-mcp"],
      "env": {
        "XAIAPI_KEY": "your-xai-api-key"
      }
    }
  }
}

Tools

generate_image

Generate images from text prompts.

Parameter

Type

Required

Description

prompt

string

Text description of the image to generate

n

number

Number of images (1–10, default 1)

aspect_ratio

string

Aspect ratio (1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, auto, etc.)

resolution

string

Resolution (1k or 2k, default 1k)

edit_image

Edit existing images using a text prompt.

Parameter

Type

Required

Description

prompt

string

Text description of the desired edits

image_urls

string[]

1–3 source images: URLs, base64 data URIs, or local file paths

n

number

Number of output images (1–10, default 1)

aspect_ratio

string

Override output aspect ratio (default: follows first input image)

resolution

string

Resolution (1k or 2k, default 1k)

Environment Variables

Variable

Required

Description

XAIAPI_KEY

xAI API key

XAIAPI_BASE_URL

API base URL (default: https://api.x.ai/v1). Use a proxy if the API is inaccessible

IMAGE_PROXY_DOMAIN

Proxy domain to replace imgen.x.ai in returned image URLs

HTTP_PROXY

HTTP/HTTPS proxy for API requests (e.g. http://127.0.0.1:7890)

Proxy Examples

API proxy:

XAIAPI_BASE_URL=https://api-proxy.me/xai/v1

Image proxy:

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

Network proxy:

HTTP_PROXY=http://127.0.0.1:7890

Using Cloudflare Workers to Proxy Image URLs

If image URLs from imgen.x.ai are inaccessible, deploy a Cloudflare Worker as a reverse proxy and set IMAGE_PROXY_DOMAIN to your custom domain:

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
  })
}

License

MIT


基于 MCP 协议的 Grok 图像生成与编辑服务。

注意: 此包的前身是 grok2-image-mcp-server,该包已弃用,请使用 grok-image-mcp

功能

  • 图像生成 — 通过文本提示生成图像,可配置宽高比、分辨率和批量数量

  • 图像编辑 — 使用自然语言编辑现有图像,支持 1–3 张源图

  • 本地文件支持 — 可提供本地图片路径进行编辑,服务端自动读取并编码

  • 图片代理 — 可选代理域名替换 imgen.x.ai,解决网络访问问题

  • 网络代理 — 支持 HTTP/HTTPS 代理

安装

使用 npx(推荐)

{
  "mcpServers": {
    "grok_image": {
      "command": "npx",
      "args": ["grok-image-mcp"],
      "env": {
        "XAIAPI_KEY": "你的 xAI API 密钥"
      }
    }
  }
}

工具

generate_image

通过文本提示生成图像。

参数

类型

必填

说明

prompt

string

描述要生成的图像内容

n

number

生成数量(1–10,默认 1)

aspect_ratio

string

宽高比(1:116:99:164:33:43:22:32:11:2auto 等)

resolution

string

分辨率(1k2k,默认 1k)

edit_image

使用文本提示编辑现有图像。

参数

类型

必填

说明

prompt

string

描述所需的编辑内容

image_urls

string[]

1–3 张源图:URL、base64 data URI 或本地文件路径

n

number

输出图像数量(1–10,默认 1)

aspect_ratio

string

覆盖输出宽高比(默认跟随第一张输入图)

resolution

string

分辨率(1k2k,默认 1k)

环境变量

变量

必填

说明

XAIAPI_KEY

xAI API 密钥

XAIAPI_BASE_URL

API 基础地址(默认 https://api.x.ai/v1),可填写代理地址

IMAGE_PROXY_DOMAIN

图片代理域名,替换返回 URL 中的 imgen.x.ai

HTTP_PROXY

HTTP/HTTPS 网络代理地址(如 http://127.0.0.1:7890

代理示例

API 代理

XAIAPI_BASE_URL=https://api-proxy.me/xai/v1

图片代理

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

网络代理

HTTP_PROXY=http://127.0.0.1:7890

使用 Cloudflare Workers 代理图片 URL

如果 imgen.x.ai 的图片无法访问,可部署 Cloudflare Worker 反向代理,然后将 IMAGE_PROXY_DOMAIN 设为你的自定义域名:

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
  })
}

许可证

MIT

Available Tools

2 tools
edit_imageA

Edit existing images using a text prompt. Provide 1-3 source images (as URLs, base64 data URIs, or local file paths) along with editing instructions. Returns edited image URLs in markdown format.

ParametersJSON Schema
NameRequiredDescriptionDefault
promptYesText description of the desired edits
image_urlsYesArray of source image URLs, base64 data URIs, or local file paths (1-3 images)
nNoNumber of images to generate (1-10, default 1)
aspect_ratioNoOverride the output aspect ratio (default: follows first input image)
resolutionNoResolution of the output image (default: 1k)

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description provides basic behavioral info: input formats (URLs, base64, file paths) and output format (markdown URLs). However, it lacks disclosure of potential side effects (e.g., whether originals are modified), rate limits, authentication requirements, or error handling. The behavior beyond input/output is opaque.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description consists of two concise sentences. The first states the core purpose, the second details input requirements and output format. Every word contributes, no redundancy, and critical information is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 5 parameters with full schema descriptions, the description adds context for image input formats and output representation. It does not detail default behaviors for optional parameters (n, aspect_ratio, resolution), but those are covered by the schema. The lack of an output schema is partially addressed by the markdown hint.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3. The description adds value by clarifying that image_urls can be URLs, base64 data URIs, or local file paths, and that the output is in markdown format—details not fully explicit in the schema parameter descriptions themselves.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description starts with 'Edit existing images using a text prompt', clearly specifying the verb (edit), resource (existing images), and method (text prompt). It explicitly mentions providing source images and editing instructions, distinguishing it from the sibling tool 'generate_image' which creates new images.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implicitly indicates usage for editing existing images by requiring 1-3 source images, but it does not explicitly state when to use this tool versus the sibling 'generate_image', nor does it provide exclusions or limitations. No guidance on prerequisites or failure scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

generate_imageA

Generate images from text prompts using the Grok image model. Returns image URLs in markdown format. Note: URLs are temporary, download or process promptly.

ParametersJSON Schema
NameRequiredDescriptionDefault
promptYesText description of the image to generate
nNoNumber of images to generate (1-10, default 1)
aspect_ratioNoAspect ratio of the generated image (default: auto)
resolutionNoResolution of the generated image (default: 1k)

TDQS

A3.9/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It discloses output format (image URLs in markdown) and the critical fact that URLs are temporary. This is valuable behavioral context. However, it omits details like rate limits, cost, or potential failure modes.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, each earning its place: the first defines core functionality, the second warns about temporary URLs. No redundant or extraneous information. Front-loaded and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description could explain more about the return format (e.g., markdown syntax, array vs single URL, example). It also lacks details on generation style or quality. While it covers the essential purpose and a key warning, it is not fully complete for a tool with 4 parameters and no output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% (all 4 parameters have descriptions). The description adds no extra meaning beyond the schema; it merely restates 'text prompts' which aligns with the prompt parameter. Therefore, baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool generates images from text prompts using the Grok image model, with a specific verb and resource. It distinguishes from the sibling tool 'edit_image' which presumably edits images, so purpose is unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides post-generation guidance (URLs are temporary, download promptly) but does not explicitly state when to use this tool versus alternatives, nor does it mention when not to use it. The guidance is helpful but lacks selection context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv1.0.0
    • First observededit_image
    • First observedgenerate_image

TDQS

A4.2/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have clearly distinct purposes: one generates new images from text, the other edits existing images. There is no overlap or confusion.

Naming Consistency5/5

Both tools follow a consistent verb_noun pattern in snake_case (edit_image, generate_image), making the naming predictable and clear.

Tool Count4/5

With only two tools, the server is minimal but covers the core operations of image generation and editing. The count is slightly low but reasonable for a focused purpose.

Completeness5/5

The server provides the essential operations for an image generation and editing tool: creating new images from prompts and editing existing images. No obvious gaps are present for its stated purpose.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers