create_style
Generate custom visual styles by extracting patterns from reference images for use in image generation tools. Input includes style type and 1-5 image URLs or file paths, output provides the style ID.
Instructions
Create a style in Recraft from the set of style reference images. A style is extracted from the provided images and can be used in image generation tools. ID of the created style will be returned in the response.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| imageURIs | Yes | Array of images to use as a style references. Each item can be a URL (starting with http:// or https://) or a file path (starting with file://). The length should be from 1 to 5. | |
| style | Yes | Basic visual style in which the style will be created. |
Implementation Reference
- src/tools/CreateStyle.ts:33-69 (handler)The createStyleHandler function that executes the 'create_style' tool: parses and validates arguments, downloads images from URIs, converts to blobs, calls the API to create style, and returns appropriate text content.export const createStyleHandler = async (server: RecraftServer, args: Record<string, unknown>): Promise<CallToolResult> => { try { const { style, imageURIs } = z.object({ style: z.nativeEnum(ImageStyle), imageURIs: z.array(z.string()).nonempty(), }).parse(args) const blobPromises = imageURIs.map(async (imageURI) => await downloadImage(imageURI).then(imageDataToBlob)) const blobs = await Promise.all(blobPromises) const result = await server.api.styleApi.createStyle({ style: style, images: blobs, }) return { content: [ { type: 'text', text: `A new style with style_id ${result.id} created.\nYou can use this style in the image generation tools.` } ], isError: false } } catch (error) { return { content: [ { type: 'text', text: `Error creating style: ${error}` } ], isError: true } } }
- src/tools/CreateStyle.ts:8-30 (schema)The createStyleTool object defines the tool's name, description, and inputSchema for validation, which specifies 'style' enum and 'imageURIs' array.export const createStyleTool = { name: "create_style", description: "Create a style in Recraft from the set of style reference images.\n" + "A style is extracted from the provided images and can be used in image generation tools.\n" + "ID of the created style will be returned in the response.", inputSchema: { type: "object", properties: { style: { type: "string", enum: [ImageStyle.RealisticImage, ImageStyle.DigitalIllustration, ImageStyle.VectorIllustration, ImageStyle.Icon], description: "Basic visual style in which the style will be created." }, imageURIs: { type: "array", items: { type: "string", }, description: "Array of images to use as a style references. Each item can be a URL (starting with http:// or https://) or a file path (starting with file://). The length should be from 1 to 5." }, }, required: ["style", "imageURIs"] }
- src/index.ts:68-82 (registration)Registration of the 'create_style' tool in the MCP server's list of available tools via createStyleTool inclusion in the ListToolsRequest handler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ generateImageTool, createStyleTool, vectorizeImageTool, imageToImageTool, removeBackgroundTool, replaceBackgroundTool, crispUpscaleTool, creativeUpscaleTool, getUserTool, ], } })
- src/index.ts:104-105 (registration)Handler dispatch registration: maps 'create_style' tool calls to the createStyleHandler function in the CallToolRequest switch statement.case createStyleTool.name: return await createStyleHandler(recraftServer, args ?? {})