Repository navigation
fix(mcp): reject an ambiguous agent name instead of the first match - #6253
Draft
shunxinyi-ljs wants to merge 1 commit into
Draft
shunxinyi-ljs wants to merge 1 commit into
shunxinyi-ljs wants to merge 1 commit into
Conversation
resolve_agent_id fell back to the first case-insensitive name match. Agent names are not unique, and the resolved id selects the model, knowledge bases and prompt a chat runs against, so a duplicate name silently ran the conversation on an arbitrary agent. Collect the name matches and fail when there is more than one, naming the candidates. An exact id match still wins, as before.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
resolve_agent_idfell back to the first case-insensitive name match:Agent names are not unique, and the id it returns selects the model, knowledge bases and system prompt the chat runs against. With two agents named
Helper,agent_chatsilently ran on one of them, and nothing in the response said which.Resolution now collects the name matches and refuses when there is more than one:
An exact
idmatch still wins and short-circuits, so callers that pass an id are untouched. This is the same rule the knowledge-base resolver got in #6240.Type of Change
Related Issue
Follow-up to #6240 (ambiguous knowledge-base name). Same failure mode in the agent resolver.
Testing
tests/test_agent_id_resolution.py::test_resolve_agent_id_rejects_ambiguous_name— two agents namedHelper/helperresolve to aValueErrornaming both ids.test_resolve_agent_id_exact_id_still_wins— passingagent-2returnsagent-2even when both agents share the name.weknora_mcp_server.py: the new test fails withFailed: DID NOT RAISE ValueErroron the pre-patch tree and passes with the patch.python -m pytest tests/test_agent_id_resolution.py— 5 passed.python -m pytest test_*.py tests/— passes; one skip (test_file_path_security.pyneeds symlink privileges on Windows).Checklist
git diff --check origin/main...HEADpassesmcp-server/)Screenshots / Recordings
Not a UI change.