Skip to main content
Glama
recraft-ai

Recraft AI MCP Server

Official

replace_background

Replace or modify the background of an image using AI by specifying a prompt, style, and substyle. Adjust parameters to refine raster or vector outputs for realistic images, illustrations, icons, or logos.

Instructions

Generate an image using Recraft from an input image with its detected background replaced based on the prompt. You can specify the input image, style, model, and number of images to generate. You should provide the same style/substyle/styleID settings as were used for input image generation (if exists) if there are no specific requirements to change the style. Other parameters are recommended to keep default if you don't have any specific requirements on them. You can use styles to refine the image background generation, and also to generate raster or vector images. Local paths or URLs to generated images and their previews will be returned in the response.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageURIYesImage to use as an input. This can be a URL (starting with http:// or https://) or an absolute file path (starting with file://).
numberOfImagesNoNumber of images to generate. Should be from 1 to 6. Default is 1.
promptYesText prompt of the background areas that will be changed. Its length should be from 1 to 1024 characters.
styleNoVisual style to apply. Default is realistic_image. Use this parameter only if you want to refine the image generation. Mutually exclusive with styleID, you can't specify both of them. realistic_image, digital_illustration, vector_illustration are available in both models, but icon is available only for recraftv2, and logo_raster is available only for recraftv3. If you will provide a style that is not available for the specified model, generation will fail. Styles use-cases: - realistic_image: for realistic images, photos, portraits, landscapes, etc. Raster is generated. - digital_illustration: for digital illustrations, concept art, fantasy art, etc. Raster is generated. - vector_illustration: for vector illustrations, logos, icons, etc. Vector is generated. - icon: for icons, small graphics (only in recraftv2). Vector is generated - logo_raster: for graphic design, raster logos, posters, emblems, and badges (only in recraftv3). Raster is generated. You should provide the same style/substyle/styleID settings as were used for input image generation (if they exist) if there are no specific requirements to change the style in the resulting image.
styleIDNoID of the style to apply. Mutually exclusive with style, you can't specify both of them. This ID can be the style ID from recraft.ai or some previously created custom style. You should provide the same style/substyle/styleID settings as were used for input image generation (if they exist) if there are no specific requirements to change the style in the resulting image.
substyleNoVisual substyle to apply. Can be specified only with style to refine more specifically. If this parameter is not specified, model will decide on the final style. Use this parameter only if you want to refine the image generation more. No need to specify if you don't have any specific requirements. Note that each combination of model and style has their own list of available substyles: - recraftv3 with style realistic_image: b_and_w, enterprise, evening_light, faded_nostalgia, forest_life, hard_flash, hdr, motion_blur, mystic_naturalism, natural_light, natural_tones, organic_calm, real_life_glow, retro_realism, retro_snapshot, studio_portrait, urban_drama, village_realism, warm_folk - recraftv2 with style realistic_image: b_and_w, enterprise, hard_flash, hdr, motion_blur, natural_light, studio_portrait - recraftv3 with style digital_illustration: 2d_art_poster, 2d_art_poster_2, antiquarian, bold_fantasy, child_book, cover, crosshatch, digital_engraving, engraving_color, expressionism, freehand_details, grain, grain_20, graphic_intensity, hand_drawn, hand_drawn_outline, handmade_3d, hard_comics, infantile_sketch, long_shadow, modern_folk, multicolor, neon_calm, noir, nostalgic_pastel, outline_details, pastel_gradient, pastel_sketch, pixel_art, plastic, pop_art, pop_renaissance, seamless, street_art, tablet_sketch, urban_glow, urban_sketching, young_adult_book, young_adult_book_2 - recraftv2 with style digital_illustration: 2d_art_poster, 2d_art_poster_2, 3d, 80s, engraving_color, glow, grain, hand_drawn, hand_drawn_outline, handmade_3d, infantile_sketch, kawaii, pixel_art, plastic, psychedelic, seamless, voxel, watercolor - recraftv3 with style vector_illustration: bold_stroke, chemistry, colored_stencil, cosmics, cutout, depressive, editorial, emotional_flat, engraving, line_art, line_circuit, linocut, marker_outline, mosaic, naivector, roundish_flat, seamless, segmented_colors, sharp_contrast, thin, vector_photo, vivid_shapes - recraftv2 with style vector_illustration: cartoon, doodle_line_art, engraving, flat_2, kawaii, line_art, line_circuit, linocut, seamless - recraftv2 with style icon: broken_line, colored_outline, colored_shapes, colored_shapes_gradient, doodle_fill, doodle_offset_fill, offset_fill, outline, outline_gradient, pictogram - recraftv3 with style logo_raster: emblem_graffiti, emblem_pop_art, emblem_punk, emblem_stamp, emblem_vintage If you will provide a substyle that is not available for the specified model and style, generation will fail. You should provide the same style/substyle/styleID settings as were used for input image generation (if they exist) if there are no specific requirements to change the style in the resulting image.

Implementation Reference

  • The main handler function that parses input arguments, downloads the input image, calls the Recraft API's replaceBackground method, transforms the response, and handles errors.
    export const replaceBackgroundHandler = async (server: RecraftServer, args: Record<string, unknown>): Promise<CallToolResult> => {
      try {
        const { imageURI, prompt, style, substyle, styleID, numberOfImages } = z.object({
          imageURI: z.string(),
          prompt: z.string(),
          style: z.nativeEnum(ImageStyle).optional(),
          substyle: z.nativeEnum(ImageSubStyle).optional(),
          styleID: z.string().optional(),
          numberOfImages: z.number().optional()
        }).parse(args)
    
        const imageData = await downloadImage(imageURI)
    
        const result = await server.api.imageApi.replaceBackground({
          image: await imageDataToBlob(imageData),
          prompt: prompt,
          style: styleID ? undefined : style,
          substyle: styleID ? undefined : substyle,
          styleId: styleID,
          responseFormat: 'url',
          n: numberOfImages,
          expire: server.isLocalResultsStorage,
        })
    
        return await server.transformGenerateImageResponseToCallToolResult(result)
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error generating image: ${error}`
            }
          ],
          isError: true
        }
      }
    }
  • The tool definition object including the name, description, and detailed inputSchema for parameter validation.
    export const replaceBackgroundTool = {
      name: "replace_background",
      description: "Generate an image using Recraft from an input image with its detected background replaced based on the prompt.\n" +
        "You can specify the input image, style, model, and number of images to generate.\n" +
        "You should provide the same style/substyle/styleID settings as were used for input image generation (if exists) if there are no specific requirements to change the style.\n" +
        "Other parameters are recommended to keep default if you don't have any specific requirements on them.\n" +
        "You can use styles to refine the image background generation, and also to generate raster or vector images.\n" +
        "Local paths or URLs to generated images and their previews will be returned in the response.",
      inputSchema: {
        type: "object",
        properties: {
          imageURI: PARAMETERS.imageURI,
          prompt: {
            type: "string",
            description: "Text prompt of the background areas that will be changed.\n" +
              "Its length should be from 1 to 1024 characters."
          },
          style: {
            ...PARAMETERS.imageStyle,
            description: PARAMETERS.imageStyle.description + "\n" + STYLE_PRESERVATION_WARNING,
          },
          substyle: {
            ...PARAMETERS.imageSubStyle,
            description: PARAMETERS.imageSubStyle.description + "\n" + STYLE_PRESERVATION_WARNING,
          },
          styleID: {
            ...PARAMETERS.imageStyleID,
            description: PARAMETERS.imageStyleID.description + "\n" + STYLE_PRESERVATION_WARNING,
          },
          numberOfImages: PARAMETERS.numberOfImages,
        },
        required: ["imageURI", "prompt"]
      }
    }
  • src/index.ts:68-82 (registration)
    Registration of the replace_background tool in the listTools handler, where replaceBackgroundTool is included in the tools array.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          generateImageTool,
          createStyleTool,
          vectorizeImageTool,
          imageToImageTool,
          removeBackgroundTool,
          replaceBackgroundTool,
          crispUpscaleTool,
          creativeUpscaleTool,
          getUserTool,
        ],
      }
    })
  • src/index.ts:112-113 (registration)
    Dispatch registration in the callTool handler switch statement, routing calls to replaceBackgroundTool.name to the replaceBackgroundHandler.
    case replaceBackgroundTool.name:
      return await replaceBackgroundHandler(recraftServer, args ?? {})
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that the tool generates images, returns local paths/URLs, and mentions potential failure conditions for incompatible style/model combinations. However, it lacks details about rate limits, authentication needs, cost implications, or what happens when the prompt doesn't match the image content.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized but not optimally structured. The first sentence clearly states the purpose, but subsequent sentences contain repetitive advice about style inheritance and default parameters that could be consolidated. The information about return values is useful but could be more front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex 6-parameter image generation tool with no annotations and no output schema, the description provides adequate coverage of the core functionality and style considerations. However, it lacks information about output format details beyond 'local paths or URLs,' error handling for invalid inputs, and doesn't fully compensate for the absence of structured behavioral annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the baseline is 3. The description adds some value by explaining style inheritance principles ('same style/substyle/styleID settings as were used for input image generation') and recommending default parameters when no specific requirements exist, but doesn't provide additional semantic context beyond what's already comprehensively documented in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('generate an image using Recraft from an input image with its detected background replaced based on the prompt'), identifies the resource ('input image'), and distinguishes from siblings like 'remove_background' (which removes rather than replaces) and 'image_to_image' (which likely doesn't focus on background replacement).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use the tool (background replacement with style preservation) and mentions style inheritance from the input image, but doesn't explicitly state when NOT to use it or name specific alternatives among siblings like 'image_to_image' or 'creative_upscale' for comparison.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/recraft-ai/mcp-recraft-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server