sheet-music-mcp / synth-mcp
CLAUDE.md4 starsChanged 2 months agoMITView on GitHub
Last changed: 2026-11-26 · Source: https://github.com/raulkivi/sheet-music-mcp Synthesizes audio from a MusicXML score. Callers select voice parts (Soprano, Alto, Tenor, Bass, or any combination) and an optional tempo factor. Returns a WAV file path. Status: Phase 1 + UX Wave 1 + UX Wave 2 (score references: musicxml_path, describe_score) + UX Wave 3 (practice tracks: measures, repeat, count-in/metronome, timbre, part gains and presets; new starting_pitches tool) complete. MCP Apps pages built: Practice Player (structuredContent, app-only read_audio_chunk and get_score_xml; page in ui/apps/practice-player/,…
- Installs packages
In this repository7 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- comparer-mcp/CLAUDE.mdCLAUDE.md
- musicxml-abc-mcp/CLAUDE.mdCLAUDE.md
- omr-mcp/CLAUDE.mdCLAUDE.md
- pitch-mcp/CLAUDE.mdCLAUDE.md
- render-mcp/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 91
Integration tests: must be @pytest.mark.integration and skipped in the default run
- Very specific: line 119
pyfluidsynth, not CLI: Use fluidsynth.Synth with audio.driver=file + fluid_player_join().
- Very specific: line 133
Test practice features at MIDI level (tests/midi_helpers.py reads bytes back with music21.midi.MidiFile), never with FluidSynth.
- Distinctive: line 198
When you finish work or reach a milestone, update:
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
synth-mcp — Claude Code Instructions
Last changed: 2026-11-26 · Source: https://github.com/raulkivi/sheet-music-mcp
What This Server Does
Synthesizes audio from a MusicXML score. Callers select voice parts (Soprano, Alto, Tenor, Bass, or any combination) and an optional tempo factor. Returns a WAV file path.
Status: Phase 1 + UX Wave 1 + UX Wave 2 (score references: musicxml_path, describe_score)
- UX Wave 3 (practice tracks:
measures,repeat, count-in/metronome,timbre, part gains and presets; newstarting_pitchestool) complete. MCP Apps pages built: Practice Player (structuredContent, app-onlyread_audio_chunkandget_score_xml; page inui/apps/practice-player/, see requirements IR-3d) and Setup Doctor (health_check). 501 unit + 21 integration tests (they need a soundfont and libfluidsynth; 14 run in CI, the other 7 also need the local omr-mcp MXL fixtures).
Running Tests
# From this directory
VIRTUAL_ENV= .venv/bin/pytest tests/ -v # 501 unit tests (fast)
# Integration tests require a soundfont
VIRTUAL_ENV= SYNTH_SOUNDFONT_PATH=/usr/share/sounds/sf2/TimGM6mb.sf2 \
.venv/bin/pytest tests/ -v -m integrationSynthesis tests skip automatically when SYNTH_SOUNDFONT_PATH is unset.
Install dependencies: uv sync --extra dev
Key Files
| File | Purpose |
src/synth_mcp/server.py | MCP tool definitions and handlers |
src/synth_mcp/engine.py | music21 + pyfluidsynth pipeline (no MCP imports) |
src/synth_mcp/practice.py | Practice-track steps: gains, repeat, clicks, timbre, MIDI post-processing (no MCP imports) |
src/synth_mcp/clip.py | starting_pitches: text, clip MIDI, render + downmix to mono 16 kHz (no MCP imports) |
src/synth_mcp/presenter.py | structuredContent + output schemas for the Practice Player tools |
src/synth_mcp/health.py | Probes mapped to the shared health report (core health) |
src/synth_mcp/ui/assets/ | practice-player.html, setup-doctor.html; built by ui/ (npm run copy-assets), gitignored |
src/synth_mcp/scorebook.py | MusicXML of each synthesized track, kept in step with the artifact store (no MCP imports) |
src/synth_mcp/utils.py | MusicXML validation, tempo validation, path helpers |
docs/HANDOVER.md | Status, remaining work, definition of done |
docs/PLAN.md | Architecture decisions and rationale |
docs/requirements.md | Functional/non-functional requirements |
docs/architecture.md | Component diagram and data-flow |
Implemented Tools
| Tool | Description |
get_parts | Parse MusicXML and return list of parts with IDs and measure counts |
synthesize | Render selected parts to WAV with optional tempo scaling and practice options: measures, repeat, count_in_bars, metronome, timbre, part_gains / preset / focus_part; links ui://synth/practice-player, returns audio_id in structuredContent |
starting_pitches | Each part's first note as text ("S: D5, A: A4, …") plus a short piano WAV (inline when ≤ 200 KB); text only, not an error, without a soundfont |
describe_score | Shared core tool: title, key, time, tempo, parts (ID, clef, range), measures, duration — no music21 |
read_audio_chunk | App-only: a base64 slice of a synthesized WAV by audio_id (offset, length ≤ 1 MiB; no paths) |
get_score_xml | App-only: the MusicXML an audio_id was made from (no paths) |
list_capabilities | Server metadata, backend, soundfont status |
health_check | Soundfont, FluidSynth and music21 readiness; structuredContent health report, linked to ui://synth/setup-doctor |
get_parts, synthesize, starting_pitches and describe_score take the score as musicxml (inline text) or
musicxml_path (.musicxml, .xml, .mxl), exactly one (oneOf). Paths are read with
sheet_music_mcp_core.references.load_score (read roots: SHEET_MUSIC_OUTPUT_ROOT, client MCP
roots, SHEET_MUSIC_INPUT_ROOTS); never open a score path yourself.
Environment
- System soundfonts:
/usr/share/sounds/sf2/TimGM6mb.sf2anddefault-GM.sf2 - libfluidsynth:
/usr/lib/x86_64-linux-gnu/libfluidsynth.so.3(installed) - Backend: music21 (MusicXML → MIDI) + pyfluidsynth with
audio.driver=file(no subprocess) - MXL fixtures:
../omr-mcp/test_samples/pdmx_satb_samples/mxl/(10 SATB files)
Hard Rules
- Never
pip install— useuv syncoruv add engine.pymust not import frommcp— keeps it unit-testable- All tool handlers must be
async def - All errors →
{"error": "...", "error_code": "..."}(codes:FILE_NOT_FOUND,INVALID_INPUT,PROCESSING_FAILED,INVALID_PARAMETER) - Integration tests must be
@pytest.mark.integrationand skipped in the default run
MCP Server Startup Pattern
import asyncio
import mcp.server.stdio
async def _run():
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
await app.run(read_stream, write_stream, app.create_initialization_options())
asyncio.run(_run())run_server() does not exist in the installed MCP SDK — use the context manager above.
Known Gotchas
- Never select parts by music21's
part.id. music21 replaces it with the part name, repeats it for same-named parts and gives unnamed parts a new integer on every parse. Part IDs are the MusicXML<score-part id>("P1") fromsheet_music_mcp_core.parts.music21_part_infos; select by position against that list. Callers passpartsas IDs, names or voices ("P1","Alto","A");part_idsis a deprecated alias. - pyfluidsynth, not CLI. Use
fluidsynth.Synthwithaudio.driver=file+fluid_player_join(). ThefluidsynthCLI binary is not required. SYNTH_SOUNDFONT_PATHmust be set for synthesis. Warn at server startup if missing — don't crash, but synthesis calls will fail with a clear error.- Score paths go through the core.
call_tool(name, arguments, ctx=None)callsload_score(arguments, ctx)first, then the unchanged inline validation and engine calls, so a path call gives the samecontent[0]as the inline call.make_handlers(..., pass_context=True)suppliesctxfor the client's roots; direct test calls pass none. confine_output_pathlives in the core.utils.confine_output_pathis a re-export ofsheet_music_mcp_core.paths.confine_output_path(raisesPathPolicyError, also aValueError).output_pathaccepts.mid/.midibut always writes WAV (known gap, not yet fixed).- Install the dev extra: plain
uv syncremoves pytest; useuv sync --extra dev. - Practice options are no-ops at their defaults (DoD-1).
call_toolpasses only the practice options the caller gave toextract_midi; with none, the MIDI is byte-identical to before. Test practice features at MIDI level (tests/midi_helpers.pyreads bytes back withmusic21.midi.MidiFile), never with FluidSynth. - music21 shares a MIDI channel between parts with the same instrument (channels are keyed by
program), so CC7 gains need
tune_midito give each melodic part its own channel (max 15). - music21's conductor track keeps tempo/time marks only in ascending offset order, first part first. The count-in's meter and tempo therefore go at offset 0 of the first part, not in the click part; the click part is appended last so it is the last MIDI track.
- Expand written repeats before
repeat_music. Copies of unexpanded volta endings confuse music21's own expansion at export (later passes replayed the first ending), soextract_midicallsexpand_repeatswhenever clicks orrepeat > 1are asked for (tests/test_practice_timing.py, which also checks click onsets in seconds). - A bare
<sound tempo>isnumberSounding, notnumber.select_measurescarries the tempo that way; music21's MIDI export prefersnumberSounding, soscale_temposcales both. starting_pitcheswithout audio is not an error. AnyProcessingErrorfromrender_clip(no soundfont, no FluidSynth, render failure) becomes"audio_unavailable"; theaudio/starting-pitches-*.wavpath is only created after rendering worked. Tests patchsynth_mcp.clip.synthesize_midi.- Reverb and chorus are set explicitly (
engine.EFFECT_SETTINGS, FluidSynth 2.3 defaults). 2.4 changed the defaults (room size 0.2 -> 0.5, ...) and the choir round trip lost its final note on Ubuntu 26.04. Floats for num settings, ints for int settings, or FluidSynth silently ignores the value (TestEffectSettingschecks the installed library keeps each one). - FluidSynth renders the full release tail (about 2.6 s after the last chord with FluidR3_GM),
so
render_clipcuts the clip 0.25 s after the chord, faded out (clip_seconds+RELEASE_SECONDS); otherwise a 4-part clip is 275 KB and never inline. - Integration tests resolve the soundfont at import (
SOUNDFONTintest_starting_pitches.py): the autouseoutput_rootfixture deletesSYNTH_SOUNDFONT_PATHbefore each test, so reading the variable inside a test gets nothing. - Practice Player (MCP Apps).
synthesizestores the finished WAV in the module-levelartifact_store(FileArtifactStore, kindaudio/wav) and returnsaudio_idinstructuredContent; a stored file must not be rewritten (_render_to_new_filerenders to a temp file andos.replaces it, giving a new inode). The store only takes files inside the output root, so the default output is now<output root>/audio/output-<timestamp>.wav(was/tmp/synth-mcp-<uid>/).ScoreBook(score_book) holds the MusicXML per id and asks the store on everyget, so it expires with the WAV; tests swap both withtests/conftest.py:use_store. Fakes ofsynthesize_midimust write a WAV (tests/midi_helpers.py:fake_render). Errors of the structured tools areisErrorresults withoutstructuredContent. - Gain 1.0 is CC7 100, not 64. A channel nothing sets keeps MIDI's default volume 100, so
cc7_valuemaps 1.0 toDEFAULT_CC7; any other value makes "no change" audibly louder or quieter (64 was 7.7 dB down, FluidSynth's CC7 curve is 40 log10). - Audio analysis windows are whole samples. At 44.1 kHz a 5 ms window is 220 samples, not
220.5;
tests/audio_features.pycounts time inwindow_seconds, never the nominal length, or onsets "drift" 1/441 late (a measurement bug once taken for FluidSynth timing drift). - Running tests:
VIRTUAL_ENV=prefix prevents uv from picking up the wrong venv.
Claude Desktop Config
{
"mcpServers": {
"synth": {
"command": "uv",
"args": ["--directory", "/path/to/synth-mcp", "run", "synth-mcp"],
"env": {
"SYNTH_SOUNDFONT_PATH": "/usr/share/sounds/sf2/TimGM6mb.sf2"
}
}
}
}Document Update Policy
When you finish work or reach a milestone, update:
docs/HANDOVER.md— check off done items, add new gotchasdocs/PLAN.md— check off phase items, note changed decisionsdocs/requirements.md— update if behaviour changeddocs/architecture.md— update if implementation changed
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

