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

sheet-music-mcp / render-mcp

CLAUDE.md4 starsChanged 2 months agoMITView on GitHub

Last changed: 2026-11-26 · Source: https://github.com/raulkivi/sheet-music-mcp Renders MusicXML scores to PDF (for printing) or PNG (for display in web/mobile apps). Uses Verovio (in-process) + cairosvg + pypdf. No MuseScore CLI required. Status: Phase 1 + UX Waves 1–3 complete; MCP Apps pages built: Score Viewer (SVG and PDF download, part filter and highlight; app-only render_page_svg, get_pdf, read_pdf_chunk) and Setup Doctor. 284 unit tests (default run) + 13 integration. tests/test_packaging.py (integration) needs the UI built first: cd ../ui && npm ci…

  • Installs packages

The file

We split this CLAUDE.md into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    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 90
  2. Distinctive:

    MuseScore not installed: Don't check for or attempt to call any MuseScore CLI command.

    line 118
  3. Distinctive:

    When you finish work or reach a milestone, update:

    line 161

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

render-mcp — Claude Code Instructions

Last changed: 2026-11-26 · Source: https://github.com/raulkivi/sheet-music-mcp

What This Server Does

Renders MusicXML scores to PDF (for printing) or PNG (for display in web/mobile apps). Uses Verovio (in-process) + cairosvg + pypdf. No MuseScore CLI required.

Status: Phase 1 + UX Waves 1–3 complete; MCP Apps pages built: Score Viewer (SVG and PDF download, part filter and highlight; app-only render_page_svg, get_pdf, read_pdf_chunk) and Setup Doctor. 284 unit tests (default run) + 13 integration.


Running Tests

# From this directory
VIRTUAL_ENV= .venv/bin/pytest tests/ -v             # 284 unit tests (integration deselected)
VIRTUAL_ENV= .venv/bin/pytest tests/ -v -m integration  # Verovio runs in-process, always fast

tests/test_packaging.py (integration) needs the UI built first: cd ../ui && npm ci && npm run build && npm run copy-assets.

Install dependencies: uv sync


Key Files

FilePurpose
src/render_mcp/server.pyMCP tool definitions and handlers, Score Viewer registry
src/render_mcp/presenter.pyEngine result → content + structuredContent; output schemas
src/render_mcp/ui/assets/score-viewer.html, setup-doctor.htmlBuilt by ui/ (npm run copy-assets), gitignored
src/render_mcp/health.pyHealth checks mapped to the shared report (core health)
src/render_mcp/engine.pyVerovio + cairosvg rendering pipeline (no MCP imports)
src/render_mcp/utils.pyMusicXML 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
render_to_pdfMusicXML → multi-page PDF at caller-specified path
render_to_imageMusicXML → PNG or SVG, single page, configurable DPI
list_capabilitiesServer metadata, active backend, format support
health_checkRuntime dependency check; structuredContent health report, linked to ui://render/setup-doctor
describe_scoreShared (core) tool: parts with IDs, key, time, tempo, measures, duration — no rendering
render_page_svgApp-only (_meta.ui.visibility: ["app"]): one page of inline MusicXML as SVG for the Score Viewer when the host blocks WebAssembly; listed only for MCP Apps clients
get_pdf / read_pdf_chunkApp-only: the Score Viewer's PDF download. get_pdf(musicxml) writes a PDF under the output root and returns an opaque pdf_id; read_pdf_chunk(pdf_id, offset, length) returns base64 chunks (core artifacts). No paths in or out

render_to_pdf and render_to_image link ui://render/score-viewer (_meta.ui.resourceUri) when the HTML is packaged, declare an output_schema and return structuredContent; their content is unchanged (tests/test_content_golden.py).

Both render tools take the score as musicxml (inline) or musicxml_path (.musicxml, .xml, .mxl; exactly one). Paths are read via sheet_music_mcp_core.references.load_score(), confined to the output root, the client's roots and SHEET_MUSIC_INPUT_ROOTS (UX Wave 2, score references). Both also take an optional measures: [start, end] (printed bar numbers, inclusive; UX Wave 3): the engine cuts the score with sheet_music_mcp_core.measures.select_measures() before backend dispatch, so MuseScore and Verovio render the same bars.


Environment

  • Backend: Verovio (MusicXML → SVG, in-process Python) + cairosvg (SVG → PNG/PDF) + pypdf (merge pages)
  • System dep: libcairo.so.2 — installed system-wide on Ubuntu, no sudo needed
  • No MuseScore CLI — do not attempt to invoke mscore4/musescore4
  • MXL fixtures: ../omr-mcp/test_samples/pdmx_satb_samples/mxl/ (10 SATB files)

Hard Rules

  • Never pip install — use uv sync --extra dev (pytest is a dev extra) or uv add
  • Never open a score path yourself — use references.load_score(); output paths go through confine_output_path (re-exported from sheet_music_mcp_core.paths in utils.py)
  • engine.py must not import from mcp — keeps it unit-testable
  • All tool handlers must be async def
  • All errors → {"error": "...", "error_code": "..."} (codes: INVALID_INPUT, PROCESSING_FAILED, INVALID_PARAMETER, FILE_NOT_FOUND)
  • 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

  • cairosvg DPI with Verovio SVGs. Verovio emits SVGs with fixed pixel dimensions — the dpi kwarg in cairosvg.svg2png(dpi=...) has no effect. Use scale=dpi/96.0 instead (96 px/in is the CSS reference density).
  • Multi-page PDF: each SVG page is converted to a single-page PDF via cairosvg, then merged with pypdf. Single-page scores skip the merge step.
  • MuseScore not installed. Don't check for or attempt to call any MuseScore CLI command.
  • Schema oneOf, not required. The render tools have no required list; musicxml / musicxml_path are an exactly_one pair. A direct call_tool with neither now returns INVALID_PARAMETER (from load_score) rather than INVALID_INPUT.
  • Measure ranges are cut in the engine, not the backends. render_to_pdf / render_to_image apply select_measures before dispatch; keep the _render_* functions unaware of ranges. The server passes measures only when given, so default engine calls keep their old signature. page counts pages of the cut score. Bad ranges are INVALID_PARAMETER with a hint ("This score has measures A–B."); the render handlers use processing_error_content so the hint survives.
  • call_tool vs call_tool_result. The server wires call_tool_result(); call_tool() returns its content only (older tests index it as a list). Render errors are isError.
  • Tests never see a local UI build. tests/conftest.py swaps server.ui_registry for in-memory assets; the packaged_ui fixture gives the linked case.
  • Layout parity. engine.page_layout() mirrors ui/packages/kit/src/score/paging.ts layoutFor() (JS rounding); both are checked against ui/packages/kit/src/score/layout-cases.json.
  • Verovio reads almost anything. Validate with validate_musicxml() before the engine.
  • Verovio's resource path is per thread. render_page_svg renders in a worker thread (asyncio.to_thread, one at a time behind a lock); engine._verovio_toolkit() sets the resource path itself, or a toolkit made off the importing thread finds no fonts.
  • Integration tests need the omr-mcp samples. They read ../omr-mcp/test_samples/pdmx_satb_samples/mxl/; without that folder they fail with "Fixture dir not found".

Claude Desktop Config

{
  "mcpServers": {
    "render": {
      "command": "uv",
      "args": ["--directory", "/path/to/render-mcp", "run", "render-mcp"]
    }
  }
}

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.