remove_background
Remove the background from any input image using Recraft AI MCP Server. Process local files or URLs to generate a raster image with the background eliminated and receive paths for the result and preview.
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
| Name | Required | Description | Default |
|---|---|---|---|
| imageURI | Yes | Image 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
- src/tools/RemoveBackground.ts:22-48 (handler)The main handler function that executes the remove_background tool. It validates the imageURI input, downloads the image, calls the Recraft Image API to remove the background, transforms the result, or returns an error.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 } } }
- src/tools/RemoveBackground.ts:8-20 (schema)Tool definition including name, description, and input schema (requiring imageURI parameter).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)Registers removeBackgroundTool in the list of tools advertised to MCP clients via ListToolsRequest.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ generateImageTool, createStyleTool, vectorizeImageTool, imageToImageTool, removeBackgroundTool, replaceBackgroundTool, crispUpscaleTool, creativeUpscaleTool, getUserTool, ], } })
- src/index.ts:110-111 (registration)Routes calls to the remove_background tool to its handler in the main CallToolRequest switch statement.case removeBackgroundTool.name: return await removeBackgroundHandler(recraftServer, args ?? {})