Skip to content

Studio: one-command MCP setup, recipe prompts, a model catalog and tool annotations - #14077

Merged
danielhanchen merged 49 commits into
unslothai:mainfrom
Etherll:feat/mcp-setup-prompts-catalog
Oct 19, 2026
Merged

danielhanchen merged 49 commits into
unslothai:mainfrom
Etherll:feat/mcp-setup-prompts-catalog

Conversation

@Etherll

@Etherll Etherll commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Includes #14072 (Studio: audio.cpp models land on the right pages); review this PR's own commits from 4d58b31 on. git diff e1d6db49bc HEAD (the #14072 head) shows only this PR's changes; the merge commit just brings #14072 up to date.

Summary

Connecting an agent to the Unsloth Studio MCP server meant copying a per-agent command from MCP.md, and the documented Claude Code command expanded $UNSLOTH_API_KEY in the shell, so the key itself was written into ~/.claude.json. Agents also had no way to see which image, video or audio models they could download, or whether one would fit on the GPU. This adds a setup command, a connection check, a download catalog in list_models, and two recipe prompts.

Changes

unsloth mcp add {claude-code,codex,cursor,generic} writes the agent's MCP entry. The entry names an environment variable (UNSLOTH_API_KEY by default, --env-var to change it) in the Authorization header, and the command never reads, prints or writes the key.

  • It uses --url, then UNSLOTH_STUDIO_URL, then a running Unsloth Studio on this machine, then http://127.0.0.1:8888.
  • Claude Code goes through claude mcp add --scope user when claude is on PATH, otherwise it edits ~/.claude.json directly. Codex gets a [mcp_servers.unsloth-studio] table with tool_timeout_sec = 300, and the edit is refused if any other TOML setting would change. Cursor gets ~/.cursor/mcp.json with ${env:UNSLOTH_API_KEY}. generic prints a JSON snippet, or merges it into --output.
  • --dry-run prints just the entry it would write and writes nothing. It never prints the old entry it would replace, since one written by hand may hold a key. Re-running with the same arguments reports "unchanged". New config files are created with mode 0600, and existing files keep their mode.

unsloth doctor --mcp [--env-var NAME] checks that Unsloth Studio answers, that the key is accepted, and that /mcp/ is on (it tells "turned off" apart from "this Unsloth Studio predates MCP"). It warns, without failing, when a configured Codex or Claude Code tool timeout is under 240 s. Plain --mcp skips the GPU checks; --mcp --gpus runs both.

list_models(source="catalog") lists image, video and audio models Unsloth Studio can download. Audio rows are forwarded from the audio.cpp catalog route in #14072 (/api/inference/audio/catalog), rather than importing its builder, so they stay filtered per account like every other MCP call. Image and video rows come from a new GET /api/inference/media/catalog, built from the diffusion and video family registries, filtered to what the calling account may load, and limited to the video families this device can run (as on the Video page). Catalog rows carry size_bytes (decimal bytes), low_vram (a video family's GGUF repo) and fits_now, which compares the size against the free memory of the single GPU with the most free memory, or is null when either value is unknown. The default source="local" output is unchanged.

LLM rows in list_models(source="catalog") are a possible follow-up pending a maintainer decision. For now the docstring tells agents to list downloaded LLMs with the default source or load a Hugging Face id.

The MCP server now offers two prompts, which Claude Code shows as slash commands:

  • make_short_film(idea, length_seconds) reads free GPU memory, loaded models and the video, music and voice catalog rows that fit now, then lists the calls from load_model through generate_video, get_job and generate_audio.
  • build_dataset_and_train(goal, base_model) reads the downloaded LLMs and lists the dataset, Data Recipe, start_training and export_model calls.

Both fall back to plain steps when Unsloth Studio can't be read, and the rendered text is capped at 4000 characters.

MCP.md gets a "One command" section for mcp add and doctor --mcp, the catalog in the list_models row, and a Prompts section. The hand-written Claude Code commands now single-quote ${UNSLOTH_API_KEY} and use --scope user, so the key stays out of ~/.claude.json.

Tool annotations (titles, idempotentHint, destructiveHint on load_model) will land as a final commit after the other MCP PRs merge.

Testing

New tests: unsloth_cli/tests/test_mcp_add.py, unsloth_cli/tests/test_doctor_mcp.py, studio/backend/tests/test_mcp_prompts.py, studio/backend/tests/test_media_catalog.py, and catalog cases in studio/backend/tests/test_mcp_tools_models.py. test_mcp_no_host_paths.py also runs list_models(source="catalog"), and the list_models schema row in test_mcp_server.py is now a superset check, so it accepts source.

  • unsloth_cli/tests/: 2084 passed, 4 skipped. The 1 failure, test_studio_update_verify.py::test_a_no_torch_install_keeps_that_mode_in_the_reinstall, fails the same way on the Studio: audio.cpp models land on the right pages #14072 head.
  • studio/backend/tests/test_mcp_*.py plus the media and audio.cpp catalog tests: 1708 passed, 3 skipped (fastmcp 3.4.8). The MCP, catalog and prompt files also pass on fastmcp 3.2.4. FastMCP.prompt(title=) exists back to the 3.0.2 floor.
  • Leak tests: a dry run over configs holding literal keys (any Bearer spelling, other headers, args, TOML bearer_token in any quoting, multi-line strings, another server's token) prints none of them, across 56 probe cases. Another test sets UNSLOTH_API_KEY to a canary and checks stdout, every written file and the claude argv for all four agents, with and without --dry-run.
  • fits_now is covered for a stubbed 24 GB and 12 GB card (Wan2.2-TI2V-5B, 24.2 GB, fits only the first), the GiB/GB boundary, and two GPUs (the max counts, not the sum).
  • Negative controls: unsloth doctor --no-gpus output is byte-identical to the Studio: audio.cpp models land on the right pages #14072 head, and doctor --help only gains the --mcp line. Dumping every MCP tool's schema, description and annotations before and after shows only list_models changed.

Against a running Unsloth Studio (no model loaded):

  • unsloth doctor --mcp with a valid key printed "API key: set, accepted", "MCP endpoint: on" and "Verdict: OK", exit 0. With a wrong key it printed "set, refused" and exit 1. The key appeared in neither output.
  • mcp add claude-code, codex and cursor, each run twice in a sandboxed home, wrote once and then reported "unchanged". --dry-run printed the diff and wrote nothing, and every created file was mode 600. claude mcp get and codex mcp get read the entries back with the env var name, not a key.
  • Claude Code 2.1.302 expands ${UNSLOTH_API_KEY} in a user-scope header when it connects, so the entry mcp add claude-code writes authenticates.
  • A no-context Claude Code agent with only this MCP server, asked to plan a 20 s film with music and a voice-over for one 24 GB GPU, called studio_status, then list_models(source="catalog") for video, audio and TTS. It picked unsloth/Wan2.2-TI2V-5B-GGUF (a low_vram row), Stable-Audio-3-Medium-GGUF (3.6 GB) and Qwen3-TTS-12Hz-1.7B-VoiceDesign-GGUF (2.8 GB). That took 6 tool calls with no errors. The full catalog is 130 rows (33 KB) and returns in 0.09 s.
  • prompts/list and prompts/get for both prompts work over HTTP with live GPU and catalog data.

Etherll and others added 7 commits October 17, 2026 12:35
A model family that Unsloth Studio's tables don't list now lands on every
Audio page its runtime spec allows, not just the first task: a spec with
tts and clone shows on Text to Speech and Clone (fish_drama3, kitten_tts2),
sep on Separate, asr on Transcribe, music/sfx on Music with a conservative
music setup. Voice conversion stays limited to the families Unsloth Studio
already configures. mira_tts and sopro_tts are Clone only, since they need a
reference on every run. The default variant follows the spec's
recommended_package, and K/IQ quants rank after the established order.

GET /api/inference/audio/catalog lists every umbrella folder (300 s TTL,
saved last-good listing, HF-cache fallback) plus Community repos named by
the runtime's model specs. The Audio pages use one pageModels() resolver
and show a "More models" group in the existing picker, with the pages,
languages and status in the row tooltip and the size in the size column.
The nightly catalog check warns on a new folder instead of failing.

MCP: list_models takes a workflow filter, generate_audio takes model, and
the switch guard names the pages a model runs on.
…tor --mcp checks the connection

unsloth mcp add {claude-code,codex,cursor,generic} points the agent at the
Unsloth Studio MCP server with an Authorization header that names an env var;
the key itself is never read, printed or written. Created files are 0600,
re-runs change nothing, and --dry-run prints the diff.

unsloth doctor --mcp checks that Unsloth Studio answers, the key works, MCP is
on, and advises when an agent's tool timeout is under 240 s.
…dels an agent can download

Audio rows come from the audio.cpp catalog route; image and video rows from a
new account-filtered /api/inference/media/catalog built from the family
registries. Rows carry size_bytes, low_vram and fits_now (one GPU's free
memory, decimal GB). LLM rows are not in the catalog.
Each prompt reads the live GPU memory, loaded models and catalog rows that fit,
then lays out the tool calls for the job. They fall back to plain steps when
Unsloth Studio can't be read.
…rompts in MCP.md

The hand-written Claude Code command now keeps ${UNSLOTH_API_KEY} unexpanded,
so the key no longer lands in ~/.claude.json.
…undtrack

The audio catalog also holds detectors and separators, and the smallest of
those crowded out music and speech models in the film recipe's candidates.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-18T13:28:29.348170Z 22e2a49 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Etherll and others added 7 commits October 17, 2026 13:17
- A catalog entry the backend could not place no longer hides a model the
  bundled seed already knows, so a degraded catalog (no runtime specs, late
  header probes) leaves every page as it was.
- A build whose family probe missed the deadline is cached for 30 s, not
  300 s; concurrent cold requests share one build; a spec package with an
  empty file list no longer fails the whole catalog.
- More models rows follow the picker's format and fit filters, show when
  the Recommended list is empty, and appear on Transcribe for catalog ASR
  models.
A More models row has no Hub pipeline tag, so a catalog ASR model picked
on Transcribe was treated as a speech model and loaded on Text to Speech.
The pick now carries the catalog's speech-recognition task.
…and film recipe to the device

Dry-run diffs and claude errors mask any literal key already in a config; the
Codex splice keeps comments about the next table; a non-object mcpServers or a
non-JSON --output is refused instead of overwritten; a failed claude add after
remove says the old entry is gone; doctor --mcp takes --env-var and only reads
timeouts for this Unsloth Studio's URL. The media catalog drops video families
the device can't run, and the film recipe asks for music and speak rows.
The picker's loading spinner and Hub failure hint replaced the whole list,
so catalog rows that were already available stayed hidden until the Hub
answered. Those states now apply only when neither list has rows.
…secrets masked

A whole-file diff could print any other server's token, and pattern masking
missed keys spelled differently. The dry run now diffs just the entry it
would write, masking every header, token and env value in the old one.
Masking an old hand-written entry kept missing keys in args, multi-line TOML
strings and unusual header names. The dry run now shows only the new entry,
which names an env var, and says when it replaces an existing one.
@Etherll

Etherll commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator Author

Status at f46a80001a: ready for review. This PR's own commits are 17 files, +2,327/−20 (git diff e1d6db49bc HEAD); the rest is #14072.

What changed since the PR opened:

  • unsloth mcp add --dry-run prints only the entry it would write. It never shows the entry it replaces, because one written by hand can hold a pasted key. It notes when an entry will be replaced.
  • A config whose mcpServers is not a JSON object is refused before anything is written, instead of being overwritten.
  • make_short_film only offers models for the step they're picked for (video for video, music and voice for the soundtrack), and only video families this device can run.

Checks on this head:

  • unsloth_cli/tests/test_mcp_add.py and test_doctor_mcp.py, plus a 56-case dry-run leak probe (lowercase bearer, other headers, stdio args, TOML bearer_token in every quoting, another server's token): 120 passed. None of the planted keys reach the output.
  • studio/backend/tests/test_mcp_prompts.py, test_media_catalog.py, test_mcp_tools_models.py, test_mcp_server.py, test_mcp_no_host_paths.py: 102 passed (fastmcp 3.2.4).
  • Codex on the mirror: two "Didn't find any major issues" in a row on this head.

Not in this PR:

  • Tool annotations (titles, idempotentHint, destructiveHint on load_model) come as a last commit once the other MCP PRs merge, so they don't conflict with tools those PRs add.
  • LLM rows in list_models(source="catalog") wait on a maintainer decision.
  • Codex flagged studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx:4146: rows that the audio catalog adds to the Recommended list skip the "Fits on device" toggle, so a GGUF too big for the device can still be picked. That code comes from Studio: audio.cpp models land on the right pages #14072, so it belongs there, not here.

…catalog rows

- More models rows now join the picker's roving option list after the
  recommended rows, in the order they are drawn. Before, each got the
  shared fallback option id and arrow keys could not reach them.
- When the backend read the installed runtime's own model specs, its
  catalog verdict decides which umbrella folders appear under More models,
  so a folder the static unoffered list holds back shows up once the
  runtime supports it. Without runtime specs the static list still applies.
… folder's spec

The audio catalog guessed a folder's family from its name when no runtime
spec placed it. Voxtral-4B-TTS reads as voxtral_realtime, whose spec places
the Voxtral Realtime folder, so on a runtime without voxtral_tts the TTS
folder was offered on Transcribe. A hint whose runtime spec places other
folders but not this one is now ignored, and the GGUF header decides.
@danielhanchen danielhanchen self-assigned this Oct 18, 2026
…mcp verdicts

Without tomllib or tomli the Codex config splice is line based, so refuse files
with multi-line strings or non-header lines starting with '[' instead of
cutting them. doctor --mcp now reports any non-2xx MCP answer other than
404/405/401 as an error, scrubs the key from every probe error (http.client
quotes a refused header value), and sends the CLI User-Agent like the health
probe.
@danielhanchen
danielhanchen merged commit 4bed2fa into unslothai:main Oct 19, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 19, 2026
…identity (unslothai#14178)

Hardening from the latest security scan, in `unsloth doctor --mcp`
(added in unslothai#14077).

**Problem.** When `UNSLOTH_STUDIO_URL` is not set, the MCP doctor finds
Unsloth Studio by probing local ports for the public `/api/health`
answer, then sends `UNSLOTH_API_KEY` as a bearer token to
`/api/inference/loaded-models` and `/mcp/`. `/api/health` is public, so
anything listening on that loopback port can answer it. On a shared
machine, another local user listening on 127.0.0.1:8888 while Studio is
stopped would receive the owner's API key. `unsloth chat` and `unsloth
start` already guard against this with `verify_studio_identity` (an HMAC
challenge only this machine's Studio can answer) before sending a
secret; the doctor skipped it.

**Change** (`unsloth_cli/commands/mcp.py`). For an auto-discovered
loopback server, the doctor calls `verify_studio_identity` first. If it
fails, the key is not sent to either endpoint and the doctor reports
`API key: set, not sent` with a hint to set `UNSLOTH_STUDIO_URL`.

- A normal local Studio passes the check, so the doctor's output is
unchanged.
- An explicit `UNSLOTH_STUDIO_URL` is still trusted as before (the user
named the server), which keeps SSH-tunnel setups working.
- Read-only and idempotent; no other command changes.

Tests (`unsloth_cli/tests/test_doctor_mcp.py`): a new case where the
found server fails the identity check asserts no `Authorization` header
reaches it, and that `UNSLOTH_STUDIO_URL` still sends the key; plus the
new hint. Both fail on main and pass here. The full `unsloth_cli/tests`
suite passes (2095 passed).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants