Skip to main content
Glama

add_pitchbends_by_index

Add pitchbend events to a specific track in a MIDI file by providing an array of pitchbend values with their timing.

Instructions

Add pitchbends to midi file by track index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsoulate File Path to midi file
trackIndexYesTrack index number
pitchbendsYes

Implementation Reference

  • The tool registration and handler for 'add_pitchbends_by_index'. It registers the tool with schema, loads the MIDI file, gets the track by index, adds pitchbends via track.addPitchBend(), saves the file, and returns success.
    server.tool(
        'add_pitchbends_by_index',
        'Add pitchbends to midi file by track index',
        {
            filePath: z.string().describe('Absoulate File Path to midi file'),
            trackIndex: z.number().describe('Track index number'),
            pitchbends: z.array(PitchBendInterfaceSchema)
        },
        withErrorHandling(({ filePath, trackIndex, pitchbends }) => {
            // 读取文件
            const midi = loadMidiFile(filePath)
            // 查找轨道
            const track = getTrackByIndex(midi, trackIndex)
            // 添加弯音
            pitchbends.forEach(pitchbend => {
                track.addPitchBend(pitchbend)
            })
            // 保存文件
            saveMidiFile(midi, filePath)
    
            return {
                content: [
                    {
                        type: 'text',
                        text: 'add pitchbend success',
                    },
                ]
            }
        })
    )
  • PitchBendInterfaceSchema: Zod schema defining the pitchbend input shape. Requires a 'value' (number) and either 'time' or 'ticks'.
    export const PitchBendInterfaceSchema = z.object({
        value: z.number(),
    }).and(z.union([
        z.object({
            time: z.number(),
        }),
        z.object({
            ticks: z.number(),
        })
    ]))
  • src/main.ts:279-308 (registration)
    The tool is registered via server.tool() with name 'add_pitchbends_by_index', description, schema, and handler.
    server.tool(
        'add_pitchbends_by_index',
        'Add pitchbends to midi file by track index',
        {
            filePath: z.string().describe('Absoulate File Path to midi file'),
            trackIndex: z.number().describe('Track index number'),
            pitchbends: z.array(PitchBendInterfaceSchema)
        },
        withErrorHandling(({ filePath, trackIndex, pitchbends }) => {
            // 读取文件
            const midi = loadMidiFile(filePath)
            // 查找轨道
            const track = getTrackByIndex(midi, trackIndex)
            // 添加弯音
            pitchbends.forEach(pitchbend => {
                track.addPitchBend(pitchbend)
            })
            // 保存文件
            saveMidiFile(midi, filePath)
    
            return {
                content: [
                    {
                        type: 'text',
                        text: 'add pitchbend success',
                    },
                ]
            }
        })
    )
  • loadMidiFile: Helper that reads a MIDI file from disk and returns a Midi object.
    export function loadMidiFile(filePath: string) {
        const midiData = fs.readFileSync(filePath)
        const midi = new Midi(midiData)
        return midi
    }
  • getTrackByIndex: Helper that retrieves a track from a 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?

No annotations provided; the description fails to disclose behavioral traits such as whether existing pitchbends are overwritten, error handling for invalid track indices, or file modification side effects. The description only states the basic action without any behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, making it concise but overly sparse. It front-loads the action but sacrifices informativeness. A slightly longer description could better explain the parameter structure without losing conciseness.

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

Completeness2/5

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

Given the complexity of the pitchbends parameter (nested array with value and either time or ticks), the description is incomplete. It does not mention return values (no output schema), error cases, or file-level considerations. Sibling tools and the parameter count suggest more detail is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no meaning beyond the input schema. The schema provides descriptions for filePath and trackIndex but not for the pitchbends array. The tool description does not explain how to structure pitchbends (value and time/ticks), leaving ambiguity for the agent.

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 action (add pitchbends) and resource (midi file by track index). It distinguishes from siblings like add_notes_by_index and add_controlchanges_by_index through specificity. However, it simply restates the tool name without additional context.

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 on when to use this tool versus alternatives like add_notes_by_index or add_controlchanges_by_index. It does not mention any prerequisites, limitations, 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