The Replicate FLUX Image Generation MCP Server is a Model Context Protocol (MCP) server that leverages Replicate's FLUX model to generate images and stores them in Cloudflare R2. This server provides a seamless integration for generating and managing images programmatically, returning accessible URLs for the generated content.
black-forest-labs/flux-schnell
model to generate images.Before setting up the server, ensure you have the following:
The server requires the following environment variables to be set in a .env
file:
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
You can install the server automatically using Smithery:
npx -y @smithery/cli install @andylee20014/mcp-replicate-flux --client claude
To set up the project manually:
Clone the repository:
shell
git clone https://github.com/andylee20014/mcp-replicate-flux.git
cd mcp-replicate-flux
Install dependencies:
shell
npm install
Create and configure the .env
file:
shell
cp .env.example .env
# Edit .env with your actual credentials
The server provides a generate-image
tool that accepts the following parameters:
prompt
: The text prompt for image generation.filename
: The desired filename for the generated image.Here’s how to integrate with the server using the MCP client library:
const { McpClient } = require('@modelcontextprotocol/sdk/client/mcp.js')
async function generateImage(prompt, filename) {
const client = new McpClient()
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 script will:
1. Generate an image using a sample prompt.
2. Upload the image to Cloudflare R2.
3. Return the accessible URL.
Create a file at ~/.cursor/mcp.json
with all environment variables:
{
"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, use this minimal configuration:
{
"mcpServers": {
"replicate-flux": {
"command": "node",
"args": ["C:\\Users\\YourUsername\\path\\to\\mcp-replicate-flux\\index.js"]
}
}
}
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
MIT