图像生成服务器

基于FLUX模型的MCP服务器,用于根据文本提示生成图像,支持自定义尺寸、批量生成和本地保存。

  • by frankdeno
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 frankdeno/flux-image-generator-mcp

使用说明

FLUX图像生成器MCP服务器

MCP(模型上下文协议)服务器,用于使用黑森林实验室的FLUX模型生成图像。使用最新的MCP SDK(v1.7.0)。

特性

  • 根据文本提示生成图像
  • 自定义图像尺寸、提示上采样和安全设置
  • 在本地保存生成的图像
  • 从多个提示批量生成图像

先决条件

  • Node.js(v18.0.0或更高版本)
  • 黑森林实验室API密钥(在https://api.bfl.ml)

安装

来源

  1. 克隆此存储库
  2. 安装依赖项:
npm install
  1. 创建一个 .env 文件基于 .env.example 并添加您的黑森林实验室API密钥:
BFL_API_KEY=your_api_key_here
  1. 构建项目:
npm run build

使用npm

npm install -g @modelcontextprotocol/server-flux-image-generator

用法

启动MCP服务器

使用以下命令启动服务器:

npm start

对于自动重新编译的开发:

npm run watch

与MCP客户端集成

要将此服务器与MCP客户端(如Claude)一起使用,请在客户端的配置中添加以下内容:

{
  "mcpServers": {
    "flux-image-generator": {
      "command": "mcp-server-flux-image-generator",
      "env": {
        "BFL_API_KEY": "your_api_key_here"
      }
    }
  }
}

可用工具

generateImage

基于具有可自定义设置的文本提示生成图像。

参数:

  • prompt (string,必填):要生成的图像的文本描述
  • width (数字,可选,默认值:1024):图像的宽度(像素)
  • height (数字,可选,默认值:1024):图像的高度(像素)
  • promptUpsampling (boolean,可选,默认值:false):通过对提示进行上采样来增强细节
  • seed (数字,可选):随机种子,可重复结果
  • safetyTolerance (数字,可选,默认值:3):内容审核容差(1-5)

例子:

{
  "prompt": "A serene lake at sunset with mountains in the background",
  "width": 1024,
  "height": 768,
  "promptUpsampling": true,
  "seed": 12345,
  "safetyTolerance": 3
}

quickImage

使用默认设置快速生成图像的简化工具。

参数:

  • prompt (string,必填):要生成的图像的文本描述

例子:

{
  "prompt": "A futuristic cityscape with flying cars"
}

batchGenerateImages

从提示列表生成多个图像。

参数:

  • prompts (字符串数组,必填):文本提示列表(最多10个)
  • width (数字,可选,默认值:1024):图像的宽度
  • height (数字,可选,默认值:1024):图像的高度

例子:

{
  "prompts": [
    "A serene lake at sunset",
    "A futuristic cityscape",
    "A magical forest with glowing plants"
  ],
  "width": 1024,
  "height": 768
}

输出格式

所有工具都以以下格式返回响应:

{
  "image_url": "https://storage.example.com/generated_image.jpg",
  "local_path": "/path/to/output/flux_1234567890.png"
}

对于错误:

{
  "error": true,
  "message": "Error description"
}

批处理工具返回:

{
  "total": 3,
  "successful": 2,
  "failed": 1,
  "results": [
    {
      "prompt": "A serene lake at sunset",
      "success": true,
      "image_url": "https://storage.example.com/image1.jpg",
      "local_path": "/path/to/output/flux_batch_1234567890_0.png"
    },
    {
      "prompt": "A futuristic cityscape",
      "success": true,
      "image_url": "https://storage.example.com/image2.jpg",
      "local_path": "/path/to/output/flux_batch_1234567890_1.png"
    },
    {
      "prompt": "Prohibited content",
      "success": false,
      "error": "Content policy violation"
    }
  ]
}

许可证

麻省理工学院