Skip to main content
Glama

add_track

Add a new track to a MIDI file to expand musical arrangements and organize different instrument parts.

Instructions

Add a new track to midi file and return the new track info

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsoulate File Path to midi file

Implementation Reference

  • Handler function for the 'add_track' tool: loads the MIDI file, adds a new track using midi.addTrack(), saves the file, and returns the new track info as JSON string.
    withErrorHandling(({ filePath }) => {
        // 读取文件
        const midi = loadMidiFile(filePath)
        // 添加新轨道
        const newTrack = midi.addTrack()
        // 保存文件
        saveMidiFile(midi, filePath)
    
        return {
            content: [
                {
                    type: 'text',
                    text: JSON.stringify(newTrack),
                },
            ]
        }
    })
  • Input schema for 'add_track' tool, requiring absolute file path to the MIDI file.
    {
        filePath: z.string().describe('Absoulate File Path to midi file'),
    },
  • src/main.ts:310-333 (registration)
    Registration of the 'add_track' tool with server.tool, including description, input schema, and handler.
    server.tool(
        'add_track',
        'Add a new track to midi file and return the new track info',
        {
            filePath: z.string().describe('Absoulate File Path to midi file'),
        },
        withErrorHandling(({ filePath }) => {
            // 读取文件
            const midi = loadMidiFile(filePath)
            // 添加新轨道
            const newTrack = midi.addTrack()
            // 保存文件
            saveMidiFile(midi, filePath)
    
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(newTrack),
                    },
                ]
            }
        })
    )

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