Image Gen (Jimeng AI) MCP server

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

This MCP server leverages the Jimeng AI platform to generate images directly from text prompts within the Cursor IDE. By integrating this tool, you can create images without leaving your development environment, with the generated images automatically saved to your specified directory.

Installation Requirements

Before installing the image generation server, ensure you have the following prerequisites:

  • Python 3.10 or higher
  • Node.js v20 (earlier versions like v15 or v16 may not work)
  • npm package manager
  • uv package installer

Step-by-Step Installation

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

Open server.py and modify the following configuration parameters:

# API Configuration
JIMENG_API_TOKEN = "057f7addf85dxxxxxxxxxxxxx"  # Your Jimeng session_id, multiple tokens can be comma-separated
IMG_SAVA_FOLDER = "D:/code/image-gen-server/images"  # Default path to save generated images

Alternative Installation via Smithery

You can also install the Image-Gen-Server automatically via Smithery:

npx -y @smithery/cli install @fengin/image-gen-server --client claude

Integrating with Cursor IDE

Configuration Steps

  1. Open Cursor settings:

    • Click the settings icon in the bottom-left corner
    • Navigate to Features > MCP Servers
    • Click "Add new MCP server"
  2. Enter the server configuration:

    • Name: image-gen-server (or any preferred name)
    • Type: command
    • Command:
uv run --with fastmcp fastmcp run /path/to/image-gen-server/server.py

Replace /path/to/image-gen-server/server.py with your actual file 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, try different slash styles if you encounter path issues.

Using the Image Generator

Once configured, a terminal window will open, indicating the server is running. You can now use the image generation tool within Cursor.

Example Prompts

In Cursor's agent mode, you can use prompts like:

Help me generate a product logo for my project and save it in the images directory.

Or:

Based on the project requirements, help me create a website header banner image.

Advanced Configuration: Getting a Jimeng Token

To use this tool, you'll need a Jimeng session token:

  1. Visit Jimeng
  2. Log in to your account
  3. Press F12 to open developer tools
  4. Navigate to Application > Cookies
  5. Find the sessionid value
  6. Copy this value to the JIMENG_API_TOKEN in server.py

Tool Function Documentation

Generate Image Function

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:
    """Generate an image based on text description

    Args:
        prompt: Text prompt describing the image
        file_name: Filename for the generated image (without path, .jpg is added if no extension)
        save_folder: Absolute directory path to save the image (optional, defaults to IMG_SAVA_FOLDER)
        sample_strength: Image generation fidelity (optional, range 0-1, default 0.5)
        width: Generated image width (optional, default 1024)
        height: Generated image height (optional, default 1024)

    Returns:
        List: Contains the generation results as JSON string
    """

Troubleshooting

Terminal Window Disappears Immediately

If the terminal window appears and quickly disappears with "No tools found" status, check:

  • Verify your command is correct and the server.py path is accurate
  • Ensure the path doesn't contain non-ASCII characters
  • Check that all dependencies are properly installed
  • Try different terminal types (cmd, PowerShell, git bash, etc.)

Debugging Mode

To view call logs or debug the application, modify the command:

uv run --with fastmcp fastmcp dev /path/to/image-gen-server/server.py

Or run this command in a terminal:

fastmcp dev /path/to/image-gen-server/server.py

This will provide a debugging URL (http://localhost:5173/) where you can open the MCP Inspector for debugging.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "image-gen-server" '{"command":"uv","args":["run","--with","fastmcp","fastmcp","run","path/to/server.py"]}'

See the official Claude Code MCP documentation for more details.

For 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 > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "image-gen-server": {
            "command": "uv",
            "args": [
                "run",
                "--with",
                "fastmcp",
                "fastmcp",
                "run",
                "path/to/server.py"
            ]
        }
    }
}

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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "image-gen-server": {
            "command": "uv",
            "args": [
                "run",
                "--with",
                "fastmcp",
                "fastmcp",
                "run",
                "path/to/server.py"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

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