mcp服务器grok镜像
用于xAI的Grok图像生成API的MCP(模型上下文协议)服务器。内置Rust,将图像生成和编辑作为MCP工具公开。
与所有MCP服务器一样,使用JSON-RPC 2.0通过stdio进行通信。
工具
| 工具 | 说明 |
|---|---|
generate_image | 从文本提示生成图像 |
edit_image | 使用自然语言指令编辑现有图像 |
list_styles | 列出可用于的图像样式 generate_image |
generate_image
根据文本描述生成图像。
参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
prompt | string | yes | 所需图像的文本描述 |
model | string | no | 要使用的模型(默认值: grok-imagine-image-pro) |
n | integer | no | 要生成的图像数量(1-10,默认为1) |
aspect_ratio | string | no | 纵横比: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, auto等等。 |
resolution | string | no | 输出分辨率: 1k (~1024px,默认值)或 2k (约2048像素) |
response_format | string | no | 输出格式: url (默认、临时)或 b64_json |
style | string | no | 要应用的样式名称(使用 list_styles 查看选项) |
设置样式后,提示将被包裹在样式的模板中。例如,与 style: "watercolor" 和 prompt: "a cat on a roof",API接收 "a cat on a roof, as a watercolor painting"。使用此参数时,避免在提示本身中包含样式语言。
响应包括已解析的提示,因此您可以确切地看到发送到API的内容。
edit_image
使用自然语言指令编辑现有图像。
参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
image_url | string | yes | URL、base64数据URI或源图像的本地文件路径 |
prompt | string | yes | 自然语言编辑指令 |
model | string | no | 要使用的模型(默认值: grok-imagine-image-pro) |
n | integer | no | 要生成的变量数(1-10,默认值1) |
resolution | string | no | 输出分辨率: 1k (~1024px,默认值)或 2k (约2048像素) |
response_format | string | no | 输出格式: url (默认、临时)或 b64_json |
注: style 参数在上故意不可用 edit_image --编辑提示是指令(例如“删除背景”),而不是描述,因此将它们包装在样式模板中会产生无稽之谈。
list_styles
返回所有可用的图像样式及其名称、描述和提示模板。没有参数。
内置样式
| 样式 | 描述 |
|---|---|
watercolor | 水彩画风格 |
oil-painting | 有明显笔触的油画 |
pencil-sketch | 详细的铅笔素描 |
pixel-art | 复古像素艺术 |
anime | 动漫风格插图 |
pop-art | 大胆的波普艺术风格 |
art-nouveau | 流动的有机线条的新艺术 |
cinematic | 戏剧性灯光下的电影摄影 |
portrait | 专业肖像摄影 |
macro | 极限微距摄影 |
aerial | 无人机航拍 |
studio | 干净背景上的工作室摄影 |
noir | 黑色电影风格 |
vintage | 褪色的复古照片 |
可用型号
| 型号 | 质量 | 分辨率 | 成本 | 费率限制 |
|---|---|---|---|---|
grok-imagine-image-pro | 高级(默认) | 1k/2k | 0.07美元/张 | 30转/分 |
grok-imagine-image | 更快 | 1k/2k | 0.02美元/张 | 300转/分 |
grok-2-image-1212 | 传统 | 修复 | 0.07美元/图像 | 300转/分 |
注:遗产 grok-2-image-1212 模型不支持 aspect_ratio 或 resolution 参数。
先决条件
- 铁锈(2024年版)
- 来自的xAI API密钥 console.x.ai
设置
创建配置文件:
mkdir -p ~/.config/mcp-server-grok-image创建 ~/.config/mcp-server-grok-image/config.toml:
api_key = "xai-..."自定义样式
将自定义样式添加到配置文件中。与内置样式同名的自定义样式将覆盖它。
api_key = "xai-..."
[[styles]]
name = "my-style"
description = "My custom look"
template = "{prompt}, in my custom style"
[[styles]]
name = "watercolor"
description = "My watercolor variant"
template = "{prompt}, as a loose expressive watercolor with ink outlines"模板必须包含 {prompt} 占位符。任何缺少的自定义样式都将被跳过,并在启动时发出警告。
构建
cargo build --release这产生 target/release/mcp-server-grok-image.
发展:
cargo build # debug build
cargo run # run in dev mode
RUST_LOG=debug cargo run # run with debug loggingMCP配置
添加到您的Claude桌面配置(~/.config/Claude/claude_desktop_config.json):
{
"mcpServers": {
"grok-image": {
"command": "/path/to/mcp-server-grok-image"
}
}
}项目结构
src/
main.rs - everything: config, styles, API types, MCP server, tool definitions许可证
麻省理工学院
