Integrations
Supports playing notes using MIDI note numbers (0-127), enabling programmatic music composition through standard MIDI note representations.
Required as a prerequisite for running the MCP server, which enables communication between AI tools and Sonic Pi.
Allows execution of Ruby code in Sonic Pi, enabling music creation and control through Ruby's syntax and Sonic Pi's musical capabilities.
Sonic Pi MCP
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
- Node.js (v18 or higher)
- 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:
Make sure this code is running in Sonic Pi before using the MCP server.
Integration with Clients
Cursor
Add to ~/.cursor/mcpServers.json
:
Claude Desktop
Add to Claude's MCP configuration:
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:
run_code
Executes arbitrary Sonic Pi code.
Parameters:
code
(required): Sonic Pi code to execute
Example:
Example Usage
Here are some example interactions using the MCP tools:
Simple Melody
Complex Pattern
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
Development
Testing with MCP Inspector
- Open your browser and navigate to http://localhost:3000
- In the MCP Inspector UI, configure the connection:
- Command:
node
- Arguments:
dist/server.mjs
- Working Directory:
/path/to/your/sonic-pi-mcp
(use your actual project path) - Transport Type: stdio
- Command:
- Test the
play_note
tool:
- Test the
run_code
tool:
- Check the Sonic Pi log window for any error messages or output
Troubleshooting Development Issues
- Build Errors
- Run
npm run build
and check for TypeScript errors - Ensure all dependencies are installed correctly
- Check
tsconfig.json
for proper configuration
- Run
- MCP Inspector Connection Issues
- Verify the server is running (
npm run dev
) - Check that the working directory path is correct
- Ensure no other instances of the server are running
- Verify the server is running (
- 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
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
This server cannot be installed
A Model Context Protocol server that allows AI assistants like Claude and Cursor to create music and control Sonic Pi programmatically through OSC messages.