Skip to main content
Glama

get_notes_by_index

Extract notes from a specific track in a MIDI file using its index number. Provide file path and track index to get the notes.

Instructions

Get notes from midi file by track index

Input Schema

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

Implementation Reference

  • src/main.ts:151-171 (registration)
    Registration of the 'get_notes_by_index' tool on the MCP server with Zod schema for filePath (string) and trackIndex (number), and handler that loads a MIDI file, gets the track by index, and returns notes as JSON.
    server.tool(
        'get_notes_by_index',
        'Get notes from midi file by track index',
        {
            filePath: z.string().describe('Absoulate File Path to midi file'),
            trackIndex: z.number().describe('Track index number'),
        },
        withErrorHandling(({ filePath, trackIndex }) => {
            const midi = loadMidiFile(filePath)
            const track = getTrackByIndex(midi, trackIndex)
            const notes = track.notes.map((note: any) => note.toJSON())
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(notes),
                    },
                ]
            }
        })
    )
  • Handler function that loads a MIDI file, retrieves the specified track, maps all notes to JSON, and returns them as text content.
    withErrorHandling(({ filePath, trackIndex }) => {
        const midi = loadMidiFile(filePath)
        const track = getTrackByIndex(midi, trackIndex)
        const notes = track.notes.map((note: any) => note.toJSON())
        return {
            content: [
                {
                    type: 'text',
                    text: JSON.stringify(notes),
                },
            ]
        }
    })
  • Zod schema defining the input parameters: filePath (string) and trackIndex (number).
    {
        filePath: z.string().describe('Absoulate File Path to midi file'),
        trackIndex: z.number().describe('Track index number'),
    },
  • Helper function that validates trackIndex bounds and returns the track from the MIDI object.
    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]
    }
  • Helper function that 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?

With no annotations provided, the description carries the full burden for behavioral disclosure. It only states what the tool does (get notes) but does not mention that it is read-only, any file access requirements, or potential 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, concise sentence with no extraneous words. While it could include more detail, it is efficient and front-loaded.

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?

The tool has no output schema, but the description does not hint at the structure of returned notes (e.g., pitch, velocity, timing). For a tool of moderate complexity with several siblings, this omission leaves the agent with incomplete information.

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?

Input schema has 100% coverage and clearly describes each parameter. The description adds no additional meaning beyond what the schema provides, so a baseline score of 3 is appropriate.

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 verb 'Get', the resource 'notes from midi file', and the parameter 'by track index', which distinguishes it from sibling tools like 'add_notes_by_index' and 'get_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 Guidelines3/5

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

The description does not explicitly specify when to use this tool versus alternatives, nor does it mention any prerequisites or exclusions. However, the tool's name and sibling context provide some implicit guidance.

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