@takeshijuan/ideogram-mcp-server 1.0.0 → 2.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/dist/config/config.d.ts +107 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/constants.d.ts +211 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -83
- package/dist/placeholder.d.ts +6 -0
- package/dist/placeholder.d.ts.map +1 -0
- package/dist/server.d.ts +146 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/services/cost.calculator.d.ts +349 -0
- package/dist/services/cost.calculator.d.ts.map +1 -0
- package/dist/services/ideogram.client.d.ts +311 -0
- package/dist/services/ideogram.client.d.ts.map +1 -0
- package/dist/services/prediction.store.d.ts +462 -0
- package/dist/services/prediction.store.d.ts.map +1 -0
- package/dist/services/storage.service.d.ts +307 -0
- package/dist/services/storage.service.d.ts.map +1 -0
- package/dist/tools/cancel-prediction.d.ts +179 -0
- package/dist/tools/cancel-prediction.d.ts.map +1 -0
- package/dist/tools/edit.d.ts +244 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/generate-async.d.ts +230 -0
- package/dist/tools/generate-async.d.ts.map +1 -0
- package/dist/tools/generate.d.ts +231 -0
- package/dist/tools/generate.d.ts.map +1 -0
- package/dist/tools/get-prediction.d.ts +188 -0
- package/dist/tools/get-prediction.d.ts.map +1 -0
- package/dist/tools/index.d.ts +320 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/types/api.types.d.ts +218 -0
- package/dist/types/api.types.d.ts.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/tool.types.d.ts +571 -0
- package/dist/types/tool.types.d.ts.map +1 -0
- package/dist/utils/error.handler.d.ts +178 -0
- package/dist/utils/error.handler.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +145 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/retry.d.ts +231 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/validation.d.ts +223 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/package.json +18 -7
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Loading and Validation
|
|
3
|
+
*
|
|
4
|
+
* This module handles loading configuration from environment variables
|
|
5
|
+
* and validating them using Zod schemas. It provides a strongly-typed
|
|
6
|
+
* configuration object for use throughout the application.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
/**
|
|
10
|
+
* Supported log levels
|
|
11
|
+
*/
|
|
12
|
+
export declare const LOG_LEVELS: readonly ["debug", "info", "warn", "error"];
|
|
13
|
+
/**
|
|
14
|
+
* Log level type
|
|
15
|
+
*/
|
|
16
|
+
export type LogLevel = (typeof LOG_LEVELS)[number];
|
|
17
|
+
/**
|
|
18
|
+
* Zod schema for environment variable validation.
|
|
19
|
+
* Transforms and validates all configuration values.
|
|
20
|
+
*/
|
|
21
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
22
|
+
/**
|
|
23
|
+
* Ideogram API key (required)
|
|
24
|
+
*/
|
|
25
|
+
ideogramApiKey: z.ZodString;
|
|
26
|
+
/**
|
|
27
|
+
* Logging level
|
|
28
|
+
*/
|
|
29
|
+
logLevel: z.ZodDefault<z.ZodEnum<["debug", "info", "warn", "error"]>>;
|
|
30
|
+
/**
|
|
31
|
+
* Directory for local image storage
|
|
32
|
+
*/
|
|
33
|
+
localSaveDir: z.ZodDefault<z.ZodString>;
|
|
34
|
+
/**
|
|
35
|
+
* Enable automatic local saving of images
|
|
36
|
+
*/
|
|
37
|
+
enableLocalSave: z.ZodDefault<z.ZodBoolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Maximum concurrent API requests
|
|
40
|
+
*/
|
|
41
|
+
maxConcurrentRequests: z.ZodDefault<z.ZodNumber>;
|
|
42
|
+
/**
|
|
43
|
+
* API request timeout in milliseconds
|
|
44
|
+
*/
|
|
45
|
+
requestTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
ideogramApiKey: string;
|
|
48
|
+
logLevel: "debug" | "info" | "warn" | "error";
|
|
49
|
+
localSaveDir: string;
|
|
50
|
+
enableLocalSave: boolean;
|
|
51
|
+
maxConcurrentRequests: number;
|
|
52
|
+
requestTimeoutMs: number;
|
|
53
|
+
}, {
|
|
54
|
+
ideogramApiKey: string;
|
|
55
|
+
logLevel?: "debug" | "info" | "warn" | "error" | undefined;
|
|
56
|
+
localSaveDir?: string | undefined;
|
|
57
|
+
enableLocalSave?: boolean | undefined;
|
|
58
|
+
maxConcurrentRequests?: number | undefined;
|
|
59
|
+
requestTimeoutMs?: number | undefined;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Validated configuration type
|
|
63
|
+
*/
|
|
64
|
+
export type Config = z.infer<typeof ConfigSchema>;
|
|
65
|
+
/**
|
|
66
|
+
* Validated application configuration.
|
|
67
|
+
*
|
|
68
|
+
* This is loaded and validated once at module load time.
|
|
69
|
+
* Any configuration errors will be thrown immediately.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { config } from './config/config.js';
|
|
74
|
+
*
|
|
75
|
+
* // Access configuration values
|
|
76
|
+
* const apiKey = config.ideogramApiKey;
|
|
77
|
+
* const logLevel = config.logLevel;
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare const config: Config;
|
|
81
|
+
/**
|
|
82
|
+
* Check if the configuration is valid without throwing.
|
|
83
|
+
* Useful for testing or conditional initialization.
|
|
84
|
+
*
|
|
85
|
+
* @returns True if configuration is valid, false otherwise
|
|
86
|
+
*/
|
|
87
|
+
export declare function isConfigValid(): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Get configuration validation errors without throwing.
|
|
90
|
+
* Returns an empty array if configuration is valid.
|
|
91
|
+
*
|
|
92
|
+
* @returns Array of validation error messages
|
|
93
|
+
*/
|
|
94
|
+
export declare function getConfigErrors(): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Create a configuration object for testing or dependency injection.
|
|
97
|
+
* Validates the provided values against the schema.
|
|
98
|
+
*
|
|
99
|
+
* @param overrides - Configuration values to use instead of environment variables
|
|
100
|
+
* @returns Validated configuration object
|
|
101
|
+
* @throws Error if validation fails
|
|
102
|
+
*/
|
|
103
|
+
export declare function createConfig(overrides: Partial<Config> & {
|
|
104
|
+
ideogramApiKey: string;
|
|
105
|
+
}): Config;
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB;;GAEG;AACH,eAAO,MAAM,UAAU,6CAA8C,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAMnD;;;GAGG;AACH,QAAA,MAAM,YAAY;IAChB;;OAEG;;IAWH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAUH;;OAEG;;;;;;;;;;;;;;;;EAOH,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAoGlD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,MAAM,EAAE,MAAqB,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,MAAM,EAAE,CAW1C;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAe5F"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Constants and Configuration
|
|
3
|
+
*
|
|
4
|
+
* This file contains all constant values for the Ideogram MCP Server including:
|
|
5
|
+
* - API endpoint URLs
|
|
6
|
+
* - Enum value arrays for validation
|
|
7
|
+
* - Default values for optional parameters
|
|
8
|
+
* - Validation constraints
|
|
9
|
+
* - Cost estimation data
|
|
10
|
+
*/
|
|
11
|
+
import type { AspectRatio, RenderingSpeed, MagicPrompt, StyleType, Model, PredictionStatus } from '../types/api.types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Ideogram API base URL
|
|
14
|
+
*/
|
|
15
|
+
export declare const API_BASE_URL: "https://api.ideogram.ai";
|
|
16
|
+
/**
|
|
17
|
+
* API endpoints for different operations
|
|
18
|
+
*/
|
|
19
|
+
export declare const API_ENDPOINTS: {
|
|
20
|
+
/** V3 Generate endpoint */
|
|
21
|
+
readonly GENERATE_V3: "/v1/ideogram-v3/generate";
|
|
22
|
+
/** Legacy Edit endpoint (inpainting only) */
|
|
23
|
+
readonly EDIT_LEGACY: "/edit";
|
|
24
|
+
/** Legacy V2 Generate endpoint */
|
|
25
|
+
readonly GENERATE_LEGACY: "/generate";
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* API header name for authentication
|
|
29
|
+
*/
|
|
30
|
+
export declare const API_KEY_HEADER: "Api-Key";
|
|
31
|
+
/**
|
|
32
|
+
* All 15 supported aspect ratios.
|
|
33
|
+
* Note: Uses "x" separator, not ":" (e.g., "16x9" not "16:9")
|
|
34
|
+
*/
|
|
35
|
+
export declare const ASPECT_RATIOS: readonly AspectRatio[];
|
|
36
|
+
/**
|
|
37
|
+
* Rendering speed options for Ideogram V3.
|
|
38
|
+
* Ordered from fastest (lowest quality) to slowest (highest quality).
|
|
39
|
+
*/
|
|
40
|
+
export declare const RENDERING_SPEEDS: readonly RenderingSpeed[];
|
|
41
|
+
/**
|
|
42
|
+
* Magic prompt enhancement options.
|
|
43
|
+
*/
|
|
44
|
+
export declare const MAGIC_PROMPT_OPTIONS: readonly MagicPrompt[];
|
|
45
|
+
/**
|
|
46
|
+
* Style type options for image generation.
|
|
47
|
+
*/
|
|
48
|
+
export declare const STYLE_TYPES: readonly StyleType[];
|
|
49
|
+
/**
|
|
50
|
+
* Ideogram model versions (for legacy V2 endpoints).
|
|
51
|
+
*/
|
|
52
|
+
export declare const MODELS: readonly Model[];
|
|
53
|
+
/**
|
|
54
|
+
* Prediction status values for async operations (local implementation).
|
|
55
|
+
*/
|
|
56
|
+
export declare const PREDICTION_STATUSES: readonly PredictionStatus[];
|
|
57
|
+
/**
|
|
58
|
+
* Default values for optional generation parameters
|
|
59
|
+
*/
|
|
60
|
+
export declare const DEFAULTS: {
|
|
61
|
+
/** Default aspect ratio */
|
|
62
|
+
readonly ASPECT_RATIO: AspectRatio;
|
|
63
|
+
/** Default number of images to generate */
|
|
64
|
+
readonly NUM_IMAGES: 1;
|
|
65
|
+
/** Default rendering speed */
|
|
66
|
+
readonly RENDERING_SPEED: RenderingSpeed;
|
|
67
|
+
/** Default magic prompt setting */
|
|
68
|
+
readonly MAGIC_PROMPT: MagicPrompt;
|
|
69
|
+
/** Default style type */
|
|
70
|
+
readonly STYLE_TYPE: StyleType;
|
|
71
|
+
/** Default save locally option */
|
|
72
|
+
readonly SAVE_LOCALLY: true;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Validation constraints for API parameters
|
|
76
|
+
*/
|
|
77
|
+
export declare const VALIDATION: {
|
|
78
|
+
/** Prompt constraints */
|
|
79
|
+
readonly PROMPT: {
|
|
80
|
+
readonly MIN_LENGTH: 1;
|
|
81
|
+
readonly MAX_LENGTH: 10000;
|
|
82
|
+
};
|
|
83
|
+
/** Number of images constraints */
|
|
84
|
+
readonly NUM_IMAGES: {
|
|
85
|
+
readonly MIN: 1;
|
|
86
|
+
readonly MAX: 8;
|
|
87
|
+
};
|
|
88
|
+
/** Seed constraints */
|
|
89
|
+
readonly SEED: {
|
|
90
|
+
readonly MIN: 0;
|
|
91
|
+
readonly MAX: 2147483647;
|
|
92
|
+
};
|
|
93
|
+
/** Expand pixels constraints for outpainting */
|
|
94
|
+
readonly EXPAND_PIXELS: {
|
|
95
|
+
readonly MIN: 1;
|
|
96
|
+
readonly MAX: 1024;
|
|
97
|
+
};
|
|
98
|
+
/** Image file constraints */
|
|
99
|
+
readonly IMAGE: {
|
|
100
|
+
/** Maximum file size in bytes (10MB) */
|
|
101
|
+
readonly MAX_SIZE_BYTES: number;
|
|
102
|
+
/** Supported image formats */
|
|
103
|
+
readonly SUPPORTED_FORMATS: readonly ["image/png", "image/jpeg", "image/webp"];
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Credit costs per image by rendering speed.
|
|
108
|
+
* Note: These are estimates based on known Ideogram pricing.
|
|
109
|
+
* Actual costs may vary - Ideogram API does not return cost info.
|
|
110
|
+
*/
|
|
111
|
+
export declare const CREDITS_PER_IMAGE: Record<RenderingSpeed, number>;
|
|
112
|
+
/**
|
|
113
|
+
* Credits cost for edit operations per image.
|
|
114
|
+
*/
|
|
115
|
+
export declare const EDIT_CREDITS_PER_IMAGE: Record<RenderingSpeed, number>;
|
|
116
|
+
/**
|
|
117
|
+
* Estimated USD per credit.
|
|
118
|
+
* Based on Ideogram's pricing tiers.
|
|
119
|
+
*/
|
|
120
|
+
export declare const USD_PER_CREDIT: 0.05;
|
|
121
|
+
/**
|
|
122
|
+
* HTTP status codes for error handling
|
|
123
|
+
*/
|
|
124
|
+
export declare const HTTP_STATUS: {
|
|
125
|
+
readonly OK: 200;
|
|
126
|
+
readonly CREATED: 201;
|
|
127
|
+
readonly BAD_REQUEST: 400;
|
|
128
|
+
readonly UNAUTHORIZED: 401;
|
|
129
|
+
readonly FORBIDDEN: 403;
|
|
130
|
+
readonly NOT_FOUND: 404;
|
|
131
|
+
readonly TOO_MANY_REQUESTS: 429;
|
|
132
|
+
readonly INTERNAL_SERVER_ERROR: 500;
|
|
133
|
+
readonly SERVICE_UNAVAILABLE: 503;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Retryable HTTP status codes
|
|
137
|
+
*/
|
|
138
|
+
export declare const RETRYABLE_STATUS_CODES: readonly number[];
|
|
139
|
+
/**
|
|
140
|
+
* Retry configuration for transient errors
|
|
141
|
+
*/
|
|
142
|
+
export declare const RETRY_CONFIG: {
|
|
143
|
+
/** Maximum number of retry attempts */
|
|
144
|
+
readonly MAX_ATTEMPTS: 3;
|
|
145
|
+
/** Initial delay in milliseconds */
|
|
146
|
+
readonly INITIAL_DELAY_MS: 1000;
|
|
147
|
+
/** Maximum delay in milliseconds */
|
|
148
|
+
readonly MAX_DELAY_MS: 10000;
|
|
149
|
+
/** Backoff multiplier for exponential backoff */
|
|
150
|
+
readonly BACKOFF_MULTIPLIER: 2;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Timeout configuration in milliseconds
|
|
154
|
+
*/
|
|
155
|
+
export declare const TIMEOUTS: {
|
|
156
|
+
/** Default API request timeout */
|
|
157
|
+
readonly DEFAULT_REQUEST_MS: 30000;
|
|
158
|
+
/** Long-running request timeout (for quality rendering) */
|
|
159
|
+
readonly LONG_REQUEST_MS: 120000;
|
|
160
|
+
/** Image download timeout */
|
|
161
|
+
readonly IMAGE_DOWNLOAD_MS: 60000;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* MCP Server identification
|
|
165
|
+
*/
|
|
166
|
+
export declare const SERVER_INFO: {
|
|
167
|
+
readonly NAME: "ideogram-mcp-server";
|
|
168
|
+
readonly VERSION: "1.0.0";
|
|
169
|
+
readonly DESCRIPTION: "Production-grade Ideogram AI image generation MCP server";
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Configuration for the local prediction queue
|
|
173
|
+
*/
|
|
174
|
+
export declare const PREDICTION_QUEUE: {
|
|
175
|
+
/** Maximum number of queued predictions */
|
|
176
|
+
readonly MAX_QUEUE_SIZE: 100;
|
|
177
|
+
/** Prediction timeout in milliseconds */
|
|
178
|
+
readonly PREDICTION_TIMEOUT_MS: 300000;
|
|
179
|
+
/** Time before prediction records are cleaned up (24 hours) */
|
|
180
|
+
readonly CLEANUP_AGE_MS: number;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Custom error codes for the MCP server
|
|
184
|
+
*/
|
|
185
|
+
export declare const ERROR_CODES: {
|
|
186
|
+
readonly INVALID_API_KEY: "INVALID_API_KEY";
|
|
187
|
+
readonly MISSING_API_KEY: "MISSING_API_KEY";
|
|
188
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
189
|
+
readonly INVALID_PROMPT: "INVALID_PROMPT";
|
|
190
|
+
readonly INVALID_ASPECT_RATIO: "INVALID_ASPECT_RATIO";
|
|
191
|
+
readonly INVALID_IMAGE: "INVALID_IMAGE";
|
|
192
|
+
readonly INVALID_MASK: "INVALID_MASK";
|
|
193
|
+
readonly IMAGE_TOO_LARGE: "IMAGE_TOO_LARGE";
|
|
194
|
+
readonly API_ERROR: "API_ERROR";
|
|
195
|
+
readonly RATE_LIMITED: "RATE_LIMITED";
|
|
196
|
+
readonly INSUFFICIENT_CREDITS: "INSUFFICIENT_CREDITS";
|
|
197
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
198
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
199
|
+
readonly PREDICTION_NOT_FOUND: "PREDICTION_NOT_FOUND";
|
|
200
|
+
readonly PREDICTION_ALREADY_COMPLETED: "PREDICTION_ALREADY_COMPLETED";
|
|
201
|
+
readonly PREDICTION_FAILED: "PREDICTION_FAILED";
|
|
202
|
+
readonly STORAGE_ERROR: "STORAGE_ERROR";
|
|
203
|
+
readonly DOWNLOAD_FAILED: "DOWNLOAD_FAILED";
|
|
204
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
205
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Type for error codes
|
|
209
|
+
*/
|
|
210
|
+
export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
211
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/config/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,WAAW,EACX,SAAS,EACT,KAAK,EACL,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAM/B;;GAEG;AACH,eAAO,MAAM,YAAY,EAAG,yBAAkC,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,aAAa;IACxB,2BAA2B;;IAE3B,6CAA6C;;IAE7C,kCAAkC;;CAE1B,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,cAAc,EAAG,SAAkB,CAAC;AAMjD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAgBtC,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,cAAc,EAK5C,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,WAAW,EAAmC,CAAC;AAE3F;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,SAAS,EAMlC,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,KAAK,EAAkC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,gBAAgB,EAMjD,CAAC;AAMX;;GAEG;AACH,eAAO,MAAM,QAAQ;IACnB,2BAA2B;2BACJ,WAAW;IAClC,2CAA2C;;IAE3C,8BAA8B;8BACA,cAAc;IAC5C,mCAAmC;2BACX,WAAW;IACnC,yBAAyB;yBACH,SAAS;IAC/B,kCAAkC;;CAE1B,CAAC;AAMX;;GAEG;AACH,eAAO,MAAM,UAAU;IACrB,yBAAyB;;;;;IAKzB,mCAAmC;;;;;IAKnC,uBAAuB;;;;;IAKvB,gDAAgD;;;;;IAKhD,6BAA6B;;QAE3B,wCAAwC;;QAExC,8BAA8B;;;CAGxB,CAAC;AAMX;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAKnD,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAKxD,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAG,IAAa,CAAC;AAM5C;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;CAUd,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAI1C,CAAC;AAMX;;GAEG;AACH,eAAO,MAAM,YAAY;IACvB,uCAAuC;;IAEvC,oCAAoC;;IAEpC,oCAAoC;;IAEpC,iDAAiD;;CAEzC,CAAC;AAMX;;GAEG;AACH,eAAO,MAAM,QAAQ;IACnB,kCAAkC;;IAElC,2DAA2D;;IAE3D,6BAA6B;;CAErB,CAAC;AAMX;;GAEG;AACH,eAAO,MAAM,WAAW;;;;CAId,CAAC;AAMX;;GAEG;AACH,eAAO,MAAM,gBAAgB;IAC3B,2CAA2C;;IAE3C,yCAAyC;;IAEzC,+DAA+D;;CAEvD,CAAC;AAMX;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;CAkCd,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Ideogram MCP Server Entry Point
|
|
4
|
+
*
|
|
5
|
+
* This is the main entry point for the Ideogram MCP (Model Context Protocol) server.
|
|
6
|
+
* It initializes the server with a StdioServerTransport for communication with
|
|
7
|
+
* MCP clients like Claude Desktop, Cursor, and other LLM applications.
|
|
8
|
+
*
|
|
9
|
+
* The server provides tools for:
|
|
10
|
+
* - ideogram_generate: Generate images from text prompts
|
|
11
|
+
* - ideogram_generate_async: Queue image generation for background processing
|
|
12
|
+
* - ideogram_edit: Edit images using inpainting or outpainting
|
|
13
|
+
* - ideogram_get_prediction: Poll for async job status and results
|
|
14
|
+
* - ideogram_cancel_prediction: Cancel queued async jobs
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```bash
|
|
18
|
+
* # Run directly
|
|
19
|
+
* node dist/index.js
|
|
20
|
+
*
|
|
21
|
+
* # Run with inspector for debugging
|
|
22
|
+
* npx @modelcontextprotocol/inspector node dist/index.js
|
|
23
|
+
*
|
|
24
|
+
* # Configure in Claude Desktop (claude_desktop_config.json)
|
|
25
|
+
* {
|
|
26
|
+
* "mcpServers": {
|
|
27
|
+
* "ideogram": {
|
|
28
|
+
* "command": "node",
|
|
29
|
+
* "args": ["/path/to/ideogram-mcp-server/dist/index.js"],
|
|
30
|
+
* "env": {
|
|
31
|
+
* "IDEOGRAM_API_KEY": "your_api_key"
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG"}
|
package/dist/index.js
CHANGED
|
@@ -370,14 +370,11 @@ function getApiErrorUserMessage(statusCode, apiMessage) {
|
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
function extractRetryAfter(headers) {
|
|
373
|
-
if (!headers)
|
|
374
|
-
return void 0;
|
|
373
|
+
if (!headers) return void 0;
|
|
375
374
|
const retryAfter = headers["retry-after"] || headers["Retry-After"];
|
|
376
|
-
if (!retryAfter)
|
|
377
|
-
return void 0;
|
|
375
|
+
if (!retryAfter) return void 0;
|
|
378
376
|
const seconds = parseInt(retryAfter, 10);
|
|
379
|
-
if (!isNaN(seconds))
|
|
380
|
-
return seconds;
|
|
377
|
+
if (!isNaN(seconds)) return seconds;
|
|
381
378
|
const date = new Date(retryAfter);
|
|
382
379
|
if (!isNaN(date.getTime())) {
|
|
383
380
|
const nowMs = Date.now();
|
|
@@ -553,10 +550,7 @@ var init_config = __esm({
|
|
|
553
550
|
localSaveDir: process.env["LOCAL_SAVE_DIR"],
|
|
554
551
|
enableLocalSave: parseBoolean(process.env["ENABLE_LOCAL_SAVE"], DEFAULTS.SAVE_LOCALLY),
|
|
555
552
|
maxConcurrentRequests: parseInteger(process.env["MAX_CONCURRENT_REQUESTS"], 3),
|
|
556
|
-
requestTimeoutMs: parseInteger(
|
|
557
|
-
process.env["REQUEST_TIMEOUT_MS"],
|
|
558
|
-
TIMEOUTS.DEFAULT_REQUEST_MS
|
|
559
|
-
)
|
|
553
|
+
requestTimeoutMs: parseInteger(process.env["REQUEST_TIMEOUT_MS"], TIMEOUTS.DEFAULT_REQUEST_MS)
|
|
560
554
|
};
|
|
561
555
|
config = loadConfig();
|
|
562
556
|
}
|
|
@@ -628,12 +622,9 @@ function serializeRequest(req) {
|
|
|
628
622
|
return {};
|
|
629
623
|
}
|
|
630
624
|
const serialized = {};
|
|
631
|
-
if ("method" in req)
|
|
632
|
-
|
|
633
|
-
if ("
|
|
634
|
-
serialized["url"] = req["url"];
|
|
635
|
-
if ("endpoint" in req)
|
|
636
|
-
serialized["endpoint"] = req["endpoint"];
|
|
625
|
+
if ("method" in req) serialized["method"] = req["method"];
|
|
626
|
+
if ("url" in req) serialized["url"] = req["url"];
|
|
627
|
+
if ("endpoint" in req) serialized["endpoint"] = req["endpoint"];
|
|
637
628
|
if ("headers" in req && typeof req["headers"] === "object" && req["headers"] !== null) {
|
|
638
629
|
const headers = req["headers"];
|
|
639
630
|
const sanitizedHeaders = {};
|
|
@@ -654,12 +645,9 @@ function serializeResponse(res) {
|
|
|
654
645
|
return {};
|
|
655
646
|
}
|
|
656
647
|
const serialized = {};
|
|
657
|
-
if ("status" in res)
|
|
658
|
-
|
|
659
|
-
if ("
|
|
660
|
-
serialized["statusCode"] = res["statusCode"];
|
|
661
|
-
if ("duration" in res)
|
|
662
|
-
serialized["duration"] = res["duration"];
|
|
648
|
+
if ("status" in res) serialized["status"] = res["status"];
|
|
649
|
+
if ("statusCode" in res) serialized["statusCode"] = res["statusCode"];
|
|
650
|
+
if ("duration" in res) serialized["duration"] = res["duration"];
|
|
663
651
|
return serialized;
|
|
664
652
|
}
|
|
665
653
|
function createChildLogger(component) {
|
|
@@ -694,10 +682,7 @@ function logApiResponse(log, context) {
|
|
|
694
682
|
}
|
|
695
683
|
function logToolInvocation(log, context) {
|
|
696
684
|
const sanitizedParams = sanitizeToolParams(context.params);
|
|
697
|
-
log.info(
|
|
698
|
-
{ tool: context.tool, params: sanitizedParams },
|
|
699
|
-
"Tool invoked"
|
|
700
|
-
);
|
|
685
|
+
log.info({ tool: context.tool, params: sanitizedParams }, "Tool invoked");
|
|
701
686
|
}
|
|
702
687
|
function logToolResult(log, context) {
|
|
703
688
|
const level = context.success ? "info" : "warn";
|
|
@@ -861,10 +846,7 @@ var init_prediction_store = __esm({
|
|
|
861
846
|
eta_seconds: this.estimateEta(options.request)
|
|
862
847
|
};
|
|
863
848
|
this.predictions.set(id, prediction);
|
|
864
|
-
this.log.info(
|
|
865
|
-
{ predictionId: id, type: options.type },
|
|
866
|
-
"Prediction created and queued"
|
|
867
|
-
);
|
|
849
|
+
this.log.info({ predictionId: id, type: options.type }, "Prediction created and queued");
|
|
868
850
|
this.processNextIfIdle();
|
|
869
851
|
return prediction;
|
|
870
852
|
}
|
|
@@ -1313,10 +1295,7 @@ var init_prediction_store = __esm({
|
|
|
1313
1295
|
if (this.cleanupTimer.unref) {
|
|
1314
1296
|
this.cleanupTimer.unref();
|
|
1315
1297
|
}
|
|
1316
|
-
this.log.debug(
|
|
1317
|
-
{ intervalMs: this.cleanupIntervalMs },
|
|
1318
|
-
"Auto cleanup started"
|
|
1319
|
-
);
|
|
1298
|
+
this.log.debug({ intervalMs: this.cleanupIntervalMs }, "Auto cleanup started");
|
|
1320
1299
|
}
|
|
1321
1300
|
};
|
|
1322
1301
|
}
|
|
@@ -1345,12 +1324,7 @@ var init_tool_types = __esm({
|
|
|
1345
1324
|
"10x16",
|
|
1346
1325
|
"16x10"
|
|
1347
1326
|
]);
|
|
1348
|
-
RenderingSpeedSchema = z2.enum([
|
|
1349
|
-
"FLASH",
|
|
1350
|
-
"TURBO",
|
|
1351
|
-
"DEFAULT",
|
|
1352
|
-
"QUALITY"
|
|
1353
|
-
]);
|
|
1327
|
+
RenderingSpeedSchema = z2.enum(["FLASH", "TURBO", "DEFAULT", "QUALITY"]);
|
|
1354
1328
|
MagicPromptSchema = z2.enum(["AUTO", "ON", "OFF"]);
|
|
1355
1329
|
StyleTypeSchema = z2.enum([
|
|
1356
1330
|
"AUTO",
|
|
@@ -1766,12 +1740,7 @@ var init_ideogram_client = __esm({
|
|
|
1766
1740
|
};
|
|
1767
1741
|
logApiRequest(this.log, requestContext);
|
|
1768
1742
|
const timeout = TIMEOUTS.LONG_REQUEST_MS;
|
|
1769
|
-
const response = await this.executeWithRetry(
|
|
1770
|
-
endpoint,
|
|
1771
|
-
formData,
|
|
1772
|
-
timeout,
|
|
1773
|
-
"edit"
|
|
1774
|
-
);
|
|
1743
|
+
const response = await this.executeWithRetry(endpoint, formData, timeout, "edit");
|
|
1775
1744
|
const responseContext = {
|
|
1776
1745
|
endpoint,
|
|
1777
1746
|
statusCode: 200,
|
|
@@ -1930,7 +1899,7 @@ var init_ideogram_client = __esm({
|
|
|
1930
1899
|
const buffer = Buffer.from(response.data);
|
|
1931
1900
|
this.validateImageSize(buffer.length);
|
|
1932
1901
|
let contentType = response.headers["content-type"]?.toString().split(";")[0];
|
|
1933
|
-
if (!contentType
|
|
1902
|
+
if (!contentType?.startsWith("image/")) {
|
|
1934
1903
|
contentType = this.detectImageType(buffer);
|
|
1935
1904
|
}
|
|
1936
1905
|
const extension = this.getExtensionForContentType(contentType);
|
|
@@ -1941,10 +1910,7 @@ var init_ideogram_client = __esm({
|
|
|
1941
1910
|
};
|
|
1942
1911
|
} catch (error) {
|
|
1943
1912
|
if (axios.isAxiosError(error)) {
|
|
1944
|
-
throw createNetworkError(
|
|
1945
|
-
`Failed to download image from URL: ${error.message}`,
|
|
1946
|
-
error
|
|
1947
|
-
);
|
|
1913
|
+
throw createNetworkError(`Failed to download image from URL: ${error.message}`, error);
|
|
1948
1914
|
}
|
|
1949
1915
|
throw wrapError(error);
|
|
1950
1916
|
}
|
|
@@ -2143,10 +2109,7 @@ var init_storage_service = __esm({
|
|
|
2143
2109
|
const filePath = path.resolve(targetDir, filename);
|
|
2144
2110
|
await this.saveFile(filePath, buffer);
|
|
2145
2111
|
const durationMs = Date.now() - startTime;
|
|
2146
|
-
this.log.info(
|
|
2147
|
-
{ filename, sizeBytes: buffer.length, durationMs },
|
|
2148
|
-
"Image saved successfully"
|
|
2149
|
-
);
|
|
2112
|
+
this.log.info({ filename, sizeBytes: buffer.length, durationMs }, "Image saved successfully");
|
|
2150
2113
|
return {
|
|
2151
2114
|
filePath,
|
|
2152
2115
|
filename,
|
|
@@ -2402,10 +2365,7 @@ var init_storage_service = __esm({
|
|
|
2402
2365
|
try {
|
|
2403
2366
|
await fs.promises.writeFile(filePath, data);
|
|
2404
2367
|
} catch (error) {
|
|
2405
|
-
throw createStorageError(
|
|
2406
|
-
"write",
|
|
2407
|
-
`Failed to write file: ${error.message}`
|
|
2408
|
-
);
|
|
2368
|
+
throw createStorageError("write", `Failed to write file: ${error.message}`);
|
|
2409
2369
|
}
|
|
2410
2370
|
}
|
|
2411
2371
|
/**
|
|
@@ -2517,11 +2477,8 @@ function createGenerateHandler(options = {}) {
|
|
|
2517
2477
|
});
|
|
2518
2478
|
for (let i = 0; i < response.data.length; i++) {
|
|
2519
2479
|
const apiImage = response.data[i];
|
|
2520
|
-
if (!apiImage)
|
|
2521
|
-
|
|
2522
|
-
const savedImage = saveResult.saved.find(
|
|
2523
|
-
(s) => s.originalUrl === apiImage.url
|
|
2524
|
-
);
|
|
2480
|
+
if (!apiImage) continue;
|
|
2481
|
+
const savedImage = saveResult.saved.find((s) => s.originalUrl === apiImage.url);
|
|
2525
2482
|
const outputImage = {
|
|
2526
2483
|
url: apiImage.url,
|
|
2527
2484
|
seed: apiImage.seed,
|
|
@@ -2539,10 +2496,7 @@ function createGenerateHandler(options = {}) {
|
|
|
2539
2496
|
images.push(outputImage);
|
|
2540
2497
|
}
|
|
2541
2498
|
if (saveResult.failureCount > 0) {
|
|
2542
|
-
log.warn(
|
|
2543
|
-
{ failedCount: saveResult.failureCount },
|
|
2544
|
-
"Some images failed to save locally"
|
|
2545
|
-
);
|
|
2499
|
+
log.warn({ failedCount: saveResult.failureCount }, "Some images failed to save locally");
|
|
2546
2500
|
}
|
|
2547
2501
|
} else {
|
|
2548
2502
|
for (const apiImage of response.data) {
|
|
@@ -2699,11 +2653,8 @@ function createEditHandler(options = {}) {
|
|
|
2699
2653
|
});
|
|
2700
2654
|
for (let i = 0; i < response.data.length; i++) {
|
|
2701
2655
|
const apiImage = response.data[i];
|
|
2702
|
-
if (!apiImage)
|
|
2703
|
-
|
|
2704
|
-
const savedImage = saveResult.saved.find(
|
|
2705
|
-
(s) => s.originalUrl === apiImage.url
|
|
2706
|
-
);
|
|
2656
|
+
if (!apiImage) continue;
|
|
2657
|
+
const savedImage = saveResult.saved.find((s) => s.originalUrl === apiImage.url);
|
|
2707
2658
|
const outputImage = {
|
|
2708
2659
|
url: apiImage.url,
|
|
2709
2660
|
seed: apiImage.seed,
|
|
@@ -2721,10 +2672,7 @@ function createEditHandler(options = {}) {
|
|
|
2721
2672
|
images.push(outputImage);
|
|
2722
2673
|
}
|
|
2723
2674
|
if (saveResult.failureCount > 0) {
|
|
2724
|
-
log.warn(
|
|
2725
|
-
{ failedCount: saveResult.failureCount },
|
|
2726
|
-
"Some images failed to save locally"
|
|
2727
|
-
);
|
|
2675
|
+
log.warn({ failedCount: saveResult.failureCount }, "Some images failed to save locally");
|
|
2728
2676
|
}
|
|
2729
2677
|
} else {
|
|
2730
2678
|
for (const apiImage of response.data) {
|
|
@@ -3051,7 +2999,7 @@ function createGetPredictionHandler(options = {}) {
|
|
|
3051
2999
|
}
|
|
3052
3000
|
}
|
|
3053
3001
|
const renderingSpeed = prediction.request.rendering_speed ?? "DEFAULT";
|
|
3054
|
-
const numImages = images.length
|
|
3002
|
+
const numImages = images.length > 0 ? images.length : prediction.request.num_images ?? 1;
|
|
3055
3003
|
const cost = prediction.type === "edit" ? calculateEditCost({ numImages, renderingSpeed }) : calculateCost({ numImages, renderingSpeed });
|
|
3056
3004
|
const completedResult = {
|
|
3057
3005
|
success: true,
|
|
@@ -3435,11 +3383,7 @@ init_logger();
|
|
|
3435
3383
|
init_constants();
|
|
3436
3384
|
var serverLogger = createChildLogger("server");
|
|
3437
3385
|
function createServer(options = {}) {
|
|
3438
|
-
const {
|
|
3439
|
-
name = SERVER_INFO.NAME,
|
|
3440
|
-
version = SERVER_INFO.VERSION,
|
|
3441
|
-
toolOptions = {}
|
|
3442
|
-
} = options;
|
|
3386
|
+
const { name = SERVER_INFO.NAME, version = SERVER_INFO.VERSION, toolOptions = {} } = options;
|
|
3443
3387
|
serverLogger.info({ name, version }, "Creating MCP server");
|
|
3444
3388
|
const server = new McpServer({
|
|
3445
3389
|
name,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholder.d.ts","sourceRoot":"","sources":["../src/placeholder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,CAAC"}
|