Skip to main content
Glama
README.md
# Image Generator MCP Server

A Laravel app that exposes AI image generation as a [Model Context Protocol](https://modelcontextprotocol.io) (MCP) tool, built with `laravel/mcp` and `laravel/ai`. Any MCP-compatible client — Claude, Claude Code, Cursor, ChatGPT, etc. — can call it to generate an image from a text prompt.

## What it does

The server registers one tool, `generate-image`. When an MCP client calls it with a prompt, the tool passes the prompt to the Laravel AI SDK, which generates the image via OpenAI, Gemini, or xAI (whichever provider you've configured), stores the result, and returns the image (or a link to it) back to the client.

## Requirements

- PHP 8.2+, Laravel 12.x or 13.x
- An API key for at least one supported image provider

## Installation

```bash
composer require laravel/mcp laravel/ai

php artisan vendor:publish --tag=ai-routes
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
php artisan migrate
```

Add a provider key to `.env`:

```env
OPENAI_API_KEY=
GEMINI_API_KEY=
XAI_API_KEY=
```

The server is registered in `routes/ai.php`:

```php
use App\Mcp\Servers\ImageGeneratorServer;
use Laravel\Mcp\Facades\Mcp;

Mcp::web('/mcp/image-generator', ImageGeneratorServer::class);
```

## How to use it

Point any MCP client at the server's URL:

```json
{
  "mcpServers": {
    "image-generator": {
      "url": "https://your-app.test/mcp/image-generator"
    }
  }
}
```

Once connected, just ask the client to generate an image — for example, "generate an image of a private jet" — and it will call the `generate-image` tool with your prompt and return the result. The tool accepts:

- `prompt` (required) — what to generate
- `aspect_ratio` — `square`, `portrait`, or `landscape` (default `square`)
- `quality` — `low`, `medium`, or `high` (default `medium`)

If the endpoint requires authentication, add a bearer token to the client config:

```json
{
  "mcpServers": {
    "image-generator": {
      "url": "https://your-app.test/mcp/image-generator",
      "headers": { "Authorization": "Bearer YOUR_TOKEN" }
    }
  }
}
```