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.
- package/.env.example +15 -0
- package/LICENSE +21 -0
- package/README.ja.md +225 -0
- package/README.md +225 -0
- package/dist/cli/batch.d.ts +19 -0
- package/dist/cli/batch.d.ts.map +1 -0
- package/dist/cli/batch.js +288 -0
- package/dist/cli/batch.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +203 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/edit.d.ts +14 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +236 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/generate.d.ts +13 -0
- package/dist/tools/generate.d.ts.map +1 -0
- package/dist/tools/generate.js +183 -0
- package/dist/tools/generate.js.map +1 -0
- package/dist/types/batch.d.ts +137 -0
- package/dist/types/batch.d.ts.map +1 -0
- package/dist/types/batch.js +5 -0
- package/dist/types/batch.js.map +1 -0
- package/dist/types/tools.d.ts +52 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +20 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/utils/batch-config.d.ts +31 -0
- package/dist/utils/batch-config.d.ts.map +1 -0
- package/dist/utils/batch-config.js +236 -0
- package/dist/utils/batch-config.js.map +1 -0
- package/dist/utils/batch-manager.d.ts +24 -0
- package/dist/utils/batch-manager.d.ts.map +1 -0
- package/dist/utils/batch-manager.js +301 -0
- package/dist/utils/batch-manager.js.map +1 -0
- package/dist/utils/debug.d.ts +5 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/debug.js +16 -0
- package/dist/utils/debug.js.map +1 -0
- package/dist/utils/image.d.ts +36 -0
- package/dist/utils/image.d.ts.map +1 -0
- package/dist/utils/image.js +85 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/path.d.ts +16 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +70 -0
- package/dist/utils/path.js.map +1 -0
- package/examples/batch-detailed.json +41 -0
- package/examples/batch-simple.json +14 -0
- package/examples/batch-variants.json +23 -0
- package/examples/batch-with-edits.json +26 -0
- package/package.json +66 -0
|
@@ -0,0 +1,288 @@
|
|
|
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
|
+
import * as dotenv from 'dotenv';
|
|
19
|
+
import { loadBatchConfig, validateBatchConfig, mergeBatchConfig, BatchConfigError, } from '../utils/batch-config.js';
|
|
20
|
+
import { BatchManager } from '../utils/batch-manager.js';
|
|
21
|
+
// Load environment variables
|
|
22
|
+
dotenv.config();
|
|
23
|
+
const VERSION = '1.0.0';
|
|
24
|
+
/**
|
|
25
|
+
* Parse command line arguments
|
|
26
|
+
*/
|
|
27
|
+
function parseArgs() {
|
|
28
|
+
const args = process.argv.slice(2);
|
|
29
|
+
const options = {
|
|
30
|
+
format: 'text',
|
|
31
|
+
};
|
|
32
|
+
let configPath;
|
|
33
|
+
let showHelp = false;
|
|
34
|
+
let showVersion = false;
|
|
35
|
+
for (let i = 0; i < args.length; i++) {
|
|
36
|
+
const arg = args[i];
|
|
37
|
+
switch (arg) {
|
|
38
|
+
case '--help':
|
|
39
|
+
case '-h':
|
|
40
|
+
showHelp = true;
|
|
41
|
+
break;
|
|
42
|
+
case '--version':
|
|
43
|
+
case '-v':
|
|
44
|
+
showVersion = true;
|
|
45
|
+
break;
|
|
46
|
+
case '--output-dir':
|
|
47
|
+
options.outputDir = args[++i];
|
|
48
|
+
if (!options.outputDir) {
|
|
49
|
+
console.error('Error: --output-dir requires a path argument');
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case '--format':
|
|
54
|
+
const format = args[++i];
|
|
55
|
+
if (format !== 'text' && format !== 'json') {
|
|
56
|
+
console.error('Error: --format must be "text" or "json"');
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
options.format = format;
|
|
60
|
+
break;
|
|
61
|
+
case '--timeout':
|
|
62
|
+
const timeout = parseInt(args[++i], 10);
|
|
63
|
+
if (isNaN(timeout) || timeout < 1000) {
|
|
64
|
+
console.error('Error: --timeout must be a number >= 1000');
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
options.timeout = timeout;
|
|
68
|
+
break;
|
|
69
|
+
case '--max-concurrent':
|
|
70
|
+
const maxConcurrent = parseInt(args[++i], 10);
|
|
71
|
+
if (isNaN(maxConcurrent) || maxConcurrent < 1 || maxConcurrent > 10) {
|
|
72
|
+
console.error('Error: --max-concurrent must be between 1 and 10');
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
options.maxConcurrent = maxConcurrent;
|
|
76
|
+
break;
|
|
77
|
+
case '--estimate-only':
|
|
78
|
+
options.estimateOnly = true;
|
|
79
|
+
break;
|
|
80
|
+
case '--allow-any-path':
|
|
81
|
+
options.allowAnyPath = true;
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
if (arg.startsWith('-')) {
|
|
85
|
+
console.error(`Error: Unknown option: ${arg}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
if (configPath) {
|
|
89
|
+
console.error('Error: Multiple config files specified');
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
configPath = arg;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { configPath, options, showHelp, showVersion };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Show help message
|
|
99
|
+
*/
|
|
100
|
+
function showHelpMessage() {
|
|
101
|
+
console.log(`
|
|
102
|
+
xAI Grok Imagine Image Batch CLI v${VERSION}
|
|
103
|
+
|
|
104
|
+
Usage:
|
|
105
|
+
grok-imagine-image-batch <config.json> [options]
|
|
106
|
+
|
|
107
|
+
Options:
|
|
108
|
+
--output-dir <path> Override output directory from config
|
|
109
|
+
--format <text|json> Output format (default: text)
|
|
110
|
+
--timeout <ms> Timeout in milliseconds (default: 600000)
|
|
111
|
+
--max-concurrent <n> Max concurrent jobs, 1-10 (default: 2)
|
|
112
|
+
--estimate-only Estimate cost without executing
|
|
113
|
+
--allow-any-path Allow any output path (for CI/CD)
|
|
114
|
+
--help, -h Show this help message
|
|
115
|
+
--version, -v Show version
|
|
116
|
+
|
|
117
|
+
Environment Variables:
|
|
118
|
+
XAI_API_KEY Required: xAI API key
|
|
119
|
+
OUTPUT_DIR Default output directory
|
|
120
|
+
DEBUG Set to "true" for debug logging
|
|
121
|
+
|
|
122
|
+
Configuration File Format:
|
|
123
|
+
{
|
|
124
|
+
"jobs": [
|
|
125
|
+
{
|
|
126
|
+
"prompt": "A beautiful sunset",
|
|
127
|
+
"output_path": "sunset.jpg",
|
|
128
|
+
"aspect_ratio": "16:9",
|
|
129
|
+
"resolution": "2k"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"prompt": "Change to nighttime",
|
|
133
|
+
"image_path": "input.jpg",
|
|
134
|
+
"output_path": "edited.jpg"
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"output_dir": "./output",
|
|
138
|
+
"max_concurrent": 3,
|
|
139
|
+
"default_model": "grok-imagine-image"
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
Examples:
|
|
143
|
+
# Run batch with config file
|
|
144
|
+
grok-imagine-image-batch batch.json
|
|
145
|
+
|
|
146
|
+
# Estimate cost only
|
|
147
|
+
grok-imagine-image-batch batch.json --estimate-only
|
|
148
|
+
|
|
149
|
+
# Custom output directory and format
|
|
150
|
+
grok-imagine-image-batch batch.json --output-dir ./images --format json
|
|
151
|
+
|
|
152
|
+
# High concurrency with extended timeout
|
|
153
|
+
grok-imagine-image-batch batch.json --max-concurrent 5 --timeout 1800000
|
|
154
|
+
`);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Format cost estimate as text
|
|
158
|
+
*/
|
|
159
|
+
function formatCostEstimateText(estimate) {
|
|
160
|
+
let output = '\n📊 Cost Estimation\n\n';
|
|
161
|
+
output += `Total jobs: ${estimate.totalJobs}\n`;
|
|
162
|
+
output += `Total images: ${estimate.totalImages}\n`;
|
|
163
|
+
output += `Estimated cost: $${estimate.estimatedCostMin.toFixed(4)}`;
|
|
164
|
+
if (estimate.estimatedCostMin !== estimate.estimatedCostMax) {
|
|
165
|
+
output += ` - $${estimate.estimatedCostMax.toFixed(4)}`;
|
|
166
|
+
}
|
|
167
|
+
output += '\n\nBreakdown by model:\n';
|
|
168
|
+
for (const item of estimate.breakdown) {
|
|
169
|
+
output += ` - ${item.count} x ${item.model}: ${item.images} images = $${item.costMin.toFixed(4)}\n`;
|
|
170
|
+
}
|
|
171
|
+
return output;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Format batch result as text
|
|
175
|
+
*/
|
|
176
|
+
function formatResultText(result) {
|
|
177
|
+
const successIcon = result.failed === 0 && result.cancelled === 0 ? '✅' : '⚠️';
|
|
178
|
+
let output = `\n${successIcon} Batch Image Generation ${result.failed === 0 && result.cancelled === 0 ? 'Completed Successfully' : 'Completed with Issues'}\n\n`;
|
|
179
|
+
output += '📊 Summary:\n';
|
|
180
|
+
output += ` - Total Jobs: ${result.total}\n`;
|
|
181
|
+
output += ` - Succeeded: ${result.succeeded}\n`;
|
|
182
|
+
output += ` - Failed: ${result.failed}\n`;
|
|
183
|
+
output += ` - Cancelled: ${result.cancelled}\n`;
|
|
184
|
+
output += ` - Duration: ${(result.total_duration_ms / 1000).toFixed(2)}s\n`;
|
|
185
|
+
output += ` - Started: ${new Date(result.started_at).toLocaleString()}\n`;
|
|
186
|
+
output += ` - Finished: ${new Date(result.finished_at).toLocaleString()}\n`;
|
|
187
|
+
if (result.estimated_cost !== undefined) {
|
|
188
|
+
output += `\n💰 Estimated Cost: $${result.estimated_cost.toFixed(4)}\n`;
|
|
189
|
+
}
|
|
190
|
+
// Succeeded jobs
|
|
191
|
+
const succeeded = result.results.filter((r) => r.status === 'completed');
|
|
192
|
+
if (succeeded.length > 0) {
|
|
193
|
+
output += '\n### ✅ Successfully Generated Images\n';
|
|
194
|
+
for (const job of succeeded) {
|
|
195
|
+
const type = job.is_edit ? 'Edited' : 'Generated';
|
|
196
|
+
output += `\n${job.index}. ${job.output_paths?.[0] || 'Unknown'}\n`;
|
|
197
|
+
output += ` ${type}: "${job.prompt.substring(0, 60)}${job.prompt.length > 60 ? '...' : ''}"\n`;
|
|
198
|
+
if (job.output_paths && job.output_paths.length > 1) {
|
|
199
|
+
output += ` (+ ${job.output_paths.length - 1} more variants)\n`;
|
|
200
|
+
}
|
|
201
|
+
if (job.duration_ms) {
|
|
202
|
+
output += ` Duration: ${(job.duration_ms / 1000).toFixed(2)}s\n`;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Failed jobs
|
|
207
|
+
const failed = result.results.filter((r) => r.status === 'failed');
|
|
208
|
+
if (failed.length > 0) {
|
|
209
|
+
output += '\n### ❌ Failed Jobs\n';
|
|
210
|
+
for (const job of failed) {
|
|
211
|
+
output += `\n${job.index}. "${job.prompt.substring(0, 60)}${job.prompt.length > 60 ? '...' : ''}"\n`;
|
|
212
|
+
output += ` Error: ${job.error}\n`;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Cancelled jobs
|
|
216
|
+
const cancelled = result.results.filter((r) => r.status === 'cancelled');
|
|
217
|
+
if (cancelled.length > 0) {
|
|
218
|
+
output += '\n### 🚫 Cancelled Jobs\n';
|
|
219
|
+
for (const job of cancelled) {
|
|
220
|
+
output += `\n${job.index}. "${job.prompt.substring(0, 60)}${job.prompt.length > 60 ? '...' : ''}"\n`;
|
|
221
|
+
output += ` Reason: ${job.error || 'Timeout'}\n`;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return output;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Main entry point
|
|
228
|
+
*/
|
|
229
|
+
async function main() {
|
|
230
|
+
const { configPath, options, showHelp, showVersion } = parseArgs();
|
|
231
|
+
if (showVersion) {
|
|
232
|
+
console.log(`grok-imagine-image-batch v${VERSION}`);
|
|
233
|
+
process.exit(0);
|
|
234
|
+
}
|
|
235
|
+
if (showHelp || !configPath) {
|
|
236
|
+
showHelpMessage();
|
|
237
|
+
process.exit(showHelp ? 0 : 1);
|
|
238
|
+
}
|
|
239
|
+
// Validate API key
|
|
240
|
+
const apiKey = process.env.XAI_API_KEY;
|
|
241
|
+
if (!apiKey) {
|
|
242
|
+
console.error('Error: XAI_API_KEY environment variable is required');
|
|
243
|
+
console.error('Get your API key from: https://console.x.ai/');
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
// Load and validate config
|
|
248
|
+
const config = await loadBatchConfig(configPath);
|
|
249
|
+
validateBatchConfig(config);
|
|
250
|
+
const mergedConfig = mergeBatchConfig(config, options);
|
|
251
|
+
// Create batch manager
|
|
252
|
+
const batchManager = new BatchManager(apiKey);
|
|
253
|
+
// Estimate only mode
|
|
254
|
+
if (options.estimateOnly) {
|
|
255
|
+
const estimate = batchManager.estimateBatchCost(mergedConfig);
|
|
256
|
+
if (options.format === 'json') {
|
|
257
|
+
console.log(JSON.stringify(estimate, null, 2));
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
console.log(formatCostEstimateText(estimate));
|
|
261
|
+
}
|
|
262
|
+
process.exit(0);
|
|
263
|
+
}
|
|
264
|
+
// Execute batch
|
|
265
|
+
console.error(`Starting batch execution: ${mergedConfig.jobs.length} jobs...`);
|
|
266
|
+
const result = await batchManager.executeBatch(mergedConfig, options);
|
|
267
|
+
// Output results
|
|
268
|
+
if (options.format === 'json') {
|
|
269
|
+
console.log(JSON.stringify(result, null, 2));
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
console.log(formatResultText(result));
|
|
273
|
+
}
|
|
274
|
+
// Exit code based on results
|
|
275
|
+
process.exit(result.failed > 0 || result.cancelled > 0 ? 1 : 0);
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
if (error instanceof BatchConfigError) {
|
|
279
|
+
console.error(`Configuration Error: ${error.message}`);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
console.error(`Error: ${error.message}`);
|
|
283
|
+
}
|
|
284
|
+
process.exit(1);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
main();
|
|
288
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.js","sourceRoot":"","sources":["../../src/cli/batch.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,6BAA6B;AAC7B,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB;;GAEG;AACH,SAAS,SAAS;IAMhB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK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AC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;QACxC,CAAC;QAED,6BAA6B;QAC7B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;YACtC,OAAO,CAAC,KAAK,CAAC,wBAAwB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* xAI Grok Imagine Image MCP Server
|
|
4
|
+
*
|
|
5
|
+
* Model Context Protocol server for xAI's Grok Imagine Image API
|
|
6
|
+
* Enables image generation and editing through Claude Desktop and other MCP clients
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* xAI Grok Imagine Image MCP Server
|
|
4
|
+
*
|
|
5
|
+
* Model Context Protocol server for xAI's Grok Imagine Image API
|
|
6
|
+
* Enables image generation and editing through Claude Desktop and other MCP clients
|
|
7
|
+
*/
|
|
8
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
9
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
10
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
11
|
+
import * as dotenv from 'dotenv';
|
|
12
|
+
import { generateImage } from './tools/generate.js';
|
|
13
|
+
import { editImage } from './tools/edit.js';
|
|
14
|
+
import { debugLog } from './utils/debug.js';
|
|
15
|
+
// Load environment variables
|
|
16
|
+
dotenv.config();
|
|
17
|
+
// Validate API key
|
|
18
|
+
const apiKey = process.env.XAI_API_KEY;
|
|
19
|
+
if (!apiKey) {
|
|
20
|
+
console.error('Error: XAI_API_KEY environment variable is required.\n' +
|
|
21
|
+
'Please set it in your environment or .env file.\n' +
|
|
22
|
+
'Get your API key from: https://console.x.ai/\n' +
|
|
23
|
+
'Example: export XAI_API_KEY="xai-..."\n');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
// Create MCP server
|
|
27
|
+
const server = new Server({
|
|
28
|
+
name: 'grok-imagine-image-mcp-server',
|
|
29
|
+
version: '1.0.0',
|
|
30
|
+
}, {
|
|
31
|
+
capabilities: {
|
|
32
|
+
tools: {},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
// Tool definitions
|
|
36
|
+
const TOOLS = [
|
|
37
|
+
{
|
|
38
|
+
name: 'generate_image',
|
|
39
|
+
description: 'Generate a new image from a text prompt using xAI Grok Imagine Image API. ' +
|
|
40
|
+
'Uses grok-imagine-image model ($0.02/image). ' +
|
|
41
|
+
'Supports aspect ratios: 1:1, 3:4, 4:3, 9:16, 16:9. ' +
|
|
42
|
+
'Can generate multiple images at once (up to 10).',
|
|
43
|
+
inputSchema: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
46
|
+
prompt: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
description: 'The text prompt describing the image to generate',
|
|
49
|
+
},
|
|
50
|
+
output_path: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
description: 'Output file path (default: generated_image.jpg)',
|
|
53
|
+
},
|
|
54
|
+
model: {
|
|
55
|
+
type: 'string',
|
|
56
|
+
enum: ['grok-imagine-image'],
|
|
57
|
+
description: 'Model to use (default: grok-imagine-image, $0.02/image)',
|
|
58
|
+
},
|
|
59
|
+
n: {
|
|
60
|
+
type: 'number',
|
|
61
|
+
description: 'Number of images to generate (1-10, default: 1)',
|
|
62
|
+
minimum: 1,
|
|
63
|
+
maximum: 10,
|
|
64
|
+
},
|
|
65
|
+
aspect_ratio: {
|
|
66
|
+
type: 'string',
|
|
67
|
+
enum: ['1:1', '3:4', '4:3', '9:16', '16:9'],
|
|
68
|
+
description: 'Aspect ratio (default: 1:1)',
|
|
69
|
+
},
|
|
70
|
+
resolution: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
enum: ['1k'],
|
|
73
|
+
description: 'Resolution of the generated image (default: 1k)',
|
|
74
|
+
},
|
|
75
|
+
quality: {
|
|
76
|
+
type: 'string',
|
|
77
|
+
enum: ['low', 'medium', 'high'],
|
|
78
|
+
description: 'Quality of the output image (currently reserved for future use)',
|
|
79
|
+
},
|
|
80
|
+
return_base64: {
|
|
81
|
+
type: 'boolean',
|
|
82
|
+
description: 'Return base64 image data in response (default: false)',
|
|
83
|
+
},
|
|
84
|
+
include_thumbnail: {
|
|
85
|
+
type: 'boolean',
|
|
86
|
+
description: 'Include thumbnail preview in MCP response for LLM recognition (default: false, overrides XAI_IMAGE_THUMBNAIL env var)',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
required: ['prompt'],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'edit_image',
|
|
94
|
+
description: 'Edit an existing image using xAI Grok Imagine Image API. ' +
|
|
95
|
+
'Only supported by grok-imagine-image model ($0.02/image + $0.002/input image). ' +
|
|
96
|
+
'Provide a source image via file path, base64, or URL along with a prompt describing the desired changes.',
|
|
97
|
+
inputSchema: {
|
|
98
|
+
type: 'object',
|
|
99
|
+
properties: {
|
|
100
|
+
prompt: {
|
|
101
|
+
type: 'string',
|
|
102
|
+
description: 'Description of the desired edits to make to the image',
|
|
103
|
+
},
|
|
104
|
+
image_path: {
|
|
105
|
+
type: 'string',
|
|
106
|
+
description: 'Path to the source image file to edit',
|
|
107
|
+
},
|
|
108
|
+
image_base64: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
description: 'Base64 encoded source image to edit',
|
|
111
|
+
},
|
|
112
|
+
image_url: {
|
|
113
|
+
type: 'string',
|
|
114
|
+
description: 'URL of the source image to edit',
|
|
115
|
+
},
|
|
116
|
+
output_path: {
|
|
117
|
+
type: 'string',
|
|
118
|
+
description: 'Output file path (default: edited_image.jpg)',
|
|
119
|
+
},
|
|
120
|
+
n: {
|
|
121
|
+
type: 'number',
|
|
122
|
+
description: 'Number of edited images to generate (1-10, default: 1)',
|
|
123
|
+
minimum: 1,
|
|
124
|
+
maximum: 10,
|
|
125
|
+
},
|
|
126
|
+
resolution: {
|
|
127
|
+
type: 'string',
|
|
128
|
+
enum: ['1k'],
|
|
129
|
+
description: 'Resolution of the output image (default: 1k). Aspect ratio is automatically detected from the input image.',
|
|
130
|
+
},
|
|
131
|
+
return_base64: {
|
|
132
|
+
type: 'boolean',
|
|
133
|
+
description: 'Return base64 image data in response (default: false)',
|
|
134
|
+
},
|
|
135
|
+
include_thumbnail: {
|
|
136
|
+
type: 'boolean',
|
|
137
|
+
description: 'Include thumbnail preview in MCP response for LLM recognition (default: false)',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
required: ['prompt'],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
// List tools handler
|
|
145
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
146
|
+
debugLog('Listing available tools');
|
|
147
|
+
return { tools: TOOLS };
|
|
148
|
+
});
|
|
149
|
+
// Call tool handler
|
|
150
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
151
|
+
const { name, arguments: args } = request.params;
|
|
152
|
+
// Redact sensitive data from logs
|
|
153
|
+
const safeArgs = { ...args };
|
|
154
|
+
if ('image_base64' in safeArgs) {
|
|
155
|
+
safeArgs.image_base64 = '[REDACTED]';
|
|
156
|
+
}
|
|
157
|
+
debugLog(`Tool called: ${name}`, safeArgs);
|
|
158
|
+
try {
|
|
159
|
+
switch (name) {
|
|
160
|
+
case 'generate_image': {
|
|
161
|
+
const result = await generateImage(apiKey, args);
|
|
162
|
+
if (typeof result === 'string') {
|
|
163
|
+
return { content: [{ type: 'text', text: result }] };
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
case 'edit_image': {
|
|
168
|
+
const result = await editImage(apiKey, args);
|
|
169
|
+
if (typeof result === 'string') {
|
|
170
|
+
return { content: [{ type: 'text', text: result }] };
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
default:
|
|
175
|
+
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
debugLog('Tool execution error:', error);
|
|
180
|
+
return {
|
|
181
|
+
content: [
|
|
182
|
+
{
|
|
183
|
+
type: 'text',
|
|
184
|
+
text: `Error: ${error.message}`,
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
isError: true,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
// Start server
|
|
192
|
+
async function main() {
|
|
193
|
+
debugLog('Starting xAI Grok Imagine Image MCP Server');
|
|
194
|
+
debugLog(`API Key configured: ${apiKey.substring(0, 10)}...`);
|
|
195
|
+
const transport = new StdioServerTransport();
|
|
196
|
+
await server.connect(transport);
|
|
197
|
+
debugLog('Server running on stdio transport');
|
|
198
|
+
}
|
|
199
|
+
main().catch((error) => {
|
|
200
|
+
console.error('Fatal error:', error);
|
|
201
|
+
process.exit(1);
|
|
202
|
+
});
|
|
203
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,SAAS,EACT,QAAQ,GACT,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,6BAA6B;AAC7B,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,mBAAmB;AACnB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;AACvC,IAAI,CAAC,MAAM,EAAE,CAAC;IACZ,OAAO,CAAC,KAAK,CACX,wDAAwD;QACtD,mDAAmD;QACnD,gDAAgD;QAChD,yCAAyC,CAC5C,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,oBAAoB;AACpB,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB;IACE,IAAI,EAAE,+BAA+B;IACrC,OAAO,EAAE,OAAO;CACjB,EACD;IACE,YAAY,EAAE;QACZ,KAAK,EAAE,EAAE;KACV;CACF,CACF,CAAC;AAEF,mBAAmB;AACnB,MAAM,KAAK,GAAG;IACZ;QACE,IAAI,EAAE,gBAAgB;QACtB,WAAW,EACT,4EAA4E;YAC5E,+CAA+C;YAC/C,qD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EAAE;iBAChC;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,eAAe;AACf,KAAK,UAAU,IAAI;IACjB,QAAQ,CAAC,4CAA4C,CAAC,CAAC;IACvD,QAAQ,CAAC,uBAAuB,MAAO,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IAE/D,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,QAAQ,CAAC,mCAAmC,CAAC,CAAC;AAChD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edit image tool - Edit images using xAI Grok Imagine
|
|
3
|
+
* Uses /v1/images/edits endpoint
|
|
4
|
+
*/
|
|
5
|
+
import type { EditImageParams } from '../types/tools.js';
|
|
6
|
+
export declare function editImage(apiKey: string, params: EditImageParams): Promise<string | {
|
|
7
|
+
content: Array<{
|
|
8
|
+
type: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
data?: string;
|
|
11
|
+
mimeType?: string;
|
|
12
|
+
}>;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=edit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,mBAAmB,CAAC;AAM3E,wBAAsB,SAAS,CAC7B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,eAAe,GACtB,OAAO,CACN,MAAM,GACN;IACE,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;CACJ,CACJ,CAsTA"}
|