Skip to main content
Glama
maoxiaoke

MCP Media Processing Server

by maoxiaoke

add-watermark

Apply a watermark to images with customizable position and opacity using the 'add-watermark' tool in the MCP Media Processing Server.

Instructions

Add watermark to image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesAbsolute path to input image file
opacityNoWatermark opacity (0-100)
outputFilenameNoOutput filename (only used if outputPath is not provided)
outputPathNoOptional absolute path for output file. If not provided, file will be saved in Downloads folder
positionNoPosition of watermarksoutheast
watermarkPathYesAbsolute path to watermark image file

Implementation Reference

  • The handler function that adds a watermark to an image using ImageMagick. It resolves absolute paths, normalizes opacity, constructs and executes the composite command with specified gravity position, and handles output path generation.
    async ({ inputPath, watermarkPath, position, opacity, outputPath, outputFilename }) => {
      try {
        await checkImageMagick();
        const absoluteInputPath = await getAbsolutePath(inputPath);
        const absoluteWatermarkPath = await getAbsolutePath(watermarkPath);
        const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output';
        const extension = absoluteInputPath.split('.').pop() || 'png';
        const defaultFilename = outputFilename || `${inputFileName}_watermarked.${extension}`;
        const finalOutputPath = await getOutputPath(outputPath, defaultFilename);
    
        // Convert opacity from 0-100 to 0-1 for ImageMagick
        const normalizedOpacity = opacity / 100;
    
        const command = `convert "${absoluteInputPath}" \\( "${absoluteWatermarkPath}" -alpha set -channel A -evaluate multiply ${normalizedOpacity} \\) -gravity ${position} -composite "${finalOutputPath}"`;
        await execSync(command);
    
        return {
          content: [
            {
              type: "text",
              text: `Watermark successfully added and saved to: ${finalOutputPath}`,
            },
          ],
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: "text",
              text: `Error adding watermark: ${errorMessage}`,
            },
          ],
        };
      }
    }
  • Zod input schema for the add-watermark tool defining parameters like inputPath, watermarkPath, position (ImageMagick gravity enum), opacity, and optional output paths.
    {
      inputPath: z.string().describe("Absolute path to input image file"),
      watermarkPath: z.string().describe("Absolute path to watermark image file"),
      position: z.enum(['northwest', 'north', 'northeast', 'west', 'center', 'east', 'southwest', 'south', 'southeast']).default('southeast').describe("Position of watermark"),
      opacity: z.number().min(0).max(100).default(50).describe("Watermark opacity (0-100)"),
      outputPath: z.string().optional().describe("Optional absolute path for output file. If not provided, file will be saved in Downloads folder"),
      outputFilename: z.string().optional().describe("Output filename (only used if outputPath is not provided)")
    },
  • src/index.ts:464-511 (registration)
    The server.tool registration call for the add-watermark tool, including name, description, input schema, and inline handler function.
    server.tool(
      "add-watermark",
      "Add watermark to image",
      {
        inputPath: z.string().describe("Absolute path to input image file"),
        watermarkPath: z.string().describe("Absolute path to watermark image file"),
        position: z.enum(['northwest', 'north', 'northeast', 'west', 'center', 'east', 'southwest', 'south', 'southeast']).default('southeast').describe("Position of watermark"),
        opacity: z.number().min(0).max(100).default(50).describe("Watermark opacity (0-100)"),
        outputPath: z.string().optional().describe("Optional absolute path for output file. If not provided, file will be saved in Downloads folder"),
        outputFilename: z.string().optional().describe("Output filename (only used if outputPath is not provided)")
      },
      async ({ inputPath, watermarkPath, position, opacity, outputPath, outputFilename }) => {
        try {
          await checkImageMagick();
          const absoluteInputPath = await getAbsolutePath(inputPath);
          const absoluteWatermarkPath = await getAbsolutePath(watermarkPath);
          const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output';
          const extension = absoluteInputPath.split('.').pop() || 'png';
          const defaultFilename = outputFilename || `${inputFileName}_watermarked.${extension}`;
          const finalOutputPath = await getOutputPath(outputPath, defaultFilename);
    
          // Convert opacity from 0-100 to 0-1 for ImageMagick
          const normalizedOpacity = opacity / 100;
    
          const command = `convert "${absoluteInputPath}" \\( "${absoluteWatermarkPath}" -alpha set -channel A -evaluate multiply ${normalizedOpacity} \\) -gravity ${position} -composite "${finalOutputPath}"`;
          await execSync(command);
    
          return {
            content: [
              {
                type: "text",
                text: `Watermark successfully added and saved to: ${finalOutputPath}`,
              },
            ],
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [
              {
                type: "text",
                text: `Error adding watermark: ${errorMessage}`,
              },
            ],
          };
        }
      }
    );
  • Helper function to resolve input paths to absolute paths, checking existence; used for both input and watermark paths.
    async function getAbsolutePath(inputPath: string): Promise<string> {
      if (isAbsolute(inputPath)) {
        return inputPath;
      }
      
      // FIXME: But it's not working, because the server is running in a different directory
      const absolutePath = resolve(process.cwd(), inputPath);
      
      try {
        await fs.access(absolutePath);
        return absolutePath;
      } catch (error) {
        throw new Error(`Input file not found: ${inputPath}`);
      }
    }
  • Helper function to verify ImageMagick installation by running 'convert -version'; called at start of handler.
    async function checkImageMagick() {
      try {
        execSync('convert -version');
        return true;
      } catch (error) {
        throw new Error('ImageMagick is not installed. Please install it first.');
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. 'Add watermark to image' implies a mutation operation that creates a new watermarked image file, but it doesn't disclose important behavioral traits like whether the original file is modified or preserved, what file formats are supported, error conditions, or performance characteristics. The description is too minimal to provide adequate behavioral context for a tool with 6 parameters.

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 at just four words, with zero wasted language. It's front-loaded with the core action and immediately communicates the tool's primary function. Every word earns its place, making this description maximally efficient in terms of word economy.

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?

For a tool with 6 parameters, no annotations, and no output schema, the description is insufficiently complete. While concise, it doesn't provide enough context about the tool's behavior, limitations, or relationship to sibling tools. The agent would need to rely heavily on the input schema alone, missing important contextual information about when and how to use this tool effectively.

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?

The schema description coverage is 100%, meaning all parameters are well-documented in the schema itself. The description adds no additional parameter semantics beyond what's already in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no parameter information in the description, which applies here.

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 'Add watermark to image' clearly states the action (add) and target resource (watermark to image), making the purpose immediately understandable. However, it doesn't differentiate this tool from its sibling tools like 'apply-effect' or 'convert-image' which might also involve image manipulation, leaving some ambiguity about when this specific tool should be chosen over alternatives.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'apply-effect', 'compress-image', and 'convert-image' available, there's no indication whether this is the only tool for watermarking or if other tools might also handle watermarks. No context about prerequisites, typical use cases, or exclusions is provided.

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/maoxiaoke/mcp-media-processor'

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