Skip to main content
Glama

add_pitchbends_by_index

Add pitch bend effects to a specific track in a MIDI file using track index, pitch values, and timing parameters for musical expression.

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 handler function that loads the MIDI file using loadMidiFile, retrieves the track by index using getTrackByIndex, iterates over the provided pitchbends and adds each one to the track using track.addPitchBend(pitchbend), then saves the modified MIDI file.
    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',
                },
            ]
        }
    })
  • src/main.ts:279-308 (registration)
    Registers the 'add_pitchbends_by_index' tool with the MCP server, including description, input schema, and the handler function.
    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',
                    },
                ]
            }
        })
    )
  • Zod schema defining the structure of a single pitchbend event: {value: number, time?: number | ticks?: number}.
    export const PitchBendInterfaceSchema = z.object({
        value: z.number(),
    }).and(z.union([
        z.object({
            time: z.number(),
        }),
        z.object({
            ticks: z.number(),
        })
    ]))
  • Helper function to safely retrieve a MIDI track by index, throwing an error if out of range. Used in the handler.
    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 full burden for behavioral disclosure. It states this is an 'add' operation (implying mutation/write), but doesn't mention whether this modifies the original file or creates a copy, what permissions are needed, error conditions, or what happens if pitchbends already exist at those positions. Significant behavioral gaps remain.

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

Conciseness5/5

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

The description is a single, efficient sentence that states the core functionality without wasted words. It's appropriately sized for this tool's complexity and gets straight to the point.

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?

For a mutation tool with no annotations, no output schema, and incomplete parameter documentation (67% coverage), the description is inadequate. It doesn't explain what the tool returns, error handling, file modification behavior, or how pitchbends interact with existing MIDI data. Significant contextual gaps exist.

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 67% (2 of 3 parameters have descriptions). The description adds no additional parameter information beyond what's in the schema. With moderate schema coverage, the baseline of 3 is appropriate since the description doesn't compensate for the undocumented 'pitchbends' parameter details.

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 target resource ('to midi file by track index'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from its sibling 'add_controlchanges_by_index' or 'add_notes_by_index' which follow the same pattern, missing explicit differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives like 'get_pitchbends_by_index' or other modification tools. There's no mention of prerequisites, constraints, or typical use cases beyond the basic operation stated.

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