Skip to content

Studio: remember MCP servers per project - #18290

Merged
shimmyshimmer merged 12 commits into
unslothai:mainfrom
Aafimalek:feat/issue-17970-project-mcp
Nov 23, 2026
Merged

shimmyshimmer merged 12 commits into
unslothai:mainfrom
Aafimalek:feat/issue-17970-project-mcp

Conversation

@Aafimalek

@Aafimalek Aafimalek commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Let each Studio project inherit the account's enabled MCP servers or choose its own subset in Edit project.
  • Use the saved preference when discovering tools and running MCP calls for project chats. The chat MCP toggle and global server disables still apply.
  • The selection is re-read when a call runs and again just before it is sent, so deselecting a server stops calls already waiting on approval or queued. MCP app widgets follow the same selection, and image attachments are only routed to MCP tools the project keeps.

Related to #17970

Verification

  • Opened a chat in each of two projects in headless Chrome using fixture-backed requests, then reopened the first project to verify its saved selection.
  • Verified project switching, inherited defaults, an empty selection, and enforcement at tool execution in a backend test using an isolated SQLite database.
  • All 147 focused frontend tests, TypeScript checks, and the production build passed.
  • The broader backend run passed 190 tests. Three MCP resource tests reported connection failures on both the PR branch and the unchanged base commit.

Screenshots

Edit project before and after this PR, on a project with two enabled MCP servers. After saving only Docs server and reopening the dialog, Docs server stays selected and the project's saved mcpServerIds holds that one id.

Edit project dialog before and after

The project edit dialog now lists the account's MCP servers. The smoke's
catch-all /api route answered that request with {}, so the dialog's
rows.filter threw and the scene's page-error check failed. Return an array
like the real endpoint and check the new MCP section in the edit dialog.
danielhanchen added a commit that referenced this pull request Nov 19, 2026
## Summary

Two gloo tests started failing in the CPU tensor-parallel shards on
several unrelated PRs (#18290, #17550):

```
tests/test_tp_kv_replicated_gloo.py::test_kv_heads_below_tp_are_replicated_per_rank
E   assert (0, 16) == (0, 128)

tests/test_tp_native_gloo.py::test_tp2_tied_norm_weight_is_summed_once
E   Max absolute difference: 7.361173629760742e-06   (tolerance 3.4e-06)
```

On a host with a cold Hugging Face cache, both fail every time,
including on commits from before any recent tensor-parallel change.

## Cause

Not a code change. The gloo tensor and pipeline parallel builders
(`build()` in `tests/test_tp_native_oracle.py` and
`tests/test_pp_native_gloo.py`) read a tiny Hub repo's `config.json` at
its latest revision and build random weights from it.
`trl-internal-testing/tiny-Qwen3ForCausalLM` was re-uploaded upstream on
2026-11-19 (commit `92ee0a3c80`), and its config changed `head_dim` from
128 to 16:

| revision | hidden_size | heads / KV heads | head_dim |
|---|---|---|---|
| `25bb9b8963` (previous) | 8 | 4 / 2 | 128 |
| `92ee0a3c80` (current) | 8 | 4 / 2 | 16 |

- `test_kv_heads_below_tp_are_replicated_per_rank` hardcoded 128 for the
expected per-rank KV row slice.
- `test_tp2_tied_norm_weight_is_summed_once` compares parity values that
the new shapes move just past their tolerance.

Runners that still have the old config cached pass and fresh fetches
fail. That is why the same base, with the same package versions
(transformers 5.18.0, torch 2.10.0), was green on some PRs and red on
others. `trl-internal-testing/tiny-Qwen3MoeForCausalLM` was re-uploaded
the same day.

The tensor-parallel code is correct. It slices by the config's
`head_dim`.

## Fix

Test-only:

- `tests/_tiny_fixture_revisions.py` pins a full commit id for every
tiny repo the two builders use:
  - Qwen3 and Qwen3-MoE at the revision before the re-upload;
  - the rest at their current revision, the one CI has been green on.
- Both builders load the config with `AutoConfig.from_pretrained(repo,
revision = revision(repo))`. Moving a fixture is now a deliberate edit
to the pin table.
- `tests/test_tiny_fixture_revisions_pinned.py` fails if either builder
module names a tiny repo without a pin, if a pin is not a full commit
id, or if a builder stops loading at the pin.
- `test_kv_heads_below_tp_are_replicated_per_rank` also pins `head_dim`
in its own overrides and derives the expected rows from it, so it states
the shape it checks.

## Verification

| | result |
|---|---|
| `test_tp_kv_replicated_gloo.py`, main | 1 failed, 10 passed |
| `test_tp_kv_replicated_gloo.py`, this branch | 11 passed |
| `test_tp_native_gloo.py` (`tied_norm`), main | 1 failed |
| `test_tp_native_gloo.py`, this branch | 57 passed |
| `test_pp_native_gloo.py`, this branch | 24 passed |
| `test_tiny_fixture_revisions_pinned.py` | 3 passed |
| `tp_native.py` sabotaged to give every rank KV head 0 | the KV test
fails on ranks 2 and 3 (`(0, 16)`) |

So the per-rank KV head check still catches wrong slicing. ruff is
clean.
@Aafimalek

Copy link
Copy Markdown
Contributor Author

@danielhanchen could you take a look when you have a moment? This lets each Studio project keep its own MCP server selection (#17970).

The three red checks don't come from this change:

  • Frontend build + bundle sanity was cancelled at the job's 40-minute limit during the browser checks. Every step that finished had passed, including the project-folders smoke this PR updates.
  • Repo tests (CPU, gloo-tp-env) and Repo tests (CPU, gloo-tp): trl-internal-testing/tiny-Qwen3ForCausalLM was re-uploaded at 05:57 UTC today, and its config now has head_dim 16 instead of 128. test_kv_heads_below_tp_are_replicated_per_rank hard-codes 128, and test_tp2_tied_norm_weight_is_summed_once misses its tolerance by about 7e-6 with the new weights. Both jobs passed on other PRs that ran before the upload, so other runs started after it will likely fail the same way.

Could you rerun the frontend job?

…ect-mcp

# Conflicts:
#	studio/backend/core/inference/tools.py
@Aafimalek

Aafimalek commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Could a maintainer rerun these two jobs? Both were cancelled at their time limits:

After merging current main, which needed a small conflict resolution in core/inference/tools.py, every other check is green.

@danielhanchen danielhanchen self-assigned this Nov 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 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-22T15:42:44.199886Z 9c78c80 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8973b8c462

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

INSERT INTO chat_projects
(id, name, instructions, root_path, archived, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?)
(id, name, instructions, mcp_server_ids, root_path, archived, created_at, updated_at)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Persist supplied MCP selections on upsert conflicts

When POST /api/chat/projects saves an existing project ID, mcp_server_ids is included in the insert but omitted from the ON CONFLICT(id) DO UPDATE SET clause. Reposting a project with another subset, [], or null therefore succeeds while retaining its previous MCP selection, even though fields such as its name update normally. Handle explicitly supplied MCP preferences in the conflict branch too, while preserving existing preferences for callers that omit the field.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

POST /api/chat/projects is the create path: the dialog creates new IDs, backup restore skips IDs that already exist, and every edit (including the MCP selection) goes through PATCH. No Studio caller reposts an existing project with a selection.

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. Keep them coming!

Reviewed commit: a875633c9c

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

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 22, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 22, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c78c80677

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

Comment on lines +15177 to +15178
if mcp_project_excludes(server_id, session_id):
return f"Error: MCP server '{display}' is not enabled for this project"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Propagate project scope to Deep Research MCP calls

When a project excludes a globally enabled server that is already configured as a Deep Research MCP source, research launched from that project's chats still sends queries to it. core/research_runs.py:_research() discovers tools without setting the project scope (lines 2415–2417), and _search_mcp_tools() calls execute_mcp_tool() without session_id (lines 1343–1349), so this new execution check receives None and does not exclude the server. Resolve the run thread's project for both discovery and execution so that empty selections and subsets also apply to research calls.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Deep Research sources are picked explicitly per run (the run config's mcpSources lists the exact server and tool pairs the user chose in the research setup). The project setting scopes the chat model's MCP catalog, as the dialog says (applies when MCP is on in a chat); overriding a source the user hand-picked for this research would silently drop it. Global disable still applies to research calls.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 22, 2026
@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. Chef's kiss.

Reviewed commit: 9c78c80677

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

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.

3 participants