sonic-pi-mcp
Enables control of a local Sonic Pi runtime to run code, stop jobs, read events, and search docs/samples/synthdefs via OSC messages.
README
sonic-pi-mcp
sonic-pi-mcp is a Python MCP server that lets an MCP client control a local
Sonic Pi runtime over the standard stdio transport.
It starts Sonic Pi's Ruby daemon, sends OSC messages to the Spider runtime, runs Sonic Pi code, stops jobs, reads runtime events/logs, and searches the local Sonic Pi docs/samples/synthdefs.
Requirements
- Python 3.11+
- A local Sonic Pi installation or checkout.
- The Sonic Pi root directory must contain:
app/server/ruby/bin/daemon.rbapp/server/ruby/bin/spider-server.rb- usually
etc/doc,etc/samples, andetc/synthdefs
No machine-specific path is baked into this package. Set SONIC_PI_ROOT in the
MCP client environment unless you pass root_path to sonic_start.
Install
From PyPI:
pip install sonic-pi-mcp
From a local checkout:
pip install .
Build a wheel/sdist:
python -m build
Then install the wheel on another machine:
pip install dist/sonic_pi_mcp-*.whl
The wheel only contains the Python package under src/sonic_pi_mcp. Generated
runtime files, exported audio, examples, tests, and local scripts are excluded
from distribution.
Configuration
Required in most deployments:
SONIC_PI_ROOT=<path to the Sonic Pi root directory>
Useful optional variables:
SONIC_PI_MCP_RUNTIME_DIR=<writable directory for temporary run_file buffers>
SONIC_PI_MCP_STARTUP_TIMEOUT=60
SONIC_PI_MCP_KEEPALIVE_INTERVAL=4
SONIC_PI_MCP_EVENT_BUFFER_SIZE=5000
SONIC_PI_MCP_DEFAULT_COLLECT_MS=1500
SONIC_PI_HOME=<custom Sonic Pi user-home root for logs, if needed>
SONIC_PI_MCP_RUNTIME_DIR is used when code is too large for Sonic Pi's OSC
packet size and must be submitted with run_file. If it is not set, the server
uses a per-user cache directory such as %LOCALAPPDATA%\sonic-pi-mcp on
Windows, ~/Library/Caches/sonic-pi-mcp on macOS, or
${XDG_CACHE_HOME:-~/.cache}/sonic-pi-mcp on Linux.
PowerShell example without hard-coding a drive:
$env:SONIC_PI_ROOT = Join-Path $env:ProgramFiles 'Sonic Pi'
$env:SONIC_PI_MCP_RUNTIME_DIR = Join-Path $env:LOCALAPPDATA 'sonic-pi-mcp'
sonic-pi-mcp
POSIX shell example:
export SONIC_PI_ROOT="$HOME/apps/sonic-pi"
export SONIC_PI_MCP_RUNTIME_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/sonic-pi-mcp"
sonic-pi-mcp
MCP Client Setup
This package is a stdio MCP server. Configure clients to run the installed
console command sonic-pi-mcp.
Generic MCP JSON shape:
{
"mcpServers": {
"sonic-pi": {
"command": "sonic-pi-mcp",
"args": [],
"env": {
"SONIC_PI_ROOT": "<path to Sonic Pi root>",
"SONIC_PI_MCP_RUNTIME_DIR": "<writable runtime directory>"
}
}
}
}
If your client does not inherit shell environment variables, put the variables in the client config. Avoid relying on the terminal profile of the user who installed the package.
If startup fails, the error includes preflight results, recent daemon output, Sonic Pi log tails, and likely fixes for common path, permission, and audio backend issues.
Run Manually
python -m sonic_pi_mcp
or:
sonic-pi-mcp
Both commands run the same stdio MCP server. They do not open an HTTP port.
MCP Tools
sonic_start(root_path?, no_inputs?)sonic_status()sonic_preflight(root_path?)sonic_run_code(code, buffer_name?, collect_ms?)sonic_play_file(path, buffer_name?, collect_ms?)sonic_start_recording(collect_ms?)sonic_stop_recording(collect_ms?)sonic_save_recording(output_path, collect_ms?, wait_timeout?)sonic_delete_recording(collect_ms?)sonic_record_file(path, output_path, duration_seconds, bit_depth?, buffer_name?, root_path?, no_inputs?, overwrite?, shutdown_after?, save_timeout?)sonic_stop(collect_ms?)sonic_shutdown()sonic_read_events(since?, limit?)sonic_get_logs(source?, tail?)sonic_send_cue(path, args?)sonic_search_docs(query, limit?, root_path?)sonic_list_samples(limit?, root_path?)sonic_list_synths(limit?, root_path?)sonic_list_fx(limit?, root_path?)
Suggested Agent Workflow
- Call
sonic_preflight()when setting up a new machine or after a boot failure. - Call
sonic_start(no_inputs=true)unless the user needs audio input. - Call
sonic_status()and confirmstateisready. - Use
sonic_search_docs,sonic_list_samples,sonic_list_synths, andsonic_list_fxto stay within the user's installed Sonic Pi version. - Send music with
sonic_run_code(code, buffer_name, collect_ms)or run a local.rbfile withsonic_play_file(path, buffer_name, collect_ms). - Export a fixed-duration WAV with
sonic_record_file(path, output_path, duration_seconds, bit_depth=24)when the user asks for a rendered file. - Inspect returned events for
syntax_error,runtime_error, or missingDefining fn :live_loop_...messages. - Call
sonic_stop()before replacing a long-running composition. - Call
sonic_shutdown()when the session is no longer needed.
Security
sonic_run_code executes local Sonic Pi code through the same token-protected
Spider API used by the Sonic Pi GUI. Treat access to this MCP server as local
code execution and local audio-device control.
License
MIT License. You may use, copy, modify, publish, distribute, sublicense, and sell copies of this package, provided the license text is included.
Packaging Notes
The package is intentionally path-neutral:
- No repository-local absolute path is embedded.
SONIC_PI_ROOTor theroot_pathtool argument identifies Sonic Pi.SONIC_PI_MCP_RUNTIME_DIRcontrols where temporary large-buffer files are written.- Build configuration excludes generated files such as
.runtime/,exports/, examples, tests, and local playback/export scripts.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。