MCP HubMCP Hub
chenyeju295

mcp_generate_images

by: chenyeju295

可用于cursor 集成 mcp server

13created 10/03/2025
Visit
cursor
integration

📌Overview

Purpose: The AI image generation service leverages Together AI technology to facilitate seamless image creation, specifically designed for integration with Cursor MCP services.

Overview: This framework offers a robust solution for generating high-quality images with features that support custom configurations such as image size and storage paths. It is well-suited for projects needing automated and error-tolerant image generation capabilities.

Key Features:

  • High-Quality Image Generation: Ensures the creation of visually appealing images suitable for various applications.

  • Automatic Retry and Error Handling: Enhances reliability by automatically retrying failed requests and providing detailed error messages, significantly improving the user experience.

  • Batch Image Generation Support: Allows for the simultaneous creation of multiple images, optimizing workflow efficiency.

  • Path and Permission Verification: Validates paths and permissions to ensure successful image saving operations.

  • Asynchronous Processing Support: Facilitates non-blocking operations that can improve performance in handling multiple requests simultaneously.


AI 图像生成服务

基于 Together AI 的图像生成服务,专门设计用于与 Cursor MCP 服务集成。支持自定义图片大小、保存路径等功能。

功能特点

  • 支持高质量图像生成
  • 自动重试和错误处理
  • 支持批量生成多张图片
  • 完整的路径和权限验证
  • 详细的错误提示
  • 异步处理支持

环境准备

1. Python 环境

  • Python 3.10+ (推荐使用 pyenv 管理 Python 版本)
# 安装 pyenv
brew install pyenv

# 安装 Python
pyenv install 3.13.2
pyenv global 3.13.2
  • Nodejs 环境(下载地址:Node.js

2. uv 包管理工具

安装 uv 包管理器:

# 安装 uv
brew install uv

# 或者使用 pip 安装
pip install uv

3. Together AI API 密钥

  1. 访问 Together AI API Keys
  2. 注册/登录账号
  3. 创建新的 API 密钥并保存

4. Cursor

下载并安装 Cursor IDE并确保配置了 Python 环境。

安装配置

  1. 克隆项目:
git clone https://github.com/chenyeju295/mcp_generate_images.git
  1. 安装依赖:
cd mcp_generate_images
python3 -m pip install fastmcp requests

如果出现证书问题,可以使用:

python3 -m pip install fastmcp requests --trusted-host pypi.org --trusted-host files.pythonhosted.org --upgrade --force-reinstall --no-cache-dir
  1. 配置 API 密钥:

mcp_server.py 中修改 TOGETHER_API_KEY

TOGETHER_API_KEY = "your_api_key_here"  # 替换为你的 Together AI API 密钥
  1. 配置服务:

mcp_server.py 中可以修改以下配置:

CONFIG = {
    "api": {
        "url": "https://api.together.xyz/v1/images/generations",
        "model": "black-forest-labs/FLUX.1-schnell-Free",
        "timeout": 30,
        "max_retries": 3,
        "retry_delay": 5
    },
    "image": {
        "max_width": 1024,
        "max_height": 1024,
        "default_width": 1024,
        "default_height": 1024,
        "default_steps": 2,
        "max_batch_size": 4
    },
    "output": {
        "base_folder": "你的默认保存路径",
        "allowed_extensions": [".png", ".jpg", ".jpeg"],
        "default_extension": ".png"
    }
}

运行服务

  1. 开发模式运行(带调试界面):
uv run --with fastmcp fastmcp dev /Users/username/Documents/mcp_generate_images/mcp_server.py
  1. 生产模式运行:
uv run --with fastmcp fastmcp run /Users/username/Documents/mcp_generate_images/mcp_server.py
  1. 如果端口被占用,可以指定其他端口:
PORT=5174 uv run --with fastmcp fastmcp dev /Users/username/Documents/mcp_generate_images/mcp_server.py

使用说明

在 Cursor IDE 中使用

  1. 确保服务正在运行。
  2. 在 Cursor 中引入 MCP:
uv run --with fastmcp fastmcp run /Users/username/Documents/mcp_generate_images/mcp_server.py
  1. 在 Cursor 中使用: 直接输入相关的提示。

错误排查

如果遇到问题,请检查:

  1. 服务是否正常运行
  2. 保存路径是否正确(必须是绝对路径)
  3. 目录权限是否正确
  4. 网络连接是否正常
  5. API 密钥是否有效
  6. Python 环境是否正确配置
  7. uv 是否正确安装
  8. 依赖包是否完整安装