Image Generation MCP Server

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Integrates with Replicate's 'black-forest-labs/flux-schnell' model to generate images from text prompts

图像生成 MCP 服务器

使用 Replicate 的black-forest-labs/flux-schnell模型生成图像的MCP(模型上下文协议)服务器实现。

理想情况下与 Cursor 的 MCP 功能一起使用,但可以与任何 MCP 客户端一起使用。

特征

  • 根据文本提示生成图像
  • 可配置图像参数(分辨率、宽高比、质量)
  • 将生成的图像保存到指定目录
  • 完全符合 MCP 协议
  • 错误处理和验证

先决条件

  • Node.js 16+
  • 复制 API 令牌
  • 适用于 MCP 的 TypeScript SDK

设置

  1. 克隆存储库
  2. 安装依赖项:
    npm install
  3. 通过更新apiToken常量,直接在src/imageService.ts代码中添加您的 Replicate API 令牌:
    // No environment variables are used since they can't be easily set in cursor const apiToken = "your-replicate-api-token-here";

    **注意:**如果与 Claude 一起使用,您可以在根目录中创建一个.env文件并在那里设置您的 API 令牌:

    REPLICATE_API_TOKEN=your-replicate-api-token-here
    然后构建项目:
    npm run build

用法

与游标一起使用:

  1. 前往“设置”
  2. 选择功能
  3. 向下滚动到“MCP 服务器”
  4. 点击“添加新的 MCP 服务器”
  5. 将类型设置为“命令”
  6. 将命令设置为: node ./path/to/dist/server.js

API 参数

范围类型必需的默认描述
prompt细绳是的-图像生成的文字提示
output_dir细绳是的-保存生成的图像的服务器目录路径
go_fast布尔值错误的启用更快的生成模式
megapixels细绳“1”分辨率质量(“1”、“2”、“4”)
num_outputs数字1生成的图像数量(1-4)
aspect_ratio细绳“1:1”宽高比(“1:1”、“4:3”、“16:9”)
output_format细绳“webp”图像格式(“webp”、“png”、“jpeg”)
output_quality数字80压缩质量(1-100)
num_inference_steps数字4去噪步数(4-20)

示例请求

{ "prompt": "black forest gateau cake spelling out 'FLUX SCHNELL'", "output_dir": "/var/output/images", "filename": "black_forest_cake", "output_format": "webp" "go_fast": true, "megapixels": "1", "num_outputs": 2, "aspect_ratio": "1:1" }

示例响应

{ "image_paths": [ "/var/output/images/output_0.webp", "/var/output/images/output_1.webp" ], "metadata": { "model": "black-forest-labs/flux-schnell", "inference_time_ms": 2847 } }

错误处理

服务器处理以下错误类型:

  • 验证错误(无效参数)
  • API 错误(重复 API 问题)
  • 服务器错误(文件系统、权限)
  • 未知错误(意外问题)

每个错误响应包括:

  • 错误代码
  • 人类可读的消息
  • 详细错误信息

执照

国际学习中心

You must be authenticated.

A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

使用户能够使用 Replicate 的模型从文本提示生成图像,具有可配置的参数和完全的 MCP 协议兼容性。

  1. Features
    1. Prerequisites
      1. Setup
        1. Usage
          1. API Parameters
            1. Example Request
              1. Example Response
                1. Error Handling
                  1. License
                    ID: 5dft5chv70