Skip to content

Add MCP stdio server for programmatic stem separation - #6

Merged
setoelkahfi merged 4 commits into
mainfrom
feature/mcp-stdio-server
Oct 6, 2026
Merged

setoelkahfi merged 4 commits into
mainfrom
feature/mcp-stdio-server

Conversation

@setoelkahfi

Copy link
Copy Markdown
Collaborator

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 support
    • list_models — reports available models with cached/downloadable status
    • Requests are serialized one-at-a-time; stdout is reserved for protocol output only
  • demucs-cli/src/separate.rs (new) — Shared separation pipeline extracted from main.rs:
    • SeparateRequest / SeparateOutput types
    • ModelCache for model discovery and loading
    • Reporter trait for progress callbacks (used by both CLI and MCP)
    • select_stems and default_output_dir helpers
  • demucs-cli/src/main.rs (modified) — Slimmed to use separate_file + ModelCache; added --mcp flag; input argument now optional
  • demucs-cli/src/download.rs (modified) — Takes &dyn Reporter; progress bar hidden in MCP mode; manual chunked read with progress callbacks
  • demucs-cli/tests/mcp_stdio.rs (new) — 8 integration tests:
    • initialize/ping handshake
    • protocol version fallback for older clients
    • tool schema validation (tools/list)
    • list_models reports cached flag
    • unknown method returns -32601
    • missing file returns tool error
    • relative input path is rejected
    • every stdout line is valid JSON
  • demucs-cli/Cargo.toml — Added serde + serde_json dependencies
  • README.md — Added MCP server usage section

Verification

  • 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 in demucs-core are unrelated)

Co-Authored-By: siGit Code v1.6.2-acp noreply@sigit.si

setoelkahfi and others added 4 commits July 4, 2026 04:44
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>

@sigit-code-review sigit-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@setoelkahfi setoelkahfi self-assigned this Oct 6, 2026
@setoelkahfi
setoelkahfi requested a review from paydii October 6, 2026 16:47
@setoelkahfi
setoelkahfi merged commit 6ee331c into main Oct 6, 2026
7 checks passed
@setoelkahfi
setoelkahfi deleted the feature/mcp-stdio-server branch October 9, 2026 22:39
setoelkahfi pushed a commit that referenced this pull request Oct 11, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants