mcp-hydrocoder-image 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +454 -0
- package/bin/install-skills.js +115 -0
- package/dist/api/geminiClient.d.ts +57 -0
- package/dist/api/geminiClient.d.ts.map +1 -0
- package/dist/api/geminiClient.js +341 -0
- package/dist/api/geminiClient.js.map +1 -0
- package/dist/api/geminiTextClient.d.ts +44 -0
- package/dist/api/geminiTextClient.d.ts.map +1 -0
- package/dist/api/geminiTextClient.js +202 -0
- package/dist/api/geminiTextClient.js.map +1 -0
- package/dist/business/fileManager.d.ts +20 -0
- package/dist/business/fileManager.d.ts.map +1 -0
- package/dist/business/fileManager.js +76 -0
- package/dist/business/fileManager.js.map +1 -0
- package/dist/business/inputValidator.d.ts +44 -0
- package/dist/business/inputValidator.d.ts.map +1 -0
- package/dist/business/inputValidator.js +213 -0
- package/dist/business/inputValidator.js.map +1 -0
- package/dist/business/responseBuilder.d.ts +21 -0
- package/dist/business/responseBuilder.d.ts.map +1 -0
- package/dist/business/responseBuilder.js +166 -0
- package/dist/business/responseBuilder.js.map +1 -0
- package/dist/business/structuredPromptGenerator.d.ts +56 -0
- package/dist/business/structuredPromptGenerator.d.ts.map +1 -0
- package/dist/business/structuredPromptGenerator.js +218 -0
- package/dist/business/structuredPromptGenerator.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/server/errorHandler.d.ts +29 -0
- package/dist/server/errorHandler.d.ts.map +1 -0
- package/dist/server/errorHandler.js +99 -0
- package/dist/server/errorHandler.js.map +1 -0
- package/dist/server/mcpServer.d.ts +159 -0
- package/dist/server/mcpServer.d.ts.map +1 -0
- package/dist/server/mcpServer.js +434 -0
- package/dist/server/mcpServer.js.map +1 -0
- package/dist/server-main.d.ts +5 -0
- package/dist/server-main.d.ts.map +1 -0
- package/dist/server-main.js +37 -0
- package/dist/server-main.js.map +1 -0
- package/dist/types/mcp.d.ts +121 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +22 -0
- package/dist/types/mcp.js.map +1 -0
- package/dist/types/result.d.ts +27 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +27 -0
- package/dist/types/result.js.map +1 -0
- package/dist/utils/config.d.ts +29 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +56 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/errors.d.ts +84 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +215 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +80 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +186 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/security.d.ts +50 -0
- package/dist/utils/security.d.ts.map +1 -0
- package/dist/utils/security.js +116 -0
- package/dist/utils/security.js.map +1 -0
- package/package.json +89 -0
- package/skills/image-generation/SKILL.md +131 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shinsuke Kagawa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# MCP HydroCoder Image 🍌
|
|
2
|
+
|
|
3
|
+
> AI image generation and editing MCP server for Cursor, Claude Code, Codex, and any MCP-compatible tool — powered by Nano Banana 2 and Nano Banana Pro (Google Gemini).
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/mcp-hydrocoder-image)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
An MCP server that turns simple text prompts into high-quality images. Unlike a simple API wrapper, this server automatically enhances your prompt and configures sensible defaults for generation — you don't need to learn prompt engineering or tune settings. Just describe what you want.
|
|
9
|
+
|
|
10
|
+
## How It Works
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
You: "cat on a roof"
|
|
14
|
+
↓
|
|
15
|
+
Your AI assistant infers context
|
|
16
|
+
(purpose, style, mood, resolution...)
|
|
17
|
+
↓
|
|
18
|
+
MCP optimizes your prompt
|
|
19
|
+
(adds lighting, composition, atmosphere, artistic details)
|
|
20
|
+
↓
|
|
21
|
+
Image generation with smart defaults
|
|
22
|
+
(grounding, consistency, resolution — all configured automatically)
|
|
23
|
+
↓
|
|
24
|
+
High-quality image, zero effort
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Your AI assistant interprets your intent — the style, purpose, and context behind your request. The MCP focuses on output quality by refining the prompt to meet a structured visual clarity standard and selecting appropriate generation settings. You just describe what you want.
|
|
28
|
+
|
|
29
|
+
The prompt optimizer uses a **Subject–Context–Style** framework (powered by Gemini 2.5 Flash) to fill in missing visual details — subject characteristics, environment, lighting, camera work — while preserving your original intent. It doesn't blindly add details: prompts that already meet the quality standard are left largely intact.
|
|
30
|
+
|
|
31
|
+
**Example — what the optimizer does to a short prompt:**
|
|
32
|
+
|
|
33
|
+
> **Input:** "cat on a roof"
|
|
34
|
+
>
|
|
35
|
+
> **After optimization:** "A sleek, midnight black cat, perched with poised elegance on the apex of a weathered, terracotta tile roof. Its emerald eyes, narrowed slightly, reflect the warm glow of a setting sun. Each individual tile is distinct, showing subtle variations in color and texture, with patches of moss clinging to the crevices. The cat's fur is sharply defined, catching the golden hour light, highlighting its sleek contours. In the background, the silhouettes of distant, old-world city buildings with ornate spires are softly blurred, bathed in a gradient of fiery orange, soft pink, and deep violet twilight. A gentle, ethereal mist begins to rise from the alleyways below, adding a touch of mystery. The composition is a medium shot, taken from a slightly low angle, emphasizing the cat's commanding presence against the vast sky. Photorealistic style, captured with a prime lens, wide aperture to create a beautiful bokeh, enhancing the depth of field."
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- **Built-in Prompt Optimization**: Your simple prompt is automatically enriched with photographic and artistic details — lighting, composition, atmosphere — using Gemini 2.5 Flash. No prompt engineering skills required.
|
|
40
|
+
- **Three Quality Tiers**: Choose between fast iteration, balanced quality, or maximum fidelity with Nano Banana 2 (Gemini 3.1 Flash Image) and Nano Banana Pro (Gemini 3 Pro Image). [See Quality Presets](#quality-presets).
|
|
41
|
+
- **Image Editing**: Transform existing images with natural language instructions (image-to-image) while preserving original style and visual consistency.
|
|
42
|
+
- **High-Resolution Output**: Up to 4K image generation for professional-grade output with superior text rendering and fine details.
|
|
43
|
+
- **Flexible Aspect Ratios**: From square (1:1) to ultra-wide (21:9) and ultra-tall (1:8) formats.
|
|
44
|
+
- **Character Consistency**: Maintain consistent character appearance across multiple generations — ideal for storyboards, product shots, and visual series.
|
|
45
|
+
- **Advanced Capabilities**:
|
|
46
|
+
- Google Search grounding for real-time factual accuracy
|
|
47
|
+
- World knowledge for photorealistic depictions of historical figures, landmarks, and factual scenarios
|
|
48
|
+
- Multi-image blending for composite scenes
|
|
49
|
+
- Purpose-aware generation (e.g., "cookbook cover" produces different results than "social media post")
|
|
50
|
+
- **Multiple Output Formats**: PNG, JPEG, WebP support.
|
|
51
|
+
|
|
52
|
+
## Agent Skill: Image Generation Prompt Guide
|
|
53
|
+
|
|
54
|
+
This project also provides a standalone **[Agent Skill](https://agentskills.io)** (`SKILL.md`) that teaches AI assistants to write better image generation prompts — no MCP server or API key required.
|
|
55
|
+
|
|
56
|
+
> **Note:** This skill does not generate images itself. It teaches your AI assistant to write better prompts for tools that already have built-in image generation (e.g., Cursor's native image generation).
|
|
57
|
+
|
|
58
|
+
Based on the **Subject-Context-Style** framework, covering prompt structure, visual details (lighting, textures, camera angles), advanced techniques (character consistency, composition), and image editing. Works with any image model (Gemini, GPT Image, Flux, Stable Diffusion, Midjourney, etc.).
|
|
59
|
+
|
|
60
|
+
### Install
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx mcp-hydrocoder-image skills install --path <target-directory>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The skill will be placed at `<path>/image-generation/SKILL.md`. Specify the skills directory for your AI tool:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Cursor
|
|
70
|
+
npx mcp-hydrocoder-image skills install --path ~/.cursor/skills
|
|
71
|
+
|
|
72
|
+
# Codex
|
|
73
|
+
npx mcp-hydrocoder-image skills install --path ~/.codex/skills
|
|
74
|
+
|
|
75
|
+
# Claude Code
|
|
76
|
+
npx mcp-hydrocoder-image skills install --path ~/.claude/skills
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### When to Use the Skill vs the MCP Server
|
|
80
|
+
|
|
81
|
+
| | MCP Server | Agent Skill |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| **Use when** | Your AI tool does not have built-in image generation | Your AI tool already generates images natively |
|
|
84
|
+
| **Requires** | Gemini API key | Nothing |
|
|
85
|
+
| **What it does** | Generates images via Gemini API with automatic prompt optimization | Teaches the AI to write better prompts |
|
|
86
|
+
| **Works with** | MCP-compatible tools (Cursor, Claude Code, Codex, etc.) | Any tool supporting the [Agent Skills](https://agentskills.io) open standard |
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Prerequisites
|
|
91
|
+
|
|
92
|
+
- **Node.js** 20 or higher
|
|
93
|
+
- **Gemini API Key** - Get yours at [Google AI Studio](https://aistudio.google.com/apikey)
|
|
94
|
+
- An MCP-compatible AI tool: **Cursor**, **Claude Code**, **Codex**, or others
|
|
95
|
+
- Basic terminal/command line knowledge
|
|
96
|
+
|
|
97
|
+
## Quick Start
|
|
98
|
+
|
|
99
|
+
### 1. Get Your Gemini API Key
|
|
100
|
+
|
|
101
|
+
Get your API key from [Google AI Studio](https://aistudio.google.com/apikey)
|
|
102
|
+
|
|
103
|
+
### 2. MCP Configuration
|
|
104
|
+
|
|
105
|
+
#### For Codex
|
|
106
|
+
|
|
107
|
+
Add to `~/.codex/config.toml`:
|
|
108
|
+
|
|
109
|
+
```toml
|
|
110
|
+
[mcp_servers.mcp-hydrocoder-image]
|
|
111
|
+
command = "npx"
|
|
112
|
+
args = ["-y", "mcp-hydrocoder-image"]
|
|
113
|
+
|
|
114
|
+
[mcp_servers.mcp-hydrocoder-image.env]
|
|
115
|
+
GEMINI_API_KEY = "your_gemini_api_key_here"
|
|
116
|
+
IMAGE_OUTPUT_DIR = "/absolute/path/to/images"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### For Cursor
|
|
120
|
+
|
|
121
|
+
Add to your Cursor settings:
|
|
122
|
+
- **Global** (all projects): `~/.cursor/mcp.json`
|
|
123
|
+
- **Project-specific**: `.cursor/mcp.json` in your project root
|
|
124
|
+
|
|
125
|
+
**macOS / Linux:**
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"mcpServers": {
|
|
129
|
+
"mcp-hydrocoder-image": {
|
|
130
|
+
"command": "npx",
|
|
131
|
+
"args": ["-y", "mcp-hydrocoder-image"],
|
|
132
|
+
"env": {
|
|
133
|
+
"GEMINI_API_KEY": "your_gemini_api_key_here",
|
|
134
|
+
"IMAGE_OUTPUT_DIR": "/absolute/path/to/images"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Windows:**
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"mcpServers": {
|
|
145
|
+
"mcp-hydrocoder-image": {
|
|
146
|
+
"command": "npx",
|
|
147
|
+
"args": ["-y", "mcp-hydrocoder-image"],
|
|
148
|
+
"env": {
|
|
149
|
+
"GEMINI_API_KEY": "your_gemini_api_key_here",
|
|
150
|
+
"IMAGE_OUTPUT_DIR": "C:\\absolute\\path\\to\\images"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### For Claude Code
|
|
158
|
+
|
|
159
|
+
Run in your project directory to enable for that project:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
cd /path/to/your/project
|
|
163
|
+
claude mcp add mcp-hydrocoder-image --env GEMINI_API_KEY=your-api-key --env IMAGE_OUTPUT_DIR=/absolute/path/to/images -- npx -y mcp-hydrocoder-image
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Or add globally for all projects:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
claude mcp add mcp-hydrocoder-image --scope user --env GEMINI_API_KEY=your-api-key --env IMAGE_OUTPUT_DIR=/absolute/path/to/images -- npx -y mcp-hydrocoder-image
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Or add via JSON config (`~/.claude/settings.json` for global, `.mcp.json` for project):
|
|
173
|
+
|
|
174
|
+
**macOS / Linux:**
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"mcpServers": {
|
|
178
|
+
"mcp-hydrocoder-image": {
|
|
179
|
+
"command": "npx",
|
|
180
|
+
"args": ["-y", "mcp-hydrocoder-image"],
|
|
181
|
+
"env": {
|
|
182
|
+
"GEMINI_API_KEY": "your_gemini_api_key_here",
|
|
183
|
+
"IMAGE_OUTPUT_DIR": "/absolute/path/to/images"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Windows:**
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"mcpServers": {
|
|
194
|
+
"mcp-hydrocoder-image": {
|
|
195
|
+
"command": "npx",
|
|
196
|
+
"args": ["-y", "mcp-hydrocoder-image"],
|
|
197
|
+
"env": {
|
|
198
|
+
"GEMINI_API_KEY": "your_gemini_api_key_here",
|
|
199
|
+
"IMAGE_OUTPUT_DIR": "C:\\absolute\\path\\to\\images"
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
⚠️ **Security Note**: Never commit your API key to version control. Keep it secure and use environment-specific configuration.
|
|
207
|
+
|
|
208
|
+
📁 **Path Requirements**:
|
|
209
|
+
- `IMAGE_OUTPUT_DIR` must be an absolute path (e.g., `/Users/username/images`, not `./images`)
|
|
210
|
+
- Defaults to `./output` in the current working directory if not specified
|
|
211
|
+
- Directory will be created automatically if it doesn't exist
|
|
212
|
+
|
|
213
|
+
## Quality Presets
|
|
214
|
+
|
|
215
|
+
Choose the right balance of speed, quality, and cost:
|
|
216
|
+
|
|
217
|
+
| Preset | Model | Best for | Speed |
|
|
218
|
+
|--------|-------|----------|-------|
|
|
219
|
+
| `fast` (default) | Nano Banana 2 (Gemini 3.1 Flash Image) | Quick iterations, drafts, high-volume generation | ~30–40s |
|
|
220
|
+
| `balanced` | Nano Banana 2 + Thinking | Production images, good quality with reasonable speed | Medium |
|
|
221
|
+
| `quality` | Nano Banana Pro (Gemini 3 Pro Image) | Final deliverables, maximum fidelity, critical visuals | Slow |
|
|
222
|
+
|
|
223
|
+
Set the default via `IMAGE_QUALITY` environment variable:
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
IMAGE_QUALITY=fast # (default) Fastest generation
|
|
227
|
+
IMAGE_QUALITY=balanced # Enhanced thinking for better quality
|
|
228
|
+
IMAGE_QUALITY=quality # Maximum quality output
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
To override per-request, just tell your AI assistant (e.g., "generate in high quality" or "use balanced quality"). The assistant will pass the appropriate `quality` parameter automatically.
|
|
232
|
+
|
|
233
|
+
**Codex:**
|
|
234
|
+
```toml
|
|
235
|
+
[mcp_servers.mcp-hydrocoder-image.env]
|
|
236
|
+
GEMINI_API_KEY = "your_gemini_api_key_here"
|
|
237
|
+
IMAGE_QUALITY = "balanced"
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
**Cursor:**
|
|
241
|
+
Add `"IMAGE_QUALITY": "balanced"` to the env section in your config.
|
|
242
|
+
|
|
243
|
+
**Claude Code:**
|
|
244
|
+
```bash
|
|
245
|
+
claude mcp add mcp-hydrocoder-image --env GEMINI_API_KEY=your-api-key --env IMAGE_QUALITY=balanced --env IMAGE_OUTPUT_DIR=/absolute/path/to/images -- npx -y mcp-hydrocoder-image
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Skip Prompt Enhancement
|
|
249
|
+
|
|
250
|
+
Control prompt enhancement via the `skipPromptEnhancement` tool parameter or the `SKIP_PROMPT_ENHANCEMENT` environment variable. **Parameter takes priority over environment variable.**
|
|
251
|
+
|
|
252
|
+
| Parameter | Env Variable | Result |
|
|
253
|
+
|-----------|-------------|--------|
|
|
254
|
+
| Not set | Not set | Enhancement enabled (default) |
|
|
255
|
+
| Not set | `true` | Enhancement skipped |
|
|
256
|
+
| `true` | Any | Enhancement skipped |
|
|
257
|
+
| `false` | `true` | Enhancement enabled (parameter overrides) |
|
|
258
|
+
|
|
259
|
+
Skipping enhancement is recommended for multi-image blending, where the prompt enhancer may rewrite your blending intent into unrelated content.
|
|
260
|
+
|
|
261
|
+
## Usage Examples
|
|
262
|
+
|
|
263
|
+
Once configured, just describe what you want in natural language:
|
|
264
|
+
|
|
265
|
+
### Basic Image Generation
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
"Generate a serene mountain landscape at sunset with a lake reflection"
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Your prompt is automatically enhanced with rich details about lighting, materials, composition, and atmosphere.
|
|
272
|
+
|
|
273
|
+
### Image Editing
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
"Edit this image to make the person face right"
|
|
277
|
+
(with inputImagePath: "/path/to/image.jpg")
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Advanced Features
|
|
281
|
+
|
|
282
|
+
**Character Consistency:**
|
|
283
|
+
```
|
|
284
|
+
"Generate a portrait of a medieval knight, maintaining character consistency for future variations"
|
|
285
|
+
(with maintainCharacterConsistency: true)
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
**High-Resolution 4K with Text Rendering:**
|
|
289
|
+
```
|
|
290
|
+
"Generate a professional product photo of a smartphone with clear text on the screen"
|
|
291
|
+
(with imageSize: "4K")
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**Custom Aspect Ratio:**
|
|
295
|
+
```
|
|
296
|
+
"Generate a cinematic landscape of a desert at golden hour"
|
|
297
|
+
(with aspectRatio: "21:9")
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## API Reference
|
|
301
|
+
|
|
302
|
+
### `generate_image` Tool
|
|
303
|
+
|
|
304
|
+
The server uses a two-stage process with separate models for each stage:
|
|
305
|
+
1. **Prompt Optimization** (Gemini 2.5 Flash): Refines your prompt using the Subject–Context–Style framework. Skippable via `SKIP_PROMPT_ENHANCEMENT`.
|
|
306
|
+
2. **Image Generation** (Nano Banana 2 or Pro): Creates the final image. Model varies by quality preset.
|
|
307
|
+
|
|
308
|
+
#### Parameters
|
|
309
|
+
|
|
310
|
+
| Parameter | Type | Required | Description |
|
|
311
|
+
|-----------|------|----------|-------------|
|
|
312
|
+
| `prompt` | string | Yes | Text description or editing instruction |
|
|
313
|
+
| `quality` | string | - | Quality preset: `fast` (default), `balanced`, `quality`. Overrides `IMAGE_QUALITY` env var for this request |
|
|
314
|
+
| `inputImagePath` | string | - | Absolute path to input image for image-to-image editing |
|
|
315
|
+
| `inputImage` | string | - | Base64 encoded image data for image-to-image editing. Alternative to `inputImagePath` |
|
|
316
|
+
| `inputImageMimeType` | string | - | MIME type of the input image (`image/jpeg`, `image/png`, `image/webp`, `image/gif`, `image/bmp`). Used with `inputImage` |
|
|
317
|
+
| `inputImages` | array | - | Multiple input images for multi-image composition. Each item: `{ data: string, mimeType: string }`. Cannot be used with `inputImage`/`inputImagePath` |
|
|
318
|
+
| `returnBase64` | boolean | - | Return the generated image as base64 data in the response. Image is always saved to disk regardless |
|
|
319
|
+
| `fileName` | string | - | Custom filename for output (auto-generated if not specified) |
|
|
320
|
+
| `aspectRatio` | string | - | `1:1` (default), `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9`, `1:4`, `1:8`, `4:1`, `8:1` |
|
|
321
|
+
| `imageSize` | string | - | `1K`, `2K`, `4K`. Leave unspecified for standard quality |
|
|
322
|
+
| `blendImages` | boolean | - | Enable multi-image blending for combining multiple visual elements naturally |
|
|
323
|
+
| `maintainCharacterConsistency` | boolean | - | Maintain character appearance consistency across different poses and scenes |
|
|
324
|
+
| `useWorldKnowledge` | boolean | - | Use real-world knowledge for accurate context (historical figures, landmarks, factual scenarios) |
|
|
325
|
+
| `useGoogleSearch` | boolean | - | Enable Google Search grounding for real-time factual accuracy |
|
|
326
|
+
| `purpose` | string | - | Intended use (e.g., "cookbook cover", "social media post"). Helps tailor visual style and details |
|
|
327
|
+
|
|
328
|
+
#### Response
|
|
329
|
+
|
|
330
|
+
```json
|
|
331
|
+
{
|
|
332
|
+
"type": "resource",
|
|
333
|
+
"resource": {
|
|
334
|
+
"uri": "file:///path/to/generated/image.png",
|
|
335
|
+
"name": "image-filename.png",
|
|
336
|
+
"mimeType": "image/png"
|
|
337
|
+
},
|
|
338
|
+
"metadata": {
|
|
339
|
+
"model": "gemini-3.1-flash-image-preview",
|
|
340
|
+
"processingTime": 5000,
|
|
341
|
+
"timestamp": "2026-01-01T12:00:00.000Z"
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## Troubleshooting
|
|
347
|
+
|
|
348
|
+
### Common Issues
|
|
349
|
+
|
|
350
|
+
**"API key not found"**
|
|
351
|
+
- Ensure `GEMINI_API_KEY` is set in your environment
|
|
352
|
+
- Verify the API key is valid and has image generation permissions
|
|
353
|
+
|
|
354
|
+
**"Input image file not found"**
|
|
355
|
+
- Use absolute file paths, not relative paths
|
|
356
|
+
- Ensure the file exists and is accessible
|
|
357
|
+
- Supported formats: PNG, JPEG, WebP (max 10MB)
|
|
358
|
+
|
|
359
|
+
**"No image data found in Gemini API response"**
|
|
360
|
+
- Try rephrasing your prompt with more specific details
|
|
361
|
+
- Ensure your prompt is appropriate for image generation
|
|
362
|
+
- Check if your API key has sufficient quota
|
|
363
|
+
|
|
364
|
+
### Performance Tips
|
|
365
|
+
|
|
366
|
+
- `fast` preset: ~30–40 seconds typical (includes prompt optimization)
|
|
367
|
+
- `balanced` preset: Slightly longer due to enhanced thinking
|
|
368
|
+
- `quality` preset: Slower but highest fidelity output
|
|
369
|
+
- High-resolution (2K/4K): Additional processing time for superior detail
|
|
370
|
+
- Simple prompts work great — the optimizer automatically adds professional details
|
|
371
|
+
- Complex prompts are preserved and further enhanced
|
|
372
|
+
- Consider `useWorldKnowledge` for historical or factual subjects
|
|
373
|
+
- Use `imageSize: "4K"` when text clarity and fine details are critical
|
|
374
|
+
|
|
375
|
+
## Usage Notes
|
|
376
|
+
|
|
377
|
+
- This MCP server uses the paid Gemini API:
|
|
378
|
+
- **Prompt optimization**: Gemini 2.5 Flash (minimal token usage)
|
|
379
|
+
- **Image generation**: Model depends on quality preset
|
|
380
|
+
- `fast` / `balanced`: Nano Banana 2 — Gemini 3.1 Flash Image (lower cost)
|
|
381
|
+
- `quality`: Nano Banana Pro — Gemini 3 Pro Image (higher cost)
|
|
382
|
+
- `balanced` uses additional thinking tokens (slightly higher cost than `fast`)
|
|
383
|
+
- Check current pricing and rate limits at [Google AI Studio](https://aistudio.google.com/)
|
|
384
|
+
- Monitor your API usage to avoid unexpected charges
|
|
385
|
+
- The prompt optimization step adds minimal cost while significantly improving output quality
|
|
386
|
+
|
|
387
|
+
## Local Development
|
|
388
|
+
|
|
389
|
+
If you want to test a local build (e.g., after cloning the repo or making changes), follow these steps instead of using `npx`.
|
|
390
|
+
|
|
391
|
+
### 1. Build the Project
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
cd /path/to/mcp-hydrocoder-image
|
|
395
|
+
npm install
|
|
396
|
+
npm run build
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### 2. Configure the MCP Server
|
|
400
|
+
|
|
401
|
+
Add the following to your MCP configuration file, pointing directly to the local `dist/index.js`:
|
|
402
|
+
|
|
403
|
+
- **Claude Code**: `~/.claude.json`
|
|
404
|
+
- **Cursor**: `~/.cursor/mcp.json` or `.cursor/mcp.json`
|
|
405
|
+
- **Codex**: `~/.codex/config.toml`
|
|
406
|
+
|
|
407
|
+
**Claude Code / Cursor (JSON):**
|
|
408
|
+
|
|
409
|
+
```json
|
|
410
|
+
{
|
|
411
|
+
"mcp-hydrocoder-image": {
|
|
412
|
+
"command": "node",
|
|
413
|
+
"args": ["/absolute/path/to/mcp-hydrocoder-image/dist/index.js"],
|
|
414
|
+
"env": {
|
|
415
|
+
"GEMINI_API_KEY": "your_gemini_api_key_here",
|
|
416
|
+
"IMAGE_OUTPUT_DIR": "/absolute/path/to/output"
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
> **Proxy users**: If you need a proxy, add `HTTPS_PROXY` and `HTTP_PROXY` to the `env` section.
|
|
423
|
+
|
|
424
|
+
### 3. Allow Tool Permissions (Claude Code)
|
|
425
|
+
|
|
426
|
+
To skip the permission prompt on every call, add the tool to your allow list in `~/.claude/settings.json`:
|
|
427
|
+
|
|
428
|
+
```json
|
|
429
|
+
{
|
|
430
|
+
"permissions": {
|
|
431
|
+
"allow": [
|
|
432
|
+
"mcp__mcp-hydrocoder-image__generate_image"
|
|
433
|
+
]
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### 4. Restart and Test
|
|
439
|
+
|
|
440
|
+
Restart your AI tool to load the new MCP server, then try:
|
|
441
|
+
|
|
442
|
+
```
|
|
443
|
+
"Generate a serene mountain landscape at sunset"
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
If the image is saved to your `IMAGE_OUTPUT_DIR`, the local setup is working correctly.
|
|
447
|
+
|
|
448
|
+
## License
|
|
449
|
+
|
|
450
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
**Need help?** [Open an issue](https://github.com/ynzys/mcp-hydrocoder-image/issues) or check the [troubleshooting section](#troubleshooting) above.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { cpSync, existsSync, mkdirSync } from 'node:fs'
|
|
4
|
+
import { dirname, resolve } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
8
|
+
const __dirname = dirname(__filename)
|
|
9
|
+
|
|
10
|
+
const SKILLS_SOURCE = resolve(__dirname, '..', 'skills', 'image-generation')
|
|
11
|
+
const SKILL_DIR_NAME = 'image-generation'
|
|
12
|
+
|
|
13
|
+
function printHelp() {
|
|
14
|
+
console.log(`
|
|
15
|
+
Image Generation Skills Installer
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
npx mcp-image skills install --path <path>
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
--path <path> Install skills to the specified directory.
|
|
22
|
+
The skill will be placed at <path>/${SKILL_DIR_NAME}/
|
|
23
|
+
|
|
24
|
+
--help, -h Show this help message
|
|
25
|
+
|
|
26
|
+
Examples:
|
|
27
|
+
npx mcp-image skills install --path ~/.claude/skills
|
|
28
|
+
npx mcp-image skills install --path ./.claude/skills
|
|
29
|
+
npx mcp-image skills install --path /custom/path
|
|
30
|
+
`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function parseArgs(args) {
|
|
34
|
+
const options = { path: undefined, help: false }
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < args.length; i++) {
|
|
37
|
+
const arg = args[i]
|
|
38
|
+
|
|
39
|
+
switch (arg) {
|
|
40
|
+
case '--help':
|
|
41
|
+
case '-h':
|
|
42
|
+
options.help = true
|
|
43
|
+
break
|
|
44
|
+
|
|
45
|
+
case '--path': {
|
|
46
|
+
const pathArg = args[i + 1]
|
|
47
|
+
if (!pathArg) {
|
|
48
|
+
console.error('Error: --path requires a path argument')
|
|
49
|
+
process.exit(1)
|
|
50
|
+
}
|
|
51
|
+
options.path = pathArg
|
|
52
|
+
i++
|
|
53
|
+
break
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
default:
|
|
57
|
+
if (arg && arg.startsWith('-')) {
|
|
58
|
+
console.error(`Unknown option: ${arg}`)
|
|
59
|
+
process.exit(1)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return options
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function install(targetPath) {
|
|
68
|
+
if (!existsSync(SKILLS_SOURCE)) {
|
|
69
|
+
console.error(`Error: Skills source not found at ${SKILLS_SOURCE}`)
|
|
70
|
+
process.exit(1)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const targetDir = dirname(targetPath)
|
|
74
|
+
if (!existsSync(targetDir)) {
|
|
75
|
+
mkdirSync(targetDir, { recursive: true })
|
|
76
|
+
console.log(`Created directory: ${targetDir}`)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
cpSync(SKILLS_SOURCE, targetPath, { recursive: true })
|
|
80
|
+
console.log(`Installed skills to: ${targetPath}`)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function run(args) {
|
|
84
|
+
if (args.length === 0) {
|
|
85
|
+
printHelp()
|
|
86
|
+
process.exit(0)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const options = parseArgs(args)
|
|
90
|
+
|
|
91
|
+
if (options.help) {
|
|
92
|
+
printHelp()
|
|
93
|
+
process.exit(0)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!options.path) {
|
|
97
|
+
console.error('Error: --path is required')
|
|
98
|
+
console.error('Run "npx mcp-image skills install --help" for usage information.')
|
|
99
|
+
process.exit(1)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const targetPath = resolve(options.path, SKILL_DIR_NAME)
|
|
103
|
+
|
|
104
|
+
console.log('Installing image-generation skills...')
|
|
105
|
+
console.log(`Path: ${targetPath}`)
|
|
106
|
+
console.log()
|
|
107
|
+
|
|
108
|
+
install(targetPath)
|
|
109
|
+
|
|
110
|
+
console.log()
|
|
111
|
+
console.log('Installation complete!')
|
|
112
|
+
console.log()
|
|
113
|
+
console.log('Installed files:')
|
|
114
|
+
console.log(' - image-generation/SKILL.md')
|
|
115
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gemini API client for image generation
|
|
3
|
+
* Integrates with Google's Gemini AI API using the official SDK
|
|
4
|
+
* Supports automatic URL Context processing and feature parameters
|
|
5
|
+
*/
|
|
6
|
+
import type { ImageQuality } from '../types/mcp.js';
|
|
7
|
+
import type { Result } from '../types/result.js';
|
|
8
|
+
import type { Config } from '../utils/config.js';
|
|
9
|
+
import { GeminiAPIError, NetworkError } from '../utils/errors.js';
|
|
10
|
+
/**
|
|
11
|
+
* Metadata for generated images
|
|
12
|
+
*/
|
|
13
|
+
export interface GeminiGenerationMetadata {
|
|
14
|
+
model: string;
|
|
15
|
+
prompt: string;
|
|
16
|
+
mimeType: string;
|
|
17
|
+
timestamp: Date;
|
|
18
|
+
inputImageProvided: boolean;
|
|
19
|
+
modelVersion?: string;
|
|
20
|
+
responseId?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parameters for Gemini API image generation
|
|
24
|
+
*/
|
|
25
|
+
export interface GeminiApiParams {
|
|
26
|
+
prompt: string;
|
|
27
|
+
inputImage?: string;
|
|
28
|
+
inputImageMimeType?: string;
|
|
29
|
+
inputImages?: Array<{
|
|
30
|
+
data: string;
|
|
31
|
+
mimeType: string;
|
|
32
|
+
}>;
|
|
33
|
+
aspectRatio?: string;
|
|
34
|
+
imageSize?: string;
|
|
35
|
+
useGoogleSearch?: boolean;
|
|
36
|
+
quality?: ImageQuality;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Result of image generation
|
|
40
|
+
*/
|
|
41
|
+
export interface GeneratedImageResult {
|
|
42
|
+
imageData: Buffer;
|
|
43
|
+
metadata: GeminiGenerationMetadata;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Gemini API client interface
|
|
47
|
+
*/
|
|
48
|
+
export interface GeminiClient {
|
|
49
|
+
generateImage(params: GeminiApiParams): Promise<Result<GeneratedImageResult, GeminiAPIError | NetworkError>>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new Gemini API client
|
|
53
|
+
* @param config Configuration containing API key and other settings
|
|
54
|
+
* @returns Result containing the client or an error
|
|
55
|
+
*/
|
|
56
|
+
export declare function createGeminiClient(config: Config): Result<GeminiClient, GeminiAPIError>;
|
|
57
|
+
//# sourceMappingURL=geminiClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geminiClient.d.ts","sourceRoot":"","sources":["../../src/api/geminiClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAsHjE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,IAAI,CAAA;IACf,kBAAkB,EAAE,OAAO,CAAA;IAE3B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,WAAW,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACvD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,wBAAwB,CAAA;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,aAAa,CACX,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,cAAc,GAAG,YAAY,CAAC,CAAC,CAAA;CACxE;AA6VD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,CAevF"}
|