Skip to main content
Glama

add_controlchanges_by_index

Add control change events to a specific track in a MIDI file using the track index. Specify the controller number, value, and timing (time or ticks).

Instructions

Add controlchanges to midi file by track index

Input Schema

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

Implementation Reference

  • The handler function that executes the 'add_controlchanges_by_index' tool logic: loads a MIDI file, finds the track by index, adds each control change via track.addCC(), then saves the modified file.
        withErrorHandling(({ filePath, trackIndex, controlchanges }) => {
            // 读取文件
            const midi = loadMidiFile(filePath)
            // 查找轨道
            const track = getTrackByIndex(midi, trackIndex)
            // 添加控制器变化
            controlchanges.forEach(controlchange => {
                track.addCC(controlchange)
            })
            // 保存文件
            saveMidiFile(midi, filePath)
    
            return {
                content: [
                    {
                        type: 'text',
                        text: 'add controlchange success',
                    },
                ]
            }
        })
    )
  • The Zod schema for ControlChangeInterfaceSchema, defining the input validation for control changes: number, value, and either time or ticks.
    export const ControlChangeInterfaceSchema = z.object({
        number: z.number(),
        value: z.number(),
    }).and(z.union([
        z.object({
            time: z.number(),
        }),
        z.object({
            ticks: z.number(),
        })
    ]))
  • src/main.ts:248-277 (registration)
    The tool registration using server.tool() with name 'add_controlchanges_by_index', description, input schema (filePath, trackIndex, controlchanges array), and handler.
    server.tool(
        'add_controlchanges_by_index',
        'Add controlchanges to midi file by track index',
        {
            filePath: z.string().describe('Absoulate File Path to midi file'),
            trackIndex: z.number().describe('Track index number'),
            controlchanges: z.array(ControlChangeInterfaceSchema)
        },
        withErrorHandling(({ filePath, trackIndex, controlchanges }) => {
            // 读取文件
            const midi = loadMidiFile(filePath)
            // 查找轨道
            const track = getTrackByIndex(midi, trackIndex)
            // 添加控制器变化
            controlchanges.forEach(controlchange => {
                track.addCC(controlchange)
            })
            // 保存文件
            saveMidiFile(midi, filePath)
    
            return {
                content: [
                    {
                        type: 'text',
                        text: 'add controlchange success',
                    },
                ]
            }
        })
    )
  • The loadMidiFile helper reads a MIDI file from disk and parses it using @tonejs/midi.
    export function loadMidiFile(filePath: string) {
        const midiData = fs.readFileSync(filePath)
        const midi = new Midi(midiData)
        return midi
    }
    
    export function saveMidiFile(midi: any, filePath: string): void {
        const arrayBuffer = midi.toArray()
        // 将ArrayBuffer转换为Buffer并写入文件
        fs.writeFileSync(filePath, Buffer.from(arrayBuffer))
    }
  • The getTrackByIndex helper retrieves a track from the MIDI object by its numeric 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, the description carries full burden but only states 'Add controlchanges'. It fails to disclose that this likely modifies the file (destructive), whether changes are reversible, or any permission or error behavior. The tool's safety profile is completely opaque.

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 a single, concise sentence without wasted words. However, it lacks structure (e.g., bullet points) that could improve readability for complex parameters.

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 tool with three required parameters and no output schema or annotations, the description is very incomplete. It does not explain return values, error conditions, file requirements, or behavior on existing data. The agent is left with significant ambiguity.

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?

Schema coverage is 67%, but the description adds no meaning beyond the schema. It does not explain 'controlchanges' structure (e.g., time vs ticks, number/value ranges). The description leaves the agent to infer entirely from schema, which is insufficient for correct invocation.

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

Purpose5/5

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

The description clearly states 'Add controlchanges to midi file by track index', specifying the action (add), resource (controlchanges), target (midi file), and identifier (track index). This distinguishes it from sibling tools like 'add_notes_by_index' or 'get_controlchanges_by_index'.

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 (e.g., whether it appends or replaces, or if one should first retrieve existing control changes). The description lacks any context about prerequisites or preferred scenarios.

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