mcp-banana-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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -0
  3. package/dist/api/geminiClient.d.ts +50 -0
  4. package/dist/api/geminiClient.d.ts.map +1 -0
  5. package/dist/api/geminiClient.js +335 -0
  6. package/dist/api/geminiClient.js.map +1 -0
  7. package/dist/api/geminiTextClient.d.ts +42 -0
  8. package/dist/api/geminiTextClient.d.ts.map +1 -0
  9. package/dist/api/geminiTextClient.js +205 -0
  10. package/dist/api/geminiTextClient.js.map +1 -0
  11. package/dist/business/fileManager.d.ts +21 -0
  12. package/dist/business/fileManager.d.ts.map +1 -0
  13. package/dist/business/fileManager.js +114 -0
  14. package/dist/business/fileManager.js.map +1 -0
  15. package/dist/business/imageProcessor.d.ts +48 -0
  16. package/dist/business/imageProcessor.d.ts.map +1 -0
  17. package/dist/business/imageProcessor.js +207 -0
  18. package/dist/business/imageProcessor.js.map +1 -0
  19. package/dist/business/inputValidator.d.ts +41 -0
  20. package/dist/business/inputValidator.d.ts.map +1 -0
  21. package/dist/business/inputValidator.js +223 -0
  22. package/dist/business/inputValidator.js.map +1 -0
  23. package/dist/business/responseBuilder.d.ts +20 -0
  24. package/dist/business/responseBuilder.d.ts.map +1 -0
  25. package/dist/business/responseBuilder.js +172 -0
  26. package/dist/business/responseBuilder.js.map +1 -0
  27. package/dist/business/structuredPromptGenerator.d.ts +56 -0
  28. package/dist/business/structuredPromptGenerator.d.ts.map +1 -0
  29. package/dist/business/structuredPromptGenerator.js +223 -0
  30. package/dist/business/structuredPromptGenerator.js.map +1 -0
  31. package/dist/http/expressApp.d.ts +24 -0
  32. package/dist/http/expressApp.d.ts.map +1 -0
  33. package/dist/http/expressApp.js +326 -0
  34. package/dist/http/expressApp.js.map +1 -0
  35. package/dist/index.d.ts +5 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +192 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/server/errorHandler.d.ts +29 -0
  40. package/dist/server/errorHandler.d.ts.map +1 -0
  41. package/dist/server/errorHandler.js +102 -0
  42. package/dist/server/errorHandler.js.map +1 -0
  43. package/dist/server/mcpServer.d.ts +131 -0
  44. package/dist/server/mcpServer.d.ts.map +1 -0
  45. package/dist/server/mcpServer.js +405 -0
  46. package/dist/server/mcpServer.js.map +1 -0
  47. package/dist/types/mcp.d.ts +104 -0
  48. package/dist/types/mcp.d.ts.map +1 -0
  49. package/dist/types/mcp.js +7 -0
  50. package/dist/types/mcp.js.map +1 -0
  51. package/dist/types/result.d.ts +27 -0
  52. package/dist/types/result.d.ts.map +1 -0
  53. package/dist/types/result.js +31 -0
  54. package/dist/types/result.js.map +1 -0
  55. package/dist/utils/config.d.ts +48 -0
  56. package/dist/utils/config.d.ts.map +1 -0
  57. package/dist/utils/config.js +101 -0
  58. package/dist/utils/config.js.map +1 -0
  59. package/dist/utils/errors.d.ts +96 -0
  60. package/dist/utils/errors.d.ts.map +1 -0
  61. package/dist/utils/errors.js +259 -0
  62. package/dist/utils/errors.js.map +1 -0
  63. package/dist/utils/logger.d.ts +80 -0
  64. package/dist/utils/logger.d.ts.map +1 -0
  65. package/dist/utils/logger.js +223 -0
  66. package/dist/utils/logger.js.map +1 -0
  67. package/dist/utils/security.d.ts +50 -0
  68. package/dist/utils/security.d.ts.map +1 -0
  69. package/dist/utils/security.js +153 -0
  70. package/dist/utils/security.js.map +1 -0
  71. package/package.json +91 -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,343 @@
1
+ <p align="center">
2
+ <img src="assets/mcp-banana-image.webp" alt="MCP Banana Image" width="400"/>
3
+ </p>
4
+
5
+ <h1 align="center">MCP Banana Image</h1>
6
+
7
+ <p align="center">
8
+ <strong>AI-Powered Image Generation MCP Server using Google Gemini</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/mcp-banana-image">
13
+ <img src="https://img.shields.io/npm/v/mcp-banana-image?style=flat-square&color=yellow" alt="npm version"/>
14
+ </a>
15
+ <a href="https://www.npmjs.com/package/mcp-banana-image">
16
+ <img src="https://img.shields.io/npm/dm/mcp-banana-image?style=flat-square&color=green" alt="npm downloads"/>
17
+ </a>
18
+ <a href="https://github.com/trigidigital/mcp-banana-image/blob/main/LICENSE">
19
+ <img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="license"/>
20
+ </a>
21
+ <a href="https://nodejs.org/">
22
+ <img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen?style=flat-square" alt="node version"/>
23
+ </a>
24
+ <a href="#">
25
+ <img src="https://img.shields.io/badge/TypeScript-5.0-blue?style=flat-square&logo=typescript" alt="TypeScript"/>
26
+ </a>
27
+ <a href="#">
28
+ <img src="https://img.shields.io/badge/MCP-1.0-purple?style=flat-square" alt="MCP SDK"/>
29
+ </a>
30
+ </p>
31
+
32
+ <p align="center">
33
+ <a href="#features">Features</a> •
34
+ <a href="#installation">Installation</a> •
35
+ <a href="#usage">Usage</a> •
36
+ <a href="#api-reference">API</a> •
37
+ <a href="#docker-deployment">Docker</a> •
38
+ <a href="#troubleshooting">Troubleshooting</a>
39
+ </p>
40
+
41
+ ---
42
+
43
+ ## Overview
44
+
45
+ **MCP Banana Image** is a Model Context Protocol (MCP) server that brings AI-powered image generation capabilities to your favorite AI coding assistants. Built with Google's Gemini AI, it offers intelligent prompt enhancement, image editing, format conversion, and smart compression - all through a simple natural language interface.
46
+
47
+ ## Features
48
+
49
+ | Feature | Description |
50
+ |---------|-------------|
51
+ | **AI Image Generation** | Create stunning images from text prompts using Gemini 3 Pro Image Preview |
52
+ | **Intelligent Prompt Enhancement** | Automatically optimizes your prompts using Gemini 2.0 Flash for better results |
53
+ | **Image Editing** | Transform existing images with natural language instructions |
54
+ | **Format Conversion** | Convert output to PNG, JPEG, WebP, or AVIF |
55
+ | **Smart Compression** | Reduce file size with configurable quality presets |
56
+ | **High Resolution** | Support for 2K and 4K image generation |
57
+ | **Flexible Aspect Ratios** | 1:1, 16:9, 9:16, 21:9, and more |
58
+ | **Character Consistency** | Maintain character appearance across generated images |
59
+ | **Image Blending** | Seamlessly blend multiple visual elements |
60
+ | **World Knowledge** | Use real-world knowledge for accurate context |
61
+ | **Google Search Grounding** | Access real-time data for factually accurate generation |
62
+ | **Dual Transport** | STDIO (default) and HTTP (Streamable HTTP Transport) |
63
+ | **Docker Support** | Deploy as HTTP server with Docker |
64
+
65
+ ## Requirements
66
+
67
+ - **Node.js** 20+
68
+ - **Gemini API Key** from [Google AI Studio](https://aistudio.google.com/apikey)
69
+
70
+ ## Installation
71
+
72
+ ### Claude Code
73
+
74
+ ```bash
75
+ claude mcp add mcp-banana-image \
76
+ --env GEMINI_API_KEY=your_api_key \
77
+ --env GEMINI_BASE_URL=https://generativelanguage.googleapis.com \
78
+ --env IMAGE_OUTPUT_DIR=/path/to/output \
79
+ --env SKIP_PROMPT_ENHANCEMENT=false \
80
+ -- npx -y mcp-banana-image
81
+ ```
82
+
83
+ Add `--scope user` for global installation.
84
+
85
+ ### Cursor
86
+
87
+ Add to `~/.cursor/mcp.json`:
88
+
89
+ ```json
90
+ {
91
+ "mcpServers": {
92
+ "mcp-banana-image": {
93
+ "command": "npx",
94
+ "args": ["-y", "mcp-banana-image"],
95
+ "env": {
96
+ "GEMINI_API_KEY": "your_api_key",
97
+ "GEMINI_BASE_URL": "https://generativelanguage.googleapis.com",
98
+ "IMAGE_OUTPUT_DIR": "/path/to/output",
99
+ "SKIP_PROMPT_ENHANCEMENT": "false"
100
+ }
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+ ### Codex
107
+
108
+ Add to `~/.codex/config.toml`:
109
+
110
+ ```toml
111
+ [mcp_servers.mcp-banana-image]
112
+ command = "npx"
113
+ args = ["-y", "mcp-banana-image"]
114
+
115
+ [mcp_servers.mcp-banana-image.env]
116
+ GEMINI_API_KEY = "your_api_key"
117
+ GEMINI_BASE_URL = "https://generativelanguage.googleapis.com"
118
+ IMAGE_OUTPUT_DIR = "/path/to/output"
119
+ SKIP_PROMPT_ENHANCEMENT = "false"
120
+ ```
121
+
122
+ ## Usage
123
+
124
+ ### Basic Generation
125
+
126
+ ```
127
+ "Generate a mountain landscape at sunset"
128
+ ```
129
+
130
+ ### Image Editing
131
+
132
+ ```
133
+ "Make the sky more dramatic"
134
+ (with inputImagePath: "/path/to/image.jpg")
135
+ ```
136
+
137
+ ### Format Conversion
138
+
139
+ ```
140
+ "Generate a product photo"
141
+ (with outputFormat: "webp", compressionPreset: "balanced")
142
+ ```
143
+
144
+ ### High Resolution
145
+
146
+ ```
147
+ "Generate a detailed cityscape"
148
+ (with imageSize: "4K", aspectRatio: "21:9")
149
+ ```
150
+
151
+ ### Character Consistency
152
+
153
+ ```
154
+ "A warrior with a red cape and scar on the left cheek"
155
+ (with maintainCharacterConsistency: true)
156
+ ```
157
+
158
+ ## API Reference
159
+
160
+ ### Tool: `generate_image`
161
+
162
+ | Parameter | Type | Required | Description |
163
+ |-----------|------|----------|-------------|
164
+ | `prompt` | string | Yes | Text description for image generation |
165
+ | `fileName` | string | No | Custom output filename |
166
+ | `inputImagePath` | string | No | Source image path for editing |
167
+ | `aspectRatio` | string | No | `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9` |
168
+ | `imageSize` | string | No | `2K` or `4K` for high resolution |
169
+ | `outputFormat` | string | No | `png`, `jpeg`, `webp`, `avif` |
170
+ | `compressionPreset` | string | No | `lossless`, `high`, `balanced`, `maximum` |
171
+ | `quality` | number | No | 1-100, overrides compressionPreset |
172
+ | `stripMetadata` | boolean | No | Remove EXIF data (default: true) |
173
+ | `blendImages` | boolean | No | Enable multi-image blending |
174
+ | `maintainCharacterConsistency` | boolean | No | Keep character appearance consistent |
175
+ | `useWorldKnowledge` | boolean | No | Use real-world knowledge for accuracy |
176
+ | `useGoogleSearch` | boolean | No | Enable Google Search for current data |
177
+ | `purpose` | string | No | Intended use (e.g., "social media post") |
178
+
179
+ ### Compression Presets
180
+
181
+ | Preset | Description | Use Case |
182
+ |--------|-------------|----------|
183
+ | `lossless` | No quality loss | Archival, source files |
184
+ | `high` | Minimal loss | Professional work |
185
+ | `balanced` | Good quality/size ratio | General use |
186
+ | `maximum` | Smallest file size | Web optimization |
187
+
188
+ ### Output Formats
189
+
190
+ | Format | Description |
191
+ |--------|-------------|
192
+ | `png` | Lossless, supports transparency |
193
+ | `jpeg` | Lossy, best for photos |
194
+ | `webp` | Modern format, good compression |
195
+ | `avif` | Best compression, limited support |
196
+
197
+ ## Environment Variables
198
+
199
+ ### Core Configuration
200
+
201
+ | Variable | Required | Default | Description |
202
+ |----------|----------|---------|-------------|
203
+ | `GEMINI_API_KEY` | Yes | - | Google AI API key |
204
+ | `GEMINI_BASE_URL` | No | - | Custom Gemini API endpoint URL |
205
+ | `IMAGE_OUTPUT_DIR` | No | `./output` | Output directory for generated images |
206
+ | `SKIP_PROMPT_ENHANCEMENT` | No | `false` | Disable automatic prompt optimization |
207
+
208
+ ### HTTP Transport Configuration
209
+
210
+ | Variable | Required | Default | Description |
211
+ |----------|----------|---------|-------------|
212
+ | `MCP_TRANSPORT` | No | `stdio` | Transport mode: `stdio` or `http` |
213
+ | `MCP_API_KEY` | Yes (http) | - | API key for HTTP authentication |
214
+ | `MCP_HTTP_PORT` | No | `3000` | HTTP server port |
215
+ | `MCP_HTTP_HOST` | No | `0.0.0.0` | HTTP server bind address |
216
+ | `MCP_CORS_ORIGIN` | No | `*` | CORS allowed origins |
217
+ | `MCP_HTTP_TIMEOUT` | No | `300000` | HTTP request timeout in ms |
218
+
219
+ ## Docker Deployment
220
+
221
+ ### Build and Run
222
+
223
+ ```bash
224
+ docker build -t mcp-banana-image .
225
+ docker-compose up
226
+ ```
227
+
228
+ ### docker-compose.yml
229
+
230
+ ```yaml
231
+ services:
232
+ mcp-banana-image:
233
+ build: .
234
+ ports:
235
+ - "3000:3000"
236
+ volumes:
237
+ - ./output:/app/output
238
+ environment:
239
+ - GEMINI_API_KEY=${GEMINI_API_KEY}
240
+ - MCP_API_KEY=${MCP_API_KEY}
241
+ - MCP_TRANSPORT=http
242
+ ```
243
+
244
+ ### Health Check
245
+
246
+ ```bash
247
+ curl http://localhost:3000/health
248
+ ```
249
+
250
+ **Response:**
251
+
252
+ ```json
253
+ {
254
+ "status": "ok",
255
+ "timestamp": "2024-01-01T00:00:00.000Z",
256
+ "sessions": 0
257
+ }
258
+ ```
259
+
260
+ ## Architecture
261
+
262
+ ```mermaid
263
+ flowchart TB
264
+ subgraph Client
265
+ A[AI Assistant]
266
+ end
267
+
268
+ subgraph MCP Server
269
+ B[Transport Layer]
270
+ C[MCP Handler]
271
+ D[Prompt Generator]
272
+ E[Gemini Client]
273
+ F[Image Processor]
274
+ G[File Manager]
275
+ end
276
+
277
+ subgraph External
278
+ H[Gemini 2.0 Flash]
279
+ I[Gemini 3 Pro Image]
280
+ end
281
+
282
+ A -->|STDIO/HTTP| B
283
+ B --> C
284
+ C --> D
285
+ D -->|Enhance Prompt| H
286
+ C --> E
287
+ E -->|Generate Image| I
288
+ I --> F
289
+ F -->|Convert & Compress| G
290
+ G -->|Save| J[(Output)]
291
+ ```
292
+
293
+ ## Troubleshooting
294
+
295
+ ### API key not found
296
+
297
+ - Verify `GEMINI_API_KEY` is set correctly
298
+ - Check key permissions at [Google AI Studio](https://aistudio.google.com/apikey)
299
+
300
+ ### Image not saved
301
+
302
+ - Ensure `IMAGE_OUTPUT_DIR` is an absolute path
303
+ - Check directory write permissions
304
+
305
+ ### Generation timeout
306
+
307
+ - High resolution images take longer
308
+ - Check network connectivity
309
+ - Consider increasing `MCP_HTTP_TIMEOUT` for HTTP mode
310
+
311
+ ### Prompt blocked by safety filters
312
+
313
+ - Rephrase your prompt to avoid potentially sensitive content
314
+ - The AI may reject prompts that could generate inappropriate imagery
315
+
316
+ ## Development
317
+
318
+ ```bash
319
+ # Install dependencies
320
+ npm install
321
+
322
+ # Build
323
+ npm run build
324
+
325
+ # Run tests
326
+ npm test
327
+
328
+ # Run with coverage
329
+ npm run test:coverage
330
+
331
+ # Lint and format
332
+ npm run check:all
333
+ ```
334
+
335
+ ## License
336
+
337
+ MIT
338
+
339
+ ---
340
+
341
+ <p align="center">
342
+ Made with ❤️ by <a href="https://bitbucket.org/trigidigital">Trigi Digital</a>
343
+ </p>
@@ -0,0 +1,50 @@
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 { Result } from '../types/result';
7
+ import type { Config } from '../utils/config';
8
+ import { GeminiAPIError, NetworkError } from '../utils/errors';
9
+ /**
10
+ * Metadata for generated images
11
+ */
12
+ export interface GeminiGenerationMetadata {
13
+ model: string;
14
+ prompt: string;
15
+ mimeType: string;
16
+ timestamp: Date;
17
+ inputImageProvided: boolean;
18
+ modelVersion?: string;
19
+ responseId?: string;
20
+ }
21
+ /**
22
+ * Parameters for Gemini API image generation
23
+ */
24
+ export interface GeminiApiParams {
25
+ prompt: string;
26
+ inputImage?: string;
27
+ aspectRatio?: string;
28
+ imageSize?: string;
29
+ useGoogleSearch?: boolean;
30
+ }
31
+ /**
32
+ * Result of image generation
33
+ */
34
+ export interface GeneratedImageResult {
35
+ imageData: Buffer;
36
+ metadata: GeminiGenerationMetadata;
37
+ }
38
+ /**
39
+ * Gemini API client interface
40
+ */
41
+ export interface GeminiClient {
42
+ generateImage(params: GeminiApiParams): Promise<Result<GeneratedImageResult, GeminiAPIError | NetworkError>>;
43
+ }
44
+ /**
45
+ * Creates a new Gemini API client
46
+ * @param config Configuration containing API key and other settings
47
+ * @returns Result containing the client or an error
48
+ */
49
+ export declare function createGeminiClient(config: Config): Result<GeminiClient, GeminiAPIError>;
50
+ //# 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,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAkH9D;;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,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;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;AA2UD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,CAsBvF"}