image-gen-server
by: fengin
一个能与Cursor集成的图片生成mcp server工具,实现调用即梦逆向接口
📌Overview
Purpose: To provide a seamless image generation service specifically designed for integration with Cursor IDE, enabling users to generate images from text descriptions.
Overview: The Image-Gen-Server is built on the JIMENG AI framework, allowing users to create images based on text prompts received from Cursor IDE. It offers functionality for generating images, along with options for saving and downloading them, enhancing the creative workflow within the IDE.
Key Features:
-
Seamless Integration with Cursor IDE: Directly interacts with the Cursor environment for efficient image generation.
-
Text-to-Image Conversion: Converts user-provided text descriptions into generated images, expanding creative possibilities.
-
Automatic Image Saving: Automatically saves generated images to a specified location, streamlining the workflow.
-
Customizable Save Path: Users can define their own image save locations, providing flexibility.
-
Multiple Image Generation: Capable of generating up to four images at once, offering users a variety of options to choose from.
Image-Gen-Server
基于即梦AI的图像生成服务,专门设计用于与Cursor IDE集成。它接收来自Cursor的文本描述,生成相应的图像,并提供图片下载和保存功能。
此插件的开发过程可以看我的网站:开发一个MCP Server与Cursor集成,给Cursor插上翅膀!
更多AI知识,见AI全书(https://aibook.ren)
特性
- 与Cursor IDE完美集成
- 支持文本到图像的生成
- 自动保存生成的图像
- 支持自定义保存路径
- 一次生成四张图,供更多选择
安装
Installing via Smithery
To install Image-Gen-Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @fengin/image-gen-server --client claude
手动安装步骤
-
环境准备
- Python 3.10+
- 安装 npm
- 安装 Node.js(实测 v20 可用)
- 安装依赖:
pip install uv
- 调试时需要:
npm install -g @modelcontextprotocol/inspector@0.4.0
-
克隆项目
git clone https://github.com/fengin/image-gen-server.git
cd image-gen-server
- 安装依赖
pip install -r requirements.txt
pip install uv
- 设置即梦Token和图片默认保存地址
修改server.py
文件中的以下配置:
# API配置
JIMENG_API_TOKEN = "057f7addf85dxxxxxxxxxxxxx" # 你登录即梦获得的session_id,多个用逗号分隔
IMG_SAVA_FOLDER = "D:/code/image-gen-server/images" # 图片默认保存路径
Cursor集成
-
打开Cursor设置
- 点击左下角的设置图标
- 选择 Features > MCP Servers
- 点击 "Add new MCP server"
-
填写服务器配置
- Name:
image-gen-server
(或其他名称) - Type:
command
- Command:
uv run --with fastmcp fastmcp run D:/code/image-gen-service/server.py
注意:将路径替换为你的实际项目路径。Windows路径建议使用正斜杠(/)。
该命令执行后会弹出黑窗口,窗口保持运行状态,暂时无法避免。
使用方法
在Cursor中,使用agent模式提示其了解图片工具用法,然后直接输入生成图片的文本描述和保存位置即可。
获取即梦Token
- 访问 即梦
- 登录账号
- 按 F12 打开开发者工具
- 在 Application > Cookies 中找到
sessionid
- 将该
sessionid
设置到server.py
中的JIMENG_API_TOKEN
工具函数说明
generate_image
async def generate_image(prompt: str, file_name: str, save_folder: str = None, sample_strength: float = 0.5, width: int = 1024, height: int = 1024) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
"""根据文本描述生成图片
Args:
prompt: 图片的文本prompt描述
file_name: 生成图片的文件名(不含路径,如无后缀默认使用.jpg)
save_folder: 图片保存绝对路径(默认使用 IMG_SAVA_FOLDER)
sample_strength: 生成图片的精细度(范围0-1,默认0.5)
width: 生成图片宽度(默认1024)
height: 生成图片高度(默认1024)
Returns:
List: 包含生成结果的JSON字符串
"""
技术实现
server.py
使用 fastmcp 实现 MCP Server 能力,供 Cursor/Claude 使用- 调用
proxy.jimeng
模块逆向与即梦AI交互,提供图像生成、同步及流式对话补全、多账号支持和完善错误处理。
详细信息见 proxy/jimeng/README.md
。
使用示例
在 Cursor agent 模式下输入:
-
例子一
根据你的项目需求,帮我生成一张产品logo,放在项目目录 images 下面 -
例子二
根据项目需求,帮我制作网站的首页,头部需要有 banner 图片。
故障排除
- 配置后弹出黑窗口很快消失,工具状态变成 No tools found
可能原因:
- 配置命令错误(如 server.py 路径错误,路径包含中文,斜杠方向错误)
- 环境依赖未准备好
- 所用终端与环境不兼容(Windows下可试用 cmd、PowerShell、Git Bash、WSL等)
- 运行正常后,想查看日志或调试
- 将命令中的最后一个
run
改为dev
:
uv run --with fastmcp fastmcp dev D:/code/image-gen-service/server.py
- 或直接运行:
fastmcp dev D:/code/image-gen-service/server.py
运行后会输出调试地址,如:http://localhost:5173/,可用浏览器打开通过 MCP Inspector 进行调试。
许可证
MIT License
作者:凌封