Replicate Flux MCP server

Connects to Replicate's image generation models, enabling text-to-image creation with automatic cloud storage of results for seamless visual content integration.
Back to servers
Provider
Andy Lee
Release date
Mar 20, 2025
Language
TypeScript
Stats
6 stars

This MCP server generates images using Replicate's FLUX model and stores them in Cloudflare R2, providing accessible image URLs. It supports custom prompts and filenames through a simple interface.

Prerequisites

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

Environment Variables

Required environment variables in your .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

Installing via Smithery

To install automatically via Smithery for Claude Desktop:

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

Manual Installation

# 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.

Running the Server

To start the MCP server locally:

node index.js

The server will listen for MCP protocol messages on standard input/output.

Usage

The server provides a generate-image tool that accepts two parameters:

  • prompt: The text prompt for image generation
  • filename: The desired filename for the generated image

Integration Example

Here's how to integrate with this MCP server using the MCP client library:

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

Testing

A test script is provided to verify functionality:

node test.js

The test script will:

  1. Generate an image with a sample prompt
  2. Upload the image to Cloudflare R2
  3. Return the accessible URL

Cursor MCP Configuration

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": "MCP server that generates images using Replicate's FLUX model",
      "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:

{
  "mcpServers": {
    "replicate-flux": {
      "command": "node",
      "args": ["C:\\Users\\YourUsername\\path\\to\\mcp-replicate-flux\\index.js"]
    }
  }
}

When using the minimal configuration, ensure your environment variables are properly set up. After changing the configuration, restart Cursor to apply the changes.

Troubleshooting

Common Issues

  • 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

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later