Skip to main content
Glama

Sonic Pi MCP

模型上下文协议 (MCP) 服务器允许 AI 助手通过 OSC 消息与 Sonic Pi 进行交互。这使得 Claude 和 Cursor 等 AI 工具能够以编程方式创作音乐并控制 Sonic Pi。

特征

  • 使用可自定义的合成器参数演奏单个音符

  • 执行任意 Sonic Pi 代码

  • 可与任何 MCP 兼容客户端(Claude Desktop、Cursor 等)配合使用

先决条件

  • Node.js (v18 或更高版本)

  • Sonic Pi (v4.0 或更高版本)

  • 与 MCP 兼容的客户端(Cursor、Claude Desktop 等)

Sonic Pi 配置

在使用 MCP 服务器之前,您需要将以下代码添加到 Sonic Pi 缓冲区。此代码用于处理服务器发送的 OSC 消息:

# 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

在使用 MCP 服务器之前,请确保此代码在 Sonic Pi 中运行。

与客户整合

光标

添加到~/.cursor/mcpServers.json

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

克劳德桌面

添加到 Claude 的 MCP 配置:

{ "mcpServers": { "sonic_pi_mcp": { "command": "npx", "args": ["-y", "sonic-pi-mcp", "start"] } } }

可用工具

播放笔记

播放具有可自定义参数的单个音符。

参数:

  • note (必填):MIDI 音符编号(0-127)

  • synth (可选):要使用的合成器(例如“:saw”、“:beep”、“:prophet”)

  • sustain (可选):音符持续时间(以秒为单位)(默认值:1)

  • cutoff (可选):滤波器截止频率(默认值:100)

例子:

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

运行代码

执行任意 Sonic Pi 代码。

参数:

  • code (必需):要执行的 Sonic Pi 代码

例子:

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

示例用法

以下是使用 MCP 工具的一些交互示例:

简单的旋律

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

复杂模式

// 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 ` }

故障排除

  1. 无声音

    • 确保 Sonic Pi 正在运行

    • 检查 OSC 处理程序代码是否在 Sonic Pi 中运行

    • 验证 Sonic Pi 是否正在监听端口 4560(默认)

  2. 连接错误

    • 检查服务器的另一个实例是否正在运行

    • 重启Sonic Pi

    • 确保没有其他应用程序正在使用端口 4560

  3. 代码执行错误

    • 检查 Sonic Pi 日志窗口中的错误消息

    • 验证 Sonic Pi 代码的语法

    • 确保所有必需的合成器和样本都可用

发展

# Clone the repository git clone https://github.com/abhishekjairath/sonic-pi-mcp.git cd sonic-pi-mcp # Install dependencies npm install # Build npm run build # Install MCP Inspector globally (for testing) npm install -g @modelcontextprotocol/inspector # Start Sonic Pi and run the OSC handler code (see Sonic Pi Configuration section) # Start the server in one terminal npm run dev # In another terminal, start the MCP Inspector mcp-inspector

使用 MCP Inspector 进行测试

  1. 打开浏览器并导航至http://localhost:3000

  2. 在 MCP Inspector UI 中,配置连接:

    • 命令: node

    • 参数: dist/server.mjs

    • 工作目录: /path/to/your/sonic-pi-mcp (使用您的实际项目路径)

    • 传输类型:stdio

  3. 测试play_note工具:

{ "name": "play_note", "parameters": { "note": 60, "synth": ":beep", "sustain": 0.5 } }
  1. 测试run_code工具:

{ "name": "run_code", "parameters": { "code": "use_synth :prophet\nplay_pattern_timed scale(:c4, :major), [0.25]" } }
  1. 检查 Sonic Pi 日志窗口是否有任何错误消息或输出

解决开发问题

  1. 构建错误

    • 运行npm run build并检查 TypeScript 错误

    • 确保所有依赖项都正确安装

    • 检查tsconfig.json是否配置正确

  2. MCP 检查器连接问题

    • 验证服务器正在运行( npm run dev

    • 检查工作目录路径是否正确

    • 确保服务器没有其他实例正在运行

  3. OSC 通信问题

    • 确认 Sonic Pi 正在运行并且 OSC 处理程序代码处于活动状态

    • 检查服务器日志是否存在连接错误

    • 验证端口 4560 可用且未被阻止

贡献

  1. 分叉存储库

  2. 创建你的功能分支( git checkout -b feature/amazing-feature

  3. 提交您的更改( git commit -m 'Add some amazing feature'

  4. 推送到分支( git push origin feature/amazing-feature

  5. 打开拉取请求

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

Deploy Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

Related MCP Servers

  • -
    security
    F
    license
    -
    quality
    A Model Context Protocol server that enables AI assistants like Claude to perform Python development tasks through file operations, code analysis, project management, and safe code execution.
    Last updated -
    5
    • Linux
    • Apple
  • A
    security
    F
    license
    A
    quality
    A lightweight Model Context Protocol server that enables AI assistants like Cursor & Claude to control Spotify playback and manage playlists.
    Last updated -
    18
    181
  • -
    security
    F
    license
    -
    quality
    A Model Context Protocol server that enables controlling Spotify playback through natural language commands in MCP clients like Cursor or Claude for Desktop.
    Last updated -
    2
  • -
    security
    F
    license
    -
    quality
    A Model Context Protocol server that enables AI assistants like Claude to interact with Spotify, allowing them to search for tracks, control playback, and manage playlists.
    Last updated -
    1
    • Apple

View all related MCP servers

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/abhishekjairath/sonic-pi-mcp'

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