style_transfer
Apply artistic styles from one image to another using Google's Gemini 2.5 Flash Image technology, with optional prompt guidance for customized results.
Instructions
Transfer style from a style image to a base image, guided by an optional prompt.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| baseImage | Yes | ||
| prompt | No | Optional additional instruction for the style transfer. | |
| saveToFilePath | No | Optional path to save the output | |
| styleImage | Yes |
Implementation Reference
- src/index.ts:233-246 (handler)Handler function that performs style transfer by calling Gemini API with base and style images, optionally saves the result, and returns image content.async (args) => { const { prompt = 'Apply the style of the second image to the first image while preserving the original content', baseImage, styleImage, saveToFilePath } = args as { prompt?: string; baseImage: InlineImageInput; styleImage: InlineImageInput; saveToFilePath?: string }; const results = await callGeminiGenerate({ prompt, images: [baseImage, styleImage] }); const first = results[0]; const savedPath = await maybeSaveImage(first.imageBase64, first.mimeType, saveToFilePath); const dataUrl = `data:${first.mimeType};base64,${first.imageBase64}`; return { content: [ { type: 'text', text: `Style transferred image${savedPath ? ` saved to ${savedPath}` : ''}` }, { type: 'image', mimeType: first.mimeType, data: first.imageBase64 }, { type: 'text', text: dataUrl }, ], }; }
- src/index.ts:219-232 (schema)Input schema using Zod for style_transfer tool parameters: optional prompt, baseImage and styleImage (each with dataBase64, path, mimeType), and optional saveToFilePath.{ prompt: z.string().optional().describe('Optional additional instruction for the style transfer.'), baseImage: z.object({ dataBase64: z.string().optional(), path: z.string().optional(), mimeType: z.string().optional(), }), styleImage: z.object({ dataBase64: z.string().optional(), path: z.string().optional(), mimeType: z.string().optional(), }), saveToFilePath: z.string().optional().describe('Optional path to save the output'), },
- src/index.ts:215-247 (registration)mcp.tool registration for 'style_transfer', including description, input schema, and inline handler function.// Tool: style_transfer (apply style image to base image) mcp.tool( 'style_transfer', 'Transfer style from a style image to a base image, guided by an optional prompt.', { prompt: z.string().optional().describe('Optional additional instruction for the style transfer.'), baseImage: z.object({ dataBase64: z.string().optional(), path: z.string().optional(), mimeType: z.string().optional(), }), styleImage: z.object({ dataBase64: z.string().optional(), path: z.string().optional(), mimeType: z.string().optional(), }), saveToFilePath: z.string().optional().describe('Optional path to save the output'), }, async (args) => { const { prompt = 'Apply the style of the second image to the first image while preserving the original content', baseImage, styleImage, saveToFilePath } = args as { prompt?: string; baseImage: InlineImageInput; styleImage: InlineImageInput; saveToFilePath?: string }; const results = await callGeminiGenerate({ prompt, images: [baseImage, styleImage] }); const first = results[0]; const savedPath = await maybeSaveImage(first.imageBase64, first.mimeType, saveToFilePath); const dataUrl = `data:${first.mimeType};base64,${first.imageBase64}`; return { content: [ { type: 'text', text: `Style transferred image${savedPath ? ` saved to ${savedPath}` : ''}` }, { type: 'image', mimeType: first.mimeType, data: first.imageBase64 }, { type: 'text', text: dataUrl }, ], }; } );