Skip to main content
Glama
williamzujkowski

Strudel MCP Server

detect_tempo

Detect BPM (beats per minute) from audio to analyze tempo for music generation and live coding in Strudel patterns.

Instructions

BPM detection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler implementing tempo detection via spectral flux onset detection, inter-onset interval calculation, BPM derivation, and confidence scoring.
    async detectTempo(page: Page): Promise<TempoAnalysis | null> {
      // Get analyzer object from browser
      const analyzer = await page.evaluate(() => {
        return (window as any).strudelAudioAnalyzer;
      });
    
      if (!analyzer || !analyzer.isConnected) {
        throw new Error('Audio analyzer not connected');
      }
    
      let onsets: number[];
    
      // Check if this is a mock with pre-calculated onset times (for testing)
      if (typeof analyzer.analyze === 'function') {
        const analysis = analyzer.analyze();
        if (analysis?.features?.onsetTimes) {
          onsets = analysis.features.onsetTimes;
        } else if (analysis?.features?.fftData === null) {
          // Explicitly null FFT data in test
          throw new Error('Invalid audio data');
        } else {
          // No mock data, use real-time detection
          if (!analyzer.dataArray) {
            throw new Error('Invalid audio data');
          }
          const fftData = new Uint8Array(analyzer.dataArray);
          const flux = this.calculateSpectralFlux(fftData);
    
          if (flux > this.ONSET_THRESHOLD) {
            this._onsetHistory.push(Date.now());
            if (this._onsetHistory.length > this.MAX_HISTORY_LENGTH) {
              this._onsetHistory.shift();
            }
          }
    
          onsets = [...this._onsetHistory];
        }
      } else {
        // No analyze function, use real-time detection
        if (!analyzer.dataArray) {
          throw new Error('Invalid audio data');
        }
        const fftData = new Uint8Array(analyzer.dataArray);
        const flux = this.calculateSpectralFlux(fftData);
    
        if (flux > this.ONSET_THRESHOLD) {
          this._onsetHistory.push(Date.now());
          if (this._onsetHistory.length > this.MAX_HISTORY_LENGTH) {
            this._onsetHistory.shift();
          }
        }
    
        onsets = [...this._onsetHistory];
      }
    
      // Need at least 4 onsets for reliable tempo detection
      if (onsets.length < 4) {
        return { bpm: 0, confidence: 0, method: 'onset' };
      }
    
      // Calculate inter-onset intervals (IOIs)
      const intervals = this.calculateIntervals(onsets);
    
      // Calculate mean interval and derive BPM
      const meanInterval = intervals.reduce((a, b) => a + b, 0) / intervals.length;
      const bpm = 60000 / meanInterval;
    
      // Validate BPM range
      if (bpm < 40 || bpm > 200) {
        return { bpm: 0, confidence: 0, method: 'onset' };
      }
    
      // Calculate confidence from interval consistency
      const variance = this.calculateVariance(intervals, meanInterval);
      const coefficientOfVariation = Math.sqrt(variance) / meanInterval;
      // More aggressive penalty for variation
      const confidence = Math.max(0, 1 - coefficientOfVariation * 1.5);
    
      return {
        bpm: Math.round(bpm),
        confidence: Math.min(1, confidence),
        method: 'onset'
      };
    }
  • MCP server handler for detect_tempo tool: checks initialization, calls controller.detectTempo(), formats response with BPM, confidence, and error handling.
    case 'detect_tempo':
      if (!this.isInitialized) {
        return 'Browser not initialized. Run init first.';
      }
      try {
        const tempoAnalysis = await this.controller.detectTempo();
        if (!tempoAnalysis || tempoAnalysis.bpm === 0) {
          return {
            bpm: 0,
            confidence: 0,
            message: 'No tempo detected. Ensure audio is playing and has a clear rhythmic pattern.'
          };
        }
        return {
          bpm: tempoAnalysis.bpm,
          confidence: Math.round(tempoAnalysis.confidence * 100) / 100,
          method: tempoAnalysis.method,
          message: `Detected ${tempoAnalysis.bpm} BPM with ${Math.round(tempoAnalysis.confidence * 100)}% confidence`
        };
      } catch (error: any) {
        return {
          bpm: 0,
          confidence: 0,
          error: error.message || 'Tempo detection failed'
        };
      }
  • Tool registration in MCP server: defines name, description, and empty input schema for detect_tempo.
    {
      name: 'detect_tempo',
      description: 'BPM detection',
      inputSchema: { type: 'object', properties: {} }
    },
  • Helper method in StrudelController that delegates tempo detection to the AudioAnalyzer instance.
    async detectTempo(): Promise<TempoAnalysis | null> {
      if (!this._page) throw new Error('Browser not initialized. Run init tool first.');
    
      return await this.analyzer.detectTempo(this._page);
    }
  • Input schema for detect_tempo tool: empty object (no parameters required).
    inputSchema: { type: 'object', properties: {} }
Behavior1/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 of behavioral disclosure. 'BPM detection' implies a read-only analysis function, but it fails to describe what the tool actually does behaviorally—whether it analyzes the current project, a specific input, returns a numeric value, or has side effects. This leaves critical operational details unspecified.

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

Conciseness3/5

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

The description is extremely concise ('BPM detection'), which could be seen as efficient, but it under-specifies the tool's purpose and usage. In this case, brevity comes at the cost of clarity, as it lacks necessary details that would help an agent understand and invoke the tool correctly.

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?

Given the tool has no parameters, no annotations, and no output schema, the description 'BPM detection' is insufficiently complete. It doesn't explain what the tool analyzes, what it returns, or how it fits within the context of sibling tools, leaving the agent with inadequate information for effective use.

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 tool has zero parameters with 100% schema description coverage, so the baseline is 4. The description doesn't need to compensate for any parameter gaps, as there are none to document, making it adequate in this dimension despite its brevity.

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

Purpose2/5

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

The description 'BPM detection' is a tautology that essentially restates the tool name 'detect_tempo' without adding meaningful context. While it indicates the tool detects beats per minute, it doesn't specify what resource or input it operates on (e.g., audio file, musical pattern, or current project) or how it differs from sibling tools like 'analyze_rhythm' or 'set_tempo'.

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

Usage Guidelines1/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. It doesn't mention prerequisites, context (e.g., after loading a file), or comparisons to sibling tools such as 'analyze_rhythm' or 'set_tempo', leaving the agent with no information to make an informed selection.

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/williamzujkowski/strudel-mcp-server'

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