Skip to main content
Glama

detect_clipping

Render the project to detect digital clipping. Identify samples at or above 0 dBFS, return peak level in dB, and indicate whether clipping occurred.

Instructions

Render the project and detect digital clipping (samples at or above 0 dBFS). Returns clipped sample count, peak level in dB, and whether clipping was found.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler for the 'detect_clipping' tool. Renders the project to a temp WAV file, reads it with soundfile, converts to mono, counts samples >= 0.9999 (clip threshold), computes peak level in dB, and returns clipping metrics.
    def detect_clipping() -> dict:
        """
        Render the project and detect digital clipping (samples at or above 0 dBFS).
        Returns clipped sample count, peak level in dB, and whether clipping was found.
        """
        try:
            import soundfile as sf
            from reaper_mcp.render_tools import render_to_temp_file
    
            tmp = render_to_temp_file()
            try:
                data, rate = sf.read(tmp)
            finally:
                if os.path.exists(tmp):
                    os.unlink(tmp)
    
            if data.ndim > 1:
                mono = np.max(np.abs(data), axis=1)
            else:
                mono = np.abs(data)
    
            clip_threshold = 0.9999
            clipped_samples = int(np.sum(mono >= clip_threshold))
            peak_linear = float(np.max(mono))
            peak_db = float(20 * np.log10(peak_linear)) if peak_linear > 0 else -120.0
    
            return {
                "success": True,
                "clipping_detected": clipped_samples > 0,
                "clipped_samples": clipped_samples,
                "peak_db": round(peak_db, 2),
                "peak_linear": round(peak_linear, 4),
            }
        except Exception as e:
            return {"success": False, "error": str(e)}
  • Registration of the analysis_tools module's register_tools function, which wraps detect_clipping (and all other analysis tools) with @mcp.tool() decorator.
    from reaper_mcp.analysis_tools import register_tools as _reg_analysis
    
    _reg_project(mcp)
    _reg_track(mcp)
    _reg_midi(mcp)
    _reg_fx(mcp)
    _reg_audio(mcp)
    _reg_mixing(mcp)
    _reg_render(mcp)
    _reg_mastering(mcp)
    _reg_analysis(mcp)
  • The @mcp.tool() decorator on the detect_clipping function that registers it as an MCP tool within the analysis_tools module.
    @mcp.tool()
    def detect_clipping() -> dict:
        """
        Render the project and detect digital clipping (samples at or above 0 dBFS).
        Returns clipped sample count, peak level in dB, and whether clipping was found.
        """
        try:
            import soundfile as sf
            from reaper_mcp.render_tools import render_to_temp_file
    
            tmp = render_to_temp_file()
            try:
                data, rate = sf.read(tmp)
            finally:
                if os.path.exists(tmp):
                    os.unlink(tmp)
    
            if data.ndim > 1:
                mono = np.max(np.abs(data), axis=1)
            else:
                mono = np.abs(data)
    
            clip_threshold = 0.9999
            clipped_samples = int(np.sum(mono >= clip_threshold))
            peak_linear = float(np.max(mono))
            peak_db = float(20 * np.log10(peak_linear)) if peak_linear > 0 else -120.0
    
            return {
                "success": True,
                "clipping_detected": clipped_samples > 0,
                "clipped_samples": clipped_samples,
                "peak_db": round(peak_db, 2),
                "peak_linear": round(peak_linear, 4),
            }
        except Exception as e:
            return {"success": False, "error": str(e)}
  • The render_to_temp_file helper function used by detect_clipping to render the project to a temporary WAV file for analysis.
    def render_to_temp_file(sample_rate: int = 48000) -> str:
        """
        Render the current project to a temporary WAV file and return its path.
        Used by analysis and mastering tools. Caller is responsible for deleting the file.
        """
        import tempfile
        tmp = tempfile.mktemp(suffix=".wav")
        _set_render_settings(tmp, "wav", sample_rate, 24, 2, bounds=0)
        RPR.Main_OnCommand(41824, 0)
        return tmp
Behavior3/5

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

No annotations are provided, so the description must disclose behaviors. It mentions that the tool renders the project to detect clipping, which is a non-trivial action, but does not specify whether rendering is destructive, performance impact, or if it requires any prerequisites. Additional context would improve transparency.

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?

Two sentences, front-loaded with the core action and result. No superfluous words. Highly concise and well-structured.

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

Completeness5/5

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

For a simple parameterless tool, the description is complete: it explains the process (render and detect), the threshold (0 dBFS), and the return values (count, peak, boolean). No output schema exists, but the description adequately covers what is returned.

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

Parameters4/5

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

The input schema has zero parameters, so schema coverage is 100%. The description does not need to add parameter detail beyond what is already captured. Per guidelines, baseline 4 applies for zero-parameter tools.

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 the action (render and detect clipping), the resource (project), and the outputs (clipped sample count, peak level, boolean). It distinguishes from sibling analysis tools like analyze_loudness or analyze_dynamics.

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 implies use when needing to check for digital clipping but does not explicitly state when to use this tool versus sibling analysis tools (e.g., analyze_dynamics). No exclusion criteria or alternative tool names are mentioned.

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