agentleFS
raulkiviraulkivi/sheet-music-mcp/synth-mcp/CLAUDE.md

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

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
  1. Very specific:

    Integration tests: must be @pytest.mark.integration and skipped in the default run

    line 91
  2. Very specific:

    pyfluidsynth, not CLI: Use fluidsynth.Synth with audio.driver=file + fluid_player_join().

    line 119
  3. Very specific:

    Test practice features at MIDI level (tests/midi_helpers.py reads bytes back with music21.midi.MidiFile), never with FluidSynth.

    line 133
  4. Distinctive:

    When you finish work or reach a milestone, update:

    line 198

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

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; 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/, 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 integration

Synthesis tests skip automatically when SYNTH_SOUNDFONT_PATH is unset.

Install dependencies: uv sync --extra dev


Key Files

FilePurpose
src/synth_mcp/server.pyMCP tool definitions and handlers
src/synth_mcp/engine.pymusic21 + pyfluidsynth pipeline (no MCP imports)
src/synth_mcp/practice.pyPractice-track steps: gains, repeat, clicks, timbre, MIDI post-processing (no MCP imports)
src/synth_mcp/clip.pystarting_pitches: text, clip MIDI, render + downmix to mono 16 kHz (no MCP imports)
src/synth_mcp/presenter.pystructuredContent + output schemas for the Practice Player tools
src/synth_mcp/health.pyProbes 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.pyMusicXML of each synthesized track, kept in step with the artifact store (no MCP imports)
src/synth_mcp/utils.pyMusicXML validation, tempo validation, path helpers
docs/HANDOVER.mdStatus, remaining work, definition of done
docs/PLAN.mdArchitecture decisions and rationale
docs/requirements.mdFunctional/non-functional requirements
docs/architecture.mdComponent diagram and data-flow

Implemented Tools

ToolDescription
get_partsParse MusicXML and return list of parts with IDs and measure counts
synthesizeRender 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_pitchesEach 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_scoreShared core tool: title, key, time, tempo, parts (ID, clef, range), measures, duration — no music21
read_audio_chunkApp-only: a base64 slice of a synthesized WAV by audio_id (offset, length ≤ 1 MiB; no paths)
get_score_xmlApp-only: the MusicXML an audio_id was made from (no paths)
list_capabilitiesServer metadata, backend, soundfont status
health_checkSoundfont, 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.sf2 and default-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 — use uv sync or uv add
  • engine.py must not import from mcp — 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.integration and 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") from sheet_music_mcp_core.parts.music21_part_infos; select by position against that list. Callers pass parts as IDs, names or voices ("P1", "Alto", "A"); part_ids is a deprecated alias.
  • pyfluidsynth, not CLI. Use fluidsynth.Synth with audio.driver=file + fluid_player_join(). The fluidsynth CLI binary is not required.
  • SYNTH_SOUNDFONT_PATH must 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) calls load_score(arguments, ctx) first, then the unchanged inline validation and engine calls, so a path call gives the same content[0] as the inline call. make_handlers(..., pass_context=True) supplies ctx for the client's roots; direct test calls pass none.
  • confine_output_path lives in the core. utils.confine_output_path is a re-export of sheet_music_mcp_core.paths.confine_output_path (raises PathPolicyError, also a ValueError).
  • output_path accepts .mid / .midi but always writes WAV (known gap, not yet fixed).
  • Install the dev extra: plain uv sync removes pytest; use uv sync --extra dev.
  • Practice options are no-ops at their defaults (DoD-1). call_tool passes only the practice options the caller gave to extract_midi; with none, the MIDI is byte-identical to before. Test practice features at MIDI level (tests/midi_helpers.py reads bytes back with music21.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_midi to 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), so extract_midi calls expand_repeats whenever clicks or repeat > 1 are asked for (tests/test_practice_timing.py, which also checks click onsets in seconds).
  • A bare <sound tempo> is numberSounding, not number. select_measures carries the tempo that way; music21's MIDI export prefers numberSounding, so scale_tempo scales both.
  • starting_pitches without audio is not an error. Any ProcessingError from render_clip (no soundfont, no FluidSynth, render failure) becomes "audio_unavailable"; the audio/starting-pitches-*.wav path is only created after rendering worked. Tests patch synth_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 (TestEffectSettings checks 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_clip cuts 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 (SOUNDFONT in test_starting_pitches.py): the autouse output_root fixture deletes SYNTH_SOUNDFONT_PATH before each test, so reading the variable inside a test gets nothing.
  • Practice Player (MCP Apps). synthesize stores the finished WAV in the module-level artifact_store (FileArtifactStore, kind audio/wav) and returns audio_id in structuredContent; a stored file must not be rewritten (_render_to_new_file renders to a temp file and os.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 every get, so it expires with the WAV; tests swap both with tests/conftest.py:use_store. Fakes of synthesize_midi must write a WAV (tests/midi_helpers.py:fake_render). Errors of the structured tools are isError results without structuredContent.
  • Gain 1.0 is CC7 100, not 64. A channel nothing sets keeps MIDI's default volume 100, so cc7_value maps 1.0 to DEFAULT_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.py counts time in window_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:

  1. docs/HANDOVER.md — check off done items, add new gotchas
  2. docs/PLAN.md — check off phase items, note changed decisions
  3. docs/requirements.md — update if behaviour changed
  4. docs/architecture.md — update if implementation changed

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.