Skip to content

Studio: let the chat model use the Decision API through MCP - #12232

Merged
mahiatlinux merged 19 commits into
unslothai:mainfrom
NilayYadav:decision-api-mcp
Sep 29, 2026
Merged

mahiatlinux merged 19 commits into
unslothai:mainfrom
NilayYadav:decision-api-mcp

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

The Decision API was only reachable over POST /v1/systemone. The chat's MCP menu had no entry for it and there was no MCP address to add, so a chat model could not ask Laya anything without running curl.

When the Decision API is on in Settings > API, the MCP menu now lists Unsloth Decisions. One click gives the chat model a decide tool that runs the same checks and model as /v1/systemone and returns the same answer. The entry is hidden while the Decision API is off. Other MCP clients can use /mcp/decisions/ on the Studio port.

That address takes exactly the sign-in /v1/systemone takes and refuses anything else with 401. Studio's own chat runs the tool in process instead of calling itself, so no API key is created or stored. Startup now imports fastmcp, about 0.2s.

@NilayYadav

NilayYadav commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Codex review (mirror)

Mirror: NilayYadav/unsloth#123. Its base is the upstream merge base (now 4e8503e437), so the diff is only this PR.

Round Commit Result
1 bafefb82a4 1 x P2: Exempt the built-in Decisions client before network validation. Genuine: reproduced by hand as a managed account (400 toast). Fixed in d1087f2a87, reacted thumbs-up on the mirror.
2 bfa109befb (current head) requested, pending

The round 1 P2: a managed account saw Unsloth Decisions but could not enable it, because validate_mcp_address refused the loopback URL before the in-process shortcut ran. d1087f2a87 lets Studio's own /mcp/decisions address through, since it is answered in process and no request leaves the machine. Any other loopback or LAN address is still refused for managed accounts, and a regression test covers both. With the fix, the managed account enables it (201) and its chat calls decide. Evidence is in the review comment below.

@danielhanchen

danielhanchen commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

The "(Python 3.13, a-k)" failure comes from this PR, not main. studio/backend/tests/test_desktop_auth.py::test_health_response_reports_desktop_capability_fields imports main.py against a stubbed routes.systemone (around line 830) that only defines router. This PR adds from routes.systemone import MCP_PATH as DECISIONS_MCP_PATH, RequireStudioAuth, decisions_mcp to main.py, so the import fails with cannot import name 'MCP_PATH' from 'routes.systemone'. Extending that stub with an MCP_PATH string, a passthrough RequireStudioAuth and a decisions_mcp whose http_app() returns a small ASGI app carrying a lifespan (main.py passes it to combine_lifespans) should clear it.

Separately, "Repo tests (CPU, studio)" and "workflow-trigger lint" fail on main right now because playwright_user_message_time.py isn't run by any workflow. #12255 fixes that, and a rerun after it merges will clear both.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review + reproduction evidence

Pinned review: bfa109befb. Three findings, all fixed and pushed on top of bafefb82a4:

  • d1087f2a87 (P2, also Codex round 1): a managed (non-owner) account saw Unsloth Decisions in the MCP menu, but enabling it always failed with 400 Managed accounts may only use public-network HTTP MCP servers., because validate_mcp_address refused the loopback URL before the in-process shortcut ran. It now lets Studio's own /mcp/decisions address through, since that address is answered in process and no request leaves the machine. Every other loopback and LAN address is still refused for managed accounts. There is a regression test for both cases.
  • 764bfdfa23 (P2, CI): test_desktop_auth.py::test_health_response_reports_desktop_capability_fields failed on the CI mirror (run) with ImportError: cannot import name 'MCP_PATH' from 'routes.systemone', because its stub of routes.systemone lacked the names main.py now imports. The stub now carries them.
  • 53690c967b (P3): the preset URL includes the port, so a server saved while Studio ran on 8888 no longer matched the preset after a restart on another port. The menu then showed two checked Unsloth Decisions rows, and the model got two decide tools. The menu now treats any loopback /mcp/decisions row as the same server. There is a test for the URL match.

bfa109befb also merges current main (#12224 conflicted in test_systemone.py; both sets of tests are kept).

I reproduced the flow on Modal (L4, Chromium 1440x900), with three Studios installed through install.sh --local: main ca5e2fd, PR head bafefb8, and PR + fixes. On each I signed in, turned on Settings > API > Decision API, loaded unsloth/Qwen3.5-4B-GGUF Q4_K_M and opened the chat MCP menu:

  • main: there is no Decisions entry; the menu lists Unsloth Docs, Context7, Hugging Face and Blender.
  • PR head: Unsloth Decisions is listed. Enabled by the owner, the model called it: Used tool: Unsloth Decisions · decide, result {"model":"laya-multilingual","answers":{"urgent":{"type":"noul","noul":0.007}}}. A managed account got the 400 toast above.
  • PR + fixes: the managed account enables it (201 POST /api/mcp/servers/), and its chat calls decide: {"answers":{"urgent":{"type":"noul","noul":0.022}}}. A row saved under :8888 shows as one checked entry.

PR 12232 before/after

  • Tests (Modal, main vs branch): the 5 new tests fail on main and pass on the branch. On the branch: test_systemone, test_desktop_auth, keyless and account-isolation suites give 333 passed, 7 skipped. Every backend test file that imports main gives 1691 passed; the one failure there, test_attachments_are_copied_into_the_sandbox_once[True], fails identically on main.
  • Startup: fastmcp is now imported on every start. import main in the Studio venv went from a median of about 1.26 s to 1.71 s, with about 26 MB more RSS. That is roughly the cost the description states.
  • Not proven: I could not exercise keyless Chat and inference access here, because Studio on Modal binds 0.0.0.0, and keyless is refused for both /v1/systemone and /mcp/decisions/ (401 on both). From the code, /mcp/decisions/ is not in the keyless inference allowlist. So the README line "takes the credentials /v1/systemone takes" may be slightly broader than what keyless inference grants.

Conclusion: the feature works end to end for the owner, and after the fixes for managed accounts too. The branch is up to date with main. Codex round 2 on the new head is next.

@mahiatlinux

Copy link
Copy Markdown
Contributor

Review and repair complete. The 12 focused fixes were landed through mirror PR #74, and the source tree matches the converged mirror exactly.

Verification:

  • Focused backend regression suite: 16 passed.
  • Decisions MCP mounted-endpoint suite: 3 passed.
  • Frontend MCP regression suite: 24 passed.
  • Ruff, Python compilation, whitespace, commit integrity, and GitGuardian checks passed.
  • All review threads are resolved; the final mirror review found no major issues.

The refreshed source CI run is in progress with no current failures.

@mahiatlinux mahiatlinux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Ready to merge, all manually checked.

@mahiatlinux
mahiatlinux merged commit e3dced1 into unslothai:main Sep 29, 2026
61 of 63 checks passed
);
}

const literal = lower.slice(1, -1).replace(/%25/i, "%").split("%", 1)[0];
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.

4 participants