Content
[](https://mseep.ai/app/fengin-image-gen-server)
# Image-Gen-Server
<div align="center">
<img src="images/logo_0.png" alt="Image-Gen-Server Logo" width="100%">
</div>
[](https://smithery.ai/server/@fengin/image-gen-server)
An image generation service based on 即梦AI (Jimeng AI), specifically designed for integration with Cursor IDE. It receives text descriptions from Cursor, generates corresponding images, and provides image download and saving functionalities.
You can check out the development process of this plugin on my website: [Developing an MCP Server integrated with Cursor, giving Cursor wings!](https://aibook.ren/archives/mcp-server-for-cursor)
For more AI knowledge, see the AI全书 (AI Book) (https://aibook.ren)
<div align="center">
<img src="images/example.png" alt="Image-Gen-Server Logo" width="100%">
</div>
## Features
- Perfect integration with Cursor IDE
- Supports text-to-image generation
- Automatically saves generated images
- Supports custom save paths
- Generates four images at once for more options
## Installation
### Installing via Smithery
To install Image-Gen-Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@fengin/image-gen-server):
```bash
npx -y @smithery/cli install @fengin/image-gen-server --client claude
```
1. Environment preparation, MCP is a relatively new thing, and the dependency environment versions are quite new
- python 3.10+
- Install npm
- Install nodejs (tested versions 15 and 16 do not work, development environment verified version 20 works, others unverified)
- Install pip install uv
- If debugging is needed, also install this: npm install -g @modelcontextprotocol/inspector@0.4.0
2. Clone the project
```bash
git clone https://github.com/fengin/image-gen-server.git
cd image-gen-server
```
3. Install dependencies
```bash
pip install -r requirements.txt
pip install uv
```
4. Set up JIMENG Token and default image save path
Modify these two configurations in the server.py file
```bash
# API configuration
JIMENG_API_TOKEN = "057f7addf85dxxxxxxxxxxxxx" # Your session_id obtained from logging into JIMENG, supports multiple, separated by commas
IMG_SAVA_FOLDER = "D:/code/image-gen-server/images" # Default image save path
```
## Cursor Integration
<div align="center">
<img src="images/cursor_config.png" alt="Image-Gen-Server Logo" width="100%">
</div>
1. Open Cursor Settings
- Click the settings icon in the lower left corner
- Select Features > MCP Servers
- Click "Add new MCP server"
2. Fill in the Server Configuration
- Name: `image-gen-server` (or any name you prefer)
- Type: `command`
- Command:
```bash
uv run --with fastmcp fastmcp run D:\code\image-gen-service\server.py
```
Note: Replace the path with your actual project path
- Windows example: ` uv run --with fastmcp fastmcp run D:/code/image-gen-service/server.py`
- macOS/Linux example: ` uv run --with fastmcp fastmcp run /Users/username/code/image-gen-server/server.py`
There are many issues with Windows paths, try various slashes for D:/code/image-gen-server/server.py
After filling in, a black window will pop up, and then you can ask Cursor to generate the images you need. Currently, the black window will keep running, and there is no way to resolve this issue of it popping up.
## Usage
In Cursor, to have the cursor generate images, you need to prompt it to understand how to use the image tool in agent mode, and then directly state your requirements for the image you want to generate, along with the save location.
## Obtain the Jimeng Token
1. Visit [Jimeng](https://jimeng.jianying.com/)
2. Log in to your account
3. Press F12 to open the developer tools
4. Find `sessionid` under Application > Cookies
5. Set the found sessionid to JIMENG_API_TOKEN in server.py
## Tool Function Description
### generate_image
```python
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]:
"""Generate an image based on the text description
Args:
prompt: The text prompt description for the image
file_name: The file name of the generated image (without path, defaults to .jpg if no extension is provided)
save_folder: The absolute directory path for saving the image (optional, defaults to IMG_SAVA_FOLDER)
sample_strength: The level of detail for the generated image (optional, range 0-1, defaults to 0.5)
width: The width of the generated image (optional, defaults to 1024)
height: The height of the generated image (optional, defaults to 1024)
Returns:
List: A JSON string containing the generation results
"""
```
### Technical Implementation
1. server.py uses fastmcp to implement the capabilities of the mcp server, providing functionality for cursor/claude.
2. server.py calls the proxy.jimeng module to interact with Jimeng AI in a reverse manner. The proxy.jimeng reverse module can also be installed and used independently, mainly providing the following key features:
- Image generation (generate_images)
- Synchronous dialogue completion (create_completion)
- Streaming dialogue completion (create_completion_stream)
- Multi-account token support
- Comprehensive error handling
For more detailed information, please refer to `proxy/jimeng/README.md`.
### Usage Example
```cmd
```
# In cursor agent mode
# Example 1
Based on the project requirements you provided, please generate a product logo and place it in the project directory under images.
# Example 2
According to the project requirements, please create the homepage of the website, with a banner image at the top.
## License
MIT License
Author: Ling Feng
## Troubleshooting
1. After configuration, a black window pops up and quickly disappears, and the tool status changes to No tools found.
Reason: The tool did not start properly, usually due to the following reasons:
- The configuration command is incorrect. Check if the command is correct; it is often due to an incorrect server.py path, or the path contains Chinese characters, or there are issues with forward and backward slashes.
- The required environment is not set up.
- The terminal for running dependencies is incorrect. For example, on my Windows, the terminals include git bash, cmd, powershell, wsl, etc. Try these terminals. The default terminal for my cursor configuration is cmd. If you encounter errors running in the corresponding terminal, it is usually because the environment is not set up correctly; installing the environment should resolve the issue.
2. After running normally, if you want to view the call logs or debug, how to do it?
Change the command to the following:
```
uv run --with fastmcp fastmcp dev D:/code/image-gen-service/server.py
```
Just change the last `run` to `dev`.
Alternatively, find a terminal and run the following command to enter debug mode:
```
fastmcp dev D:/code/image-gen-service/server.py
```
A debug address will be output: http://localhost:5173/. You can open this address in your browser to use the MCP Inspector for debugging. For details on how to use MCP Inspector, please refer to the official documentation.
Connection Info
You Might Also Like
semantic-kernel
Build and deploy intelligent AI agents with Semantic Kernel's orchestration...
repomix
Repomix packages your codebase into AI-friendly formats for easy integration.
Serena
Serena is a free, open-source toolkit that enhances LLMs with IDE-like coding tools.
Blender
BlenderMCP integrates Blender with Claude AI for enhanced 3D modeling.
pydantic-ai
Pydantic AI: A GenAI Agent Framework designed for ease of use.
cua
Cua enables building and deploying AI agents for reasoning and action on computers.