Replicate FLUX Image Generator
STDIOMCP server generating images using Replicate's FLUX model and storing in Cloudflare R2.
MCP server generating images using Replicate's FLUX model and storing in Cloudflare R2.
A Model Context Protocol (MCP) server that generates images using Replicate's FLUX model and stores them in Cloudflare R2.
使用 Replicate 的 FLUX 模型生成图片并存储到 Cloudflare R2 的模型上下文协议(MCP)服务器。
Generate images using Replicate's black-forest-labs/flux-schnell model
Store generated images in Cloudflare R2
Return accessible image URLs
Support for custom prompts and filenames
使用 Replicate 的 black-forest-labs/flux-schnell 模型生成图片
将生成的图片存储到 Cloudflare R2
返回可访问的图片链接
支持自定义提示词和文件名
Node.js (v16 or higher)
Replicate API token
Cloudflare R2 bucket and credentials
npm or yarn
Node.js(v16 或更高版本)
Replicate API 令牌
Cloudflare R2 存储桶和凭证
npm 或 yarn
Required environment variables in .env
file:
.env
文件中需要的环境变量:
REPLICATE_API_TOKEN=your_replicate_token STORAGE_ENDPOINT=your_r2_endpoint STORAGE_ACCESS_KEY=your_r2_access_key STORAGE_SECRET_KEY=your_r2_secret_key STORAGE_BUCKET=your_bucket_name STORAGE_DOMAIN=your_domain
To install MCP Replicate FLUX for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @andylee20014/mcp-replicate-flux --client claude
Follow these steps to set up the project locally:
按照以下步骤在本地设置项目:
# Clone the repository git clone https://github.com/andylee20014/mcp-replicate-flux.git cd mcp-replicate-flux # Install dependencies npm install # Create .env file and add your credentials cp .env.example .env # Edit .env with your actual credentials
Make sure your Cloudflare R2 bucket has appropriate CORS settings for public access to the uploaded images.
确保您的 Cloudflare R2 存储桶具有适当的 CORS 设置,以允许公共访问上传的图片。
To start the MCP server locally:
在本地启动 MCP 服务器:
node index.js
The server will start and listen for MCP protocol messages on standard input/output.
服务器将启动并通过标准输入/输出监听 MCP 协议消息。
The server provides a generate-image
tool that accepts two parameters:
prompt
: The text prompt for image generationfilename
: The desired filename for the generated image服务器提供了一个 generate-image
工具,接受两个参数:
prompt
:用于生成图片的文本提示词filename
:生成的图片所需的文件名Here's an example of how to integrate with this MCP server using the MCP client library:
以下是使用 MCP 客户端库与此 MCP 服务器集成的示例:
const { McpClient } = require('@modelcontextprotocol/sdk/client/mcp.js') async function generateImage(prompt, filename) { const client = new McpClient() // Connect to your running MCP server await client.connect(yourTransport) const result = await client.tools.call('generate-image', { prompt, filename }) return result }
Example response 示例响应:
{ "content": [ { "type": "text", "text": "Image successfully generated and uploaded to Cloudflare R2" }, { "type": "image", "url": "https://your-domain.com/filename.jpg" } ] }
A test script is provided to verify the image generation and upload functionality.
提供了一个测试脚本,用于验证图片生成和上传功能。
node test.js
The test script will:
测试脚本将:
Example test output 测试输出示例:
Generating image with prompt: "a beautiful girl"
Filename: test-1234567890.jpg
Image generated and uploaded successfully!
Image URL: https://your-domain.com/test-1234567890.jpg
You can modify the prompt in test.js
to test different image generation scenarios.
您可以在 test.js
中修改提示词来测试不同的图片生成场景。
There are two ways to configure the MCP server in Cursor:
在Cursor中配置MCP服务器有两种方式:
Create a file at ~/.cursor/mcp.json
with all environment variables:
在 ~/.cursor/mcp.json
创建完整配置文件,包含所有环境变量:
{ "mcpServers": { "replicate-flux": { "command": "node", "args": ["C:\\Users\\YourUsername\\path\\to\\mcp-replicate-flux\\index.js"], "description": "使用Replicate的FLUX模型生成图片并存储到Cloudflare R2的MCP服务器", "env": { "REPLICATE_API_TOKEN": "your_replicate_token", "STORAGE_ENDPOINT": "your_r2_endpoint", "STORAGE_ACCESS_KEY": "your_r2_access_key", "STORAGE_SECRET_KEY": "your_r2_secret_key", "STORAGE_BUCKET": "your_bucket_name", "STORAGE_DOMAIN": "your_domain" } } } }
If you prefer to manage environment variables separately (using system environment variables or .env file), you can use a minimal configuration:
如果你想单独管理环境变量(使用系统环境变量或.env文件),可以使用最小配置:
{ "mcpServers": { "replicate-flux": { "command": "node", "args": ["C:\\Users\\YourUsername\\path\\to\\mcp-replicate-flux\\index.js"] } } }
When using the minimal configuration, make sure your environment variables are properly set up either in:
.env
file in the project directory使用最小配置时,请确保你的环境变量正确设置在以下位置之一:
.env
文件The description
field is optional in both methods
Environment variables in the configuration file take precedence over system environment variables
After changing the configuration, restart Cursor to apply the changes
description
描述字段在两种方式中都是可选的
配置文件中的环境变量优先级高于系统环境变量
更改配置后,需要重启Cursor以应用更改
mcp-replicate-flux/
├── .env # Environment variables
├── index.js # MCP server entry point
├── generateImage.js # Image generation and R2 upload logic
├── test.js # Test script
└── README.md # Project documentation
Image generation fails: Check your Replicate API token and quota
R2 upload fails: Verify your R2 credentials and bucket permissions
Cannot access generated images: Ensure your R2 bucket has proper CORS configuration
图片生成失败:检查您的 Replicate API 令牌和配额
R2 上传失败:验证您的 R2 凭证和存储桶权限
无法访问生成的图片:确保您的 R2 存储桶具有正确的 CORS 配置
The Model Context Protocol (MCP) is a standard for AI model interaction that enables interoperability between different AI systems. This server implements an MCP tool that can be used with any MCP-compatible client.
模型上下文协议(MCP)是一种 AI 模型交互标准,可实现不同 AI 系统之间的互操作性。此服务器实现了一个 MCP 工具,可与任何兼容 MCP 的客户端一起使用。
For more information about MCP, visit: https://mcp.freeaigen.com/
MIT