Skip to main content
Glama

trim_audio

Cut audio files to specific durations by setting start time, end time, or duration parameters using FFmpeg processing capabilities.

Instructions

Trim an audio file to a specific duration

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to the input audio file
outputPathYesPath for the output audio file
startTimeNoStart time (format: HH:MM:SS.mmm or seconds)
durationNoDuration (format: HH:MM:SS.mmm or seconds)
endTimeNoEnd time (format: HH:MM:SS.mmm or seconds)
formatNoAudio format for output (mp3, aac, etc.)

Implementation Reference

  • The handler function for the 'trim_audio' tool. It processes input arguments, builds an FFmpeg command to trim the audio file based on start time, duration or end time, optionally re-encodes with a specified format or copies the codec, ensures output directory exists, executes the command, and returns a success message with FFmpeg output.
    case "trim_audio": {
      const inputPath = validatePath(String(args?.inputPath), true);
      const outputPath = validatePath(String(args?.outputPath));
      const startTime = String(args?.startTime || "0");
      const duration = String(args?.duration || "");
      const endTime = String(args?.endTime || "");
      const format = String(args?.format || "");
      
      await ensureDirectoryExists(outputPath);
      
      // Build the FFmpeg command
      let command = `-i "${inputPath}" -ss ${startTime}`;
      
      // Add duration or end time if provided
      if (duration) {
        command += ` -t ${duration}`;
      } else if (endTime) {
        command += ` -to ${endTime}`;
      }
      
      // Add format if specified, otherwise use copy codec
      if (format) {
        command += ` -acodec ${format}`;
      } else {
        command += ` -acodec copy`;
      }
      
      command += ` "${outputPath}" -y`;
      
      const result = await runFFmpegCommand(command);
      
      return {
        content: [{
          type: "text",
          text: `Audio trimming completed: ${inputPath} → ${outputPath}\n\n${result}`
        }]
      };
    }
  • The input schema and metadata definition for the 'trim_audio' tool, specifying required and optional parameters with descriptions.
    {
      name: "trim_audio",
      description: "Trim an audio file to a specific duration",
      inputSchema: {
        type: "object",
        properties: {
          inputPath: {
            type: "string",
            description: "Path to the input audio file"
          },
          outputPath: {
            type: "string",
            description: "Path for the output audio file"
          },
          startTime: {
            type: "string",
            description: "Start time (format: HH:MM:SS.mmm or seconds)"
          },
          duration: {
            type: "string",
            description: "Duration (format: HH:MM:SS.mmm or seconds)"
          },
          endTime: {
            type: "string",
            description: "End time (format: HH:MM:SS.mmm or seconds)"
          },
          format: {
            type: "string",
            description: "Audio format for output (mp3, aac, etc.)"
          }
        },
        required: ["inputPath", "outputPath"]
      }
    },
  • src/index.ts:46-50 (registration)
    Registers the 'trim_audio' tool (along with others) by providing the toolDefinitions array in response to ListTools requests.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: toolDefinitions
      };
    });
  • src/index.ts:56-68 (registration)
    Registers the handleToolCall dispatcher which routes 'trim_audio' calls to its specific handler implementation.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        return await handleToolCall(request.params.name, request.params.arguments);
      } catch (error: any) {
        console.error("Tool execution error:", error.message);
        return {
          content: [{
            type: "text",
            text: `Error: ${error.message}`
          }]
        };
      }
    });
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. It states the tool 'trims' audio, implying mutation, but doesn't disclose behavioral traits such as whether it modifies the original file, requires specific permissions, handles errors, or has performance constraints like file size limits. The description is minimal and lacks critical operational context.

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 that directly states the tool's purpose without unnecessary words. It is front-loaded and earns its place by clearly conveying the core functionality.

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 mutation tool with 6 parameters, no annotations, and no output schema, the description is insufficient. It lacks details on behavior, error handling, output specifics, or usage context, leaving significant gaps for an AI agent to understand how to invoke it correctly.

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%, with all parameters well-documented in the schema (e.g., paths, time formats, output format). The description adds no additional meaning beyond the schema, such as explaining parameter interactions (e.g., using 'duration' vs. 'endTime') or default behaviors. 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 clearly states the action ('trim') and resource ('audio file') with a specific purpose ('to a specific duration'). It distinguishes from siblings like 'trim_video' by specifying audio rather than video, though it doesn't explicitly contrast with 'extract_audio' which might also involve segmenting audio files.

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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention when to choose 'trim_audio' over 'extract_audio' or other audio/video processing siblings, nor does it specify prerequisites like file formats or system requirements.

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/sworddut/mcp-ffmpeg-helper'

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