synth-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,127 @@
1
+ # synth-mcp — Copilot Instructions
2
+
3
+ ## What This Server Does
4
+
5
+ Synthesizes audio from a MusicXML score. Callers select voice parts (Soprano, Alto, Tenor, Bass,
6
+ or any combination) and an optional tempo factor. Returns a path to a rendered WAV file.
7
+
8
+ **Status:** Phase 1 complete. 60 unit + 7 integration tests pass.
9
+
10
+ ---
11
+
12
+ ## Before You Write Any Code
13
+
14
+ Read these documents in order:
15
+ 1. **`docs/HANDOVER.md`** — current status, remaining work, pre-flight checks, known gotchas, definition of done
16
+ 2. **`docs/PLAN.md`** — architecture decisions and technology rationale
17
+ 3. **`docs/requirements.md`** — functional and non-functional requirements, error codes
18
+ 4. **`docs/architecture.md`** — component diagram, data-flow, module responsibilities
19
+
20
+ ---
21
+
22
+ ## Project Structure
23
+
24
+ ```
25
+ synth-mcp/
26
+ ├── pyproject.toml
27
+ ├── .python-version # "llm311"
28
+ ├── src/synth_mcp/
29
+ │ ├── server.py # MCP tool definitions and async handlers
30
+ │ ├── engine.py # music21 + pyfluidsynth pipeline — NO mcp imports
31
+ │ └── utils.py # MusicXML validation, tempo validation, path helpers
32
+ ├── tests/
33
+ │ ├── test_server.py # protocol tests
34
+ │ ├── test_engine.py # unit + integration tests
35
+ │ ├── test_utils.py # unit tests
36
+ │ └── fixtures/
37
+ └── docs/
38
+ ├── requirements.md
39
+ └── architecture.md
40
+ ```
41
+
42
+ MXL test fixtures are in `../omr-mcp/test_samples/pdmx_satb_samples/mxl/` — 10 SATB files.
43
+
44
+ ---
45
+
46
+ ## Implemented Tools
47
+
48
+ | Tool | Description |
49
+ |------|-------------|
50
+ | `get_parts` | Parse MusicXML → list of parts with IDs, names, measure counts |
51
+ | `synthesize` | Render selected parts to WAV with optional tempo scaling |
52
+ | `list_capabilities` | Server metadata, backend, soundfont path status |
53
+
54
+ ---
55
+
56
+ ## Environment
57
+
58
+ - **System soundfonts:** `/usr/share/sounds/sf2/TimGM6mb.sf2` and `default-GM.sf2`
59
+ - **libfluidsynth:** `/usr/lib/x86_64-linux-gnu/libfluidsynth.so.3` (installed)
60
+ - **Backend:** music21 (MusicXML → MIDI) + pyfluidsynth with `audio.driver=file` (no subprocess)
61
+ - Synthesis tests skip automatically when `SYNTH_SOUNDFONT_PATH` env var is unset
62
+
63
+ ---
64
+
65
+ ## Coding Standards
66
+
67
+ - **Package manager:** `uv` only — never `pip install`
68
+ - **`engine.py` must not import from `mcp`** — keeps it independently unit-testable
69
+ - **All tool handlers must be `async def`**
70
+ - **All error responses:** `{"error": "human description", "error_code": "SCREAMING_SNAKE"}`
71
+ - **Standard error codes:** `FILE_NOT_FOUND`, `INVALID_INPUT`, `PROCESSING_FAILED`, `INVALID_PARAMETER`
72
+ - **Integration tests** must be `@pytest.mark.integration` — not run in the default `pytest` invocation
73
+ - **Python 3.11+**; `asyncio_mode = "auto"` in pytest config
74
+
75
+ ---
76
+
77
+ ## Running Tests
78
+
79
+ ```bash
80
+ # Unit tests (fast, default)
81
+ VIRTUAL_ENV= .venv/bin/pytest tests/ -v
82
+
83
+ # Integration tests (needs soundfont)
84
+ VIRTUAL_ENV= SYNTH_SOUNDFONT_PATH=/usr/share/sounds/sf2/TimGM6mb.sf2 \
85
+ .venv/bin/pytest tests/ -v -m integration
86
+
87
+ # Install dependencies
88
+ uv sync
89
+ ```
90
+
91
+ ---
92
+
93
+ ## MCP Server Startup Pattern
94
+
95
+ ```python
96
+ import asyncio
97
+ import mcp.server.stdio
98
+
99
+ async def _run():
100
+ async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
101
+ await app.run(read_stream, write_stream, app.create_initialization_options())
102
+
103
+ asyncio.run(_run())
104
+ ```
105
+
106
+ `mcp.server.stdio.run_server()` does not exist — always use the context manager above.
107
+
108
+ ---
109
+
110
+ ## Known Gotchas
111
+
112
+ - **music21 9.x: `part.id` is the part name** (e.g. `"Soprano"`), not the XML `<part id>`
113
+ attribute (`"P1"`). Callers must pass part names to `part_ids`, not XML IDs.
114
+ - **pyfluidsynth, not CLI.** Use `fluidsynth.Synth` with `audio.driver=file` +
115
+ `fluid_player_join()` to render MIDI → WAV. The `fluidsynth` CLI binary is not needed.
116
+ - **`SYNTH_SOUNDFONT_PATH` must be set for synthesis.** Warn at startup if missing — don't crash.
117
+ - **`tempo_factor` changes MIDI tempo, not audio pitch** — this is correct behaviour.
118
+
119
+ ---
120
+
121
+ ## When You Finish Work
122
+
123
+ Update these documents so the next session starts with accurate information:
124
+ - **`docs/HANDOVER.md`** — check off done items, add new gotchas, update status
125
+ - **`docs/PLAN.md`** — check off completed phase items, note changed decisions
126
+ - **`docs/requirements.md`** — update if behaviour or interfaces changed
127
+ - **`docs/architecture.md`** — update if implementation structure changed
@@ -0,0 +1,38 @@
1
+ # Working development docs — tracked locally only (live in each server's docs/ folder)
2
+ HANDOVER.md
3
+ PLAN.md
4
+
5
+ # Python
6
+ __pycache__/
7
+ *.pyc
8
+ *.pyo
9
+ *.pyd
10
+ *.egg-info/
11
+ dist/
12
+ build/
13
+ .eggs/
14
+
15
+ # Virtual environments
16
+ .venv/
17
+ venv/
18
+
19
+ # Test caches
20
+ .pytest_cache/
21
+ .mypy_cache/
22
+ .ruff_cache/
23
+
24
+ # Test samples (large data — not committed)
25
+ test_samples/
26
+
27
+ # Editor / OS
28
+ .vscode/
29
+ .idea/
30
+ .DS_Store
31
+ Thumbs.db
32
+
33
+ # Environment overrides
34
+ .env
35
+ .env.*
36
+
37
+ # Snyk Security Extension - AI Rules (auto-generated)
38
+ .github/instructions/snyk_rules.instructions.md
@@ -0,0 +1 @@
1
+ llm311
@@ -0,0 +1,125 @@
1
+ # synth-mcp — Claude Code Instructions
2
+
3
+ ## What This Server Does
4
+
5
+ Synthesizes audio from a MusicXML score. Callers select voice parts (Soprano, Alto, Tenor, Bass,
6
+ or any combination) and an optional tempo factor. Returns a WAV file path.
7
+
8
+ **Status:** Phase 1 complete. 60 unit + 7 integration tests pass.
9
+
10
+ ---
11
+
12
+ ## Running Tests
13
+
14
+ ```bash
15
+ # From this directory
16
+ VIRTUAL_ENV= .venv/bin/pytest tests/ -v # 60 unit tests (fast)
17
+
18
+ # Integration tests require a soundfont
19
+ VIRTUAL_ENV= SYNTH_SOUNDFONT_PATH=/usr/share/sounds/sf2/TimGM6mb.sf2 \
20
+ .venv/bin/pytest tests/ -v -m integration
21
+ ```
22
+
23
+ Synthesis tests **skip automatically** when `SYNTH_SOUNDFONT_PATH` is unset.
24
+
25
+ Install dependencies: `uv sync`
26
+
27
+ ---
28
+
29
+ ## Key Files
30
+
31
+ | File | Purpose |
32
+ |------|---------|
33
+ | `src/synth_mcp/server.py` | MCP tool definitions and handlers |
34
+ | `src/synth_mcp/engine.py` | music21 + pyfluidsynth pipeline (no MCP imports) |
35
+ | `src/synth_mcp/utils.py` | MusicXML validation, tempo validation, path helpers |
36
+ | `docs/HANDOVER.md` | Status, remaining work, definition of done |
37
+ | `docs/PLAN.md` | Architecture decisions and rationale |
38
+ | `docs/requirements.md` | Functional/non-functional requirements |
39
+ | `docs/architecture.md` | Component diagram and data-flow |
40
+
41
+ ---
42
+
43
+ ## Implemented Tools
44
+
45
+ | Tool | Description |
46
+ |------|-------------|
47
+ | `get_parts` | Parse MusicXML and return list of parts with IDs and measure counts |
48
+ | `synthesize` | Render selected parts to WAV with optional tempo scaling |
49
+ | `list_capabilities` | Server metadata, backend, soundfont status |
50
+
51
+ ---
52
+
53
+ ## Environment
54
+
55
+ - **System soundfonts:** `/usr/share/sounds/sf2/TimGM6mb.sf2` and `default-GM.sf2`
56
+ - **libfluidsynth:** `/usr/lib/x86_64-linux-gnu/libfluidsynth.so.3` (installed)
57
+ - **Backend:** music21 (MusicXML → MIDI) + pyfluidsynth with `audio.driver=file` (no subprocess)
58
+ - **MXL fixtures:** `../omr-mcp/test_samples/pdmx_satb_samples/mxl/` (10 SATB files)
59
+
60
+ ---
61
+
62
+ ## Hard Rules
63
+
64
+ - **Never `pip install`** — use `uv sync` or `uv add`
65
+ - **`engine.py` must not import from `mcp`** — keeps it unit-testable
66
+ - **All tool handlers must be `async def`**
67
+ - **All errors** → `{"error": "...", "error_code": "..."}` (codes: `FILE_NOT_FOUND`, `INVALID_INPUT`, `PROCESSING_FAILED`, `INVALID_PARAMETER`)
68
+ - **Integration tests** must be `@pytest.mark.integration` and skipped in the default run
69
+
70
+ ---
71
+
72
+ ## MCP Server Startup Pattern
73
+
74
+ ```python
75
+ import asyncio
76
+ import mcp.server.stdio
77
+
78
+ async def _run():
79
+ async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
80
+ await app.run(read_stream, write_stream, app.create_initialization_options())
81
+
82
+ asyncio.run(_run())
83
+ ```
84
+
85
+ `run_server()` does not exist in the installed MCP SDK — use the context manager above.
86
+
87
+ ---
88
+
89
+ ## Known Gotchas
90
+
91
+ - **music21 9.x: `part.id` is the part name** (e.g. `"Soprano"`), not the XML `<part id>`
92
+ attribute (`"P1"`). Callers must pass part names to `part_ids`, not XML IDs.
93
+ - **pyfluidsynth, not CLI.** Use `fluidsynth.Synth` with `audio.driver=file` +
94
+ `fluid_player_join()`. The `fluidsynth` CLI binary is not required.
95
+ - **`SYNTH_SOUNDFONT_PATH` must be set for synthesis.** Warn at server startup if missing —
96
+ don't crash, but synthesis calls will fail with a clear error.
97
+ - **Running tests:** `VIRTUAL_ENV=` prefix prevents uv from picking up the wrong venv.
98
+
99
+ ---
100
+
101
+ ## Claude Desktop Config
102
+
103
+ ```json
104
+ {
105
+ "mcpServers": {
106
+ "synth": {
107
+ "command": "uv",
108
+ "args": ["--directory", "/path/to/synth-mcp", "run", "synth-mcp"],
109
+ "env": {
110
+ "SYNTH_SOUNDFONT_PATH": "/usr/share/sounds/sf2/TimGM6mb.sf2"
111
+ }
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Document Update Policy
120
+
121
+ When you finish work or reach a milestone, update:
122
+ 1. `docs/HANDOVER.md` — check off done items, add new gotchas
123
+ 2. `docs/PLAN.md` — check off phase items, note changed decisions
124
+ 3. `docs/requirements.md` — update if behaviour changed
125
+ 4. `docs/architecture.md` — update if implementation changed
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: synth-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server that synthesizes audio from MusicXML with selectable voice parts and tempo control
5
+ Project-URL: Homepage, https://github.com/raulkivi/music-assistant
6
+ Project-URL: Repository, https://github.com/raulkivi/music-assistant
7
+ Project-URL: Bug Tracker, https://github.com/raulkivi/music-assistant/issues
8
+ Author-email: Raul Kivi <raulkivi@users.noreply.github.com>
9
+ License: MIT
10
+ Keywords: audio,choir,fluidsynth,mcp,music,musicxml,synthesis
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: End Users/Desktop
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Multimedia :: Sound/Audio :: MIDI
19
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Sound Synthesis
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: mcp>=1.0.0
22
+ Requires-Dist: music21>=9.0.0
23
+ Requires-Dist: pyfluidsynth>=1.3.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
26
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
@@ -0,0 +1,126 @@
1
+ # synth-mcp
2
+
3
+ MCP server that synthesizes audio from MusicXML. Supports voice part selection (Soprano, Alto, Tenor, Bass) and tempo control.
4
+
5
+ ## What it does
6
+
7
+ Takes a MusicXML score, optionally filters to one or more voice parts, and renders a WAV audio file using FluidSynth. Useful for choir singers who want to practice a specific voice part.
8
+
9
+ ## Tools
10
+
11
+ | Tool | Description |
12
+ |------|-------------|
13
+ | `get_parts` | List all voice parts in a score — returns part name, ID, and measure count |
14
+ | `synthesize` | Render the score (or selected parts) to a WAV file, with optional tempo adjustment |
15
+ | `list_capabilities` | Return server metadata: backend version, soundfont status, FluidSynth availability |
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ cd synth-mcp
21
+ uv sync
22
+ ```
23
+
24
+ System library required:
25
+
26
+ ```bash
27
+ # Ubuntu / Debian
28
+ sudo apt install libfluidsynth-dev
29
+
30
+ # macOS
31
+ brew install fluid-synth
32
+ ```
33
+
34
+ A soundfont (SF2) file is also required. Free options:
35
+
36
+ | Soundfont | Size | Notes |
37
+ |-----------|------|-------|
38
+ | TimGM6mb | ~6 MB | Ships with Ubuntu (`/usr/share/sounds/sf2/TimGM6mb.sf2`) |
39
+ | MuseScore General | ~200 MB | Better quality; download from musescore.org |
40
+ | GeneralUser GS | ~30 MB | Download from schristiancollins.com |
41
+
42
+ ## Running
43
+
44
+ ```bash
45
+ SYNTH_SOUNDFONT_PATH=/usr/share/sounds/sf2/TimGM6mb.sf2 uv run synth-mcp
46
+ ```
47
+
48
+ ## Configuration
49
+
50
+ | Variable | Required | Description |
51
+ |----------|----------|-------------|
52
+ | `SYNTH_SOUNDFONT_PATH` | Yes | Path to an SF2 soundfont file |
53
+
54
+ ## Claude Desktop configuration
55
+
56
+ ```json
57
+ {
58
+ "mcpServers": {
59
+ "synth": {
60
+ "command": "uv",
61
+ "args": ["--directory", "/absolute/path/to/synth-mcp", "run", "synth-mcp"],
62
+ "env": {
63
+ "SYNTH_SOUNDFONT_PATH": "/absolute/path/to/soundfont.sf2"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## Usage examples
71
+
72
+ ```json
73
+ // List parts in a score
74
+ {"tool": "get_parts", "arguments": {"musicxml": "<score-partwise>...</score-partwise>"}}
75
+
76
+ // Synthesize the full score
77
+ {
78
+ "tool": "synthesize",
79
+ "arguments": {
80
+ "musicxml": "<score-partwise>...</score-partwise>",
81
+ "output_path": "/tmp/full.wav"
82
+ }
83
+ }
84
+
85
+ // Synthesize Soprano part only at 80% tempo
86
+ {
87
+ "tool": "synthesize",
88
+ "arguments": {
89
+ "musicxml": "<score-partwise>...</score-partwise>",
90
+ "output_path": "/tmp/soprano.wav",
91
+ "part_ids": ["P1"],
92
+ "tempo_factor": 0.8
93
+ }
94
+ }
95
+ ```
96
+
97
+ `tempo_factor` range: 0.25–4.0. Values below 1.0 slow down; above 1.0 speed up. Does not affect pitch.
98
+
99
+ ## Testing
100
+
101
+ ```bash
102
+ # Unit tests (no soundfont required)
103
+ VIRTUAL_ENV= .venv/bin/pytest tests/ -v
104
+
105
+ # Integration tests (synthesizes real audio)
106
+ VIRTUAL_ENV= SYNTH_SOUNDFONT_PATH=/usr/share/sounds/sf2/TimGM6mb.sf2 \
107
+ .venv/bin/pytest tests/ -v -m integration
108
+ ```
109
+
110
+ ## Dependencies
111
+
112
+ - [music21](https://web.mit.edu/music21/) — score parsing and MIDI export
113
+ - [pyfluidsynth](https://github.com/nwhitehead/pyfluidsynth) — Python bindings for FluidSynth
114
+ - [mcp](https://github.com/modelcontextprotocol/python-sdk) — MCP protocol
115
+
116
+ ## Known limitations
117
+
118
+ - music21's MIDI export may drop some articulations and dynamics
119
+ - Audio output is always WAV; convert with `ffmpeg -i out.wav out.mp3` if needed
120
+ - Large scores (100+ measures) may take several seconds to synthesize
121
+
122
+ ## System requirements
123
+
124
+ - Python 3.11+
125
+ - `libfluidsynth` shared library (`libfluidsynth.so.3` on Linux)
126
+ - An SF2 soundfont file