Skip to main content

MCP Server for Cloudflare AI image generation

Project description

AI Image Generation MCP Server

MCP Server for the Cloudflare AI API, enabling image generation operations with multiple models and prompt generation capabilities.

Overview

This MCP server provides tools to generate images using Cloudflare's AI models while preserving quality and supporting multiple model types.

Features

  • Multiple Model Support: Supports various Stable Diffusion models from Cloudflare AI
  • Concurrent Generation: Generate images with multiple models simultaneously
  • Prompt Generation: AI-powered prompt generation for better results
  • Comprehensive Error Handling: Clear error messages for common issues
  • Batch Operations: Support for generating multiple images in parallel

Tools

  1. generate_images

    • Generate images using multiple models simultaneously
    • Inputs:
      • prompt (string): Image generation prompt
      • size_id (string): Image size (e.g., "1024x1024")
    • Returns: Dictionary of model IDs to generated images
  2. generate_prompt

    • Generate detailed image prompts using AI
    • Inputs:
      • theme (string): Basic theme to expand
    • Returns: Detailed generation prompt

Setup

Prerequisites

  • Python 3.10 or higher
  • Sufficient disk space (1GB+ recommended)
  • Stable network connection
  • Cloudflare account and API token

Cloudflare API Token

Create a Cloudflare API Token with appropriate permissions:

  1. Log in to Cloudflare Dashboard

  2. Get Account ID:

    • Click account icon in top right
    • Select "Account Home"
    • Find "Account ID" in overview
  3. Create API Token:

    • Go to "My Profile"
    • Select "API Tokens"
    • Click "Create Token"
    • Choose "Create Custom Token"
    • Add permissions:
      • Account.AI - Read & Edit
      • Account.Workers AI - Read & Edit

Installation

Option 1: Manual Installation via Configuration File

Add to your Claude Desktop config file:

  • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "CloudflareAI": {
      "command": "uvx",
      "args": ["cloudflare-ai"]
    }
  }
}

Option 2: Automatic Installation via Smithery

npx -y @smithery/cli install cloudflare-ai --client claude

Development

Building and Publishing

# Sync dependencies
uv sync

# Build package
uv build

# Publish to PyPI
uv publish

Debugging

For the best debugging experience, use the MCP Inspector:

npx @modelcontextprotocol/inspector python serv.py

Project Structure

cloudflare-ai/
├── src/
│   └── cloudflare_ai/
│       ├── __init__.py
│       ├── server.py
│       ├── tools/
│       │   ├── __init__.py
│       │   ├── generate_images.py
│       │   └── generate_prompt.py
│       └── utils/
│           ├── __init__.py
│           ├── cloudflare.py
│           └── logging.py
├── demo/
│   └── examples.py
├── tests/
│   └── test_tools.py
├── pyproject.toml
├── uv.lock
├── README.md
└── README_CN.md

Configuration

Local Development

  1. Copy example config:
cp .env.example .env
  1. Edit configuration:
CLOUDFLARE_ACCOUNT_ID=your_account_id
CLOUDFLARE_API_TOKEN=your_api_token

Production Environment

For production, use environment variables:

# Linux/Mac
export CLOUDFLARE_ACCOUNT_ID="your_account_id"
export CLOUDFLARE_API_TOKEN="your_api_token"

# Windows
set CLOUDFLARE_ACCOUNT_ID=your_account_id
set CLOUDFLARE_API_TOKEN=your_api_token

Running the Server

MCP Client Configuration

Add the following configuration to your MCP client settings:

{
  "mcpServers": {
    "CloudflareAI": {
      "command": "python",
      "args": ["serv.py"],
      "env": {
        "CLOUDFLARE_ACCOUNT_ID": "your_account_id",
        "CLOUDFLARE_API_TOKEN": "your_api_token"
      },
      "cwd": "/path/to/server/directory"
    }
  }
}

Configuration options:

  • command: Python executable path
  • args: Server script and arguments
  • env: Environment variables for authentication
  • cwd: Working directory for the server

You can also use the server with custom port:

{
  "mcpServers": {
    "CloudflareAI": {
      "command": "python",
      "args": ["serv.py", "--port", "8080"],
      "env": {
        "CLOUDFLARE_ACCOUNT_ID": "your_account_id",
        "CLOUDFLARE_API_TOKEN": "your_api_token"
      }
    }
  }
}

Development Mode

# Run server in test mode
python serv.py

Production Deployment

Using uvicorn or gunicorn:

  1. Install server:
pip install uvicorn gunicorn
  1. Run with uvicorn:
uvicorn serv:app --host 0.0.0.0 --port 8000 --workers 4
  1. Or with gunicorn (Linux/Mac only):
gunicorn serv:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000

Monitoring & Logging

Log Configuration

Create logging.conf:

import logging

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler('server.log'),
        logging.StreamHandler()
    ]
)

Performance Monitoring

Recommended tools:

  • Prometheus + Grafana
  • New Relic
  • Datadog

Security Recommendations

  1. Use HTTPS
  2. Implement rate limiting
  3. Keep dependencies updated
  4. Never hardcode credentials
  5. Set proper file permissions

Troubleshooting

Common Issues

  1. API Credential Errors:

    • Verify Account ID and API Token
    • Check token permissions
  2. Network Issues:

    • Check firewall settings
    • Verify network connectivity
  3. Memory Issues:

    • Adjust worker count
    • Monitor memory usage

Debug Mode

# Run with debug mode enabled
DEBUG=1 python serv.py

Maintenance

  1. Update dependencies:
pip install --upgrade -r requirements.txt
  1. Monitor Cloudflare API changes
  2. Monitor disk usage
  3. Backup configuration files regularly

Support

For assistance:

  1. Check documentation
  2. Submit GitHub Issue
  3. Contact technical support

License

This MCP server is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloudflare_ai_mcp-0.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cloudflare_ai_mcp-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file cloudflare_ai_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: cloudflare_ai_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for cloudflare_ai_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 24822914fec01881e177f7f919cc53e1578722292e28a4c7e25113685a997484
MD5 d0af707a00c390e2164a9e21847272e6
BLAKE2b-256 ddc1b4db13c10fc64d471d3183d6702383f53ecfb43523dac21afc0e2b506e22

See more details on using hashes here.

File details

Details for the file cloudflare_ai_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudflare_ai_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a7f3862987cb301c8644ddbc80a0ce1da388854093186116b22d80a6351d4a9
MD5 23e297c2c517472aaf0c65365a6e07ad
BLAKE2b-256 29aee7f9f2c7286e7a3d1ec082c2e1433d98fe092014cc27ab728197f11d3fdf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page