Skip to main content
Glama

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
NameRequiredDescriptionDefault
filePathYesAbsoulate File Path to midi file
trackIndexYesTrack index number

Implementation Reference

  • 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), }, ] } })
  • 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), }, ] } }) )
  • 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] }

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