get_track_info_by_index
Retrieve detailed track information from MIDI files by specifying track index, including instrument, duration, and note count for analysis.
Instructions
Get track info from midi file by track index. name, instrument, channel, endOfTrackTicks, duration, durationTicks, noteCount
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absoulate File Path to midi file | |
| trackIndex | Yes | Track index number |
Implementation Reference
- src/main.ts:128-148 (handler)The handler function that loads the MIDI file, retrieves the specific track using getTrackByIndex, constructs track info object, and returns it as JSON text content.withErrorHandling(({ filePath, trackIndex }) => { const midi = loadMidiFile(filePath) const track = getTrackByIndex(midi, trackIndex) const trackInfo = { 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(trackInfo), }, ] } })
- src/main.ts:124-127 (schema)Zod schema defining input parameters: filePath (absolute path to MIDI file) and trackIndex (number).{ filePath: z.string().describe('Absoulate File Path to midi file'), trackIndex: z.number().describe('Track index number'), },
- src/main.ts:120-149 (registration)Registration of the 'get_track_info_by_index' tool with McpServer using server.tool(name, description, inputSchema, handler).server.tool( 'get_track_info_by_index', `Get track info from midi file by track index. name, instrument, channel, endOfTrackTicks, duration, durationTicks, noteCount`, { 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 trackInfo = { 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(trackInfo), }, ] } }) )
- src/utils/obj-utils.ts:1-6 (helper)Helper function to safely retrieve a track from the MIDI object by index, with bounds checking.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] }