使用说明
MIDI MCP服务器
A. 模型上下文协议(MCP) 用于AI驱动的MIDI作曲的服务器。从结构化JSON数据生成MIDI文件,支持和弦名称、交互式钢琴滚动预览UI和多种部署模式。
寻找代理技能方法? 它用更少的上下文创作出更好的歌曲: 大号24/midi代理技能
特性
- 两个MCP工具:
create_midi(带交互式预览UI)和parse_chord - 丰富的音调输入:MIDI数字、音符名称字符串(
"C4")、音高数组或和弦名称("Cmaj7") - 和弦库:25+和弦品质——大调、小调、小调、8月、7日、maj7、m7、sus2、sus4、power等
- 灵活的持续时间:数字节拍,标准字符串(
'4','8'),点缀('d4'),三胞胎('T8') - 音乐理论资源:7个内置参考文件可作为MCP资源访问
- 三种运输方式:stdio、HTTP或Cloudflare Workers(远程)
- MCP应用程序用户界面:对话中直接呈现的钢琴滚动可视化和音频播放
部署选项
选项A——远程(Cloudflare Workers)
预部署的远程服务器可用:
https://midi-mcp-server.tubone24.workers.dev/mcp
将其添加到任何支持流式HTTP的MCP客户端(例如Claude.ai):
{
"mcpServers": {
"midi": {
"type": "http",
"url": "https://midi-mcp-server.tubone24.workers.dev/mcp"
}
}
}
选项B——本地stdio(建议用于桌面客户端)
构建并配置为本地stdio服务器:
npm install
npm run build
{
"mcpServers": {
"musicComposer": {
"command": "node",
"args": ["/path/to/midi-mcp-server/build/index.js"]
}
}
}
选项C——本地HTTP
作为本地Streamable HTTP服务器运行:
node build/index.js --http
# or with a custom port:
node build/index.js --http --port=8080
服务器公开:
POST /mcp--MCP可流式HTTP端点GET /health--健康检查({"status":"ok","version":"0.2.0"})
工具
create_midi
从结构化作曲数据生成MIDI文件。返回base64编码的MIDI,并在支持的MCP客户端(MCP App)中呈现交互式钢琴滚动预览和音频播放。
输入
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
title |
string |
✓ | 作文标题 |
composition |
object |
✓ | 成分数据(见下图) |
输出 (结构化内容)
| 字段 | 类型 | 描述 |
|---|---|---|
midiBase64 |
string |
Base64编码的MIDI文件数据 |
title |
string |
作文标题 |
bpm |
number |
使用的温度 |
trackCount |
number |
生成的曲目数量 |
parse_chord
解析和弦名称并返回其分量MIDI音高和音符名称。有助于在写作前理解语音。
输入
| 字段 | 类型 | 必填 | 描述 |
|---|---|---|---|
chord |
string |
✓ | 和弦名称,例如。 "Cmaj7", "F#m7", "G7sus4" |
octave |
number |
-- | 根倍频程(默认值: 4) |
输出示例
{
"chord": "Cmaj7",
"octave": 4,
"midiNumbers": [60, 64, 67, 71],
"noteNames": ["C4", "E4", "G4", "B4"]
}
组合模式
{
"bpm": 120, // tempo (also accepted: "tempo")
"timeSignature": { "numerator": 4, "denominator": 4 }, // optional, default 4/4
"tracks": [
{
"name": "Piano", // optional
"instrument": 0, // GM program number 0–127 (optional)
"notes": [
{
"pitch": 60, // MIDI number, note name "C4", or array [60, 64, 67]
"chord": "Cmaj7", // OR use chord name (overrides pitch)
"beat": 1, // beat position (1-based); OR use startTime
"startTime": 0, // tick offset (alias: "time")
"duration": "4", // see Duration Reference below
"velocity": 100, // 0–127 (optional, default 100)
"channel": 0 // MIDI channel 0–15 (optional)
}
]
}
]
}
音高输入格式
| 格式 | 示例 | 说明 |
|---|---|---|
| MIDI编号 | 60 |
标准MIDI音符编号(0–127) |
| 备注名称 | "C4" |
字母+可选意外+八度音阶 |
| 俯仰阵列 | [60, 64, 67] |
多个投球同时进行 |
| 和弦场 | chord: "Cmaj7" |
和弦名称自动展开 |
支持的事故: # (尖锐), b (平坦)。示例: "F#5", "Bb3".
持续时间参考
| 值 | 描述 |
|---|---|
'1' |
整篇笔记 |
'2' |
半音符 |
'4' |
季度报告 |
'8' |
第八条注释 |
'16' |
第十六条注释 |
'32' |
第三十二条注释 |
'd1' 'd2' 'd4' 'd8' 'd16' |
点状变体 |
'dd4' |
双点四分之一 |
'T4' 'T8' … |
三胞胎变体 |
4 (数字) |
基于节拍: 1一刻钟 2=一半, 4=整体, 0.5=第八名 |
支持的和弦质量
| 质量 | 示例 | 描述 |
|---|---|---|
(无) / maj |
C, Cmaj |
专业 |
m / min |
Dm |
未成年人 |
dim |
Bdim |
减少 |
aug |
Eaug |
增强型 |
7 |
G7 |
统治第七 |
maj7 / M7 |
Cmaj7 |
大七 |
m7 / min7 |
Am7 |
小七 |
dim7 |
Bdim7 |
缩小第七 |
m7b5 |
Bm7b5 |
减少一半 |
aug7 |
Eaug7 |
增强7 |
6 / m6 |
C6, Am6 |
第六名 |
9 / maj9 / m9 |
G9 |
第9变体 |
add9 |
Cadd9 |
添加第9个 |
11 / 13 |
C11 |
扩展 |
sus2 / sus4 |
Gsus4 |
暂停 |
7sus4 / 7sus2 |
G7sus4 |
第七次暂停 |
power / 5 |
G5 |
电源弦 |
MCP资源
服务器公开7个音乐理论参考文献作为MCP资源:
| URI | 描述 |
|---|---|
music-theory://harmony |
音程、和弦类型、全音阶和弦、节奏、语音引导 |
music-theory://chord-progressions |
按情绪/流派、替换、调制的常见进展 |
music-theory://counterpoint |
物种对位规则、协和/不协和、运动类型 |
music-theory://modes-scales |
双声调式、小调变奏曲、五声/蓝调、流派指南 |
music-theory://orchestration |
仪器范围、GM程序编号、纹理类型 |
music-theory://rhythm-patterns |
时间签名、MIDI持续时间参考、流派凹槽 |
music-theory://voice-leading |
禁止的平行音、发声策略、非和弦音调 |
支持资源读取的MCP客户端可以将这些作为上下文传递给AI,从而实现理论感知的组合。
示例组成
const composition = {
bpm: 120,
timeSignature: { numerator: 4, denominator: 4 },
tracks: [
{
name: "Piano",
instrument: 0,
notes: [
{ chord: "Cmaj7", beat: 1, duration: "2", velocity: 90 },
{ chord: "Am7", beat: 3, duration: "2", velocity: 90 },
{ chord: "Fmaj7", beat: 5, duration: "2", velocity: 90 },
{ chord: "G7", beat: 7, duration: "2", velocity: 90 }
]
},
{
name: "Melody",
instrument: 0,
notes: [
{ pitch: "E4", beat: 1, duration: "4", velocity: 100 },
{ pitch: "G4", beat: 2, duration: "4", velocity: 100 },
{ pitch: "A4", beat: 3, duration: "2", velocity: 110 }
]
}
]
};
演示
下面的提示生成了一首8小节旋律小调合唱曲:
Create an 8-bar choral piece in a slightly minor, melodic scale.
https://github.com/user-attachments/assets/e20ebef0-fdbf-4e72-910d-41b94183f9d9
构建与开发
npm install
# Full build (UI + server)
npm run build
# Build steps individually
npm run build:ui # Vite — builds the MCP App preview HTML
npm run build:server # tsc — compiles TypeScript server
# Deploy to Cloudflare Workers
npm run deploy
# Run tests
npm test
npm run test:coverage
依赖项
| 包装 | 用途 |
|---|---|
@modelcontextprotocol/sdk |
MCP服务器实现(stdio和HTTP传输) |
@modelcontextprotocol/ext-apps |
MCP Apps扩展——对话中的交互式UI |
midi-writer-js |
MIDI文件生成 |
@tonejs/midi |
MIDI解析(预览UI) |
soundfont-player |
预览UI中的音频播放 |
zod |
输入模式验证 |