Skip to main content
Glama
williamzujkowski

Strudel MCP Server

analyze_rhythm

Analyze musical rhythms to identify patterns and structures for music generation and live coding applications.

Instructions

Rhythm analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Tool registration definition for 'analyze_rhythm' in the getTools() array.
    {
      name: 'analyze_rhythm',
      description: 'Rhythm analysis',
      inputSchema: { type: 'object', properties: {} }
    },
  • MCP tool handler in executeTool switch statement (currently stubbed, calls analyzeAudio but returns placeholder).
    case 'analyze_rhythm':
      if (!this.isInitialized) {
        return 'Browser not initialized. Run init first.';
      }
      const analysis = await this.controller.analyzeAudio();
      return {
        isPlaying: analysis.features?.isPlaying,
        tempo: 'Analysis pending implementation',
        pattern: 'Rhythm pattern analysis'
      };
  • Core rhythm analysis implementation in AudioAnalyzer class, performing onset detection, complexity analysis, syncopation detection, etc.
    async analyzeRhythm(page: Page): Promise<RhythmAnalysis> {
      // Get analyzer object from browser
      const analyzer = await page.evaluate(() => {
        return (window as any).strudelAudioAnalyzer;
      });
    
      if (!analyzer || !analyzer.isConnected) {
        return {
          pattern: 'X...',
          complexity: 0,
          density: 0,
          syncopation: 0,
          onsets: [],
          isRegular: true
        };
      }
    
      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?.onsets) {
          onsets = analysis.features.onsets;
        } else if (analysis?.features?.onsetTimes) {
          onsets = analysis.features.onsetTimes;
        } else {
          // No mock data, use real-time detection
          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
        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 2 onsets for rhythm analysis
      if (onsets.length < 2) {
        return {
          pattern: 'X...',
          complexity: 0,
          density: 0,
          syncopation: 0,
          onsets: [],
          isRegular: true
        };
      }
    
      // Calculate intervals
      const intervals = this.calculateIntervals(onsets);
    
      // Calculate density (events per second)
      const duration = (onsets[onsets.length - 1] - onsets[0]) / 1000;
      const density = duration > 0 ? (onsets.length - 1) / duration : 0;
    
      // Calculate complexity from interval variance
      const meanInterval = intervals.reduce((a, b) => a + b, 0) / intervals.length;
      const variance = this.calculateVariance(intervals, meanInterval);
      const coefficientOfVariation = Math.sqrt(variance) / meanInterval;
    
      // Analyze subdivisions
      const subdivisionScore = this.analyzeSubdivisions(intervals);
    
      // Combine variance and subdivision complexity with higher sensitivity
      const varianceComponent = Math.min(1, coefficientOfVariation * 5);
      const complexity = Math.min(1, varianceComponent * 0.8 + subdivisionScore * 0.2);
    
      // Calculate syncopation (off-beat events)
      const syncopation = this.detectSyncopation(onsets, meanInterval);
    
      // Determine regularity
      const isRegular = coefficientOfVariation < 0.2;
    
      // Generate pattern string
      const pattern = this.generatePatternString(onsets, meanInterval);
    
      return {
        pattern,
        complexity,
        density,
        syncopation,
        onsets,
        isRegular
      };
    }
  • TypeScript interface defining the RhythmAnalysis return type (schema).
    export interface RhythmAnalysis {
      pattern: string;
      complexity: number; // 0-1 scale
      density: number; // events per second
      syncopation: number; // 0-1 scale
      onsets: number[];
      isRegular: boolean;
    }
  • Helper function for subdivision complexity calculation used in analyzeRhythm.
    private analyzeSubdivisions(intervals: number[]): number {
      if (intervals.length === 0) return 0;
    
      const meanInterval = intervals.reduce((a, b) => a + b, 0) / intervals.length;
    
      // Count how many different subdivision levels are present
      const subdivisions = new Set<number>();
    
      for (const interval of intervals) {
        const ratio = interval / meanInterval;
        // Quantize to common subdivisions (1, 0.5, 0.25, 0.75, 0.33, etc.)
        const quantized = Math.round(ratio * 8) / 8; // Higher resolution
        subdivisions.add(quantized);
      }
    
      // More subdivision levels = more complex (more aggressive scaling)
      return Math.min(1, subdivisions.size / 4);
    }
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. 'Rhythm analysis' gives no insight into whether this is a read-only operation, if it modifies data, requires specific inputs, or has side effects like rate limits. It fails to describe what the tool does beyond its name, offering no behavioral context.

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

Conciseness2/5

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

While concise with only two words, the description is under-specified rather than efficiently structured. It lacks front-loaded critical information such as the resource being analyzed or the output type. Conciseness should not come at the cost of clarity, making this overly brief without earning its place with useful details.

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 complexity implied by the tool name (analysis suggests non-trivial processing) and the lack of annotations and output schema, the description is incomplete. It does not explain what the tool returns, how it behaves, or what inputs it expects, leaving significant gaps for an agent to understand its use in context with many sibling tools.

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 0 parameters with 100% coverage, meaning no parameters need documentation. The description does not add parameter details, which is acceptable given the absence of parameters. A baseline of 4 is appropriate as the schema fully covers the parameter semantics, and the description does not need to compensate.

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 'Rhythm analysis' is a tautology that merely restates the tool name 'analyze_rhythm'. It does not specify what resource is being analyzed (e.g., audio, MIDI, pattern) or what specific analysis is performed (e.g., tempo detection, pattern recognition). While it distinguishes from siblings like 'analyze_spectrum' by focusing on rhythm, it lacks the verb+resource specificity needed for higher scores.

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 does not mention prerequisites, context, or exclusions, nor does it reference sibling tools like 'detect_tempo' or 'compare_patterns' that might overlap in functionality. This leaves the agent with no information to make an informed selection among related 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/williamzujkowski/strudel-mcp-server'

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