Skip to main content
Glama
maoxiaoke

MCP Media Processing Server

by maoxiaoke

trim-video

Cut video files to a specified duration and save them in a desired location using start and end timestamps. Ideal for precise editing and reducing file size.

Instructions

Trim video to specified duration

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
durationYesDuration in format HH:MM:SS
inputPathYesAbsolute path to input video file
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
startTimeYesStart time in format HH:MM:SS

Implementation Reference

  • The handler function that performs video trimming using fluent-ffmpeg. It resolves input/output paths, constructs the FFmpeg command with start time and duration, executes it, and returns a success or error message.
    async ({ inputPath, startTime, duration, outputPath, outputFilename }) => {
      try {
        const absoluteInputPath = await getAbsolutePath(inputPath);
        const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output';
        const defaultFilename = outputFilename || `${inputFileName}_trimmed.mp4`;
        const finalOutputPath = await getOutputPath(outputPath, defaultFilename);
    
        const command = ffmpeg(absoluteInputPath)
          .setStartTime(startTime)
          .setDuration(duration)
          .save(finalOutputPath);
    
        await executeFFmpeg(command);
    
        return {
          content: [
            {
              type: "text",
              text: `Video successfully trimmed and saved to: ${finalOutputPath}`,
            },
          ],
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: "text",
              text: `Error trimming video: ${errorMessage}`,
            },
          ],
        };
      }
    }
  • Zod schema defining the input parameters for the trim-video tool.
    {
      inputPath: z.string().describe("Absolute path to input video file"),
      startTime: z.string().describe("Start time in format HH:MM:SS"),
      duration: z.string().describe("Duration in format HH:MM:SS"),
      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:226-270 (registration)
    Registration of the trim-video tool with the MCP server, specifying name, description, input schema, and handler function.
    server.tool(
      "trim-video",
      "Trim video to specified duration",
      {
        inputPath: z.string().describe("Absolute path to input video file"),
        startTime: z.string().describe("Start time in format HH:MM:SS"),
        duration: z.string().describe("Duration in format HH:MM:SS"),
        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, startTime, duration, outputPath, outputFilename }) => {
        try {
          const absoluteInputPath = await getAbsolutePath(inputPath);
          const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output';
          const defaultFilename = outputFilename || `${inputFileName}_trimmed.mp4`;
          const finalOutputPath = await getOutputPath(outputPath, defaultFilename);
    
          const command = ffmpeg(absoluteInputPath)
            .setStartTime(startTime)
            .setDuration(duration)
            .save(finalOutputPath);
    
          await executeFFmpeg(command);
    
          return {
            content: [
              {
                type: "text",
                text: `Video successfully trimmed and saved to: ${finalOutputPath}`,
              },
            ],
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [
              {
                type: "text",
                text: `Error trimming video: ${errorMessage}`,
              },
            ],
          };
        }
      }
    );
  • Helper function to execute FFmpeg commands as promises, used by trim-video and other video tools.
    const executeFFmpeg = (command: any): Promise<void> => {
      return new Promise((resolve, reject) => {
        command
          .on('end', () => resolve())
          .on('error', (err: Error) => reject(err))
          .run();
      });
    };
  • Helper function to resolve relative input paths to absolute paths and verify file existence, used in trim-video.
    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}`);
      }
    }
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. 'Trim video' implies a mutation operation that modifies video content, but the description doesn't specify whether this is destructive to the original file, what permissions are required, or any rate limits. It mentions saving to the Downloads folder in the schema, but this isn't highlighted in the description itself, leaving behavioral traits largely undocumented.

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 a single, efficient sentence with zero waste—'Trim video to specified duration' directly conveys the core action. It's appropriately sized for a tool with clear parameters and no complex behavioral nuances needing elaboration.

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 complexity of a video editing tool with 5 parameters, no annotations, and no output schema, the description is incomplete. It doesn't address key contextual aspects like file format support, error handling, output behavior (e.g., where files are saved by default), or how trimming is applied. The schema covers parameter details, but the description lacks overall operational context.

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%, with all parameters well-documented in the schema (e.g., 'Duration in format HH:MM:SS', 'Absolute path to input video file'). The description adds no additional parameter semantics beyond implying 'duration' and possibly 'startTime' from 'specified duration', but it doesn't explain the relationship between startTime and duration or mention optional parameters like outputPath. Baseline 3 is appropriate as the schema does the heavy lifting.

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 'Trim video to specified duration' clearly states the action (trim) and resource (video) with a specific scope (to specified duration). It distinguishes from siblings like 'compress-video' or 'convert-video' by focusing on temporal editing rather than compression or format conversion. However, it doesn't explicitly mention the start time parameter, making it slightly less specific than a perfect 5.

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. It doesn't mention prerequisites (e.g., needing a video file), exclusions (e.g., not for audio files), or comparisons to siblings like 'execute-ffmpeg' for more complex editing. The agent must infer usage from the tool name and parameters alone.

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