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QAAQ,MAAM,0CAClB,CACA,MAAO,GAEH,YADM,YAAY,OAAO,MAAM,yBAA0B,CAAC,EAAG,GACvD,CACV,CACJ,EAGJ,QAAQ,GAAG,UAAU,gBACX,YAAY,OAAO,KAAK,gDAC9B,QAAQ,MAAM,gDACd,QAAQ,KAAK,EAAE,IAEnB,QAAQ,GAAG,WAAW,gBACZ,YAAY,OAAO,KAAK,iDAC9B,QAAQ,MAAM,iDACd,QAAQ,KAAK,EAAE,IAGnB,MAAM,KAAO,YACT,KAAK,OACL,WACA,QAAQ,KAAK,IAEjB,MAAM,OAAS,IAAI,kBAAkB,KAAK,QAC1C,OAAO,MAAM,OAAM,MAAO,UAChB,YAAY,OAAO,MAAM,yBAA0B,CAAC,EAAG,GAC7D,QAAQ,MAAM,0BAA2B,GACzC,QAAQ,KAAK,EAAE","file":"/npm/@graisol/gpt-image-mcp@1.1.4/build/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@graisol/gpt-image-mcp@1.1.4/build/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\n\"use strict\";\n/**\n * MCP Server for OpenAI GPT-Image-1 API Integration\n *\n * This server provides image generation, editing, and management capabilities\n * using OpenAI's GPT-Image-1 model through the Model Context Protocol.\n */\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst index_js_1 = require(\"@modelcontextprotocol/sdk/server/index.js\");\nconst stdio_js_1 = require(\"@modelcontextprotocol/sdk/server/stdio.js\");\nconst types_js_1 = require(\"@modelcontextprotocol/sdk/types.js\");\nconst path_1 = __importDefault(require(\"path\"));\nconst os_1 = __importDefault(require(\"os\"));\nconst fs_1 = __importDefault(require(\"fs\"));\nconst openai_client_js_1 = require(\"./utils/openai-client.js\");\nconst image_manager_js_1 = require(\"./utils/image-manager.js\");\nconst index_js_2 = require(\"./tools/index.js\");\nconst logger_js_1 = require(\"./utils/logger.js\");\n// Determine the best storage path for images\nfunction getDefaultStoragePath() {\n    // First try the current working directory\n    const localPath = path_1.default.join(process.cwd(), 'mcp-images');\n    try {\n        // Check if we can write to the current directory\n        const testDir = path_1.default.join(process.cwd(), '.gpt-image-mcp-test');\n        fs_1.default.mkdirSync(testDir, { recursive: true });\n        fs_1.default.rmdirSync(testDir);\n        // If we get here, we have write permissions in the current directory\n        return localPath;\n    }\n    catch (error) {\n        // Fall back to user's home directory if we can't write to current directory\n        return path_1.default.join(os_1.default.homedir(), '.gpt-image-mcp', 'mcp-images');\n    }\n}\n// Parse command line arguments\nfunction parseArgs() {\n    const args = process.argv.slice(2);\n    const result = {};\n    for (let i = 0; i < args.length; i++) {\n        const arg = args[i];\n        if (arg === '--help' || arg === '-h') {\n            result.help = true;\n        }\n        else if (arg === '--api-key' || arg === '-k') {\n            if (i + 1 < args.length) {\n                result.apiKey = args[i + 1];\n                i++; // Skip the next argument as it's the value\n            }\n        }\n    }\n    return result;\n}\nfunction showHelp() {\n    console.log(`\nGPT-Image-1 MCP Server\n\nUsage: gpt-image-mcp [options]\n\nOptions:\n  --api-key, -k <key>    OpenAI API key (required)\n  --help, -h             Show this help message\n\nEnvironment Variables:\n  OPENAI_API_KEY         OpenAI API key (alternative to --api-key)\n  OPENAI_ORG_ID          OpenAI organization ID (optional)\n  DEFAULT_IMAGE_SIZE     Default image size (default: 1024x1024)\n  DEFAULT_IMAGE_QUALITY  Default image quality (default: high)\n  DEFAULT_MODERATION     Default moderation level (default: auto)\n  IMAGE_STORAGE_PATH     Path to store images (default: ./mcp-images in current working directory)\n  MAX_STORED_IMAGES      Maximum number of stored images (default: 100)\n\nExample:\n  gpt-image-mcp --api-key your_openai_api_key_here\n  npx @graisol/gpt-image-mcp --api-key your_openai_api_key_here\n`);\n}\nclass GPTImageMCPServer {\n    server;\n    openaiClient;\n    imageManager;\n    config;\n    tools;\n    constructor(apiKey) {\n        this.config = this.loadConfig(apiKey);\n        this.server = new index_js_1.Server({\n            name: 'gpt-image-mcp-server',\n            version: '1.0.0',\n        }, {\n            capabilities: {\n                tools: {},\n            },\n        });\n        this.openaiClient = new openai_client_js_1.OpenAIClient(this.config);\n        this.imageManager = new image_manager_js_1.ImageManager(this.config);\n        this.tools = (0, index_js_2.setupTools)({\n            openaiClient: this.openaiClient,\n            imageManager: this.imageManager,\n        });\n        this.setupHandlers();\n    }\n    loadConfig(apiKey) {\n        const config = {\n            openai_api_key: apiKey || process.env.OPENAI_API_KEY || '',\n            openai_org_id: process.env.OPENAI_ORG_ID,\n            default_size: process.env.DEFAULT_IMAGE_SIZE || '1024x1024',\n            default_quality: process.env.DEFAULT_IMAGE_QUALITY || 'high',\n            default_moderation: process.env.DEFAULT_MODERATION || 'auto',\n            image_storage_path: process.env.IMAGE_STORAGE_PATH || getDefaultStoragePath(),\n            max_stored_images: parseInt(process.env.MAX_STORED_IMAGES || '100'),\n        };\n        if (!config.openai_api_key) {\n            throw new Error('OpenAI API key is required. Provide it via --api-key argument or OPENAI_API_KEY environment variable');\n        }\n        return config;\n    }\n    setupHandlers() {\n        this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {\n            return {\n                tools: [\n                    {\n                        name: 'generate_image',\n                        description: 'Generate images from text prompts using OpenAI GPT-Image-1',\n                        inputSchema: {\n                            type: 'object',\n                            properties: {\n                                prompt: {\n                                    type: 'string',\n                                    description: 'Text description of the image to generate',\n                                },\n                                n: {\n                                    type: 'number',\n                                    minimum: 1,\n                                    maximum: 10,\n                                    description: 'Number of images to generate',\n                                    default: 1,\n                                },\n                                size: {\n                                    type: 'string',\n                                    enum: ['1024x1024', '1024x1536', '1536x1024', 'auto'],\n                                    description: 'Size of the generated image',\n                                    default: this.config.default_size,\n                                },\n                                quality: {\n                                    type: 'string',\n                                    enum: ['high', 'medium', 'low'],\n                                    description: 'Quality of the generated image',\n                                    default: this.config.default_quality,\n                                },\n                                background: {\n                                    type: 'string',\n                                    enum: ['transparent', 'opaque', 'auto'],\n                                    description: 'Background type for the image',\n                                    default: 'auto',\n                                },\n                                output_compression: {\n                                    type: 'number',\n                                    minimum: 0,\n                                    maximum: 100,\n                                    description: 'Compression level for output image',\n                                },\n                                output_format: {\n                                    type: 'string',\n                                    enum: ['png', 'jpeg', 'webp'],\n                                    description: 'Output format for the image',\n                                    default: 'png',\n                                },\n                                moderation: {\n                                    type: 'string',\n                                    enum: ['auto', 'low'],\n                                    description: 'Moderation level for content filtering',\n                                    default: this.config.default_moderation,\n                                },\n                            },\n                            required: ['prompt'],\n                        },\n                    },\n                    {\n                        name: 'edit_image',\n                        description: 'Edit existing images with new prompts using OpenAI GPT-Image-1',\n                        inputSchema: {\n                            type: 'object',\n                            properties: {\n                                image: {\n                                    type: 'string',\n                                    description: 'Base64 encoded image or image URL to edit',\n                                },\n                                prompt: {\n                                    type: 'string',\n                                    description: 'Text description of the desired changes',\n                                },\n                                mask: {\n                                    type: 'string',\n                                    description: 'Mask PNG for inpainting edits',\n                                },\n                                n: {\n                                    type: 'number',\n                                    minimum: 1,\n                                    maximum: 10,\n                                    description: 'Number of images to generate',\n                                    default: 1,\n                                },\n                                size: {\n                                    type: 'string',\n                                    enum: ['1024x1024', '1024x1536', '1536x1024', 'auto'],\n                                    description: 'Size of the edited image',\n                                    default: this.config.default_size,\n                                },\n                                quality: {\n                                    type: 'string',\n                                    enum: ['high', 'medium', 'low'],\n                                    description: 'Quality of the edited image',\n                                    default: this.config.default_quality,\n                                },\n                                background: {\n                                    type: 'string',\n                                    enum: ['transparent', 'opaque', 'auto'],\n                                    description: 'Background type for the image',\n                                    default: 'auto',\n                                },\n                                output_compression: {\n                                    type: 'number',\n                                    minimum: 0,\n                                    maximum: 100,\n                                    description: 'Compression level for output image',\n                                },\n                                output_format: {\n                                    type: 'string',\n                                    enum: ['png', 'jpeg', 'webp'],\n                                    description: 'Output format for the image',\n                                    default: 'png',\n                                },\n                                moderation: {\n                                    type: 'string',\n                                    enum: ['auto', 'low'],\n                                    description: 'Moderation level for content filtering',\n                                    default: this.config.default_moderation,\n                                },\n                            },\n                            required: ['image', 'prompt'],\n                        },\n                    },\n                    {\n                        name: 'get_image_info',\n                        description: 'Get information about generated images',\n                        inputSchema: {\n                            type: 'object',\n                            properties: {\n                                image_id: {\n                                    type: 'string',\n                                    description: 'ID of the image to get information about',\n                                },\n                            },\n                            required: ['image_id'],\n                        },\n                    },\n                    {\n                        name: 'list_generations',\n                        description: 'List recent image generations with optional filtering',\n                        inputSchema: {\n                            type: 'object',\n                            properties: {\n                                limit: {\n                                    type: 'number',\n                                    description: 'Maximum number of generations to return',\n                                    default: 10,\n                                },\n                                offset: {\n                                    type: 'number',\n                                    description: 'Number of generations to skip',\n                                    default: 0,\n                                },\n                                filter: {\n                                    type: 'string',\n                                    description: 'Filter generations by prompt content',\n                                },\n                            },\n                        },\n                    },\n                ],\n            };\n        });\n        this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {\n            const { name, arguments: args } = request.params;\n            try {\n                await logger_js_1.logger.info(`Executing tool: ${name}`, { args });\n                switch (name) {\n                    case 'generate_image':\n                        return await this.handleGenerateImage(args);\n                    case 'edit_image':\n                        return await this.handleEditImage(args);\n                    case 'get_image_info':\n                        return await this.handleGetImageInfo(args);\n                    case 'list_generations':\n                        return await this.handleListGenerations(args);\n                    default:\n                        throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown tool: ${name}`);\n                }\n            }\n            catch (error) {\n                await logger_js_1.logger.error(`Error executing tool ${name}`, { args }, error);\n                if (error instanceof types_js_1.McpError) {\n                    throw error;\n                }\n                throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Error executing tool ${name}: ${error}`);\n            }\n        });\n    }\n    async handleGenerateImage(args) {\n        const result = await this.tools.generateImage(args);\n        return {\n            content: [\n                {\n                    type: 'text',\n                    text: JSON.stringify(result, null, 2),\n                },\n            ],\n        };\n    }\n    async handleEditImage(args) {\n        const result = await this.tools.editImage(args);\n        return {\n            content: [\n                {\n                    type: 'text',\n                    text: JSON.stringify(result, null, 2),\n                },\n            ],\n        };\n    }\n    async handleGetImageInfo(args) {\n        const info = await this.tools.getImageInfo(args);\n        return {\n            content: [\n                {\n                    type: 'text',\n                    text: JSON.stringify(info, null, 2),\n                },\n            ],\n        };\n    }\n    async handleListGenerations(args) {\n        const generations = await this.tools.listGenerations(args);\n        return {\n            content: [\n                {\n                    type: 'text',\n                    text: JSON.stringify(generations, null, 2),\n                },\n            ],\n        };\n    }\n    async run() {\n        try {\n            await logger_js_1.logger.info('Starting GPT-Image-1 MCP Server');\n            // Test OpenAI connection\n            const connectionOk = await this.openaiClient.testConnection();\n            if (!connectionOk) {\n                throw new Error('Failed to connect to OpenAI API');\n            }\n            const transport = new stdio_js_1.StdioServerTransport();\n            await this.server.connect(transport);\n            await logger_js_1.logger.info('GPT-Image-1 MCP Server running on stdio');\n            console.error('GPT-Image-1 MCP Server running on stdio');\n        }\n        catch (error) {\n            await logger_js_1.logger.error('Failed to start server', {}, error);\n            throw error;\n        }\n    }\n}\n// Handle process termination gracefully\nprocess.on('SIGINT', async () => {\n    await logger_js_1.logger.info('Received SIGINT, shutting down gracefully...');\n    console.error('Received SIGINT, shutting down gracefully...');\n    process.exit(0);\n});\nprocess.on('SIGTERM', async () => {\n    await logger_js_1.logger.info('Received SIGTERM, shutting down gracefully...');\n    console.error('Received SIGTERM, shutting down gracefully...');\n    process.exit(0);\n});\n// Start the server\nconst args = parseArgs();\nif (args.help) {\n    showHelp();\n    process.exit(0);\n}\nconst server = new GPTImageMCPServer(args.apiKey);\nserver.run().catch(async (error) => {\n    await logger_js_1.logger.error('Failed to start server', {}, error);\n    console.error('Failed to start server:', error);\n    process.exit(1);\n});\n"]}