grok-imagine-image-mcp-server 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 (53) hide show
  1. package/.env.example +15 -0
  2. package/LICENSE +21 -0
  3. package/README.ja.md +225 -0
  4. package/README.md +225 -0
  5. package/dist/cli/batch.d.ts +19 -0
  6. package/dist/cli/batch.d.ts.map +1 -0
  7. package/dist/cli/batch.js +288 -0
  8. package/dist/cli/batch.js.map +1 -0
  9. package/dist/index.d.ts +9 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +203 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/tools/edit.d.ts +14 -0
  14. package/dist/tools/edit.d.ts.map +1 -0
  15. package/dist/tools/edit.js +236 -0
  16. package/dist/tools/edit.js.map +1 -0
  17. package/dist/tools/generate.d.ts +13 -0
  18. package/dist/tools/generate.d.ts.map +1 -0
  19. package/dist/tools/generate.js +183 -0
  20. package/dist/tools/generate.js.map +1 -0
  21. package/dist/types/batch.d.ts +137 -0
  22. package/dist/types/batch.d.ts.map +1 -0
  23. package/dist/types/batch.js +5 -0
  24. package/dist/types/batch.js.map +1 -0
  25. package/dist/types/tools.d.ts +52 -0
  26. package/dist/types/tools.d.ts.map +1 -0
  27. package/dist/types/tools.js +20 -0
  28. package/dist/types/tools.js.map +1 -0
  29. package/dist/utils/batch-config.d.ts +31 -0
  30. package/dist/utils/batch-config.d.ts.map +1 -0
  31. package/dist/utils/batch-config.js +236 -0
  32. package/dist/utils/batch-config.js.map +1 -0
  33. package/dist/utils/batch-manager.d.ts +24 -0
  34. package/dist/utils/batch-manager.d.ts.map +1 -0
  35. package/dist/utils/batch-manager.js +301 -0
  36. package/dist/utils/batch-manager.js.map +1 -0
  37. package/dist/utils/debug.d.ts +5 -0
  38. package/dist/utils/debug.d.ts.map +1 -0
  39. package/dist/utils/debug.js +16 -0
  40. package/dist/utils/debug.js.map +1 -0
  41. package/dist/utils/image.d.ts +36 -0
  42. package/dist/utils/image.d.ts.map +1 -0
  43. package/dist/utils/image.js +85 -0
  44. package/dist/utils/image.js.map +1 -0
  45. package/dist/utils/path.d.ts +16 -0
  46. package/dist/utils/path.d.ts.map +1 -0
  47. package/dist/utils/path.js +70 -0
  48. package/dist/utils/path.js.map +1 -0
  49. package/examples/batch-detailed.json +41 -0
  50. package/examples/batch-simple.json +14 -0
  51. package/examples/batch-variants.json +23 -0
  52. package/examples/batch-with-edits.json +26 -0
  53. package/package.json +66 -0
package/.env.example ADDED
@@ -0,0 +1,15 @@
1
+ # xAI API Key (Required)
2
+ # Get your API key from: https://console.x.ai/
3
+ XAI_API_KEY=xai-....
4
+
5
+ # Debug mode (optional)
6
+ # Set to "true" to enable debug logging
7
+ DEBUG=false
8
+
9
+ # Default output directory for generated images (optional)
10
+ # If not set, images are saved in the current working directory
11
+ # OUTPUT_DIR=/path/to/output
12
+
13
+ # Include thumbnail in MCP response (optional)
14
+ # Set to "true" to include base64 thumbnail preview in response
15
+ # XAI_IMAGE_THUMBNAIL=false
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Junji Takashima
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.ja.md ADDED
@@ -0,0 +1,225 @@
1
+ # Grok Imagine Image MCP Server
2
+
3
+ [![npm version](https://badge.fury.io/js/grok-imagine-image-mcp-server.svg)](https://www.npmjs.com/package/grok-imagine-image-mcp-server)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ xAI の Grok Imagine Image API 用 MCP (Model Context Protocol) サーバー。テキストプロンプトからの画像生成と、既存画像の編集をサポートします。
7
+
8
+ ## クイックスタート (npx)
9
+
10
+ 最も簡単な方法は `npx` を使用することです:
11
+
12
+ ```bash
13
+ # APIキーを設定
14
+ export XAI_API_KEY="xai-your-api-key"
15
+
16
+ # サーバーを実行
17
+ npx grok-imagine-image-mcp-server
18
+ ```
19
+
20
+ ## 機能
21
+
22
+ - **画像生成**: テキストプロンプトから新規画像を生成
23
+ - **画像編集**: 既存画像をプロンプトで編集(grok-imagine-image のみ)
24
+ - **バッチ処理**: CLIで複数画像を一括処理
25
+ - 多様なアスペクト比をサポート(1:1, 4:3, 16:9 など)
26
+ - 解像度: 1k(標準)
27
+ - 一度に最大10枚の画像を生成
28
+ - MCP レスポンスにサムネイルプレビューを含めるオプション
29
+
30
+ ## サポートモデル
31
+
32
+ | モデル | 価格 | 画像編集 | 備考 |
33
+ |--------|------|---------|------|
34
+ | `grok-imagine-image` | $0.02/枚 | ✅ (+$0.002/入力) | **推奨・デフォルト** |
35
+
36
+ ## 必要条件
37
+
38
+ - Node.js 18.0.0 以上
39
+ - xAI API キー([console.x.ai](https://console.x.ai/) から取得)
40
+
41
+ ## インストール
42
+
43
+ ### 方法1: npx(推奨)
44
+
45
+ ```bash
46
+ npx grok-imagine-image-mcp-server
47
+ ```
48
+
49
+ ### 方法2: グローバルインストール
50
+
51
+ ```bash
52
+ npm install -g grok-imagine-image-mcp-server
53
+ grok-imagine-image-mcp-server
54
+ ```
55
+
56
+ ## 設定
57
+
58
+ ### 環境変数
59
+
60
+ | 変数 | 必須 | 説明 |
61
+ |------|------|------|
62
+ | `XAI_API_KEY` | Yes | xAI API キー |
63
+ | `DEBUG` | No | `true` でデバッグログを有効化 |
64
+ | `OUTPUT_DIR` | No | 画像のデフォルト出力ディレクトリ |
65
+ | `XAI_IMAGE_THUMBNAIL` | No | `true` でサムネイルを含める |
66
+
67
+ ### Claude Desktop 設定
68
+
69
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
70
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
71
+
72
+ ```json
73
+ {
74
+ "mcpServers": {
75
+ "grok-imagine-image": {
76
+ "command": "npx",
77
+ "args": ["-y", "grok-imagine-image-mcp-server"],
78
+ "env": {
79
+ "XAI_API_KEY": "xai-your-api-key-here"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ ## ツール
87
+
88
+ ### generate_image
89
+
90
+ テキストプロンプトから画像を生成します。
91
+
92
+ | パラメータ | 型 | 必須 | 説明 |
93
+ |-----------|-----|------|------|
94
+ | `prompt` | string | Yes | 生成する画像の説明テキスト |
95
+ | `output_path` | string | No | 出力ファイルパス(デフォルト: generated_image.jpg) |
96
+ | `model` | string | No | モデル(デフォルト: grok-imagine-image) |
97
+ | `n` | number | No | 生成枚数(1-10、デフォルト: 1) |
98
+ | `aspect_ratio` | string | No | アスペクト比(デフォルト: 1:1) |
99
+ | `resolution` | string | No | 解像度(デフォルト: 1k) |
100
+ | `return_base64` | boolean | No | Base64データを返す(デフォルト: false) |
101
+ | `include_thumbnail` | boolean | No | サムネイルを含める(デフォルト: false) |
102
+
103
+ ### edit_image
104
+
105
+ 既存画像を編集します(grok-imagine-image のみ対応)。
106
+
107
+ | パラメータ | 型 | 必須 | 説明 |
108
+ |-----------|-----|------|------|
109
+ | `prompt` | string | Yes | 編集内容の説明 |
110
+ | `image_path` | string | No* | 編集する画像のファイルパス |
111
+ | `image_base64` | string | No* | 編集する画像のBase64データ |
112
+ | `image_url` | string | No* | 編集する画像のURL |
113
+ | `output_path` | string | No | 出力ファイルパス(デフォルト: edited_image.jpg) |
114
+ | `n` | number | No | 生成枚数(1-10、デフォルト: 1) |
115
+ | `resolution` | string | No | 解像度(デフォルト: 1k)。アスペクト比は入力画像から自動検出。 |
116
+
117
+ *`image_path`、`image_base64`、`image_url` のいずれか1つが必須
118
+
119
+ > **注意**: edit_image は入力画像を「参照」として使用し、画像全体を再生成します。全体の構図やスタイルは維持されますが、ピクセル単位の精密な編集(インペインティング)ではありません。スタイル変換、被写体の置換、シーンの変更に適しています。
120
+
121
+ ## バッチ処理 CLI
122
+
123
+ バッチCLIで複数の画像を一括処理できます:
124
+
125
+ ```bash
126
+ # 設定ファイルでバッチ実行
127
+ npx grok-imagine-image-batch batch.json
128
+
129
+ # コスト見積もりのみ
130
+ npx grok-imagine-image-batch batch.json --estimate-only
131
+
132
+ # 出力先とフォーマットを指定
133
+ npx grok-imagine-image-batch batch.json --output-dir ./images --format json
134
+ ```
135
+
136
+ ### CLI オプション
137
+
138
+ | オプション | 説明 | デフォルト |
139
+ |-----------|------|-----------|
140
+ | `--output-dir <path>` | 出力ディレクトリを上書き | 設定ファイルから |
141
+ | `--format <text\|json>` | 出力フォーマット | `text` |
142
+ | `--timeout <ms>` | タイムアウト(ミリ秒) | `600000` |
143
+ | `--max-concurrent <n>` | 最大同時実行数(1-10) | `2` |
144
+ | `--estimate-only` | コスト見積もりのみ(実行しない) | - |
145
+ | `--allow-any-path` | 任意の出力パスを許可(CI/CD用) | - |
146
+
147
+ ### バッチ設定ファイル
148
+
149
+ ```json
150
+ {
151
+ "jobs": [
152
+ {
153
+ "prompt": "美しい山の夕焼け",
154
+ "output_path": "sunset.jpg",
155
+ "aspect_ratio": "16:9"
156
+ },
157
+ {
158
+ "prompt": "夜景に変更",
159
+ "image_path": "input.jpg",
160
+ "output_path": "edited.jpg"
161
+ }
162
+ ],
163
+ "output_dir": "./output",
164
+ "max_concurrent": 3,
165
+ "default_model": "grok-imagine-image",
166
+ "retry_policy": {
167
+ "max_retries": 2,
168
+ "retry_delay_ms": 1000
169
+ }
170
+ }
171
+ ```
172
+
173
+ 設定例は `examples/` ディレクトリを参照してください。
174
+
175
+ ## サポートされているアスペクト比
176
+
177
+ | アスペクト比 | 用途例 |
178
+ |-------------|--------|
179
+ | `1:1` | 正方形、SNSプロフィール画像(デフォルト) |
180
+ | `3:4` / `4:3` | 標準的な縦長/横長 |
181
+ | `9:16` / `16:9` | スマホ縦 / ワイドスクリーン |
182
+
183
+ ## サポートされている解像度
184
+
185
+ | 解像度 | 説明 |
186
+ |--------|------|
187
+ | `1k` | 標準解像度(1024x1024、デフォルト) |
188
+
189
+
190
+ ## 使用例
191
+
192
+ ```
193
+ # 画像生成
194
+ 山の上の夕日の画像を16:9で生成して
195
+
196
+ # 画像編集
197
+ この画像の背景を宇宙に変更して
198
+ ```
199
+
200
+ ## API リファレンス
201
+
202
+ | 機能 | エンドポイント |
203
+ |------|---------------|
204
+ | 画像生成 | `https://api.x.ai/v1/images/generations` |
205
+ | 画像編集 | `https://api.x.ai/v1/images/edits` |
206
+
207
+ - **ドキュメント**: [docs.x.ai/docs/guides/image-generations](https://docs.x.ai/docs/guides/image-generations)
208
+
209
+ ## 開発
210
+
211
+ ```bash
212
+ git clone https://github.com/takajun/grok-imagine-image-mcp-server.git
213
+ cd grok-imagine-image-mcp-server
214
+ npm install
215
+ npm run build
216
+ npm start
217
+ ```
218
+
219
+ ## ライセンス
220
+
221
+ MIT
222
+
223
+ ## 作者
224
+
225
+ Junji Takashima <takajyun00@gmail.com>
package/README.md ADDED
@@ -0,0 +1,225 @@
1
+ # Grok Imagine Image MCP Server
2
+
3
+ [![npm version](https://badge.fury.io/js/grok-imagine-image-mcp-server.svg)](https://www.npmjs.com/package/grok-imagine-image-mcp-server)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ [日本語版 README はこちら](README.ja.md)
7
+
8
+ MCP (Model Context Protocol) server for xAI's Grok Imagine Image API. Supports image generation from text prompts and editing existing images.
9
+
10
+ ## Quick Start with npx
11
+
12
+ ```bash
13
+ # Set your API key
14
+ export XAI_API_KEY="xai-your-api-key"
15
+
16
+ # Run the server
17
+ npx grok-imagine-image-mcp-server
18
+ ```
19
+
20
+ ## Features
21
+
22
+ - **Image Generation**: Generate new images from text prompts
23
+ - **Image Editing**: Edit existing images with prompts (grok-imagine-image only)
24
+ - **Batch Processing**: Process multiple images via CLI
25
+ - Various aspect ratios (1:1, 4:3, 16:9, and more)
26
+ - Resolution: 1k (standard)
27
+ - Generate multiple images at once (up to 10)
28
+ - Optional thumbnail preview in MCP responses
29
+
30
+ ## Supported Models
31
+
32
+ | Model | Price | Image Editing | Notes |
33
+ |-------|-------|---------------|-------|
34
+ | `grok-imagine-image` | $0.02/image | ✅ (+$0.002/input) | **Recommended, Default** |
35
+
36
+ ## Requirements
37
+
38
+ - Node.js 18.0.0 or higher
39
+ - xAI API key (get from [console.x.ai](https://console.x.ai/))
40
+
41
+ ## Installation
42
+
43
+ ### Option 1: npx (Recommended)
44
+
45
+ ```bash
46
+ npx grok-imagine-image-mcp-server
47
+ ```
48
+
49
+ ### Option 2: Global Install
50
+
51
+ ```bash
52
+ npm install -g grok-imagine-image-mcp-server
53
+ grok-imagine-image-mcp-server
54
+ ```
55
+
56
+ ## Configuration
57
+
58
+ ### Environment Variables
59
+
60
+ | Variable | Required | Description |
61
+ |----------|----------|-------------|
62
+ | `XAI_API_KEY` | Yes | Your xAI API key |
63
+ | `DEBUG` | No | Set to `true` for debug logging |
64
+ | `OUTPUT_DIR` | No | Default output directory for images |
65
+ | `XAI_IMAGE_THUMBNAIL` | No | Set to `true` to include thumbnails |
66
+
67
+ ### Claude Desktop Configuration
68
+
69
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
70
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
71
+
72
+ ```json
73
+ {
74
+ "mcpServers": {
75
+ "grok-imagine-image": {
76
+ "command": "npx",
77
+ "args": ["-y", "grok-imagine-image-mcp-server"],
78
+ "env": {
79
+ "XAI_API_KEY": "xai-your-api-key-here"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ ## Tools
87
+
88
+ ### generate_image
89
+
90
+ Generate images from text prompts.
91
+
92
+ | Parameter | Type | Required | Description |
93
+ |-----------|------|----------|-------------|
94
+ | `prompt` | string | Yes | Text description of the image to generate |
95
+ | `output_path` | string | No | Output file path (default: generated_image.jpg) |
96
+ | `model` | string | No | Model to use (default: grok-imagine-image) |
97
+ | `n` | number | No | Number of images (1-10, default: 1) |
98
+ | `aspect_ratio` | string | No | Aspect ratio (default: 1:1) |
99
+ | `resolution` | string | No | Resolution (default: 1k) |
100
+ | `return_base64` | boolean | No | Return base64 data (default: false) |
101
+ | `include_thumbnail` | boolean | No | Include thumbnail (default: false) |
102
+
103
+ ### edit_image
104
+
105
+ Edit existing images (grok-imagine-image only).
106
+
107
+ | Parameter | Type | Required | Description |
108
+ |-----------|------|----------|-------------|
109
+ | `prompt` | string | Yes | Description of desired edits |
110
+ | `image_path` | string | No* | Path to source image file |
111
+ | `image_base64` | string | No* | Base64 encoded source image |
112
+ | `image_url` | string | No* | URL of source image |
113
+ | `output_path` | string | No | Output file path (default: edited_image.jpg) |
114
+ | `n` | number | No | Number of images (1-10, default: 1) |
115
+ | `resolution` | string | No | Resolution (default: 1k). Aspect ratio is auto-detected from input image. |
116
+
117
+ *One of `image_path`, `image_base64`, or `image_url` is required
118
+
119
+ > **Note**: The edit_image tool uses the source image as a reference and regenerates the entire image. It maintains the overall composition and style but is not pixel-level inpainting. Best suited for style transformations, subject replacements, and scene modifications.
120
+
121
+ ## Batch Processing CLI
122
+
123
+ Process multiple images at once using the batch CLI:
124
+
125
+ ```bash
126
+ # Run batch with config file
127
+ npx grok-imagine-image-batch batch.json
128
+
129
+ # Estimate cost only
130
+ npx grok-imagine-image-batch batch.json --estimate-only
131
+
132
+ # Custom output directory
133
+ npx grok-imagine-image-batch batch.json --output-dir ./images --format json
134
+ ```
135
+
136
+ ### CLI Options
137
+
138
+ | Option | Description | Default |
139
+ |--------|-------------|---------|
140
+ | `--output-dir <path>` | Override output directory | From config |
141
+ | `--format <text\|json>` | Output format | `text` |
142
+ | `--timeout <ms>` | Timeout in milliseconds | `600000` |
143
+ | `--max-concurrent <n>` | Max concurrent jobs (1-10) | `2` |
144
+ | `--estimate-only` | Estimate cost without executing | - |
145
+ | `--allow-any-path` | Allow any output path (CI/CD) | - |
146
+
147
+ ### Batch Configuration File
148
+
149
+ ```json
150
+ {
151
+ "jobs": [
152
+ {
153
+ "prompt": "A beautiful sunset over mountains",
154
+ "output_path": "sunset.jpg",
155
+ "aspect_ratio": "16:9"
156
+ },
157
+ {
158
+ "prompt": "Change to nighttime scene",
159
+ "image_path": "input.jpg",
160
+ "output_path": "edited.jpg"
161
+ }
162
+ ],
163
+ "output_dir": "./output",
164
+ "max_concurrent": 3,
165
+ "default_model": "grok-imagine-image",
166
+ "retry_policy": {
167
+ "max_retries": 2,
168
+ "retry_delay_ms": 1000
169
+ }
170
+ }
171
+ ```
172
+
173
+ See `examples/` directory for more configuration examples.
174
+
175
+ ## Supported Aspect Ratios
176
+
177
+ | Aspect Ratio | Use Case |
178
+ |--------------|----------|
179
+ | `1:1` | Square, social media profiles (default) |
180
+ | `3:4` / `4:3` | Standard portrait/landscape |
181
+ | `9:16` / `16:9` | Smartphone / widescreen |
182
+
183
+ ## Supported Resolutions
184
+
185
+ | Resolution | Description |
186
+ |------------|-------------|
187
+ | `1k` | Standard resolution (1024x1024, default) |
188
+
189
+
190
+ ## Usage Examples
191
+
192
+ ```
193
+ # Image generation
194
+ Generate an image of a sunset over mountains with aspect ratio 16:9
195
+
196
+ # Image editing
197
+ Change the background of this image to space
198
+ ```
199
+
200
+ ## API Reference
201
+
202
+ | Function | Endpoint |
203
+ |----------|----------|
204
+ | Image Generation | `https://api.x.ai/v1/images/generations` |
205
+ | Image Editing | `https://api.x.ai/v1/images/edits` |
206
+
207
+ - **Documentation**: [docs.x.ai/docs/guides/image-generations](https://docs.x.ai/docs/guides/image-generations)
208
+
209
+ ## Development
210
+
211
+ ```bash
212
+ git clone https://github.com/takajun/grok-imagine-image-mcp-server.git
213
+ cd grok-imagine-image-mcp-server
214
+ npm install
215
+ npm run build
216
+ npm start
217
+ ```
218
+
219
+ ## License
220
+
221
+ MIT
222
+
223
+ ## Author
224
+
225
+ Junji Takashima <takajyun00@gmail.com>
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Batch processing CLI for xAI Grok Imagine Image
4
+ *
5
+ * Usage:
6
+ * grok-imagine-image-batch <config.json> [options]
7
+ *
8
+ * Options:
9
+ * --output-dir <path> Override output directory
10
+ * --format <text|json> Output format (default: text)
11
+ * --timeout <ms> Timeout in milliseconds (default: 600000)
12
+ * --max-concurrent <n> Max concurrent jobs (1-10, default: 2)
13
+ * --estimate-only Estimate cost without executing
14
+ * --allow-any-path Allow any output path (for CI/CD)
15
+ * --help, -h Show help message
16
+ * --version, -v Show version
17
+ */
18
+ export {};
19
+ //# sourceMappingURL=batch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../src/cli/batch.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;GAeG"}