get_tracks_info
Get track information from a MIDI file. Provide the absolute file path to obtain details about each track.
Instructions
Get tracks info from midi file
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absoulate File Path to midi file eg: D:programmingProjectmy-projectmidi-parser-mcp est.mid |
Implementation Reference
- src/main.ts:96-117 (handler)The handler function that executes the 'get_tracks_info' tool logic. It loads a MIDI file via loadMidiFile, maps over tracks to extract info (name, instrument, channel, endOfTrackTicks, duration, durationTicks, noteCount), and returns JSON.
withErrorHandling(({ filePath }) => { const midi = loadMidiFile(filePath) const tracksInfo = midi.tracks.map(track => { return { name: track.name, instrument: track.instrument.toJSON(), channel: track.channel, endOfTrackTicks: track.endOfTrackTicks, duration: track.duration, durationTicks: track.durationTicks, noteCount: track.notes.length, } }) return { content: [ { type: 'text', text: JSON.stringify(tracksInfo), }, ] } }) - src/main.ts:92-95 (schema)Zod schema defining the input parameter for the tool: 'filePath' (string) describing the absolute path to a MIDI file.
{ filePath: z.string().describe(`Absoulate File Path to midi file eg: D:\programming\Project\my-project\midi-parser-mcp\test.mid`), }, - src/main.ts:89-118 (registration)Registration of the 'get_tracks_info' tool with the MCP server using server.tool(), including name, description, schema, and handler.
server.tool( 'get_tracks_info', 'Get tracks info from midi file', { filePath: z.string().describe(`Absoulate File Path to midi file eg: D:\programming\Project\my-project\midi-parser-mcp\test.mid`), }, withErrorHandling(({ filePath }) => { const midi = loadMidiFile(filePath) const tracksInfo = midi.tracks.map(track => { return { name: track.name, instrument: track.instrument.toJSON(), channel: track.channel, endOfTrackTicks: track.endOfTrackTicks, duration: track.duration, durationTicks: track.durationTicks, noteCount: track.notes.length, } }) return { content: [ { type: 'text', text: JSON.stringify(tracksInfo), }, ] } }) ) - src/utils/file-util.ts:5-9 (helper)Helper function loadMidiFile that reads a file from disk synchronously and parses it using the @tonejs/midi library's Midi class.
export function loadMidiFile(filePath: string) { const midiData = fs.readFileSync(filePath) const midi = new Midi(midiData) return midi } - src/main.ts:23-23 (helper)The withErrorHandling wrapper that catches errors from the handler and returns an error response with isError flag.
const withErrorHandling = <T extends Record<string, any>>(handler: (args: T) => any) => {