Image Gen (Jimeng AI) MCP server

Accepts text descriptions, generates corresponding images, and offers image download and save functions.
Back to servers
Provider
fengin
Release date
Feb 07, 2025
Language
Python
Stats
123 stars

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.

Installation Requirements

Before installing the Image-Gen-Server, ensure you have the following prerequisites:

  • Python 3.10 or higher
  • npm
  • Node.js v20 (v15 and v16 have been tested and do not work)
  • uv package installer

Setup Process

  1. Clone the repository:
git clone https://github.com/fengin/image-gen-server.git
cd image-gen-server
  1. Install dependencies:
pip install -r requirements.txt
pip install uv
  1. Configure the API token and image save location:

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

Cursor IDE Integration

To connect the Image-Gen-Server with Cursor:

  1. Open Cursor settings:

    • Click the settings icon in the bottom-left corner
    • Navigate to 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:
uv run --with fastmcp fastmcp run D:/code/image-gen-server/server.py

Replace the path with your actual project path:

  • Windows example: uv run --with fastmcp fastmcp run D:/code/image-gen-server/server.py
  • macOS/Linux example: 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.

Usage Guide

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.

Getting a JiMeng API Token

To obtain the necessary API token:

  1. Visit JiMeng AI
  2. Log in to your account
  3. Press F12 to open developer tools
  4. Go to Application > Cookies
  5. Locate the sessionid cookie
  6. Copy this value and set it as the JIMENG_API_TOKEN in server.py

Available Functions

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]:
    """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
    """

Troubleshooting

Issue: Terminal window appears briefly then disappears with "No tools found" status

Potential causes:

  • Incorrect command configuration (check path to server.py, avoid Chinese characters in path)
  • Missing environment dependencies
  • Incompatible terminal - try running in different terminals (cmd, PowerShell, git bash, etc.)

Issue: Need to see API call logs or debug the server

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.

How to add this MCP server to Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later