Skip to main content
Glama
recraft-ai

Recraft AI MCP Server

Official

remove_background

Removes the background from an input image, returning a raster image with the background removed. Accepts a URL or local file path.

Instructions

Remove background in the input image using Recraft. This operation takes an input image and returns the same image with detected background removed. Raster image will be always returned. Local path or URL to resulting image and its preview 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://).

Implementation Reference

  • The main handler function for the remove_background tool. It parses the imageURI argument, downloads the image, calls the API's removeBackground method, and returns the result via transformSingleImageOperationToCallToolResult.
    export const removeBackgroundHandler = async (server: RecraftServer, args: Record<string, unknown>): Promise<CallToolResult> => {
      try {
        const { imageURI } = z.object({
          imageURI: z.string(),
        }).parse(args)
    
        const imageData = await downloadImage(imageURI)
    
        const result = await server.api.imageApi.removeBackground({
          image: await imageDataToBlob(imageData),
          responseFormat: 'url',
          expire: server.isLocalResultsStorage,
        })
    
        return await server.transformSingleImageOperationToCallToolResult(result.image, 'Removed background.')
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Remove Background error: ${error}`
            }
          ],
          isError: true
        }
      }
    }
  • The tool registration object defining name 'remove_background', description, and inputSchema (requiring imageURI). Also references the PARAMETERS.imageURI definition.
    export const removeBackgroundTool = {
      name: "remove_background",
      description: "Remove background in the input image using Recraft.\n" +
        "This operation takes an input image and returns the same image with detected background removed. Raster image will be always returned.\n" +
        "Local path or URL to resulting image and its preview will be returned in the response.",
      inputSchema: {
        type: "object",
        properties: {
          imageURI: PARAMETERS.imageURI,
        },
        required: ["imageURI"]
      }
    }
  • src/index.ts:68-82 (registration)
    Registration of the removeBackgroundTool in the ListToolsRequestSchema handler so it appears in the tool list.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          generateImageTool,
          createStyleTool,
          vectorizeImageTool,
          imageToImageTool,
          removeBackgroundTool,
          replaceBackgroundTool,
          crispUpscaleTool,
          creativeUpscaleTool,
          getUserTool,
        ],
      }
    })
  • src/index.ts:110-120 (registration)
    Routing for the remove_background tool call: dispatches to removeBackgroundHandler when tool name matches.
    case removeBackgroundTool.name:
      return await removeBackgroundHandler(recraftServer, args ?? {})
    case replaceBackgroundTool.name:
      return await replaceBackgroundHandler(recraftServer, args ?? {})
    case crispUpscaleTool.name:
      return await crispUpscaleHandler(recraftServer, args ?? {})
    case creativeUpscaleTool.name:
      return await creativeUpscaleHandler(recraftServer, args ?? {})
    case getUserTool.name:
      return await getUserHandler(recraftServer, args ?? {})
    default:
  • The API client method removeBackground that sends a POST request to /v1/images/removeBackground with the image as form data. The RemoveBackgroundRequest interface (lines 150-155) defines the schema for image, expire, imageFormat, and responseFormat.
    /**
     * Remove background
     */
    async removeBackgroundRaw(requestParameters: RemoveBackgroundRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ProcessImageResponse>> {
        if (requestParameters['image'] == null) {
            throw new runtime.RequiredError(
                'image',
                'Required parameter "image" was null or undefined when calling removeBackground().'
            );
        }
    
        const queryParameters: any = {};
    
        const headerParameters: runtime.HTTPHeaders = {};
    
        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("auth0", []);
    
            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }
        const consumes: runtime.Consume[] = [
            { contentType: 'multipart/form-data' },
        ];
        // @ts-ignore: canConsumeForm may be unused
        const canConsumeForm = runtime.canConsumeForm(consumes);
    
        let formParams: { append(param: string, value: any): any };
        let useForm = false;
        // use FormData to transmit files using content-type "multipart/form-data"
        useForm = canConsumeForm;
        if (useForm) {
            formParams = new FormData();
        } else {
            formParams = new URLSearchParams();
        }
    
        if (requestParameters['expire'] != null) {
            formParams.append('expire', requestParameters['expire'] as any);
        }
    
        if (requestParameters['image'] != null) {
            formParams.append('image', requestParameters['image'] as any);
        }
    
        if (requestParameters['imageFormat'] != null) {
            formParams.append('image_format', requestParameters['imageFormat'] as any);
        }
    
        if (requestParameters['responseFormat'] != null) {
            formParams.append('response_format', requestParameters['responseFormat'] as any);
        }
    
        const response = await this.request({
            path: `/v1/images/removeBackground`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: formParams,
        }, initOverrides);
    
        return new runtime.JSONApiResponse(response, (jsonValue) => ProcessImageResponseFromJSON(jsonValue));
    }
    
    /**
     * Remove background
     */
    async removeBackground(requestParameters: RemoveBackgroundRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ProcessImageResponse> {
        const response = await this.removeBackgroundRaw(requestParameters, initOverrides);
        return await response.value();
    }
Behavior4/5

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

Without annotations, the description carries full burden. It states the operation is non-destructive (removes background, returns same image) and notes that a raster image is always returned, along with preview availability.

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

Conciseness4/5

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

Three clear sentences with no wasted words. Front-loaded with purpose. Slightly verbose in the second sentence but overall concise.

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

Completeness4/5

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

Given no output schema, the description covers return value (local path/URL and preview). It does not detail edge cases or performance, but for a simple removal tool this is adequate.

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?

Schema description coverage is 100%, so the description adds little beyond the schema. It mentions 'input image' but does not elaborate on format or constraints beyond what the parameter description already provides.

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 verb 'remove' and resource 'background in the input image'. It distinguishes from siblings like 'replace_background' by specifying it returns the same image with background removed.

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

Usage Guidelines3/5

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

No explicit guidance on when to use this tool versus alternatives like 'replace_background' or 'image_to_image'. The description mentions 'using Recraft' but does not provide context for selection.

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

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