Grok Image MCP
Grok Image MCP generates and edits images using xAI's Grok image API.
Generate images from text prompts.
Edit images by providing 1–3 source images (URLs, base64 data URIs, or local paths) and editing instructions.
Choose model (
grok-imagine-imageorgrok-imagine-image-2.0), quality (2.0: low/medium/auto), aspect ratio, resolution (1k/2k), and output count (1–10).Receive results as temporary URLs (also Markdown) or inline MCP image content via
b64_json.Save images to xAI Files API with
storage_optionsand reuse them in later edits viafile_id.Configure API key, default model, timeout, proxies, and image URL reverse proxy via environment variables.
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 Image MCP Generate a 16:9 image of a sunset over mountains"
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 Image MCP
An MCP server for generating and editing images with the xAI image API. Supports model and quality selection, local images, stored files, and inline image results over stdio.
Requires Node.js 22.19+ and an xAI API key.
Quick start
Add this to your MCP client's configuration:
{
"mcpServers": {
"grok_image": {
"command": "npx",
"args": ["-y", "grok-image-mcp"],
"env": {
"XAI_API_KEY": "your-xai-api-key"
}
}
}
}The server exposes generate_image and edit_image. Example generate_image arguments:
{
"prompt": "A watercolor illustration of a quiet mountain lake",
"model": "grok-imagine-image-2.0",
"quality": "low",
"aspect_ratio": "16:9"
}Related MCP server: image-studio-mcp
Models and quality
Capability |
|
|
Default model | Yes | Select per call or set |
Source images per edit | 1–3 | 1–5 |
Resolution |
|
|
Quality parameter | — |
|
Additional aspect ratios | — |
|
The model argument overrides XAI_IMAGE_MODEL. The default is grok-imagine-image.
On 2.0, quality defaults to auto: low for generation and medium for editing. See xAI pricing for costs.
Tools
Both tools accept these parameters:
Parameter | Type | Description |
| string, required | Image description or editing instructions |
| string | One of the two models above |
| integer | Output count, 1–10; default 1 |
| string | Generation defaults to |
| string |
|
| string | 2.0: |
| string |
|
| object | Save generated images to the Files API |
Aspect ratios: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20, auto; 2.0 additionally supports 21:9 and 5:2.
Editing
For edit_image, supply one of these source lists:
image_urls: ordered array of public URLs, base64 data URIs, or local paths.images: ordered array of{ "url": "..." }or{ "file_id": "..." }objects.urlalso accepts data URIs and local paths.
{
"prompt": "Replace the background with a snowy forest",
"image_urls": ["/absolute/path/to/photo.png"]
}Local files support PNG, JPEG and WebP. Relative paths resolve from the server's working directory.
Results
structuredContent.images contains image URLs, revised prompts, MIME types and stored-file metadata. Model, quality and usage are included when returned by xAI.
url: temporary image links, also returned as Markdown. Usestorage_optionsto save images.b64_json: MCPimagecontent blocks, withinline: truein the corresponding structured entry.
Save images and reuse them
Add storage_options to either tool to persist output in the xAI Files API:
{
"prompt": "A small cabin in a pine forest",
"model": "grok-imagine-image-2.0",
"quality": "low",
"storage_options": {
"filename": "cabin.jpg",
"expires_after": 86400
}
}This saves the image privately for one day. Use structuredContent.images[0].file_output.file_id in a subsequent edit:
{
"prompt": "Change the season to winter",
"model": "grok-imagine-image-2.0",
"quality": "low",
"images": [{ "file_id": "file-id-from-the-previous-result" }]
}Storage option | Description |
| Required filename for the stored image |
| File lifetime in seconds, 3600–2592000; default: permanent |
|
|
| Use |
See xAI storage documentation for details.
Configuration and networking
Environment variable | Description |
| xAI API key; takes precedence over |
| Alternative API-key variable |
| Default model; |
| API base URL; default |
| Request timeout in milliseconds; default |
| Network proxy for API requests; takes precedence over |
| Network proxy, e.g. |
| Reverse proxy for returned |
For IMAGE_PROXY_DOMAIN, configure your reverse proxy to forward paths and query strings to https://imgen.x.ai.
For long generations, set the MCP client's tool timeout to XAI_TIMEOUT_MS or longer.
Development
npm ci
npm testTo use a local build, configure your MCP client to run node with the absolute path to dist/index.js.
License
MIT
基于 xAI 图像 API 的 MCP 服务,支持选择模型与质量、编辑本地图片或已存储的图片,并返回图片链接或内联图片。使用 stdio 传输。
需要 Node.js 22.19+ 和 xAI API 密钥。
快速开始
在 MCP 客户端中添加:
{
"mcpServers": {
"grok_image": {
"command": "npx",
"args": ["-y", "grok-image-mcp"],
"env": {
"XAI_API_KEY": "你的 xAI API 密钥"
}
}
}
}服务提供 generate_image 和 edit_image 两个工具。generate_image 调用示例:
{
"prompt": "一幅宁静山间湖泊的水彩插画",
"model": "grok-imagine-image-2.0",
"quality": "low",
"aspect_ratio": "16:9"
}模型与质量
能力 |
|
|
默认模型 | 是 | 每次调用指定,或设置 |
编辑源图数量 | 1–3 张 | 1–5 张 |
分辨率 |
|
|
质量参数 | — |
|
新增宽高比 | — |
|
调用时的 model 优先于环境变量 XAI_IMAGE_MODEL,默认值为 grok-imagine-image。
2.0 的质量默认为 auto:生成对应 low,编辑对应 medium。费用见 xAI 定价。
工具参数
两个工具共用以下参数:
参数 | 类型 | 说明 |
| string,必填 | 图片描述或编辑指令 |
| string | 上表中的模型之一 |
| integer | 输出数量,1–10,默认 1 |
| string | 生成默认 |
| string |
|
| string | 2.0: |
| string | 默认 |
| object | 将输出保存至 Files API |
宽高比支持 1:1、16:9、9:16、4:3、3:4、3:2、2:3、2:1、1:2、19.5:9、9:19.5、20:9、9:20、auto;2.0 还支持 21:9、5:2。
编辑图片
edit_image 的源图列表使用以下一种形式:
image_urls:按顺序提供公开 URL、base64 data URI 或本地路径。images:按顺序提供{ "url": "..." }或{ "file_id": "..." }对象。url也接受 data URI 和本地路径。
{
"prompt": "将背景替换成雪中的森林",
"image_urls": ["/absolute/path/to/photo.png"]
}本地文件支持 PNG、JPEG、WebP。相对路径以服务的工作目录为基准。
返回结果
structuredContent.images 包含图片 URL、修改后的提示词、MIME 类型和文件存储信息;模型、质量、用量信息随 xAI 返回内容提供。
url:临时图片链接,同时以 Markdown 返回。使用storage_options可保存图片。b64_json:MCPimage内容块,对应的结构化条目标记为inline: true。
保存与复用图片
为任一工具添加 storage_options,即可保存输出:
{
"prompt": "松林中的一间小木屋",
"model": "grok-imagine-image-2.0",
"quality": "low",
"storage_options": {
"filename": "cabin.jpg",
"expires_after": 86400
}
}上述配置将图片私有保存一天。从 structuredContent.images[0].file_output.file_id 取得文件 ID,随后编辑时复用:
{
"prompt": "将季节改成冬季",
"model": "grok-imagine-image-2.0",
"quality": "low",
"images": [{ "file_id": "上一次返回的文件 ID" }]
}存储选项 | 说明 |
| 必填,存储文件名 |
| 文件有效期,3600–2592000 秒;默认永久保存 |
| 设为 |
| 使用 |
详见 xAI 存储文档。
环境变量与网络
变量 | 说明 |
| API 密钥,优先于 |
| API 密钥的另一个变量名 |
| 默认模型,未设置时为 |
| API 基础地址,默认 |
| 请求超时毫秒数,默认 |
| API 网络代理,优先于 |
| API 网络代理,例如 |
| 返回图片的反向代理地址,例如 |
使用 IMAGE_PROXY_DOMAIN 时,反向代理需将路径与查询参数转发到 https://imgen.x.ai。
生成耗时较长时,将 MCP 客户端的工具超时设为 XAI_TIMEOUT_MS 或更长。
开发
npm ci
npm test使用本地构建时,在 MCP 客户端中配置 node 和 dist/index.js 的绝对路径。
许可证
MIT
Available Tools
2 toolsedit_imageA
Edit images with xAI using ordered URLs, data URIs, local paths, or Files API IDs. Supports up to 3 source images with 1.0 or 5 with 2.0. URLs are temporary unless persisted.
Inputs: prompt (required), n, model, images, +6 more. Returns: model, usage, images, quality
generate_imageA
Generate images with xAI. Model and quality affect cost. URLs are temporary unless persisted with storage_options. b64_json returns inline image content.
Inputs: prompt (required), n, model, quality, +4 more. Returns: model, usage, images, quality
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
generate_image creates new images, while edit_image modifies existing images using source inputs. The two tools target distinct actions with clearly different parameters and use cases, leaving no ambiguity.
Both tools follow a consistent snake_case verb_noun pattern: generate_image and edit_image. This is predictable and easy to parse.
Only 2 tools are provided, which feels thin for an image generation/editing service. While they cover the core operations, additional tools like listing models or retrieving image details would make the set feel more complete.
The core create and edit operations are present, covering the main lifecycle for image generation. Minor gaps exist, such as no tool for listing available models or managing stored images, but agents can work around these using external means.
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 Midjourney AI image generation and editing
Related MCP Servers
- AlicenseAqualityBmaintenanceUse XAI's latest api functionalities with Grok MCP. It supports image understanding and generation, live search, latest models and more.2254MIT
- AlicenseBqualityDmaintenanceA local MCP server for generating and editing images using OpenAI-compatible APIs. It provides text-to-image generation and image editing capabilities with configurable endpoints and saves output directly to local files.225 npmMIT
- AlicenseNot gradedqualityCmaintenanceMCP server for generating, editing, and processing images via multiple providers including Kilo, OpenRouter, OpenAI, and Gemini, with local tools for background removal, resizing, and cropping.27 npm3MIT
- AlicenseAqualityCmaintenanceMCP server for generating, editing, and batch processing videos using xAI's Grok Imagine Video API, with support for text-to-video, image-to-video, and video editing via natural language prompts.472 npm1MIT