Skip to main content
Glama

add_track

Add a new track to a MIDI file and retrieve its information.

Instructions

Add a new track to midi file and return the new track info

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsoulate File Path to midi file

Implementation Reference

  • Handler function that implements the add_track tool logic: loads a MIDI file, calls midi.addTrack() to add a new track, saves the file, and returns the new track info as JSON.
    withErrorHandling(({ filePath }) => {
        // 读取文件
        const midi = loadMidiFile(filePath)
        // 添加新轨道
        const newTrack = midi.addTrack()
        // 保存文件
        saveMidiFile(midi, filePath)
    
        return {
            content: [
                {
                    type: 'text',
                    text: JSON.stringify(newTrack),
                },
            ]
        }
    })
  • src/main.ts:310-333 (registration)
    Registration of the 'add_track' tool via server.tool() with its name, description, and Zod schema for the filePath parameter.
    server.tool(
        'add_track',
        'Add a new track to midi file and return the new track info',
        {
            filePath: z.string().describe('Absoulate File Path to midi file'),
        },
        withErrorHandling(({ filePath }) => {
            // 读取文件
            const midi = loadMidiFile(filePath)
            // 添加新轨道
            const newTrack = midi.addTrack()
            // 保存文件
            saveMidiFile(midi, filePath)
    
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(newTrack),
                    },
                ]
            }
        })
    )
  • Input schema for the add_track tool: expects a single required string parameter 'filePath' describing the absolute path to the MIDI file.
    {
        filePath: z.string().describe('Absoulate File Path to midi file'),
    },
  • Helper function loadMidiFile that reads a MIDI file from disk and creates a Midi instance from @tonejs/midi.
    export function loadMidiFile(filePath: string) {
        const midiData = fs.readFileSync(filePath)
        const midi = new Midi(midiData)
        return midi
    }
  • Helper function saveMidiFile that converts the Midi instance back to an ArrayBuffer and writes it to disk.
    export function saveMidiFile(midi: any, filePath: string): void {
        const arrayBuffer = midi.toArray()
        // 将ArrayBuffer转换为Buffer并写入文件
        fs.writeFileSync(filePath, Buffer.from(arrayBuffer))
    }
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavioral traits. While it states that a track is added and info is returned, it omits critical details: whether the file is mutated, what happens if the file does not exist or is read-only, and how the new track is initialized (e.g., empty?). The minimal description leaves significant ambiguity about side effects.

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

Conciseness4/5

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

The description is a single sentence with no unnecessary words, making it concise. However, it lacks structure (e.g., separating action from return) and front-loading key constraints. While efficient, it could be slightly more organized.

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 mutation tool with no annotations and no output schema, the description is incomplete. It does not explain error conditions, file modification behavior, or the format of the returned info. An agent would need additional context to use the tool correctly in all scenarios.

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 input schema covers the single parameter (filePath) with 100% description coverage, stating 'Absoulate File Path to midi file'. The tool description adds no additional meaning beyond the schema, so it meets the baseline expectation but does not enhance understanding.

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 clearly states the action ('Add') and the resource ('a new track to midi file'), and specifies that it returns the new track info. This distinguishes it from sibling tools that add notes, control changes, or pitch bends, making its purpose unambiguous.

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, such as when the file must exist, whether the file is modified in-place, or any prerequisites. An agent gets no context for selecting this over other add-related tools.

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/xiaolaa2/midi-file-mcp'

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