Repository navigation
Add MCP stdio server for programmatic stem separation - #6
Conversation
burn = { version = "0.20.1" } pulled in burn's default feature set, which
turns on burn-wgpu's fusion and autotune. On Apple mobile GPUs autotune
benchmarks every kernel shape on first inference and hangs the device.
Set default-features = false and keep only std. Everything demucs-core uses
(tensor, nn, module) lives in non-optional burn sub-crates, and callers that
want fusion or autotune already opt in through this crate's own features, so
desktop builds keep them.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Expose demucs as a Model Context Protocol (MCP) stdio server so AI agents and other clients can invoke stem separation via JSON-RPC 2.0. The server provides two tools: `separate_stems` (runs the full pipeline with progress notifications and cancellation support) and `list_models` (reports cached vs. downloadable models). Requests are serialized one-at-a-time. To support this, the separation pipeline is extracted from main.rs into a shared `separate.rs` module (SeparateRequest, SeparateOutput, ModelCache, Reporter trait), which both the CLI and MCP server consume. The downloader gains progress callbacks via Reporter, with progress bars suppressed in MCP mode. The CLI gains a `--mcp` flag to launch the server. Includes 8 integration tests covering initialize/ping, protocol fallback, tool schemas, list_models, unknown method, missing file, relative path rejection, and stdout-is-JSON-only. Co-Authored-By: siGit Code v1.6.2-acp <noreply@sigit.si>
There was a problem hiding this comment.
This change introduces an MCP stdio server for demucs, allowing programmatic stem separation via JSON-RPC 2.0. The new mcp.rs implements the server, handling requests for stem separation and model listing, with progress and cancellation support. The separation pipeline is refactored into separate.rs, which is now used by both the CLI and MCP server. The CLI (main.rs) is simplified, with an added --mcp flag and optional input argument. Download logic in download.rs now supports progress callbacks and disables the progress bar in MCP mode. Eight integration tests in tests/mcp_stdio.rs cover protocol, schema, error, and output correctness. The README documents MCP usage. All earlier findings appear addressed, and the new code is well-structured for both CLI and programmatic use.
Automated review by siGit Code Review · commit 236f15e · see the review dashboard
…ippy #6 set `default-features = false` on burn to stop burn-wgpu's autotune from hanging Apple mobile GPUs. Correct fix, but it had two side effects, since burn depends on burn-ndarray with default-features = false and only `burn/default` restores burn-ndarray's own defaults. - `demucs-core/ndarray` silently lost `simd` (and `multi-threads`). Add `burn/simd` to the feature. `multi-threads` has no passthrough on the burn facade and is not recoverable here; documented inline. - The test build could no longer validate the defaults-off config, because demucs-core's dev-dependency on burn re-enables `burn/default` crate-wide. Disabling defaults there fixes the blind spot but costs 3x on the suite (76s -> 207s) from losing rayon, so instead keep the dev-dependency as-is and add `cargo check -p demucs-core` steps to the CI lint job: `-p` excludes dev-dependencies, so those compile what consumers actually get. Separately, fix a pre-existing `clippy::collapsible_match` error in demucs-cli/src/progress.rs. It is unrelated to #6 — the code dates to a0bbef9 (Feb) and main has been red since a newer clippy started catching this pattern; main just had not run CI since March, so #6 was the first run to surface it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Summary
Exposes demucs as an MCP (Model Context Protocol) stdio server, enabling AI agents and other JSON-RPC 2.0 clients to invoke stem separation programmatically.
Changes
demucs-cli/src/mcp.rs(new) — MCP stdio server with JSON-RPC 2.0 handling, two tools:separate_stems— runs the full separation pipeline with progress notifications and cancellation supportlist_models— reports available models with cached/downloadable statusdemucs-cli/src/separate.rs(new) — Shared separation pipeline extracted frommain.rs:SeparateRequest/SeparateOutputtypesModelCachefor model discovery and loadingReportertrait for progress callbacks (used by both CLI and MCP)select_stemsanddefault_output_dirhelpersdemucs-cli/src/main.rs(modified) — Slimmed to useseparate_file+ModelCache; added--mcpflag;inputargument now optionaldemucs-cli/src/download.rs(modified) — Takes&dyn Reporter; progress bar hidden in MCP mode; manual chunked read with progress callbacksdemucs-cli/tests/mcp_stdio.rs(new) — 8 integration tests:tools/list)list_modelsreports cached flagdemucs-cli/Cargo.toml— Addedserde+serde_jsondependenciesREADME.md— Added MCP server usage sectionVerification
cargo build✅cargo test --test mcp_stdio✅ (8/8 passed)cargo fmt --check✅cargo clippy -p demucs-cli --tests -- -D warnings✅ (pre-existing clippy issues indemucs-coreare unrelated)Co-Authored-By: siGit Code v1.6.2-acp noreply@sigit.si