AstrBot
AstrBot copied to clipboard
[Bug] MCP 工具竞态条件导致 "API 返回的 completion 无法解析" 错误
What happened / 发生了什么
问题描述
在 AstrBot 启动后立即发送消息时,会出现以下错误:
Exception: API 返回的 completion 无法解析:ChatCompletion(...)
错误日志显示 AI 尝试调用 MCP 工具(如 read_file、run_command),但这些工具在 tools.func_list 中找不到,导致解析失败。
Reproduce / 如何复现?
复现步骤
- 配置 MCP 服务器(如
windows-control) - 启动 AstrBot
- 立即(启动后 1-2 秒内)向 AI 发送需要使用工具的消息
- 观察到 "无法解析" 错误
预期行为
AI 应该能够正常调用 MCP 工具,不应该出现解析错误。
实际行为
- 启动后立即使用:❌ 失败,抛出 "无法解析" 异常
- 启动后等待 3-5 秒:✅ 成功,工具正常工作
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
环境信息
- AstrBot 版本: v4.18.1 (commit
0b45c45f) - Python 版本: 3.11+
- 操作系统: Windows 11 -提供商:gemini 3 flash -适配器:napcat qq
OS
Windows
Logs / 报错日志
[2026-02-27 19:14:26.903] [Core] [ERRO] [v4.18.1] [sources.openai_source:538]: API 返回的 completion 无法解析:ChatCompletion( id='gXyhaY6KCbOCk7QP26_a-QI', choices=[Choice( finish_reason='tool_calls', message=ChatCompletionMessage( content=None, tool_calls=[ChatCompletionMessageFunctionToolCall( id='run_command-1772190850887260679-111', function=Function( arguments='{"command": "Get-Content -Path \"D:\\code\\...\", ...}', name='run_command' ), type='function' )] ) )], model='gemini-3-flash-preview', ... )
### 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](https://docs.github.com/zh/site-policy/github-terms/github-community-code-of-conduct)。