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]
    }
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 of behavioral disclosure. It lists output fields (name, instrument, etc.), which hints at read-only behavior, but doesn't explicitly state that this is a safe read operation or address potential errors (e.g., invalid file paths or indices). It omits details like performance, file access permissions, or response format beyond field names.

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 front-loaded with the core purpose in the first sentence, followed by a concise list of output fields. It avoids unnecessary words, though the list format could be slightly more structured (e.g., using commas). Every element contributes value, making it efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description partially compensates by listing output fields, but it lacks details on return structure (e.g., object format) and error handling. For a read operation with two parameters, it's minimally adequate but leaves gaps in behavioral context, such as how to interpret the output fields or handle edge cases.

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?

Schema description coverage is 100%, so the schema fully documents the two parameters (filePath and trackIndex). The description doesn't add any parameter-specific details beyond what the schema provides, such as explaining track index ranges or file format requirements. Baseline 3 is appropriate when the schema handles parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and the resource 'track info from midi file by track index', making the purpose immediately understandable. It distinguishes from siblings like 'get_tracks_info' (plural) by specifying retrieval for a single track via index. However, it doesn't explicitly contrast with other track-specific getters like 'get_notes_by_index' beyond listing fields.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. It doesn't mention when to choose 'get_track_info_by_index' over 'get_tracks_info' for multiple tracks, or how it differs from other index-based getters like 'get_notes_by_index'. The description lacks context about prerequisites or typical use cases.

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