Sonic Pi MCP server

Enables music creation and sound manipulation through Sonic Pi by sending OSC messages for playing notes with customizable synth parameters and executing arbitrary code.
Back to servers
Setup instructions
Provider
Abhishek Jairath
Release date
Mar 23, 2025
Language
TypeScript
Package
Stats
306 downloads
7 stars

This MCP server allows AI assistants to interact with Sonic Pi through OSC messages, enabling AI tools like Claude and Cursor to create music and control Sonic Pi programmatically. You can play individual notes with customizable parameters or execute arbitrary Sonic Pi code through a simple interface.

Prerequisites

  • Bun
  • Sonic Pi (v4.0 or higher)
  • An MCP-compatible client (Cursor, Claude Desktop, etc.)

Sonic Pi Configuration

Before using the MCP server, add this code to your Sonic Pi buffer to handle OSC messages:

live_loop :code_runner do
  use_real_time
  code = sync "/osc*/run-code"
  
  # Since we receive the code as a string, we can use eval to execute it
  # The code comes as the first element of the message
  begin
    eval(code[0].to_s)
  rescue Exception => e
    puts "Error executing code: #{e.message}"
  end
end

Make sure this code is running in Sonic Pi before using the MCP server.

Setting Up Client Integration

Cursor

Add to ~/.cursor/mcpServers.json:

{
  "mcpServers": {
    "sonic_pi_mcp": {
      "name": "Sonic Pi MCP",
      "command": "bunx",
      "args": ["sonic-pi-mcp"],
      "transport": {
        "type": "stdio"
      }
    }
  }
}

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "sonic_pi_mcp": {
      "command": "bunx",
      "args": ["sonic-pi-mcp"],
    }
  }
}

Available Tools

play_note

Plays a single note with customizable parameters.

Parameters:

  • note (required): MIDI note number (0-127)
  • synth (optional): Synth to use (e.g., ":saw", ":beep", ":prophet")
  • sustain (optional): Note duration in seconds (default: 1)
  • cutoff (optional): Filter cutoff frequency (default: 100)

Example:

// Play middle C with saw wave synth
{
  "name": "play_note",
  "parameters": {
    "note": 60,
    "synth": ":saw",
    "sustain": 0.5,
    "cutoff": 80
  }
}

run_code

Executes arbitrary Sonic Pi code.

Parameters:

  • code (required): Sonic Pi code to execute

Example:

{
  "name": "run_code",
  "parameters": {
    "code": "use_synth :prophet\nplay_pattern_timed [60, 64, 67], [0.5]"
  }
}

Example Usage

Here are some example interactions using the MCP tools:

Simple Melody

// Play a C major arpeggio
{
  "code": `
    use_synth :piano
    play_pattern_timed [60, 64, 67, 72], [0.25], release: 0.1
  `
}

Complex Pattern

// Create a rhythmic pattern
{
  "code": `
    live_loop :rhythm do
      use_synth :tb303
      play choose(chord(:C3, :minor)), release: 0.2, cutoff: rrand(60, 120)
      sleep 0.25
    end
  `
}

Troubleshooting

No Sound

  • Ensure Sonic Pi is running
  • Check that the OSC handler code is running in Sonic Pi
  • Verify Sonic Pi is listening on port 4560 (default)

Connection Errors

  • Check if another instance of the server is running
  • Restart Sonic Pi
  • Ensure no other applications are using port 4560

Code Execution Errors

  • Check the Sonic Pi log window for error messages
  • Verify the syntax of your Sonic Pi code
  • Ensure all required synths and samples are available

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "sonic_pi_mcp" '{"name":"Sonic Pi MCP","command":"bunx","args":["sonic-pi-mcp"],"transport":{"type":"stdio"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "sonic_pi_mcp": {
            "name": "Sonic Pi MCP",
            "command": "bunx",
            "args": [
                "sonic-pi-mcp"
            ],
            "transport": {
                "type": "stdio"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "sonic_pi_mcp": {
            "name": "Sonic Pi MCP",
            "command": "bunx",
            "args": [
                "sonic-pi-mcp"
            ],
            "transport": {
                "type": "stdio"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later