letzai_upscale_image
Enhance image resolution and clarity using the Letz AI MCP server. Provide an image ID or URL, set upscaling strength (1-3), and generate high-quality versions.
Instructions
Upscale an image using the LetzAI public api
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| imageId | No | The unique identifier of the image to be upscaled. | |
| imageUrl | No | The URL of the image to be upscaled. Must be a publicly available URL. | |
| strength | Yes | The strength of the upscaling process. Min. 1, Max. 3. |
Implementation Reference
- src/tools.ts:131-233 (handler)Main execution logic for the letzai_upscale_image tool: parses arguments, makes POST to LetzAI /upscale API, polls status until ready, opens image in browser, and returns success message with URL.} else if (request.params.name === "letzai_upscale_image") { try { let { imageId, imageUrl, strength } = request.params.arguments as any; strength = parseInt(strength) || 1; let body = {}; if (imageId) { body = { imageId, strength, }; } else if (imageUrl) { body = { imageUrl, strength, }; } else { throw new Error("Provide image ID or Image URL"); } // Step 1: Create the image request const responseCreate = await axios.post( "https://api.letz.ai/upscale", body, { headers: { Authorization: `Bearer ${process.env.LETZAI_API_KEY}`, }, } ); let imageFinished = false; let imageVersions: { original: string; "96x96": string; "240x240": string; "640x640": string; "1920x1920": string; } | null = null; let upscaleId = responseCreate.data.id; // Step 2: Poll for image creation status while (!imageFinished) { await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait before checking again const responseImage = await axios.get( `https://api.letz.ai/upscale/${upscaleId}`, { headers: { Authorization: `Bearer ${process.env.LETZAI_API_KEY}`, }, } ); if (responseImage.data.status != "ready") { // Send a progress notification (through stdout for Stdio transport) console.log( JSON.stringify({ jsonrpc: "2.0", method: "progress_update", params: { message: `Image is still being processed. Progress: ${responseImage.data.progress}%`, }, }) ); } else { imageFinished = true; imageVersions = responseImage.data.imageVersions; } } // Convert the image to Base64 after processing is complete /* const imageBase64 = convertImageUrlToBase64( imageVersions?.["640x640"] as string ); */ // Open the image in browser open(imageVersions?.original as string); // Return the response to the client return { content: [ { type: "text", text: `Image upscaled successfully!\nThe image has been opened in your default browser.\n\n Image URL: ${imageVersions?.original}\n\nYou can also click the URL above to view the image again.`, }, ], }; } catch (err: any) { return { content: [ { type: "text", text: `Error happened: ${err.toString()}`, }, ], }; } }
- src/tools/upscaleImage.ts:1-24 (schema)Defines the tool metadata, description, and input schema (imageId or imageUrl, strength).export const upscaleImageTool = { name: "letzai_upscale_image", description: "Upscale an image using the LetzAI public api", inputSchema: { type: "object", properties: { imageId: { type: "string", description: "The unique identifier of the image to be upscaled.", }, imageUrl: { type: "string", description: "The URL of the image to be upscaled. Must be a publicly available URL.", }, strength: { type: "number", default: 1, description: "The strength of the upscaling process. Min. 1, Max. 3.", }, }, required: ["strength"], }, };
- src/tools.ts:13-17 (registration)Registers the upscaleImageTool (imported from ./tools/upscaleImage.js) in the list of available tools for ListToolsRequest.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [createImageTool, upscaleImageTool], }; });