mcp-server-openai-image-generator
Generates images from text prompts using OpenAI's API, saves them locally, and serves them via an integrated HTTP static file server.
README
mcp-server-openai-image-generator
An MCP (Model Context Protocol) server that exposes an OpenAI image generation tool over HTTP. It generates images from text prompts, saves them locally, and serves them via an integrated static file server.
Stack
- Runtime / Language: Bun + TypeScript
- MCP Transport: HTTP — standard JSON responses (
POST /mcp) - Image generation: OpenAI Images API (
gpt-image-2by default) - CORS:
Access-Control-Allow-Origin: *on all routes
Prerequisites
- Bun >= 1.0
- An OpenAI API key with access to the Images API
Installation
bun install
Configuration
Edit config.json at the project root:
{
"port": 1980,
"model": "gpt-image-2",
"size": "1024x1536",
"quality": "low",
"imagesDir": "images"
}
| Field | Description | Default |
|---|---|---|
port |
HTTP server listening port | 1980 |
model |
OpenAI image model | "gpt-image-2" |
size |
Generated image dimensions | "1024x1536" |
quality |
Image quality ("low", "medium", "high") |
"low" |
imagesDir |
Directory where generated images are stored | "images" |
The imagesDir directory is created automatically if it does not exist.
API Key
Provide your OpenAI key via the environment variable:
export OPENAI_API_KEY=sk-...
Usage
# production
bun run start
# development (watch mode)
bun run dev
The server starts on the configured port (default: http://localhost:1980).
MCP Tool: generate_image
Request
POST /mcp with a JSON-RPC 2.0 body:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "generate_image",
"arguments": {
"description": "A futuristic city at sunset, digital art"
}
}
}
Response
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"url": "http://localhost:1980/images/1720000000000.png",
"filename": "1720000000000.png",
"model": "gpt-image-2",
"size": "1024x1536",
"prompt": "A futuristic city at sunset, digital art"
}
}
Generated images are saved as <timestamp>.png in imagesDir and immediately accessible at GET /images/:filename.
Project Structure
src/
index.ts # Entry point — loads config, starts server
server.ts # Bun HTTP server, routes requests
mcpHandler.ts # JSON-RPC 2.0 MCP handler
imageGenerator.ts # OpenAI Images API integration
staticHandler.ts # Static file serving for generated images
config.ts # Config loading from config.json
types.ts # Shared TypeScript types
config.json # Server configuration
images/ # Generated images (auto-created)
License
Private — all rights reserved.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.