Skip to content

Studio: stop hiding MCP tools that have a dot or a long name - #11051

Merged
Lyxot merged 8 commits into
unslothai:mainfrom
NilayYadav:fix-mcp-tool-name-alias
Sep 16, 2026
Merged

Lyxot merged 8 commits into
unslothai:mainfrom
NilayYadav:fix-mcp-tool-name-alias

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

MCP tools with a dot in the name (like Backstage's catalog.get-catalog-entity) or a name longer than 41 characters never reached the model. Settings still said "Connected (6 tools)", but the model said the tool did not exist or picked a similar one. The MCP spec allows these names, but OpenAI style tool names do not.

Instead of skipping them, Studio now gives these tools a short valid name and maps it back to the real tool when it is called. Approval checks use the real tool name. The tool card, the approval prompt and the chat after a page reload all show the real tool name. Tools with normal names are unchanged.

With an MCP server that has dotted and long tool names, the model on main could not use them. With this change it calls catalog.get-catalog-entity and the 42 character tool and gets their results, the approval prompt and tool card show their real names before and after reloading the page, and get_weather still works and looks the same. Updated the tests that expected the old behavior and added new ones.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 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 ✅ Completed 2026-09-16T09:16:38.003392Z 428c8e4 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: 19efb0366c

ℹ️ 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 thread studio/backend/core/inference/tools.py Resolved
@NilayYadav
NilayYadav force-pushed the fix-mcp-tool-name-alias branch from 19efb03 to 695cfbd Compare September 15, 2026 20:26
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@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: fbeb6b994c

ℹ️ 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 thread studio/backend/core/inference/tools.py Resolved
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 8341b0b5de

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

Confirmed this hits studio/backend/core/inference/tools.py, where a composed MCP name failing the OpenAI function.name regex is still dropped with only a log line while Settings keeps counting the tool, and the alias map plus raw-name resolution in approvals and the tool card look right. Will get this reviewed.

@Lyxot Lyxot self-assigned this Sep 16, 2026
The approval classifiers find a verb by its term boundaries, and those patterns treat only `_` and `-` as separators, because until now a name could not reach them containing anything else. Aliasing changed that: the raw name a tool is dispatched under is what gets classified, and MCP allows a dot in it.

So a tool named `get_file.delete` classified as ordinary work while `get_file_delete` prompted, and `read_file.secret` disclosed credentials without asking. In auto mode both ran with no approval prompt. These are exactly the names that used to be dropped and now ship, so the gap arrived with them.

Fold every separator to `_` where the raw name enters each classifier, rather than teaching a dozen patterns about dots. A verb behind a `.`, a `/` or a space is now its own term, and camelCase keeps its existing split.

This also stops a spurious prompt: `catalog.get-catalog-entity` used to fail closed as high risk because the dot hid its `get` from the known-verb check.
Two places still showed an alias where the tool's own name belongs.

`execute_tool` reported a missing server as `MCP server for tool 'catalog_get-catalog-entity_b9d734f2' not found`, because it resolved the raw name only after that check. Resolve first, so the error names the tool the user knows.

A tool whose alias slot was already taken by another tool's real name was logged as a duplicate, which it is not, and the log is the only evidence that a tool went missing. Give it its own message and leave the duplicate warning to actual duplicates.
The stem an alias keeps was truncated at `55 - len(prefix)`, where 55 was the 64-character `function.name` limit with the alias suffix already subtracted by hand. Name both, so the arithmetic says what it is and the two move together. A prefix longer than the budget now yields an empty stem instead of a negative slice that would silently truncate from the wrong end.

Also document why an aliased tool repeats its raw name in its description, and why valid names claim their spelling before any alias is minted.
@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Reviewed and pushed four follow-up commits. The approach here is right: aliasing the names instead of dropping them, and resolving back to the raw name at dispatch, approval and display. I traced every consumer of an mcp__ name on both sides and found none that were missed.

One of the four is a behaviour fix, the rest are small.

a53afe1 classify MCP tool names by term, whatever separates them. The approval classifiers find a verb by its term boundaries, and those patterns treat only _ and - as separators, because until this PR a name could not reach them containing anything else. Aliasing changed that: what gets classified is the raw name, and MCP allows a dot in it. Measured on the branch before the fix:

get_file.delete   -> unsafe=False  high_risk=False     (get_file_delete   -> True/True)
read_file.secret  -> unsafe=False  high_risk=False     (read_file_secret  -> True/True)

Those are exactly the names that used to be dropped and now ship, so in auto mode a destructive call and a credential read would have run with no approval prompt. Fixed by folding every separator to _ where the raw name enters each classifier, rather than teaching a dozen patterns about dots. Checked that it does not over-refuse: dotted read tools still run silently and agree with their underscore twins (list.issues, get.weather, search.catalog-entities all classify False/False). It also removes a spurious prompt, since catalog.get-catalog-entity used to fail closed as high risk because the dot hid its get from the known-verb check.

78c5ca3 name the real MCP tool in alias diagnostics. execute_tool reported a missing server as MCP server for tool 'catalog_get-catalog-entity_b9d734f2' not found, because it resolved the raw name only after that check. Separately, a tool whose alias slot was already taken by another tool's real name was logged as a duplicate, which it is not, and that log is the only evidence a tool went missing.

4edc1ea derive the alias name budget from the name limit. The stem was truncated at 55 - len(prefix), where 55 is the 64-character limit with the alias suffix subtracted by hand. Named both so the arithmetic says what it is; a prefix longer than the budget now yields an empty stem rather than a negative slice truncating from the wrong end. Behaviour is unchanged for real server ids.

51bfb0c cover the raw name reaching the markdown export. Dropping mcpToolFromProvenance from the exporter left every formatter and export test green while the exported label regressed to the alias.

Every added test was mutation-checked: reverting the change it covers fails that test and no other. 2809 backend and 102 frontend tests pass locally, tsc -b clean. The four CI failures on this PR reproduce on a clean main checkout and are unrelated to these changes.

Both open review threads were verified as real, confirmed fixed, and resolved. On the stale-alias one I left a note: dropping the retired alias moves the collision to an in-flight call rather than removing it, which I reproduced but deliberately did not fix, since it needs a same-server SHA-256 digest collision and closing it properly would mean generation-tagged aliases, which is beyond this PR.

@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

@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: 51bfb0cae0

ℹ️ 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 thread studio/backend/core/inference/tools.py Resolved
@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 51bfb0cae0

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

The exporter reads the raw tool name out of provenance, but nothing asserted it: dropping that argument left every formatter and export test green while the exported label regressed to the alias.
@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 428c8e49eb

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

@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Correction to my previous comment, and a force-push: 51bfb0c → 428c8e4.

That comment said tsc -b was clean. It was, but that is only half of this repo's typecheck, which is tsc -b && tsc -p tsconfig.test.json. I had not run the second half, and the test I added in that commit failed it:

tests/conversation-markdown.test.ts(243,26): error TS2339: Property 'name' does not exist on type 'ConversationMarkdownBlock'

ConversationMarkdownBlock is a union and name exists only on its tool-call member. That broke Frontend build + bundle sanity, and fail-fast then cancelled Frontend unit tests (Windows). My fault, and my earlier claim of a clean typecheck was wrong.

The assertion now checks the rendered output, which is how every other test in that file works, and additionally asserts the alias never leaks into the export. Folded into the commit that introduced it rather than added as a separate fix. Verified: the whole npm run typecheck exits 0, all 7716 frontend unit tests pass, the backend suites pass, and the test is still mutation-proof, so deleting mcpToolFromProvenance from the exporter fails exactly this test and no other.

No production code changed between 51bfb0c and 428c8e4; the diff is confined to that one test file.

I also ran the branch merged with current main through a staging CI run to check for drift, since main has moved several times today. The merge is clean and no new upstream commit touches tools.py, tool_loop_controller.py, studio_tool_loop.py or the frontend chat utils. Every remaining red job there was checked individually and none is attributable to this branch: test_close_generation_keys_hold_no_secrets fails in isolation on a clean main checkout because it depends on ordering to populate mcp_client generation maps, and this branch does not touch mcp_client; the rest are Playwright timeouts, a preexec_fn subprocess flake, and the preset-sheet and pwsh-runner checks that reproduce on main.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving on the state at 428c8e4.

The problem is real: on main a composed MCP name failing ^[a-zA-Z0-9_-]{1,64}$ is dropped with only a log line while Settings keeps counting the tool, which silently loses every dotted name and every name past 41 characters. Aliasing them and resolving back to the raw name at dispatch, approval and display is the right shape, and I traced every consumer of an mcp__ name on both the backend and the frontend without finding one that was missed.

What I checked rather than assumed:

The change cannot disturb a tool that already worked. The separator fold is the identity on the whole character set that could ship before, verified exhaustively per character and across 200k generated names, and for a name with no alias entry the raw-name lookup returns exactly what the old split returned. So classification and dispatch are unchanged for every tool that shipped on main, and the new behaviour is reachable only by names that previously did not exist at all.

End to end, a server advertising get_weather, catalog.get-catalog-entity, a 49-character tool and delete.catalog-entity now ships all four within the 64-character limit, dispatches each to its own raw name, shows the real name on the card, prompts on the destructive one and stays silent on the reads, with get_weather keeping byte-identical naming.

Merges cleanly with current main, and no commit landed today touches tools.py, tool_loop_controller.py, studio_tool_loop.py or the frontend chat utils.

Two things a maintainer should weigh rather than take from me:

Upstream CI has not completed on this head; the Backend CI run has been queued with no job started for some time. My evidence is a staging run of the same tree in a fork, where Frontend build + bundle sanity passes, plus local runs: 2809 backend tests, the full npm run typecheck across both projects, and 7719 of 7720 frontend tests. The single frontend failure is every locale keeps the shortcut in the threshold description, which reproduces on latest main alone with nothing from this branch present, so it is a main regression rather than a cost of this PR.

The in-flight alias redirect discussed above is genuine and deliberately left open. If a catalog refresh advertises a tool whose literal name equals another tool's sanitized stem plus the first 8 hex of its SHA-256, a call already in flight resolves to the new tool. Closing it needs generation-scoped resolution, which is a larger mechanism than a same-server digest collision warrants, and the alternative behaviour is the bug fixed in 8341b0b.

Disclosure: I wrote four of the commits here, so treat this as one signal on a change I am partly the author of, not an independent review of the whole.

@Lyxot
Lyxot merged commit 8453ef4 into unslothai:main Sep 16, 2026
44 of 46 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…ai#11051)

* Studio: alias MCP tool names that are not valid function names instead of dropping them

* Studio: keep MCP tool aliases resolvable after the tool cache is evicted

* Studio: drop a stale MCP alias when its name ships directly

* fix(studio): classify MCP tool names by term, whatever separates them

The approval classifiers find a verb by its term boundaries, and those patterns treat only `_` and `-` as separators, because until now a name could not reach them containing anything else. Aliasing changed that: the raw name a tool is dispatched under is what gets classified, and MCP allows a dot in it.

So a tool named `get_file.delete` classified as ordinary work while `get_file_delete` prompted, and `read_file.secret` disclosed credentials without asking. In auto mode both ran with no approval prompt. These are exactly the names that used to be dropped and now ship, so the gap arrived with them.

Fold every separator to `_` where the raw name enters each classifier, rather than teaching a dozen patterns about dots. A verb behind a `.`, a `/` or a space is now its own term, and camelCase keeps its existing split.

This also stops a spurious prompt: `catalog.get-catalog-entity` used to fail closed as high risk because the dot hid its `get` from the known-verb check.

* fix(studio): name the real MCP tool in alias diagnostics

Two places still showed an alias where the tool's own name belongs.

`execute_tool` reported a missing server as `MCP server for tool 'catalog_get-catalog-entity_b9d734f2' not found`, because it resolved the raw name only after that check. Resolve first, so the error names the tool the user knows.

A tool whose alias slot was already taken by another tool's real name was logged as a duplicate, which it is not, and the log is the only evidence that a tool went missing. Give it its own message and leave the duplicate warning to actual duplicates.

* refactor(studio): derive the MCP alias name budget from the name limit

The stem an alias keeps was truncated at `55 - len(prefix)`, where 55 was the 64-character `function.name` limit with the alias suffix already subtracted by hand. Name both, so the arithmetic says what it is and the two move together. A prefix longer than the budget now yields an empty stem instead of a negative slice that would silently truncate from the wrong end.

Also document why an aliased tool repeats its raw name in its description, and why valid names claim their spelling before any alias is minted.

* test(studio): cover the raw MCP name reaching the markdown export

The exporter reads the raw tool name out of provenance, but nothing asserted it: dropping that argument left every formatter and export test green while the exported label regressed to the alias.

---------

Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: Lyxot <[email protected]>
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