Skip to main content
Glama
james-see

Draw Things MCP Server

by james-see

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";

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.9/5.0
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 does not mention whether the original image is preserved, whether the tool writes to output_path by default, what side effects occur, or what the return value looks like. For a transformation tool with no annotations, this is a meaningful transparency 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?

One focused sentence communicates the operation, the input requirement, and the key constraint. Every word earns its place, and the critical either/or input requirement is stated up front.

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?

The schema covers all parameter details, so the description does not need to repeat them. However, with no annotations and no output schema, the description should provide more context about output behavior, side effects, or when to choose this tool over generate_image. It is adequate but not fully complete for a 9-parameter tool with no behavioral metadata.

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

Parameters4/5

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

The schema already documents all 9 parameters with 100% coverage, establishing a baseline of 3. The description adds value by explicitly calling out that either image_path or image_base64 must be provided, which is not captured by the schema's required list (only prompt is marked required). This helps agents avoid invalid calls.

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 names a specific verb ('Transform'), a specific resource ('an existing image'), and the method ('using a text prompt (img2img)'). This clearly distinguishes it from the sibling generate_image, which is for creating new images rather than modifying existing ones.

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 makes the core use case clear: transform an already-existing image rather than generate a new one. However, it does not explicitly state 'use generate_image for new images' or provide explicit exclusion criteria, so it stops short of fully explicit routing guidance.

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