andylee20014_mcp_replicate_flux

andylee20014_mcp_replicate_flux

by andylee20014
An MCP server that generates images using Replicate's FLUX model and stores them in Cloudflare R2.

Replicate FLUX Image Generation MCP Server

Overview

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.


Features

  • Image Generation: Uses Replicate's black-forest-labs/flux-schnell model to generate images.
  • Cloudflare R2 Storage: Stores generated images in a Cloudflare R2 bucket.
  • Customizable Prompts: Supports custom prompts and filenames for image generation.
  • Accessible URLs: Returns publicly accessible URLs for the generated images.

Prerequisites

Before setting up the server, ensure you have the following:

  • Node.js (v16 or higher)
  • Replicate API Token
  • Cloudflare R2 Bucket and credentials
  • npm or yarn

Environment Variables

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

Installation

Via Smithery

You can install the server automatically using Smithery:

npx -y @smithery/cli install @andylee20014/mcp-replicate-flux --client claude

Manual Installation

To set up the project manually:

  1. Clone the repository:
    shell git clone https://github.com/andylee20014/mcp-replicate-flux.git cd mcp-replicate-flux

  2. Install dependencies:
    shell npm install

  3. Create and configure the .env file:
    shell cp .env.example .env # Edit .env with your actual credentials


Usage

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.

Example Integration

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" }
  ]
}

Testing

A test script is provided to verify the image generation and upload functionality.

Running the Test

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.


Configuration for Cursor

Method 1: Complete Configuration

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"
      }
    }
  }
}

Method 2: Minimal Configuration

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"]
    }
  }
}

Troubleshooting

Common Issues

  1. Image generation fails: Check your Replicate API token and quota.
  2. R2 upload fails: Verify your R2 credentials and bucket permissions.
  3. Cannot access generated images: Ensure your R2 bucket has proper CORS configuration.

Project Structure

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

References


License

MIT

Features & Capabilities

Categories
mcp_server model_context_protocol javascript replicate cloudflare_r2 image_generation api_integration docker

Implementation Details

Stats

0 Views
5 GitHub Stars

Repository Info

andylee20014 Organization

Similar MCP Servers

continuedev_continue by continuedev
25049
21423
9300