[Bug]MCP 工具在配置 plugin_set 时被错误过滤
What happened / 发生了什么
Bug 描述
当用户配置了 plugin_set 为特定插件列表(而非 ["*"])时,MCP 工具会被错误地过滤掉,导致模型无法使用通过 MCP 协议加载的工具。
Reproduce / 如何复现?
复现步骤
- 配置
mcp_server.json添加一个 MCP 服务器(我是用的本地mcp服务器) - 在 Pipeline 配置中设置
plugin_set为特定插件列表,如["astrbot-plugin-xxx"] - 发送消息触发 LLM 请求
- 观察到 MCP 工具未被传递给模型
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
4.13.2 windows gemini 3 flash onebot
OS
Windows
Logs / 报错日志
以下部分日志是我加了调试日志产生的,以便展示bug的原理 [01:07:18] [Core] [DBUG] [astrbot.process_llm_request:132]: Tool set for persona 卿安: ['gemini_image_generation', 'create_memory', 'recall_memory', 'delete_memory', 'adjust_impression', 'record_impression', 'reminder', 'web_search', 'fetch_url', 'web_search_tavily', 'tavily_extract_web_page', 'run_command', 'read_file', 'write_file', 'list_directory', 'get_system_info', 'take_screenshot', 'get_running_processes', 'kill_process', 'open_application', 'search_files', 'clipboard_read', 'clipboard_write', 'type_text', 'mouse_click', 'git_status', 'git_diff_unstaged', 'git_diff_staged', 'git_diff', 'git_commit', 'git_add', 'git_reset', 'git_log', 'git_create_branch', 'git_checkout', 'git_show', 'git_branch'] [01:07:18] [Core] [DBUG] [pipeline.context_utils:95]: hook(OnLLMRequestEvent) -> astrbot-web-searcher - edit_web_search_tools [01:07:18] [Core] [DBUG] [process_stage.utils:182]: [知识库] 使用全局配置,知识库数量: 0 [01:07:18] [Core] [DBUG] [agent_sub_stages.internal:353]: [_plugin_tool_fix] 开始过滤工具, 原始数量: 35, 插件白名单: ['astrbot_plugin_recall_cancel', 'mirage_tank', 'astrbot_plugin_llm_amnesia', 'astrbot_plugin_fox_status', 'intelligent_retry', 'astrbot_plugin_Favour_Ultra', 'astrbot_plugin_gemini_image_generation', 'astrbot_plugin_lzpersona'] [01:07:18] [Core] [DBUG] [agent_sub_stages.internal:376]: [_plugin_tool_fix] 过滤完成: [01:07:18] [Core] [DBUG] [agent_sub_stages.internal:377]: - MCP/外部工具被错误过滤: ['run_command', 'read_file', 'write_file', 'list_directory', 'get_system_info', 'take_screenshot', 'get_running_processes', 'kill_process', 'open_application', 'search_files', 'clipboard_read', 'clipboard_write', 'type_text', 'mouse_click', 'git_status', 'git_diff_unstaged', 'git_diff_staged', 'git_diff', 'git_commit', 'git_add', 'git_reset', 'git_log', 'git_create_branch', 'git_checkout', 'git_show', 'git_branch'] [01:07:18] [Core] [DBUG] [agent_sub_stages.internal:378]: - 插件工具保留: ['reminder (astrbot-reminder)', 'web_search (astrbot-web-searcher)', 'fetch_url (astrbot-web-searcher)'] [01:07:18] [Core] [DBUG] [agent_sub_stages.internal:379]: - 被过滤工具: ['gemini_image_generation (插件未找到: data.plugins.astrbot_plugin_gemini_image_generation)', 'create_memory (astrbot_plugin_memora_connect 不在白名单)', 'recall_memory (astrbot_plugin_memora_connect 不在白名单)', 'delete_memory (astrbot_plugin_memora_connect 不在白名单)', 'adjust_impression (astrbot_plugin_memora_connect 不在白名单)', 'record_impression (astrbot_plugin_memora_connect 不在白名单)'] [01:07:18] [Core] [DBUG] [agent_sub_stages.internal:380]: - 最终工具数量: 3 [01:07:18] [Core] [DBUG] [agent_sub_stages.internal:681]: handle provider[id: cliproxy] request: ProviderRequest(prompt=晚上好啊, session_id=default:FriendMessage:2064480632, image_count=0, func_tool=ToolSet(tools=[FuncTool(name=reminder, parameters={'type': 'object', 'properties': {'text': {'type': 'string', 'description': 'Must Required. The content of the reminder.'}, 'datetime_str': {'type': 'string', 'description': "Required when user's reminder is a single reminder. The datetime string of the reminder, Must format with %Y-%m-%d %H:%M"}, 'cron_expression': {'type': 'string', 'description': "Required when user's reminder is a repeated reminder. The cron expression of the reminder. Monday is 0 and Sunday is 6."}, 'human_readable_cron': {'type': 'string', 'description': 'Optional. The human readable cron expression of the reminder.'}}}, description=Call this function when user is asking for setting a reminder.), FuncTool(name=web_search, parameters={'type': 'object', 'properties': {'query': {'type': 'string', 'description': '和用户的问题最相关的搜索关键词,用于在 Google 上搜索。'}, 'max_results': {'type': 'number', 'description': '返回的最大搜索结果数量,默认为 5。'}}}, description=搜索网络以回答用户的问题。当用户需要搜索网络以获取即时性的信息时调用此工具。), FuncTool(name=fetch_url, parameters={'type': 'object', 'properties': {'url': {'type': 'string', 'description': 'The url of the website to fetch content from'}}}, description=Fetch the content of a website with the given web url)]), contexts=prompt: 晚上好啊, image_count: 0, system_prompt=You are running in Safe Mode.
Are you willing to submit a PR? / 你愿意提交 PR 吗?
- [x] Yes!
Code of Conduct
- [x] I have read and agree to abide by the project's Code of Conduct。
Hi @idiotsj! I'm Dosu and I’m helping the AstrBot team.
这是已知的 AstrBot bug,根因是 MCP 工具(通过 MCP 协议加载的工具)在 plugin_set 白名单过滤时被误排除了。具体原因是过滤逻辑(_plugin_tool_fix,见 astr_main_agent.py#L710-L723)会跳过所有 handler_module_path 为空的工具,而 MCP 工具的 handler_module_path 恰好就是空的,所以它们总是被过滤掉。
修复建议:
你可以在 _plugin_tool_fix 里加一条判断,保留 origin 为 "mcp" 的工具。例如:
def _plugin_tool_fix(event: AstrMessageEvent, req: ProviderRequest) -> None:
if event.plugins_name is not None and req.func_tool:
new_tool_set = ToolSet()
for tool in req.func_tool.tools:
# 保留 MCP 工具
if getattr(tool, "origin", None) == "mcp":
new_tool_set.add_tool(tool)
continue
mp = tool.handler_module_path
if not mp:
continue
plugin = star_map.get(mp)
if not plugin:
continue
if plugin.name in event.plugins_name or plugin.reserved:
new_tool_set.add_tool(tool)
req.func_tool = new_tool_set
这样可以让 MCP 工具不受 plugin_set 白名单影响,正常传递给模型。
测试建议: 修复后,配置 plugin_set 为特定插件列表时,MCP 工具应该会出现在最终的 tool set 里,模型可以正常调用。
如需进一步区分 MCP 工具类型,也可以用 tool.origin == "mcp" 或 tool.handler_module_path is None/"" 作为判断条件。
相关讨论和根因分析可参考 issue #4097 和 代码实现。
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
已修复