This MCP server leverages an AI image generation API to create images directly from Cursor IDE. With a simple setup process, you can quickly integrate image generation capabilities into your workflow.
Before installing the Image-Gen-Server, ensure you have the following prerequisites:
git clone https://github.com/fengin/image-gen-server.git
cd image-gen-server
pip install -r requirements.txt
pip install uv
Edit the server.py
file and update these two configuration parameters:
# API Configuration
JIMENG_API_TOKEN = "057f7addf85dxxxxxxxxxxxxx" # Your JiMeng session_id (multiple tokens can be separated by commas)
IMG_SAVA_FOLDER = "D:/code/image-gen-server/images" # Default image save path
To connect the Image-Gen-Server with Cursor:
Open Cursor settings:
Fill in the server configuration:
image-gen-server
(or any name you prefer)command
uv run --with fastmcp fastmcp run D:/code/image-gen-server/server.py
Replace the path with your actual project path:
uv run --with fastmcp fastmcp run D:/code/image-gen-server/server.py
uv run --with fastmcp fastmcp run /Users/username/code/image-gen-server/server.py
Note: On Windows, you might need to experiment with different slash types if you encounter issues.
In Cursor's agent mode, you can ask it to generate images by making requests like:
Please generate an image of a mountain landscape for my project, save it in the images folder.
The server will process your request, generate four image variations, and save them to your specified location.
To obtain the necessary API token:
sessionid
cookieJIMENG_API_TOKEN
in server.pyasync 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 text description
Args:
prompt: Text prompt describing the image
file_name: Filename for the generated image (without path, .jpg extension added if missing)
save_folder: Absolute folder path for saving (optional, defaults to IMG_SAVA_FOLDER)
sample_strength: Generation precision (optional, range 0-1, default 0.5)
width: Image width (optional, default 1024)
height: Image height (optional, default 1024)
Returns:
List: Contains the generation results
"""
Potential causes:
Use debug mode by changing the command to:
uv run --with fastmcp fastmcp dev D:/code/image-gen-server/server.py
Or run this command in a terminal:
fastmcp dev D:/code/image-gen-server/server.py
This will output a debug URL (http://localhost:5173/) where you can access the MCP Inspector for debugging.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.