Skip to main content
Glama

add_notes_by_index

Add notes to a specific track in a MIDI file by specifying the track index, note properties (pitch, name, or MIDI number), velocity, and timing in seconds or ticks.

Instructions

Add notes to midi file by track index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsoulate File Path to midi file
trackIndexYesTrack index number
notesYes

Implementation Reference

  • The handler function for 'add_notes_by_index' tool. Loads a MIDI file, finds the specified track by index, adds each note from the input array, saves the file, and returns success.
    withErrorHandling(({ filePath, trackIndex, notes }) => {
        // 读取文件
        const midi = loadMidiFile(filePath)
        // 查找轨道
        const track = getTrackByIndex(midi, trackIndex)
        // 添加音符
        notes.forEach(note => {
            track.addNote(note)
        })
        // 保存文件
        saveMidiFile(midi, filePath)
    
        return {
            content: [
                {
                    type: 'text',
                    text: 'add note success',
                },
            ]
        }
    })
  • src/main.ts:217-246 (registration)
    Registration of the 'add_notes_by_index' tool on the MCP server with name, description, schema, and handler.
    server.tool(
        'add_notes_by_index',
        'Add notes to midi file by track index',
        {
            filePath: z.string().describe('Absoulate File Path to midi file'),
            trackIndex: z.number().describe('Track index number'),
            notes: z.array(NoteConstructorInterfaceSchema)
        },
        withErrorHandling(({ filePath, trackIndex, notes }) => {
            // 读取文件
            const midi = loadMidiFile(filePath)
            // 查找轨道
            const track = getTrackByIndex(midi, trackIndex)
            // 添加音符
            notes.forEach(note => {
                track.addNote(note)
            })
            // 保存文件
            saveMidiFile(midi, filePath)
    
            return {
                content: [
                    {
                        type: 'text',
                        text: 'add note success',
                    },
                ]
            }
        })
    )
  • NoteConstructorInterfaceSchema - the Zod schema for individual notes in the array. Composed from PitchDescriptionSchema, VelocityDescriptionSchema, and TimeDescriptionSchema.
    export const NoteConstructorInterfaceSchema = PitchDescriptionSchema
        .and(VelocityDescriptionSchema)
        .and(TimeDescriptionSchema)
  • getTrackByIndex helper - validates track index bounds and returns the track from the MIDI file.
    export function getTrackByIndex(midi: any, trackIndex: number) {
        if (trackIndex < 0 || trackIndex >= midi.tracks.length) {
            throw new Error('Track index out of range')
        }
        return midi.tracks[trackIndex]
    }
  • loadMidiFile helper - reads a MIDI file from disk and parses it using @tonejs/midi.
    export function loadMidiFile(filePath: string) {
        const midiData = fs.readFileSync(filePath)
        const midi = new Midi(midiData)
        return midi
    }
Behavior2/5

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

No annotations are provided, and the description does not disclose behavioral details such as whether notes are appended, overwritten, or if the file is modified in place. Important side effects remain undocumented.

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 short sentence, which is concise. However, it could include more useful information without becoming overly long.

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?

With no output schema and no annotations, the description lacks completeness. It should clarify behavior (e.g., file modification vs new file) and error conditions for a mutating operation.

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 67%, with filePath and trackIndex described. The complex notes schema is well-defined in the schema itself, so the description adds little beyond stating the operation. It does not compensate for missing parameter descriptions.

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 notes) and the target (midi file by track index). It effectively distinguishes from sibling tools like add_controlchanges_by_index.

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 information on when to use this tool versus alternatives such as add_controlchanges_by_index. No context about prerequisites or limitations.

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