Skip to main content
Glama

create_drum_pattern

Create drum patterns on MIDI tracks using step-sequencer strings. Define beats like 'k...h...s...h...' for rock, with characters for kick, snare, hihat, toms, cymbal, and rest. Automatically places notes on MIDI channel 9.

Instructions

Create a drum pattern on a track using a step-sequencer string. Each character = one step. Characters: k=kick, s=snare, h=hihat(closed), o=hihat(open), t=tom(low), m=tom(mid), f=tom(high), c=crash, r=ride, .=rest. Example 4/4 rock beat (16 steps): "k...h...s...h..." All drum notes are placed on MIDI channel 9 (GM standard).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
track_indexYes
patternYes
start_positionYes
beatsNo
repeatsNo

Implementation Reference

  • The create_drum_pattern function that implements the tool logic. It reads a step-sequencer pattern string, maps characters to GM drum MIDI notes via DRUM_MAPPINGS, and creates a MIDI item with drum notes on channel 9.
    @mcp.tool()
    def create_drum_pattern(
        track_index: int,
        pattern: str,
        start_position: float,
        beats: int = 4,
        repeats: int = 1,
    ) -> dict:
        """
        Create a drum pattern on a track using a step-sequencer string.
        Each character = one step. Characters: k=kick, s=snare, h=hihat(closed),
        o=hihat(open), t=tom(low), m=tom(mid), f=tom(high), c=crash, r=ride, .=rest.
        Example 4/4 rock beat (16 steps): "k...h...s...h..."
        All drum notes are placed on MIDI channel 9 (GM standard).
        """
        try:
            project = get_project()
            track = project.tracks[track_index]
            seconds_per_beat = 60.0 / project.bpm
            pattern_length = seconds_per_beat * beats
            total_length = pattern_length * repeats
    
            item = track.add_midi_item(start_position, start_position + total_length)
            take = item.active_take
            time_per_step = pattern_length / len(pattern)
    
            for repeat in range(repeats):
                offset = repeat * pattern_length
                for i, char in enumerate(pattern):
                    if char in DRUM_MAPPINGS:
                        note_start = offset + i * time_per_step
                        take.add_note(
                            start=note_start,
                            end=note_start + time_per_step * 0.5,
                            pitch=DRUM_MAPPINGS[char],
                            velocity=100,
                            channel=9,
                        )
    
            return {
                "success": True,
                "item_id": item.id,
                "pattern": pattern,
                "repeats": repeats,
                "start_position": start_position,
                "total_length": total_length,
            }
        except Exception as e:
            logger.error(f"create_drum_pattern failed: {e}")
            return {"success": False, "error": str(e)}
  • DRUM_MAPPINGS constant that defines the mapping from step-sequencer characters to GM standard drum MIDI note numbers. This acts as the schema/validation for which characters are valid in the pattern string.
    # GM standard drum MIDI notes
    DRUM_MAPPINGS = {
        "k": 36,  # kick  - C1
        "s": 38,  # snare - D1
        "h": 42,  # hihat closed - F#1
        "o": 46,  # hihat open   - A#1
        "t": 41,  # tom low  - F1
        "m": 45,  # tom mid  - A1
        "f": 48,  # tom high - C2
        "c": 49,  # crash - C#2
        "r": 51,  # ride  - D#2
    }
  • The register_tools function wraps all tool definitions with @mcp.tool() decorator. When called from server.py, it registers create_drum_pattern (and the other MIDI tools) with the MCP server.
    def register_tools(mcp):
    
        @mcp.tool()
  • The server.py imports register_tools from midi_tools and calls it to register all MIDI tools including create_drum_pattern with the MCP server.
    from reaper_mcp.project_tools import register_tools as _reg_project
    from reaper_mcp.track_tools import register_tools as _reg_track
    from reaper_mcp.midi_tools import register_tools as _reg_midi
    from reaper_mcp.fx_tools import register_tools as _reg_fx
    from reaper_mcp.audio_tools import register_tools as _reg_audio
    from reaper_mcp.mixing_tools import register_tools as _reg_mixing
    from reaper_mcp.render_tools import register_tools as _reg_render
    from reaper_mcp.mastering_tools import register_tools as _reg_mastering
    from reaper_mcp.analysis_tools import register_tools as _reg_analysis
    
    _reg_project(mcp)
    _reg_track(mcp)
    _reg_midi(mcp)
  • The get_project helper used by create_drum_pattern to obtain a reference to the current REAPER project.
    def get_project() -> reapy.Project:
        ensure_connected()
        return reapy.Project()
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It reveals that drum notes are placed on MIDI channel 9, which is helpful, but does not discuss overwrite behavior, error handling, or permission requirements.

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 reasonably concise and front-loaded with the core action. The character list is necessary but slightly lengthy. Overall 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 5 parameters and no output schema, the description covers pattern format and MIDI channel but leaves ambiguity on start_position units, beats parameter, and whether it creates a new item. Not fully complete.

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?

With 0% schema description coverage, the description compensates by explaining the pattern string format. However, it does not clarify the meaning of start_position (units), beats (effect on pattern), or repeats (over what? pattern or item?).

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?

Description clearly states the tool creates a drum pattern on a track using a step-sequencer string. It explains the characters and provides an example, making the purpose distinct from siblings like add_midi_note.

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

Usage Guidelines3/5

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

The description does not explicitly guide when to use this tool vs alternatives. It implies usage for drum pattern creation but lacks context on when it's preferred over other MIDI tools.

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/bonfire-audio/reaper-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server