Skip to main content
Glama

get_notes_by_index

Retrieve musical notes from a specific track in a MIDI file using track index to access and analyze individual instrument data.

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

  • Primary implementation block: registers and defines the handler for 'get_notes_by_index' tool. Includes inline schema, loads MIDI file, retrieves track by index, extracts and JSONifies notes for return.
    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), }, ] } }) )
  • Supporting helper function called by the tool handler to safely retrieve a MIDI track by its index.
    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] }
  • Supporting helper function called by the tool handler to load a MIDI file from the filesystem into a Midi object.
    export function loadMidiFile(filePath: string) { const midiData = fs.readFileSync(filePath) const midi = new Midi(midiData) return midi }

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