npm package: @renzof/mcp-image-gen
Description: MCP server for AI image generation supporting multiple providers
Author: RenzoF
Latest version: 1.0.1

# MCP Image Generation Server

An MCP (Model Context Protocol) server that provides AI image generation capabilities through multiple providers including OpenAI DALL-E and Replicate.

## Features

- **Multi-provider support**: OpenAI (DALL-E 2/3) and Replicate (Stable Diffusion, etc.)
- **Flexible configuration**: Configure providers via environment variables
- **Size handling**: Automatic size conversion for different providers
- **Model selection**: Choose specific models per request
- **Error handling**: Graceful error handling with informative messages

## Installation

### From npm (Recommended)

```bash
npm install @renzof/mcp-image-gen
```

### From Source

Alternatively, you can clone and build locally:

```bash
git clone https://github.com/RenzoF/mcp-image-gen.git
cd mcp-image-gen
npm install
npm run build
```

## Configuration

### API Keys

API keys can be provided in two ways:

1. **Through MCP configuration** (recommended for Claude Desktop):
   - Pass API keys as command-line arguments in the MCP configuration
   - Keys are securely passed when the server starts

2. **Through environment variables** (for development/testing):
   - Set `OPENAI_API_KEY` for OpenAI
   - Set `REPLICATE_API_TOKEN` for Replicate

### Claude Desktop Configuration

Add to your Claude Desktop configuration file:

#### If installed via npm:
```json
{
  "mcpServers": {
    "image-gen": {
      "command": "npx",
      "args": [
        "@renzof/mcp-image-gen",
        "--openai-api-key",
        "sk-your-openai-api-key",
        "--replicate-api-token",
        "r8_your-replicate-token"
      ]
    }
  }
}
```

#### If cloned locally:
```json
{
  "mcpServers": {
    "image-gen": {
      "command": "node",
      "args": [
        "/path/to/mcp-image-gen/dist/index.js",
        "--openai-api-key",
        "sk-your-openai-api-key",
        "--replicate-api-token",
        "r8_your-replicate-token"
      ]
    }
  }
}
```

**Notes**: 
- Replace the API key placeholders with your actual API keys
- At least one provider API key is required (OpenAI or Replicate)
- For local installation, replace `/path/to/mcp-image-gen` with your actual path
- The npm package will be automatically downloaded when first used with `npx`

## Usage

The server provides a `generate_image` tool with the following parameters:

### Parameters

- **prompt** (required): Text description of the image to generate
- **size** (optional): Image dimensions (default: "1024x1024")
  - Common sizes: "256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"
- **provider** (optional): Image generation provider ("openai" or "replicate")
- **model** (optional): Specific model to use
  - OpenAI: "dall-e-2", "dall-e-3" (default)
  - Replicate: Model version string (e.g., "stability-ai/stable-diffusion:...")

### Example Usage in Claude

```
Generate an image of a sunset over mountains
```

```
Generate an image with size 1792x1024 of a futuristic city
```

```
Generate an image using replicate provider of a cat wearing sunglasses
```

## Supported Providers

### OpenAI

- Models: DALL-E 2, DALL-E 3
- Sizes: 256x256, 512x512, 1024x1024, 1792x1024, 1024x1792
- Requires: `OPENAI_API_KEY`

### Replicate

- Models: Stable Diffusion and other models on Replicate
- Sizes: Any custom size (provider handles dynamically)
- Requires: `REPLICATE_API_TOKEN`

## Development

### Building

```bash
npm install
npm run build
```

### Running locally

```bash
npm run dev
```

### Project Structure

```
mcp-image-gen/
├── src/
│   ├── index.ts          # MCP server implementation
│   ├── image-generator.ts # Image generation logic
│   └── types.ts          # TypeScript type definitions
├── dist/                 # Compiled JavaScript (generated)
├── package.json
├── tsconfig.json
└── README.md
```

## Error Handling

The server handles various error cases:
- Missing API keys
- Invalid provider selection
- API errors from providers
- Network issues
- Invalid parameters

Errors are returned with descriptive messages to help troubleshoot issues.

## License

MIT