Skip to content

Commit cd6bef4

Browse files
idiotsjSoulter
andauthored
fix: MCP tools being filtered out when a specific plugin set is configured in the WebUI (#4825)
* fix: preserve MCP tools in _plugin_tool_fix filter Tools without handler_module_path (such as MCP tools and built-in tools) were being incorrectly skipped during plugin-based tool filtering. This fix ensures that tools without plugin association are preserved, as they should not be affected by plugin-level filtering logic. * fix: retain MCP tools in _plugin_tool_fix function --------- Co-authored-by: idiotsj <idiotsj@users.noreply.github.com> Co-authored-by: Soulter <905617992@qq.com>
1 parent de1304d commit cd6bef4

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

astrbot/core/astr_main_agent.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from astrbot.api import sp
1313
from astrbot.core import logger
1414
from astrbot.core.agent.handoff import HandoffTool
15+
from astrbot.core.agent.mcp_client import MCPTool
1516
from astrbot.core.agent.message import TextPart
1617
from astrbot.core.agent.tool import ToolSet
1718
from astrbot.core.astr_agent_context import AgentContextWrapper, AstrAgentContext
@@ -715,9 +716,18 @@ def _sanitize_context_by_modalities(
715716

716717

717718
def _plugin_tool_fix(event: AstrMessageEvent, req: ProviderRequest) -> None:
719+
"""根据事件中的插件设置,过滤请求中的工具列表。
720+
721+
注意:没有 handler_module_path 的工具(如 MCP 工具)会被保留,
722+
因为它们不属于任何插件,不应被插件过滤逻辑影响。
723+
"""
718724
if event.plugins_name is not None and req.func_tool:
719725
new_tool_set = ToolSet()
720726
for tool in req.func_tool.tools:
727+
if isinstance(tool, MCPTool):
728+
# 保留 MCP 工具
729+
new_tool_set.add_tool(tool)
730+
continue
721731
mp = tool.handler_module_path
722732
if not mp:
723733
continue

0 commit comments

Comments
 (0)