Skip to content

Studio: per-tool MCP switches at the end of Settings > Agents - #15629

Merged
danielhanchen merged 20 commits into
unslothai:mainfrom
Etherll:studio/mcp-agents-tools
Nov 8, 2026
Merged

danielhanchen merged 20 commits into
unslothai:mainfrom
Etherll:studio/mcp-agents-tools

Conversation

@Etherll

@Etherll Etherll commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Replaces #14348, with the same final code as one commit on current main. It includes the fixes Daniel made there, and he is credited as co-author.

Summary

Unsloth Studio's MCP server serves 23 tools. With all of them on, an agent spends about 18k tokens on tool definitions before it does anything. This PR lets the owner choose which tools agents can see.

Everything lives at the end of Settings > Agents, under an "Unsloth MCP" heading, so the name "MCP" stays free for a future tab that manages MCP servers:

  • The "Agent access (MCP)" switch and the setup snippet, which used to sit in Settings > API.
  • A new Tools row ("20 of 23 on") with a Choose tools button that opens the tools dialog.
  • Settings > API keeps a one-line "Agent access (MCP)" row in "Access & monitoring". It shows On or Off and has an Open in Agents link that jumps to the section.

Settings > Agents, Unsloth MCP section

Settings > API, Access & monitoring

The tools dialog

The first version had a switch per tool and per group, 28 in all. It read as a wall of switches, and a group switch showed off when only some of its tools were off. The dialog now works like the Hub filter:

  • Each tool is a pill with an icon and a name. On is the stronger fill with a tick; off is the lighter fill with muted text and no tick, so the tick carries the state, not color. Clicking the pill toggles the tool.
  • Each group, and the whole list under All tools, gets one row that reads "7 of 8 on" and ends in Select all, or Select none once every tool in it is on. The whole row is the button.
  • The description says why to turn tools off: every tool left on adds to what agents read before they start.
  • Hovering a tool says what it does, with the raw tool name under it.
  • Three columns fit every group without scrolling at a normal window height. On a short window the list scrolls between a fixed header and footer, and a rule shows above Done while more is below. Narrow windows drop to two columns, then one.
  • A change shows at once. The dialog no longer greys out while each save runs; a reply that arrives after a newer change is ignored, and a rejected change still resyncs and shows the error.

Tools dialog, light

Tools dialog, dark

Short window and phone width

Tools dialog, short window

Tools dialog, phone width

Behavior

  • Every tool is on by default, including tools added by a later update. The choice covers the whole installation and every API key.
  • A tool that is off is left out of tools/list. A call to it fails with [tool_disabled] <tool> is turned off in Unsloth Studio. The owner can turn it on in Settings > Agents.
  • The make_short_film and build_dataset_and_train prompts are hidden while a tool they read (studio_status or list_models) is off.
  • GET /api/settings/mcp-access adds tools: [{name, area, enabled}].
  • PUT accepts {tool_states: {"<tool>": true|false}}. The server merges that into the stored list, so two windows toggling different tools both keep their change. The dialog only ever sends the tools that change. {disabled_tools: [...]} still replaces the whole list. An unknown tool name returns 422.
  • UNSLOTH_STUDIO_ENABLE_MCP=1 locks only the access switch, not the tool choice.
  • If the stored list can't be read, every tool counts as off, the same way the access switch fails closed.
  • Agents read the tool list when they connect. An agent that is already connected keeps showing a tool that was turned off until it reconnects, but its calls to that tool are refused right away.

studio/MCP.md documents the tool choice, and unsloth doctor now points at Settings > Agents.

Testing

cd studio/backend
python -m pytest tests/test_mcp_*.py tests/test_settings*.py
cd ../.. && python -m pytest unsloth_cli/tests/test_doctor_mcp.py
cd studio/frontend
npm run typecheck && npm run i18n:check:strict && npm test && npm run build && npm run bundle:check
  • Backend: unchanged by the dialog redesign. 2,146 passed. 3 tests in test_mcp_images.py fail here and also fail on main at a595688.
  • CLI: test_doctor_mcp.py, 30 passed.
  • Frontend, on this head: typecheck clean, i18n:check:strict passes for every locale, and the MCP, settings, API-key and agents tests pass (175). Each of the four redesign commits typechecks and passes those tests on its own.
  • Bundle: within budget (168.7 KB transfer to spare). The new strings are in the eager English catalog; the Agents panel and the dialog load lazily.
  • In the browser: a group row goes "0 of 3 on · Select all" → "3 of 3 on · Select none" → back; All tools does the same for every tool; Tab and Space work on the chips, and the dialog opens without focusing a control, so Enter can't flip a group by accident.

The tool descriptions and the new dialog strings in the 24 non-English locales were written without a native speaker and would benefit from a native read.

Studio UI regression check

Base 073f6e0cc vs head 069a35528. Functional: NO_REGRESSION, UI coverage 82%, 1 visual change(s), 2 text-only change(s). Only steps whose screenshots differ are shown.

settings/s06_tab_api: | reproduced on confirm (VISUAL_DIFF)
settings/s06_tab_api

Step Text / structure change
settings/s10_tab_agents {'removed': [], 'added': ['Unsloth MCP', 'Agent access (MCP)', 'Let coding agents […] use Unsloth over MCP.', '23 of 23 on', 'Choose t
crawl/r_export

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T15:12:08.379091Z 761e71f 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.

Lets the owner choose which of Unsloth Studio's MCP tools agents can see.
The Agent access (MCP) switch and setup snippet move to the end of
Settings > Agents, under an "Unsloth MCP" heading, with a Tools row
("20 of 23 on") that opens a dialog. The dialog groups the tools (Models,
Generate, Training and export, Data and library, Jobs) with one switch per
tool, one per group, and Turn all on. Settings > API keeps a one-line link
to it.

A tool that is off is left out of tools/list and calls to it are refused.
Saves send only the changed tools (tool_states) and the server merges them,
so two windows toggling different tools both keep their change.

Co-authored-by: Daniel Han <[email protected]>
@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Tested at d285df0ef4 (your merge of main since then only changes the bundle-budget numbers) and it does what it says. On a Colab T4 (Linux) I booted Unsloth Studio from main and from this branch, loaded Qwen3-1.7B-GGUF, and pointed a real MCP client at /mcp with an owner API key. With Chat turned off, tools/list drops to 22, a chat call comes back [tool_disabled], and turning off Status also hides both prompts. Turning them back on restores everything. Main still lists 23 and answers, as expected. The Choose tools dialog saved the switch and it survived a reload.

On a Mac (macOS 26) the backend MCP and settings suites pass with the same 9 unrelated failures as main, and typecheck, build and bundle:check are clean. i18n:check:strict fails, but identically on main (the trainingApi keys). I also threw malformed stored lists at it (non-list, corrupt JSON, duplicates, unknown names, 200k entries), 23 parallel toggles, and the env-forced switch. Unreadable data fails closed, every toggle lands, and missing data on an upgrade means everything's on.

Settings > API: the MCP section moves out, a status row stays

Before

Before: Settings > API holds the Agent access (MCP) switch, agent picker and setup snippet

After

After: Settings > API shows Agent access (MCP), On, with Open in Agents

Settings > Agents: the new Unsloth MCP section at the end

Before: Agents ends at "Preview without launching".

Before: Settings > Agents ends at Preview without launching

After: the access switch, the new Tools row, the snippet and a link to create a key.

After: Unsloth MCP section with Agent access on, Tools 23 of 23 on, Choose tools

Turning a tool off: Choose tools, flip Chat

All on Chat off
Generate group 8/8, every switch on Generate group 7/8, Chat off

The Tools row then reads 22 of 23:

Tools: 22 of 23 on

Two small things, neither blocking:

  1. The switch picks what agents see over MCP, but the same API key can still call the REST routes behind a turned-off tool (with Chat off, /v1/chat/completions answered fine). Worth one sentence in MCP.md and the dialog so nobody reads it as a permission.
  2. A stored list made only of non-strings (say [123]) reads as every tool on. It's pinned by test_non_string_and_stale_names_are_ignored_on_read and junk can't name a tool, so I'd leave it; just flagging it since an earlier review raised it.

Nits: the null-tools comments in routes/settings.py and mcp-access.ts don't match when it's actually null, and the bundle-budget comment still cites #14348 and a5956882f6.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Codex is clean at 68c0a3be46 (the current head, with main merged in): no findings on the review mirror, LeoBorcherding#647. CI is still queued on this head.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 68c0a3be46

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
Etherll and others added 5 commits November 4, 2026 04:12
A description key per catalog tool, null for a tool this build doesn't know.
The 28 switches read as a wall, and a group switch looked off when only some of
its tools were. Tools are now pills like the Hub filter: on is the stronger
fill with a tick, off the lighter fill with muted text. Each group and the whole
list get one row that reads "7 of 8 on" and ends in Select all or Select none.
Three columns fit every group without scrolling, and a rule shows above Done
when the list does scroll. Hover says what a tool does above its raw name.

Changes flip at once instead of disabling the dialog while each save runs; a
late reply can't undo a newer change, and a rejected one still resyncs.
turnAllOn and groupToggle, in every locale.
@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Tested the new tools dialog (9fc6914f7b) in Unsloth Studio, and it works. Tool switches save right away and survive a reload. Select none / Select all work per group and for all tools, and the count on the Tools row keeps up. Nothing broken found.

Setup: Colab T4 (15 GB, driver 580.82.07), Ubuntu 24.04.4, headless Chromium 156 driven with Playwright on the VM against localhost.

  • Before = 073f6e0cc7, this PR's merge base with main.
  • After = 39681f0825, which is 9fc6914f7b plus one non-visual commit on our review mirror that sends tool changes one at a time.

Before and after were separate frontend builds on separate ports, sharing one Unsloth Studio home. Captured at 2x, light and dark.

Settings > Agents: the new Unsloth MCP card at the end

Before: Agents ends at Preview without launching. After: an Unsloth MCP card with Agent access, Tools 23 of 23 on, Choose tools, and the setup snippet

The tools dialog: all on, then with Generate video, Start training and Export model off. Groups that are partly on switch their action to Select all.

Unsloth MCP tools dialog, all on vs three tools off

Hovering a tool shows what it does, with the raw tool name under it:

Tooltip on Export model

Settings > API: the full MCP section becomes one status row that links to Agents.

Before: full Agent access section. After: Agent access (MCP), On, Open in Agents

Dark mode Agents, dark Tools dialog, dark Tooltip, dark Settings > API, dark

What I checked (in the UI, plus GET /api/settings/mcp-access after each step)

step result
Turn off Generate video, Start training, Export model, close, reload 20 of 23 on; the same 3 are off in the dialog and on the server
Models: Select none, then Select all all 6 off (survives a reload), then all 6 on; the label flips each time
Generate (7 of 8): Select all Generate video back on, 8 of 8
All tools: Select all / Select none 23 on, then 0 on, and the server and the Tools row agree
Click Chat five times fast ends off in the UI, on the server, and after a reload (this exercises our mirror's ordering commit, not 9fc6914f7b alone)
Settings > API, Open in Agents lands on Agents with the card in view

Not tested:

  • Unsloth Desktop
  • narrow windows
  • keyboard-only use
  • RTL locales
  • a non-owner account
  • a real MCP client against this head (the agent-side checks ran on d285df0ef4)

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to Etherll/unsloth that referenced this pull request Nov 7, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: f04b7aacea

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 761e71f362

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit to Etherll/unsloth that referenced this pull request Nov 8, 2026
@danielhanchen
danielhanchen merged commit decd94a into unslothai:main Nov 8, 2026
danielhanchen added a commit that referenced this pull request Nov 8, 2026
Replaces #14349, with the same final code as one commit. It is stacked
on #15629, so merge that first. Until then this diff also shows #15629's
changes, and only the last commit is new. It includes the fixes Daniel
and Nilay made on #14349, and both are credited as co-authors.

## Summary

This PR adds an **Unsloth** preset at the top of the chat MCP dropdown.
Ticking it lets the chat model call Unsloth Studio's own MCP tools in
process, with no API key to paste and no network listener.

![Chat MCP
dropdown](https://raw.githubusercontent.com/Etherll/unsloth/ui-evidence/chat-unsloth-tools-15155c54/b-chat-mcp-menu.png)

- **Which tools the chat gets:** only the tools the owner left on in
Settings > Agents > Choose tools, minus the ones that would evict or
re-enter the chat that calls them: `chat`, `load_model`, `unload_model`,
`cancel`, `start_training`, `export_model` and `run_recipe`
(`CHAT_DENYLIST` in `mcp_server.py`). The tools dialog names those once,
in a note under the groups.
- **Toggles apply right away:** the row's tools are re-listed on every
send, so a change in Settings applies to the next message.
- **External agent access is unaffected:** it works whether or not
"Agent access (MCP)" is on, and `/mcp` still returns 404 while that is
off.

![Tools dialog
note](https://raw.githubusercontent.com/Etherll/unsloth/ui-evidence/chat-unsloth-tools-15155c54/b-note-crop.png)

## Safety

- **Per-call key:** each tool call runs as the chat's own account, with
an internal API key minted for that call. The key is deleted when the
call ends, including on Stop, timeout and error.
- **No host files:** host file paths are refused for these calls, even
for the owner.
- **Who can turn it on:** only a signed-in UI session can add the row or
point another row at it. API keys and keyless callers get 403, and
keyless callers never see the row.
- **Stop:** a chat Stop also stops the image, audio or video job a tool
call started.
- **Model switches:** a chat tool call never switches the loaded model.
- **Media links:** links open through the user's session, so they work
in the desktop app and behind a proxy path prefix.

## Testing

```bash
cd studio/backend
python -m pytest tests/test_studio_tools_chat.py tests/test_mcp_*.py tests/test_settings*.py tests/test_systemone_connections.py tests/test_research_internal_key_monitor.py tests/test_fine_tuned_model_serving.py tests/test_openai_tool_passthrough.py
cd ../frontend
npm run typecheck && npm run i18n:check:strict && npm test && npm run build && npm run bundle:check
```

- **Backend:** 2,237 passed, plus 499 in the model-switch and
tool-passthrough files. The same 3 `test_mcp_images.py` tests fail here
and on main.
- **Frontend:** typecheck clean, `i18n:check:strict` passes, and the
settings, MCP and chat-composer tests pass (871).
- **Bundle:** within budget. The budget grows by +1,363 B raw / +366 B
transfer over #15629, from the chat preset and the note.

I also ran Unsloth Studio from this branch to check the dropdown and the
dialog note.

<!-- studio-regress:start -->
### Studio UI regression check
Base `81dc73ac4` vs head `fe799ee49`. Functional: **NO_REGRESSION**, UI
coverage 83%, 1 visual change(s), 5 text-only change(s). Only steps
whose screenshots differ are shown.

Note: in this run diffusion_video failed once on head inside the
regression harness's own fixture copy (a temp-dir race between the two
arms, fixed in the harness), before any request reached Unsloth. A rerun
of that journey on both arms at the same head gave 6/6 identical steps;
its results are used here.

**settings/s06_tab_api**:  | reproduced on confirm (VISUAL_DIFF)

![settings/s06_tab_api](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/15631/settings_s06_tab_api-78bbeb6f21de.png)

| Step | Text / structure change |
|---|---|
| `settings/s10_tab_agents` | {'removed': [], 'added': ['Unsloth MCP',
'Agent access (MCP)', 'Let coding agents […] use Unsloth over MCP.', '23
of 23 on', 'Choose t |
| `parallel/stop_training` | {'removed': ['65/4.1k', 'Three fruits are
named:', '#ctrl button:Name three fruits.', '#ctrl button:Context usage:
65 of 4.1k tokens'], 'added': ['Name three an |
| `crawl/r_projects` |  |
| `crawl/r_export` |  |
| `crawl/r_data_recipes` |  |
<!-- studio-regress:end -->


### Chat MCP preset: before and after this layer

BEFORE is #15629's head (`069a35528`), AFTER is this PR's head
(`fe799ee49`), so only this layer's change shows; this is not the PR's
own merge base.

The chat's MCP menu now offers **Unsloth** first, which answers with
Unsloth's own tools in process:

![Chat MCP menu, before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/15631/q_00-9d621edce6c6.png)

The tools dialog in Settings > Agents ends with the tools a chat never
gets ("The chat never gets Load model, Unload model, Plan a load, Chat,
Run Data Recipe, Start training, Export model, and Cancel work."):

![Unsloth MCP tools dialog, before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/15631/q_01-31bf4d099ec3.png)

---------

Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: Nilay Yadav <[email protected]>
Co-authored-by: Etherl <[email protected]>
Co-authored-by: LeoBorcherding <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

4 participants