commit 510a722f7482366f2b4bcd31953657f38ee4e828 Author: fdciabdul Date: Tue Mar 24 21:15:54 2026 +0700 Initial release: MCP Image Generator Multi-provider MCP server for AI image generation. Supports OpenRouter, Together AI, Replicate, and fal.ai. Works with Claude Code, Cursor, Claude Desktop, OpenCode, and Charm. Install via: npx -y mcp-image-generator Co-Authored-By: Claude Opus 4.6 (1M context) diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..4f340a2 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,11 @@ +{ + "permissions": { + "allow": [ + "Bash(npm run:*)", + "Bash(chmod:*)", + "Bash(git init:*)", + "Bash(git checkout:*)", + "Bash(git add:*)" + ] + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ebc8da --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +dist/ +*.js.map +.env +generated-images/ diff --git a/.mcp.json b/.mcp.json new file mode 100644 index 0000000..0ff3d25 --- /dev/null +++ b/.mcp.json @@ -0,0 +1,11 @@ +{ + "mcpServers": { + "image-gen": { + "command": "node", + "args": ["dist/index.js"], + "env": { + "OPENROUTER_API_KEY": "${OPENROUTER_API_KEY}" + } + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..fbaeb28 --- /dev/null +++ b/README.md @@ -0,0 +1,205 @@ +

+ MCP Image Generator Logo +

+ +

MCP Image Generator

+ +

+MCP server for AI image generation. Works with Claude Code, Cursor, Claude Desktop, OpenCode, Charm (Crush/Mods), and any MCP-compatible AI agent. +

+ +**Providers supported** (image models only): +- **OpenRouter** (default) — Gemini Flash Image, FLUX 2, Sourceful Riverflow, GPT-5 Image +- **Together AI** — FLUX.1 Schnell/Dev/Pro, Stable Diffusion XL +- **Replicate** — FLUX Schnell, FLUX 1.1 Pro, SDXL, Ideogram +- **fal.ai** — FLUX Dev/Schnell/2 Pro, Recraft V3 + +## Quick Start + +No install needed — just use `npx`: + +```bash +OPENROUTER_API_KEY="sk-or-v1-..." npx -y mcp-image-generator +``` + +## Tools + +### `generate_image` +Generate an image from a text prompt. + +| Parameter | Type | Description | +|-----------|------|-------------| +| `prompt` | string (required) | Text description of the image | +| `model` | string | Model ID (e.g. `google/gemini-2.5-flash-image`) | +| `provider` | string | `openrouter` (default), `together`, `replicate`, `fal` | +| `aspect_ratio` | string | `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `3:2`, `2:3` | +| `image_size` | string | `1K` (default), `2K`, `4K` | +| `negative_prompt` | string | What to exclude (not all providers support this) | +| `seed` | number | Random seed for reproducibility | +| `save_to` | string | Custom file path to save the image | + +### `list_providers` +List all configured providers and their available image models. + +| Parameter | Type | Description | +|-----------|------|-------------| +| `provider` | string | Filter by provider name | + +--- + +## Setup for AI Agents / IDEs + +### Claude Code + +```bash +claude mcp add --scope user --transport stdio image-gen \ + --env OPENROUTER_API_KEY=sk-or-v1-xxx \ + -- npx -y mcp-image-generator +``` + +Or create `.mcp.json` in your project root: +```json +{ + "mcpServers": { + "image-gen": { + "command": "npx", + "args": ["-y", "mcp-image-generator"], + "env": { + "OPENROUTER_API_KEY": "sk-or-v1-..." + } + } + } +} +``` + +### Cursor + +Edit `~/.cursor/mcp.json`: +```json +{ + "mcpServers": { + "image-gen": { + "command": "npx", + "args": ["-y", "mcp-image-generator"], + "env": { + "OPENROUTER_API_KEY": "sk-or-v1-..." + } + } + } +} +``` + +### Claude Desktop + +Edit the config file: +- **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json` +- **Windows:** `%APPDATA%\Claude\claude_desktop_config.json` +- **Linux:** `~/.config/Claude/claude_desktop_config.json` + +```json +{ + "mcpServers": { + "image-gen": { + "command": "npx", + "args": ["-y", "mcp-image-generator"], + "env": { + "OPENROUTER_API_KEY": "sk-or-v1-..." + } + } + } +} +``` + +### OpenCode (by SST) + +Edit `~/.config/opencode/opencode.json` or `opencode.json` in project root: +```json +{ + "mcp": { + "image-gen": { + "type": "local", + "command": ["npx", "-y", "mcp-image-generator"], + "environment": { + "OPENROUTER_API_KEY": "sk-or-v1-..." + }, + "enabled": true, + "timeout": 120000 + } + } +} +``` + +### Charm Crush + +Add to `crush.json` in your project root: +```json +{ + "mcp": { + "image-gen": { + "type": "stdio", + "command": "npx", + "args": ["-y", "mcp-image-generator"], + "env": { + "OPENROUTER_API_KEY": "sk-or-v1-..." + } + } + } +} +``` + +### Charm Mods + +Edit `mods.yml` (`mods --settings`): +```yaml +mcp-servers: + image-gen: + command: [npx] + args: + - -y + - mcp-image-generator + env: + - OPENROUTER_API_KEY=sk-or-v1-... +``` + +### Any MCP-compatible agent + +This server uses **stdio transport** (JSON-RPC over stdin/stdout). Any agent that supports MCP stdio can use it: + +```bash +npx -y mcp-image-generator + +# Required environment variables (at least one) +OPENROUTER_API_KEY=... # OpenRouter (default) +TOGETHER_API_KEY=... # Together AI +REPLICATE_API_TOKEN=... # Replicate +FAL_KEY=... # fal.ai +``` + +## Using Multiple Providers + +Set multiple API keys to use different providers: + +```bash +export OPENROUTER_API_KEY="sk-or-v1-..." +export TOGETHER_API_KEY="..." +export FAL_KEY="..." +``` + +Then specify the provider when generating: +``` +generate_image(prompt="a cat", provider="together", model="black-forest-labs/FLUX.1-schnell") +``` + +## Environment Variables + +| Variable | Provider | Required | +|----------|----------|----------| +| `OPENROUTER_API_KEY` | OpenRouter | At least one | +| `TOGETHER_API_KEY` | Together AI | provider key | +| `REPLICATE_API_TOKEN` | Replicate | is required | +| `FAL_KEY` | fal.ai | | +| `IMAGE_OUTPUT_DIR` | — | Optional. Default: `~/generated-images/` | + +## License + +MIT diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..9404629 Binary files /dev/null and b/logo.png differ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..9b0457d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1175 @@ +{ + "name": "mcp-image-generator", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "mcp-image-generator", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@modelcontextprotocol/sdk": "^1.27.1", + "zod": "^4.3.6" + }, + "devDependencies": { + "@types/node": "^25.5.0", + "typescript": "^6.0.2" + } + }, + "node_modules/@hono/node-server": { + "version": "1.19.11", + "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-1.19.11.tgz", + "integrity": "sha512-dr8/3zEaB+p0D2n/IUrlPF1HZm586qgJNXK1a9fhg/PzdtkK7Ksd5l312tJX2yBuALqDYBlG20QEbayqPyxn+g==", + "license": "MIT", + "engines": { + "node": ">=18.14.1" + }, + "peerDependencies": { + "hono": "^4" + } + }, + "node_modules/@modelcontextprotocol/sdk": { + "version": "1.27.1", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.27.1.tgz", + "integrity": "sha512-sr6GbP+4edBwFndLbM60gf07z0FQ79gaExpnsjMGePXqFcSSb7t6iscpjk9DhFhwd+mTEQrzNafGP8/iGGFYaA==", + "license": "MIT", + "dependencies": { + "@hono/node-server": "^1.19.9", + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", + "content-type": "^1.0.5", + "cors": "^2.8.5", + "cross-spawn": "^7.0.5", + "eventsource": "^3.0.2", + "eventsource-parser": "^3.0.0", + "express": "^5.2.1", + "express-rate-limit": "^8.2.1", + "hono": "^4.11.4", + "jose": "^6.1.3", + "json-schema-typed": "^8.0.2", + "pkce-challenge": "^5.0.0", + "raw-body": "^3.0.0", + "zod": "^3.25 || ^4.0", + "zod-to-json-schema": "^3.25.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@cfworker/json-schema": "^4.1.1", + "zod": "^3.25 || ^4.0" + }, + "peerDependenciesMeta": { + "@cfworker/json-schema": { + "optional": true + }, + "zod": { + "optional": false + } + } + }, + "node_modules/@types/node": { + "version": "25.5.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.5.0.tgz", + "integrity": "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.18.0" + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ajv": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", + "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/body-parser": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.2.tgz", + "integrity": "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.3", + "http-errors": "^2.0.0", + "iconv-lite": "^0.7.0", + "on-finished": "^2.4.1", + "qs": "^6.14.1", + "raw-body": "^3.0.1", + "type-is": "^2.0.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.1.tgz", + "integrity": "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/eventsource": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz", + "integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==", + "license": "MIT", + "dependencies": { + "eventsource-parser": "^3.0.1" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.6.tgz", + "integrity": "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/express": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.1", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express-rate-limit": { + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.3.1.tgz", + "integrity": "sha512-D1dKN+cmyPWuvB+G2SREQDzPY1agpBIcTa9sJxOPMCNeH3gwzhqJRDWCXW3gg0y//+LQ/8j52JbMROWyrKdMdw==", + "license": "MIT", + "dependencies": { + "ip-address": "10.1.0" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/express-rate-limit" + }, + "peerDependencies": { + "express": ">= 4.11" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, + "node_modules/fast-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", + "integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/hono": { + "version": "4.12.9", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.12.9.tgz", + "integrity": "sha512-wy3T8Zm2bsEvxKZM5w21VdHDDcwVS1yUFFY6i8UobSsKfFceT7TOwhbhfKsDyx7tYQlmRM5FLpIuYvNFyjctiA==", + "license": "MIT", + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.2.tgz", + "integrity": "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ip-address": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz", + "integrity": "sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "license": "ISC" + }, + "node_modules/jose": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.2.tgz", + "integrity": "sha512-d7kPDd34KO/YnzaDOlikGpOurfF0ByC2sEV4cANCtdqLlTfBlw2p14O/5d/zv40gJPbIQxfES3nSx1/oYNyuZQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "node_modules/json-schema-typed": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.2.tgz", + "integrity": "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA==", + "license": "BSD-2-Clause" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.3.0.tgz", + "integrity": "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/pkce-challenge": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz", + "integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==", + "license": "MIT", + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz", + "integrity": "sha512-mAZTtNCeetKMH+pSjrb76NAM8V9a05I9aBZOHztWy/UqcJdQYNsf59vrRKWnojAT9Y+GbIvoTBC++CPHqpDBhQ==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", + "license": "MIT", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/typescript": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.2.tgz", + "integrity": "sha512-bGdAIrZ0wiGDo5l8c++HWtbaNCWTS4UTv7RaTH/ThVIgjkveJt83m74bBHMJkuCbslY8ixgLBVZJIOiQlQTjfQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "7.18.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", + "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", + "dev": true, + "license": "MIT" + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/zod": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz", + "integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zod-to-json-schema": { + "version": "3.25.1", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.25.1.tgz", + "integrity": "sha512-pM/SU9d3YAggzi6MtR4h7ruuQlqKtad8e9S0fmxcMi+ueAK5Korys/aWcV9LIIHTVbj01NdzxcnXSN+O74ZIVA==", + "license": "ISC", + "peerDependencies": { + "zod": "^3.25 || ^4" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..9e7dab6 --- /dev/null +++ b/package.json @@ -0,0 +1,48 @@ +{ + "name": "mcp-image-generator", + "version": "1.0.0", + "description": "MCP server for AI image generation via OpenRouter, Together AI, Replicate, and fal.ai", + "type": "module", + "main": "dist/index.js", + "bin": { + "mcp-image-generator": "dist/index.js" + }, + "files": [ + "dist", + "README.md", + "logo.png" + ], + "scripts": { + "build": "tsc", + "start": "node dist/index.js", + "prepublishOnly": "npm run build" + }, + "keywords": [ + "mcp", + "image-generation", + "openrouter", + "together-ai", + "replicate", + "fal-ai", + "ai", + "claude-code", + "cursor", + "claude-desktop", + "opencode", + "model-context-protocol" + ], + "author": "fdciabdul", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://git.imtaqin.id/fdciabdul/MCP-IMAGE-GENERATOR.git" + }, + "dependencies": { + "@modelcontextprotocol/sdk": "^1.27.1", + "zod": "^4.3.6" + }, + "devDependencies": { + "@types/node": "^25.5.0", + "typescript": "^6.0.2" + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..31496f9 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,245 @@ +#!/usr/bin/env node +import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; +import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; +import { z } from "zod"; +import { createProviders, getDefaultProvider } from "./providers/index.js"; +import type { ImageProvider, ImageModel } from "./types.js"; +import { writeFile, mkdir } from "node:fs/promises"; +import { join, resolve } from "node:path"; +import { existsSync } from "node:fs"; + +const providers = createProviders(); + +if (providers.size === 0) { + console.error( + "No API keys configured. Set at least one of: OPENROUTER_API_KEY, TOGETHER_API_KEY, REPLICATE_API_TOKEN, FAL_KEY" + ); + process.exit(1); +} + +const server = new McpServer({ + name: "mcp-image-generator", + version: "1.0.0", +}); + +// ─── Tool: list_providers ─────────────────────────────────────────────────── + +server.registerTool("list_providers", { + title: "List Image Providers", + description: "List all configured image generation providers and their available models", + inputSchema: { + provider: z + .string() + .optional() + .describe("Filter by provider name: openrouter, together, replicate, fal"), + }, +}, async ({ provider: providerName }) => { + const targetProviders: ImageProvider[] = []; + + if (providerName) { + const p = providers.get(providerName); + if (!p) { + return { + content: [ + { + type: "text" as const, + text: `Provider "${providerName}" is not configured. Available: ${[...providers.keys()].join(", ")}`, + }, + ], + }; + } + targetProviders.push(p); + } else { + targetProviders.push(...providers.values()); + } + + const allModels: ImageModel[] = []; + for (const p of targetProviders) { + try { + const models = await p.listModels(); + allModels.push(...models); + } catch (err) { + allModels.push({ + id: `error-${p.name}`, + name: `Error loading ${p.name} models`, + provider: p.name, + description: String(err), + inputModalities: [], + outputModalities: [], + modalities: [], + }); + } + } + + const grouped = new Map(); + for (const m of allModels) { + const list = grouped.get(m.provider) ?? []; + list.push(m); + grouped.set(m.provider, list); + } + + let text = `# Available Image Generation Models\n\n`; + text += `**Configured providers:** ${[...providers.keys()].join(", ")}\n\n`; + + for (const [provName, models] of grouped) { + text += `## ${provName}\n\n`; + for (const m of models) { + text += `- **${m.id}** — ${m.name}`; + if (m.description) text += ` — ${m.description}`; + if (m.pricing) text += ` (${m.pricing})`; + text += `\n`; + } + text += `\n`; + } + + return { content: [{ type: "text" as const, text }] }; +}); + +// ─── Tool: generate_image ─────────────────────────────────────────────────── + +const outputDir = resolve(process.env["IMAGE_OUTPUT_DIR"] ?? process.env["HOME"] ?? ".", "generated-images"); + +server.registerTool("generate_image", { + title: "Generate Image", + description: + "Generate an image from a text prompt. Uses OpenRouter by default. Supports multiple providers: openrouter, together, replicate, fal.", + inputSchema: { + prompt: z.string().describe("Text description of the image to generate"), + model: z + .string() + .optional() + .describe("Model ID (e.g. 'google/gemini-2.5-flash-image', 'black-forest-labs/flux-schnell')"), + provider: z + .string() + .optional() + .describe("Provider to use: openrouter (default), together, replicate, fal"), + aspect_ratio: z + .string() + .optional() + .describe("Aspect ratio: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3"), + image_size: z + .string() + .optional() + .describe("Image resolution: 1K (default), 2K, 4K"), + negative_prompt: z + .string() + .optional() + .describe("What to exclude from the image (not supported by all providers)"), + seed: z.number().optional().describe("Random seed for reproducibility"), + save_to: z + .string() + .optional() + .describe("Custom file path to save the image. Defaults to ~/generated-images/"), + }, +}, async ({ prompt, model, provider: providerName, aspect_ratio, image_size, negative_prompt, seed, save_to }) => { + // Select provider + let selectedProvider: ImageProvider | undefined; + if (providerName) { + selectedProvider = providers.get(providerName); + if (!selectedProvider) { + return { + content: [ + { + type: "text" as const, + text: `Provider "${providerName}" is not configured. Available: ${[...providers.keys()].join(", ")}`, + }, + ], + }; + } + } else { + selectedProvider = getDefaultProvider(providers); + } + + if (!selectedProvider) { + return { + content: [{ type: "text" as const, text: "No providers configured." }], + }; + } + + try { + const result = await selectedProvider.generateImage({ + prompt, + model, + provider: selectedProvider.name, + aspectRatio: aspect_ratio, + imageSize: image_size, + negativePrompt: negative_prompt, + seed, + }); + + if (result.images.length === 0) { + return { + content: [ + { + type: "text" as const, + text: `Image generation completed but no images were returned. Model: ${result.model}, Provider: ${result.provider}`, + }, + ], + }; + } + + // Save images to disk + const saveDir = save_to ? resolve(save_to, "..") : outputDir; + if (!existsSync(saveDir)) { + await mkdir(saveDir, { recursive: true }); + } + + const contentItems: Array< + | { type: "text"; text: string } + | { type: "image"; data: string; mimeType: string } + > = []; + + for (let i = 0; i < result.images.length; i++) { + const img = result.images[i]!; + const ext = img.mimeType.includes("webp") + ? "webp" + : img.mimeType.includes("jpeg") || img.mimeType.includes("jpg") + ? "jpg" + : "png"; + + const filename = save_to + ? save_to + : join(saveDir, `img_${Date.now()}_${i}.${ext}`); + + await writeFile(filename, Buffer.from(img.base64, "base64")); + + contentItems.push({ + type: "text" as const, + text: `Image ${i + 1} saved to: ${filename}\nModel: ${result.model} | Provider: ${result.provider}${ + result.usage?.cost != null ? ` | Cost: $${result.usage.cost.toFixed(4)}` : "" + }`, + }); + + contentItems.push({ + type: "image" as const, + data: img.base64, + mimeType: img.mimeType, + }); + } + + return { content: contentItems }; + } catch (err) { + return { + content: [ + { + type: "text" as const, + text: `Image generation failed: ${err instanceof Error ? err.message : String(err)}`, + }, + ], + }; + } +}); + +// ─── Start Server ─────────────────────────────────────────────────────────── + +async function main() { + const transport = new StdioServerTransport(); + await server.connect(transport); + console.error("MCP Image Generator server started"); + console.error(`Providers: ${[...providers.keys()].join(", ")}`); +} + +main().catch((err) => { + console.error("Fatal error:", err); + process.exit(1); +}); diff --git a/src/providers/fal.ts b/src/providers/fal.ts new file mode 100644 index 0000000..6be622f --- /dev/null +++ b/src/providers/fal.ts @@ -0,0 +1,124 @@ +import type { ImageProvider, ImageModel, GenerateImageRequest, GenerateImageResult } from "../types.js"; + +const API_BASE = "https://queue.fal.run"; + +const FAL_IMAGE_MODELS: ImageModel[] = [ + { + id: "fal-ai/flux/dev", + name: "FLUX.1 Dev", + provider: "fal", + description: "FLUX.1 development model on fal.ai", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, + { + id: "fal-ai/flux/schnell", + name: "FLUX.1 Schnell", + provider: "fal", + description: "Fast FLUX model on fal.ai", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, + { + id: "fal-ai/flux-2-pro", + name: "FLUX 2 Pro", + provider: "fal", + description: "Professional FLUX 2 model", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, + { + id: "fal-ai/recraft-v3", + name: "Recraft V3", + provider: "fal", + description: "High quality image generation", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, +]; + +export class FalProvider implements ImageProvider { + name = "fal"; + private apiKey: string; + + constructor(apiKey: string) { + this.apiKey = apiKey; + } + + async listModels(): Promise { + return FAL_IMAGE_MODELS; + } + + private parseImageSize(aspectRatio?: string): string { + const sizeMap: Record = { + "1:1": "square_hd", + "16:9": "landscape_16_9", + "9:16": "portrait_16_9", + "4:3": "landscape_4_3", + "3:4": "portrait_4_3", + }; + return sizeMap[aspectRatio ?? "1:1"] ?? "square_hd"; + } + + async generateImage(request: GenerateImageRequest): Promise { + const model = request.model ?? "fal-ai/flux/schnell"; + + const body: Record = { + prompt: request.prompt, + image_size: this.parseImageSize(request.aspectRatio), + num_images: request.n ?? 1, + output_format: "png", + sync_mode: true, + }; + + if (request.negativePrompt) body.negative_prompt = request.negativePrompt; + if (request.steps) body.num_inference_steps = request.steps; + if (request.seed != null) body.seed = request.seed; + + const res = await fetch(`${API_BASE}/${model}`, { + method: "POST", + headers: { + Authorization: `Key ${this.apiKey}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + }); + + if (!res.ok) { + throw new Error(`fal.ai error: ${res.status} ${await res.text()}`); + } + + const data = (await res.json()) as { + images: Array<{ + url: string; + width: number; + height: number; + content_type?: string; + }>; + }; + + // Download images and convert to base64 + const images = await Promise.all( + data.images.map(async (img) => { + const imgRes = await fetch(img.url); + const arrayBuf = await imgRes.arrayBuffer(); + const base64 = Buffer.from(arrayBuf).toString("base64"); + return { + base64, + mimeType: img.content_type ?? "image/png", + url: img.url, + }; + }) + ); + + return { + images, + model, + provider: "fal", + }; + } +} diff --git a/src/providers/index.ts b/src/providers/index.ts new file mode 100644 index 0000000..bbf9396 --- /dev/null +++ b/src/providers/index.ts @@ -0,0 +1,43 @@ +import type { ImageProvider } from "../types.js"; +import { OpenRouterProvider } from "./openrouter.js"; +import { TogetherProvider } from "./together.js"; +import { ReplicateProvider } from "./replicate.js"; +import { FalProvider } from "./fal.js"; + +export function createProviders(): Map { + const providers = new Map(); + + const openrouterKey = process.env["OPENROUTER_API_KEY"]; + if (openrouterKey) { + providers.set("openrouter", new OpenRouterProvider(openrouterKey)); + } + + const togetherKey = process.env["TOGETHER_API_KEY"]; + if (togetherKey) { + providers.set("together", new TogetherProvider(togetherKey)); + } + + const replicateKey = process.env["REPLICATE_API_TOKEN"]; + if (replicateKey) { + providers.set("replicate", new ReplicateProvider(replicateKey)); + } + + const falKey = process.env["FAL_KEY"]; + if (falKey) { + providers.set("fal", new FalProvider(falKey)); + } + + return providers; +} + +export function getDefaultProvider(providers: Map): ImageProvider | undefined { + // Priority: openrouter > together > fal > replicate + return ( + providers.get("openrouter") ?? + providers.get("together") ?? + providers.get("fal") ?? + providers.get("replicate") + ); +} + +export { OpenRouterProvider, TogetherProvider, ReplicateProvider, FalProvider }; diff --git a/src/providers/openrouter.ts b/src/providers/openrouter.ts new file mode 100644 index 0000000..5822901 --- /dev/null +++ b/src/providers/openrouter.ts @@ -0,0 +1,138 @@ +import type { ImageProvider, ImageModel, GenerateImageRequest, GenerateImageResult } from "../types.js"; + +const API_BASE = "https://openrouter.ai/api/v1"; + +export class OpenRouterProvider implements ImageProvider { + name = "openrouter"; + private apiKey: string; + + constructor(apiKey: string) { + this.apiKey = apiKey; + } + + private headers(): Record { + return { + Authorization: `Bearer ${this.apiKey}`, + "Content-Type": "application/json", + "HTTP-Referer": "https://github.com/mcp-image-generator", + "X-Title": "MCP Image Generator", + }; + } + + async listModels(): Promise { + const res = await fetch(`${API_BASE}/models?output_modalities=image`, { + headers: this.headers(), + }); + + if (!res.ok) { + throw new Error(`OpenRouter models API error: ${res.status} ${await res.text()}`); + } + + const data = (await res.json()) as { + data: Array<{ + id: string; + name: string; + description?: string; + pricing?: { prompt?: string; completion?: string; image?: string }; + architecture?: { + input_modalities?: string[]; + output_modalities?: string[]; + }; + }>; + }; + + return data.data.map((m) => ({ + id: m.id, + name: m.name, + provider: "openrouter", + description: m.description, + pricing: m.pricing?.image ?? m.pricing?.completion, + inputModalities: m.architecture?.input_modalities ?? ["text"], + outputModalities: m.architecture?.output_modalities ?? ["image"], + modalities: this.getModalities(m.architecture?.output_modalities ?? ["image"]), + supportedAspectRatios: [ + "1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "21:9", "9:21", + ], + supportedSizes: ["1K", "2K", "4K"], + })); + } + + private getModalities(outputModalities: string[]): string[] { + if (outputModalities.includes("text") && outputModalities.includes("image")) { + return ["image", "text"]; + } + return ["image"]; + } + + async generateImage(request: GenerateImageRequest): Promise { + const model = request.model ?? "google/gemini-2.5-flash-image"; + + // Determine modalities based on model + const isImageOnly = model.includes("flux") || model.includes("sourceful") || model.includes("riverflow"); + const modalities = isImageOnly ? ["image"] : ["image", "text"]; + + const body: Record = { + model, + modalities, + messages: [ + { + role: "user", + content: request.prompt, + }, + ], + }; + + const imageConfig: Record = {}; + if (request.aspectRatio) imageConfig.aspect_ratio = request.aspectRatio; + if (request.imageSize) imageConfig.image_size = request.imageSize; + if (Object.keys(imageConfig).length > 0) body.image_config = imageConfig; + + const res = await fetch(`${API_BASE}/chat/completions`, { + method: "POST", + headers: this.headers(), + body: JSON.stringify(body), + }); + + if (!res.ok) { + const errText = await res.text(); + throw new Error(`OpenRouter generation error: ${res.status} ${errText}`); + } + + const data = (await res.json()) as { + model: string; + choices: Array<{ + message: { + content?: string; + images?: Array<{ image_url: { url: string } }>; + }; + }>; + usage?: { + prompt_tokens?: number; + total_tokens?: number; + cost?: number; + }; + }; + + const message = data.choices[0]?.message; + const images = + message?.images?.map((img) => { + const url = img.image_url.url; + // Strip data URL prefix to get raw base64 + const base64 = url.replace(/^data:image\/\w+;base64,/, ""); + const mimeMatch = url.match(/^data:(image\/\w+);base64,/); + const mimeType = mimeMatch?.[1] ?? "image/png"; + return { base64, mimeType, url }; + }) ?? []; + + return { + images, + model: data.model, + provider: "openrouter", + usage: { + promptTokens: data.usage?.prompt_tokens, + totalTokens: data.usage?.total_tokens, + cost: data.usage?.cost, + }, + }; + } +} diff --git a/src/providers/replicate.ts b/src/providers/replicate.ts new file mode 100644 index 0000000..a434cfb --- /dev/null +++ b/src/providers/replicate.ts @@ -0,0 +1,126 @@ +import type { ImageProvider, ImageModel, GenerateImageRequest, GenerateImageResult } from "../types.js"; + +const API_BASE = "https://api.replicate.com/v1"; + +const REPLICATE_IMAGE_MODELS: ImageModel[] = [ + { + id: "black-forest-labs/flux-schnell", + name: "FLUX Schnell", + provider: "replicate", + description: "Fast, high-quality image generation", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, + { + id: "black-forest-labs/flux-1.1-pro", + name: "FLUX 1.1 Pro", + provider: "replicate", + description: "Professional quality FLUX model", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, + { + id: "stability-ai/sdxl", + name: "Stable Diffusion XL", + provider: "replicate", + description: "Stable Diffusion XL on Replicate", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, + { + id: "ideogram-ai/ideogram-v2-turbo", + name: "Ideogram V2 Turbo", + provider: "replicate", + description: "Excellent text rendering in images", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, +]; + +export class ReplicateProvider implements ImageProvider { + name = "replicate"; + private apiKey: string; + + constructor(apiKey: string) { + this.apiKey = apiKey; + } + + async listModels(): Promise { + return REPLICATE_IMAGE_MODELS; + } + + async generateImage(request: GenerateImageRequest): Promise { + const model = request.model ?? "black-forest-labs/flux-schnell"; + + const input: Record = { + prompt: request.prompt, + }; + + if (request.aspectRatio) input.aspect_ratio = request.aspectRatio; + if (request.negativePrompt) input.negative_prompt = request.negativePrompt; + if (request.steps) input.num_inference_steps = request.steps; + if (request.seed != null) input.seed = request.seed; + if (request.n) input.num_outputs = request.n; + + // Create prediction + const createRes = await fetch(`${API_BASE}/models/${model}/predictions`, { + method: "POST", + headers: { + Authorization: `Bearer ${this.apiKey}`, + "Content-Type": "application/json", + Prefer: "wait=60", + }, + body: JSON.stringify({ input }), + }); + + if (!createRes.ok) { + throw new Error(`Replicate error: ${createRes.status} ${await createRes.text()}`); + } + + let prediction = (await createRes.json()) as { + id: string; + status: string; + output?: string[]; + error?: string; + urls?: { get?: string }; + }; + + // Poll if not yet complete + if (prediction.status !== "succeeded" && prediction.status !== "failed") { + const getUrl = prediction.urls?.get ?? `${API_BASE}/predictions/${prediction.id}`; + for (let i = 0; i < 60; i++) { + await new Promise((r) => setTimeout(r, 2000)); + const pollRes = await fetch(getUrl, { + headers: { Authorization: `Bearer ${this.apiKey}` }, + }); + prediction = (await pollRes.json()) as typeof prediction; + if (prediction.status === "succeeded" || prediction.status === "failed") break; + } + } + + if (prediction.status === "failed") { + throw new Error(`Replicate prediction failed: ${prediction.error}`); + } + + // Download images and convert to base64 + const images = await Promise.all( + (prediction.output ?? []).map(async (url) => { + const imgRes = await fetch(url); + const arrayBuf = await imgRes.arrayBuffer(); + const base64 = Buffer.from(arrayBuf).toString("base64"); + const contentType = imgRes.headers.get("content-type") ?? "image/webp"; + return { base64, mimeType: contentType, url }; + }) + ); + + return { + images, + model, + provider: "replicate", + }; + } +} diff --git a/src/providers/together.ts b/src/providers/together.ts new file mode 100644 index 0000000..234f33d --- /dev/null +++ b/src/providers/together.ts @@ -0,0 +1,124 @@ +import type { ImageProvider, ImageModel, GenerateImageRequest, GenerateImageResult } from "../types.js"; + +const API_BASE = "https://api.together.xyz/v1"; + +const TOGETHER_IMAGE_MODELS: ImageModel[] = [ + { + id: "black-forest-labs/FLUX.1-schnell", + name: "FLUX.1 Schnell", + provider: "together", + description: "Fast image generation (free tier available)", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, + { + id: "black-forest-labs/FLUX.1-dev", + name: "FLUX.1 Dev", + provider: "together", + description: "Development quality FLUX model", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, + { + id: "black-forest-labs/FLUX.1.1-pro", + name: "FLUX 1.1 Pro", + provider: "together", + description: "Professional quality FLUX model", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, + { + id: "stabilityai/stable-diffusion-xl-base-1.0", + name: "Stable Diffusion XL", + provider: "together", + description: "Stable Diffusion XL base model", + inputModalities: ["text"], + outputModalities: ["image"], + modalities: ["image"], + }, +]; + +export class TogetherProvider implements ImageProvider { + name = "together"; + private apiKey: string; + + constructor(apiKey: string) { + this.apiKey = apiKey; + } + + async listModels(): Promise { + return TOGETHER_IMAGE_MODELS; + } + + private parseSize(aspectRatio?: string, imageSize?: string): { width: number; height: number } { + const baseSize = imageSize === "2K" ? 2048 : imageSize === "4K" ? 2048 : 1024; + + if (!aspectRatio || aspectRatio === "1:1") { + return { width: baseSize, height: baseSize }; + } + + const ratioMap: Record = { + "16:9": [1344, 768], + "9:16": [768, 1344], + "4:3": [1152, 896], + "3:4": [896, 1152], + "3:2": [1216, 832], + "2:3": [832, 1216], + }; + + const dims = ratioMap[aspectRatio]; + if (dims) return { width: dims[0], height: dims[1] }; + return { width: baseSize, height: baseSize }; + } + + async generateImage(request: GenerateImageRequest): Promise { + const model = request.model ?? "black-forest-labs/FLUX.1-schnell"; + const { width, height } = this.parseSize(request.aspectRatio, request.imageSize); + + const body: Record = { + model, + prompt: request.prompt, + width, + height, + n: request.n ?? 1, + response_format: "b64_json", + }; + + if (request.negativePrompt) body.negative_prompt = request.negativePrompt; + if (request.steps) body.steps = request.steps; + if (request.seed != null) body.seed = request.seed; + + const res = await fetch(`${API_BASE}/images/generations`, { + method: "POST", + headers: { + Authorization: `Bearer ${this.apiKey}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(body), + }); + + if (!res.ok) { + throw new Error(`Together AI error: ${res.status} ${await res.text()}`); + } + + const data = (await res.json()) as { + model: string; + data: Array<{ b64_json?: string; url?: string }>; + }; + + const images = data.data.map((d) => ({ + base64: d.b64_json ?? "", + mimeType: "image/png" as const, + url: d.url, + })); + + return { + images, + model: data.model ?? model, + provider: "together", + }; + } +} diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..2268d58 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,47 @@ +export interface ImageModel { + id: string; + name: string; + provider: string; + description?: string; + pricing?: string; + inputModalities: string[]; + outputModalities: string[]; + modalities: string[]; + supportedAspectRatios?: string[]; + supportedSizes?: string[]; +} + +export interface GenerateImageRequest { + prompt: string; + model?: string; + provider?: string; + aspectRatio?: string; + imageSize?: string; + negativePrompt?: string; + steps?: number; + seed?: number; + n?: number; +} + +export interface GenerateImageResult { + images: GeneratedImage[]; + model: string; + provider: string; + usage?: { + promptTokens?: number; + totalTokens?: number; + cost?: number; + }; +} + +export interface GeneratedImage { + base64: string; + mimeType: string; + url?: string; +} + +export interface ImageProvider { + name: string; + listModels(): Promise; + generateImage(request: GenerateImageRequest): Promise; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..764ddc9 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "module": "nodenext", + "target": "es2022", + "types": ["node"], + "lib": ["es2022"], + "sourceMap": true, + "declaration": true, + "strict": true, + "verbatimModuleSyntax": true, + "isolatedModules": true, + "moduleDetection": "force", + "skipLibCheck": true, + "moduleResolution": "nodenext", + "esModuleInterop": true + }, + "include": ["src/**/*"] +}