Skip to main content
Glama

transform_image

Modify existing images using text prompts to apply visual transformations, adjust styles, or add elements while preserving the original composition.

Instructions

Transform an existing image using a text prompt (img2img). Either image_path or image_base64 must be provided.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText description of the desired transformation
image_pathNoPath to the source image file to transform
image_base64NoBase64-encoded source image (alternative to image_path)
negative_promptNoElements to exclude from the transformed image
denoising_strengthNoStrength of the transformation (0.0-1.0, default: 0.75). Lower values keep more of the original image.
stepsNoNumber of inference steps (default: 20)
cfg_scaleNoClassifier-free guidance scale (default: 7.5)
seedNoRandom seed for reproducibility (-1 for random)
output_pathNoCustom file path to save the transformed image

Implementation Reference

  • The handler function that validates parameters, checks server status, reads the source image if needed, calls the DrawThingsClient img2img method to transform the image, saves the result, and returns a JSON summary.
    export async function transformImage(
      client: DrawThingsClient,
      params: z.infer<typeof transformImageSchema>
    ): Promise<{ type: "text"; text: string }[]> {
      try {
        // Validate input
        if (!params.image_path && !params.image_base64) {
          return [
            {
              type: "text",
              text: "Error: Either image_path or image_base64 must be provided",
            },
          ];
        }
    
        // Check if server is running first
        const status = await client.checkStatus();
        if (!status.running) {
          return [
            {
              type: "text",
              text: `Error: ${status.message}`,
            },
          ];
        }
    
        // Get base64 image data
        let imageBase64 = params.image_base64;
        if (params.image_path && !imageBase64) {
          try {
            imageBase64 = await client.readImageAsBase64(params.image_path);
          } catch (error) {
            const message = error instanceof Error ? error.message : String(error);
            return [
              {
                type: "text",
                text: `Error reading image file: ${message}`,
              },
            ];
          }
        }
    
        // Transform the image
        const response = await client.img2img({
          prompt: params.prompt,
          init_images: [imageBase64!],
          negative_prompt: params.negative_prompt,
          denoising_strength: params.denoising_strength,
          steps: params.steps,
          cfg_scale: params.cfg_scale,
          seed: params.seed,
        });
    
        if (!response.images || response.images.length === 0) {
          return [
            {
              type: "text",
              text: "Error: No images were generated",
            },
          ];
        }
    
        // Save the image(s)
        const savedPaths: string[] = [];
        for (let i = 0; i < response.images.length; i++) {
          const outputPath =
            params.output_path && response.images.length === 1
              ? params.output_path
              : undefined;
          const path = await client.saveImage(response.images[i], outputPath);
          savedPaths.push(path);
        }
    
        return [
          {
            type: "text",
            text: JSON.stringify(
              {
                success: true,
                message: `Transformed image, generated ${savedPaths.length} result(s)`,
                files: savedPaths,
                prompt: params.prompt,
                source: params.image_path || "(base64 input)",
                parameters: {
                  denoising_strength: params.denoising_strength ?? 0.75,
                  steps: params.steps || 20,
                  cfg_scale: params.cfg_scale || 7.5,
                  seed: params.seed ?? -1,
                },
              },
              null,
              2
            ),
          },
        ];
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return [
          {
            type: "text",
            text: `Error transforming image: ${message}`,
          },
        ];
      }
    }
  • Zod schema defining the input parameters for the transform_image tool, including prompt, image source (path or base64), optional negative prompt, denoising strength, steps, CFG scale, seed, and output path.
    export const transformImageSchema = z.object({
      prompt: z
        .string()
        .describe("Text description of the desired transformation"),
      image_path: z
        .string()
        .optional()
        .describe("Path to the source image file to transform"),
      image_base64: z
        .string()
        .optional()
        .describe("Base64-encoded source image (alternative to image_path)"),
      negative_prompt: z
        .string()
        .optional()
        .describe("Elements to exclude from the transformed image"),
      denoising_strength: z
        .number()
        .min(0)
        .max(1)
        .optional()
        .describe(
          "Strength of the transformation (0.0-1.0, default: 0.75). Lower values keep more of the original image."
        ),
      steps: z
        .number()
        .int()
        .min(1)
        .max(150)
        .optional()
        .describe("Number of inference steps (default: 20)"),
      cfg_scale: z
        .number()
        .min(1)
        .max(30)
        .optional()
        .describe("Classifier-free guidance scale (default: 7.5)"),
      seed: z
        .number()
        .int()
        .optional()
        .describe("Random seed for reproducibility (-1 for random)"),
      output_path: z
        .string()
        .optional()
        .describe("Custom file path to save the transformed image"),
    });
  • src/index.ts:67-75 (registration)
    Registration of the transform_image tool on the MCP server, importing the handler, schema, and description from the tool module and wrapping the handler call.
    server.tool(
      "transform_image",
      transformImageDescription,
      transformImageSchema.shape,
      async (params) => {
        const result = await transformImage(client, params);
        return { content: result };
      }
    );
  • src/index.ts:22-25 (registration)
    Import statement for the transform_image tool components (schema, description, handler).
      transformImageSchema,
      transformImageDescription,
      transformImage,
    } from "./tools/transform-image.js";
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the img2img method and the requirement for an image source, but fails to describe critical behaviors such as whether the transformation is destructive to the original image, what permissions or authentication are needed, rate limits, error handling, or the output format (e.g., returns a file path or base64). For a mutation tool with zero annotation coverage, this is a significant gap.

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

Conciseness5/5

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

The description is extremely concise and front-loaded, consisting of just two sentences that directly state the purpose and a key requirement. Every word earns its place with no redundancy or fluff, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given the tool's complexity (9 parameters, mutation operation), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a transformed image file or metadata), error conditions, side effects, or how it differs from siblings. For a tool that modifies images, more behavioral context is needed to ensure correct agent usage.

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 schema already documents all 9 parameters thoroughly with descriptions, ranges, and defaults. The description adds minimal value beyond the schema by noting the 'Either image_path or image_base64 must be provided' constraint, which isn't explicitly in the schema (though 'prompt' is required). This provides slight additional context, but most parameter semantics are covered by the schema, justifying a baseline score of 3.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Transform an existing image using a text prompt (img2img).' It specifies the verb ('transform'), resource ('existing image'), and method ('text prompt'), distinguishing it from sibling tools like 'generate_image' (likely text-to-image) and 'check_status'. However, it doesn't explicitly contrast with 'generate_image' beyond implying img2img vs text-to-image.

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?

The description provides some usage context by stating 'Either image_path or image_base64 must be provided,' which helps the agent understand prerequisites. However, it lacks explicit guidance on when to use this tool versus alternatives like 'generate_image' (e.g., for modifying vs creating from scratch) or 'check_status' (e.g., for monitoring). The usage is implied but not clearly articulated.

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/james-see/mcp-drawthings'

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