From f009e098945da5a247c737e6ea957a2ec3001dde Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 03:08:02 +0000 Subject: [PATCH 1/3] Initial plan From c6118409d026e9b9f470bd5b43a4290da414adfb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 03:12:51 +0000 Subject: [PATCH 2/3] feat: deactivate built-in web_search tools when disabled to allow MCP tools Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com> --- astrbot/builtin_stars/web_searcher/main.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/astrbot/builtin_stars/web_searcher/main.py b/astrbot/builtin_stars/web_searcher/main.py index e8388c816..bb864feb8 100644 --- a/astrbot/builtin_stars/web_searcher/main.py +++ b/astrbot/builtin_stars/web_searcher/main.py @@ -49,6 +49,18 @@ def __init__(self, context: star.Context) -> None: self.sogo_search = Sogo() self.baidu_initialized = False + # Deactivate built-in web search tools if web_search is disabled + # This allows MCP to provide custom web_search tools + websearch_enable = ( + provider_settings.get("web_search", False) if provider_settings else False + ) + if not websearch_enable: + func_tool_mgr = self.context.get_llm_tool_manager() + for tool_name in self.TOOLS: + tool = func_tool_mgr.get_func(tool_name) + if tool: + tool.active = False + async def _tidy_text(self, text: str) -> str: """清理文本,去除空格、换行符等""" return text.strip().replace("\n", " ").replace("\r", " ").replace(" ", " ") @@ -394,6 +406,15 @@ async def edit_web_search_tools( websearch_enable = prov_settings.get("web_search", False) provider = prov_settings.get("websearch_provider", "default") + func_tool_mgr = self.context.get_llm_tool_manager() + + # Globally activate/deactivate built-in web search tools based on config + # This allows MCP to provide custom web_search tools when built-in is disabled + for tool_name in self.TOOLS: + tool = func_tool_mgr.get_func(tool_name) + if tool: + tool.active = websearch_enable + tool_set = req.func_tool if isinstance(tool_set, FunctionToolManager): req.func_tool = tool_set.get_full_tool_set() From 31aae304c2eced6ed4d55e8902ac0da7e52e97be Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 03:16:02 +0000 Subject: [PATCH 3/3] refactor: extract helper method to reduce code duplication Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com> --- astrbot/builtin_stars/web_searcher/main.py | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/astrbot/builtin_stars/web_searcher/main.py b/astrbot/builtin_stars/web_searcher/main.py index bb864feb8..d68aae336 100644 --- a/astrbot/builtin_stars/web_searcher/main.py +++ b/astrbot/builtin_stars/web_searcher/main.py @@ -51,15 +51,21 @@ def __init__(self, context: star.Context) -> None: # Deactivate built-in web search tools if web_search is disabled # This allows MCP to provide custom web_search tools - websearch_enable = ( - provider_settings.get("web_search", False) if provider_settings else False - ) + websearch_enable = (provider_settings or {}).get("web_search", False) if not websearch_enable: - func_tool_mgr = self.context.get_llm_tool_manager() - for tool_name in self.TOOLS: - tool = func_tool_mgr.get_func(tool_name) - if tool: - tool.active = False + self._set_tools_active(False) + + def _set_tools_active(self, active: bool) -> None: + """Set the active status of all built-in web search tools. + + Args: + active: True to activate tools, False to deactivate them + """ + func_tool_mgr = self.context.get_llm_tool_manager() + for tool_name in self.TOOLS: + tool = func_tool_mgr.get_func(tool_name) + if tool: + tool.active = active async def _tidy_text(self, text: str) -> str: """清理文本,去除空格、换行符等""" @@ -406,14 +412,9 @@ async def edit_web_search_tools( websearch_enable = prov_settings.get("web_search", False) provider = prov_settings.get("websearch_provider", "default") - func_tool_mgr = self.context.get_llm_tool_manager() - # Globally activate/deactivate built-in web search tools based on config # This allows MCP to provide custom web_search tools when built-in is disabled - for tool_name in self.TOOLS: - tool = func_tool_mgr.get_func(tool_name) - if tool: - tool.active = websearch_enable + self._set_tools_active(websearch_enable) tool_set = req.func_tool if isinstance(tool_set, FunctionToolManager):