-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: deactivate built-in web_search tools when disabled to allow MCP overrides #4904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
3
commits into
master
Choose a base branch
from
copilot/featuredisable-bot-web-search
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
🚨 _set_tools_active 可能误伤 MCP 覆盖的同名工具(以及其他来源的同名工具)
当前实现通过 func_tool_mgr.get_func(tool_name) 获取“当前注册表里该名字对应的工具”,然后直接写 tool.active。若 MCP 在 built-in 被禁用后注册了同名工具(PR 目标场景),get_func("web_search") 可能返回 MCP 的自定义工具;随后 edit_web_search_tools 每次请求都会调用 _set_tools_active(websearch_enable),当 web_search=false 时会把 MCP 工具也设置为 inactive,导致 MCP 工具不可用,反而违背“允许 MCP overrides”的目标。同样地,在 init 里禁用也可能提前把后续注册/已注册的同名非内置工具置为 inactive。要真正做到“内置工具不占名”,应只切换“本插件定义的工具实例”,而不是按名字从全局注册表取当前实例。
建议: 将本插件定义的工具对象在初始化阶段缓存为实例引用(例如 self._builtin_tool_instances = {name: <tool_obj>}),后续只对这些实例改 active;或者在工具对象上有 owner/module 标识时,先校验 tool 是否属于本插件再修改。至少应避免通过 get_func(name) 修改到已被覆盖的工具。