Back to MCP directory
publicPublicdnsLocal runtime

Image Generation (Flux-Schnell)

一个基于MCP协议的图像生成服务器,使用Replicate的flux-schnell模型,支持通过文本提示生成图像,并可配置多种参数。

article

README

🚀 图像生成 MCP 服务器

本项目是一个 MCP (Model Context Protocol) 服务器实现,可借助 Replicate 的 black-forest-labs/flux-schnell 模型生成图像。它既适合与 Cursor 的 MCP 功能搭配使用,也能和其他 MCP 客户端兼容。

🚀 快速开始

先决条件

  • Node.js 16+
  • Replicate API 令牌
  • TypeScript 的 MCP SDK

设置

  1. 克隆仓库。

  2. 安装依赖:

    npm install
    
  3. 将你的 Replicate API 令牌直接在 src/imageService.ts 中更新 apiToken 常量:

    // 在这里直接添加您的 API 令牌,因为环境变量在 Cursor 中不易设置
    const apiToken = "your-replicate-api-token-here";
    

    ⚠️ 重要提示

    如果使用 Claude,请在根目录创建一个 .env 文件,并将 API 令牌设置为:

    REPLICATE_API_TOKEN=your-replicate-api-token-here
    

    然后构建项目:

    npm run build
    

使用说明

与 Cursor 一起使用时:

  1. 转到设置。
  2. 选择功能。
  3. 滚动到底部的 "MCP 服务器"。
  4. 点击 "添加新的 MCP 服务器"。
  5. 设置类型为 "Command"。
  6. 设置命令为:node ./path/to/dist/server.js

✨ 主要特性

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

📚 详细文档

API 参数

| 参数名称 | 类型 | 是否必填 | 默认值 | 描述 | |--------------------|---------|----------|---------|------------------------------------------| | prompt | string | 是 | - | 文本提示,用于生成图像 | | output_dir | string | 是 | - | 服务器上的保存图像目录路径 | | go_fast | boolean | 否 | false | 开启更快的生成模式 | | megapixels | string | 否 | "1" | 分辨率质量("1","2","4") | | num_outputs | number | 否 | 1 | 要生成的图像数量(1 - 4) | | aspect_ratio | string | 否 | "1:1" | 宽高比("1:1","4:3","16:9") | | output_format | string | 否 | "webp" | 图像格式("webp","png","jpeg") | | output_quality | number | 否 | 80 | 压缩质量(1 - 100) | | num_inference_steps| number | 否 | 4 | 去噪化步骤数量(4 - 20) |

示例请求

{
  "prompt": "黑色森林蛋糕,上面写着 '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"
}

示例响应

{
  "status": "success",
  "message": "图像已生成并保存到指定目录。",
  "data": {
    "filename": "black_forest_cake.png",
    "size": "2.5 MB",
    "dimensions": "1920x1080"
  }
}

错误处理

  • 输入错误:如果提示或参数无效,将返回验证错误。
  • API 错误:如果调用 Replicate API 失败,将返回相关错误信息。
  • 保存错误:如果无法将图像保存到指定目录,将返回存储错误。

📄 许可证

该代码受 MIT License 保护。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client