abhishekjairath sonic pi mcp

abhishekjairath sonic pi mcp avatar

by abhishekjairath

Model Context Protocol (MCP) server for controlling Sonic Pi through AI assistants

What is abhishekjairath sonic pi mcp

Sonic Pi MCP

*smithery badge*

A Model Context Protocol (MCP) server that allows AI assistants to interact with Sonic Pi through OSC messages. This enables AI tools like Claude and Cursor to create music and control Sonic Pi programmatically.

Features

  • Play individual notes with customizable synth parameters
  • Execute arbitrary Sonic Pi code
  • Works with any MCP-compatible client (Claude Desktop, Cursor, etc.)

Prerequisites

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

Sonic Pi Configuration

Before using the MCP server, you need to add the following code to your Sonic Pi buffer. This code handles the OSC messages sent by the server:

# Required Sonic Pi configuration
# Add this to a buffer in Sonic Pi and run it

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.

Integration with Clients

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

  1. 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)
  2. Connection Errors

    • Check if another instance of the server is running
    • Restart Sonic Pi
    • Ensure no other applications are using port 4560
  3. 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

Development

# Clone the repository
git clone https://github.com/abhishekjairath/sonic-pi-mcp.git
cd sonic-pi-mcp

# Install Bun if you haven't already
curl -fsSL https://bun.sh/install | bash

# Install dependencies
bun install

# Start Sonic Pi and run the OSC handler code (see Sonic Pi Configuration section)

# Start the server in development mode
bun run dev

Testing with MCP Inspector

  1. Install and start the MCP Inspector:
npm install -g @modelcontextprotocol/inspector
mcp-inspector
  1. Open your browser and navigate to http://localhost:3000

  2. In the MCP Inspector UI, configure the connection:

    • Command: bun
    • Arguments: run src/server.ts
    • Working Directory: /path/to/your/sonic-pi-mcp (use your actual project path)
    • Transport Type: stdio
  3. Test the play_note tool:

{
  "name": "play_note",
  "parameters": {
    "note": 60,
    "synth": ":beep",
    "sustain": 0.5
  }
}
  1. Test the run_code tool:
{
  "name": "run_code",
  "parameters": {
    "code": "use_synth :prophet\nplay_pattern_timed scale(:c4, :major), [0.25]"
  }
}

Troubleshooting Development Issues

  1. Bun Installation Issues

    • Make sure Bun is in your PATH
    • Try running bun --version to verify the installation
    • If using Claude Desktop, use the full path to Bun in the config
  2. MCP Inspector Connection Issues

    • Verify the server is running (bun run dev)
    • Check that the working directory path is correct
    • Ensure no other instances of the server are running
  3. OSC Communication Issues

    • Confirm Sonic Pi is running and the OSC handler code is active
    • Check the server logs for connection errors
    • Verify port 4560 is available and not blocked

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Leave a Comment

Frequently Asked Questions

What is MCP?

MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.

What are MCP Servers?

MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.

How do MCP Servers work?

MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.

Are MCP Servers secure?

Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.

Related MCP Servers

chrisdoc hevy mcp avatar

chrisdoc hevy mcp

mcp
sylphlab pdf reader mcp avatar

sylphlab pdf reader mcp

An MCP server built with Node.js/TypeScript that allows AI agents to securely read PDF files (local or URL) and extract text, metadata, or page counts. Uses pdf-parse.

pdf-parsetypescriptnodejs
aashari mcp server atlassian bitbucket avatar

aashari mcp server atlassian bitbucket

Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MCP interface.

atlassianrepositorymcp
aashari mcp server atlassian confluence avatar

aashari mcp server atlassian confluence

Node.js/TypeScript MCP server for Atlassian Confluence. Provides tools enabling AI systems (LLMs) to list/get spaces & pages (content formatted as Markdown) and search via CQL. Connects AI seamlessly to Confluence knowledge bases using the standard MCP interface.

atlassianmcpconfluence
prisma prisma avatar

prisma prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

cockroachdbgomcp
Zzzccs123 mcp sentry avatar

Zzzccs123 mcp sentry

mcp sentry for typescript sdk

mcptypescript
zhuzhoulin dify mcp server avatar

zhuzhoulin dify mcp server

mcp
zhongmingyuan mcp my mac avatar

zhongmingyuan mcp my mac

mcp
zhixiaoqiang desktop image manager mcp avatar

zhixiaoqiang desktop image manager mcp

MCP 服务器,用于管理桌面图片、查看详情、压缩、移动等(完全让Trae实现)

mcp
zhixiaoqiang antd components mcp avatar

zhixiaoqiang antd components mcp

An MCP service for Ant Design components query | 一个减少 Ant Design 组件代码生成幻觉的 MCP 服务,包含系统提示词、组件文档、API 文档、代码示例和更新日志查询

designantdapi

Submit Your MCP Server

Share your MCP server with the community

Submit Now