[Bug] The C# local stdio server fails to start in AstrBot.(C# 本地的stdio服务器在AstrBot无法启动)
What happened / 发生了什么
使用https://learn.microsoft.com/zh-cn/dotnet/ai/quickstarts/build-mcp-client所示的官方示例,并在Copilot和Cherry Studio跑通后,在AstrBot中测试失败。
Reproduce / 如何复现?
新增服务器,在Stdio模板填入以下Json数据并测试连接后报错{ "command": "dotnet", "args": [ "run", "--project", "G:\CSharp\AIservice\McpServer1\McpServer1\McpServer1.csproj" ] }
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
AstrBot v4.22.1
OS
Windows
Logs / 报错日志
[2026-03-27 20:43:09.586] [Core] [ERRO] [v4.22.1] [routes.tools:163]: Traceback (most recent call last): File "C:\Users\Admin.astrbot_launcher\instances\df021017-be3c-48e9-a909-3b2fa3c9aa06\core\astrbot\dashboard\routes\tools.py", line 161, in add_mcp_server await self.tool_mgr.test_mcp_server_connection(server_config) File "C:\Users\Admin.astrbot_launcher\instances\df021017-be3c-48e9-a909-3b2fa3c9aa06\core\astrbot\core\provider\func_tool_manager.py", line 670, in test_mcp_server_connection await mcp_client.connect_to_server(config, "test") File "C:\Users\Admin.astrbot_launcher\instances\df021017-be3c-48e9-a909-3b2fa3c9aa06\core\astrbot\core\agent\mcp_client.py", line 269, in connect_to_server await self.session.initialize() File "C:\Users\Admin.astrbot_launcher\instances\df021017-be3c-48e9-a909-3b2fa3c9aa06\venv\Lib\site-packages\mcp\client\session.py", line 171, in initialize result = await self.send_request( ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin.astrbot_launcher\instances\df021017-be3c-48e9-a909-3b2fa3c9aa06\venv\Lib\site-packages\mcp\shared\session.py", line 306, in send_request raise McpError(response_or_error.error)
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 @BuXiangShangBanYT! I'm Dosu and I’m helping the AstrBot team.
这是一个已知的 Windows 平台问题。在 Windows 下,MCP 库不会继承 PATHEXT 环境变量,导致无法正确解析 dotnet 命令。
解决方案:在 Stdio 配置中手动添加 env 参数:
{
"command": "dotnet",
"args": [
"run",
"--project",
"G:\\CSharp\\AIservice\\McpServer1\\McpServer1\\McpServer1.csproj"
],
"env": {
"PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC"
}
}
其他可能的原因:
dotnet run首次编译时输出的构建信息可能干扰 JSON-RPC 握手 — 尝试更新到最新版本 AstrBot(PR #6136 已改进这一点)- 初始化超时(默认 20 秒可能不足)— 可设置环境变量
ASTRBOT_MCP_INIT_TIMEOUT=180
相关 issue: #5820
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
这是由于dotnet不在环境变量中,我已提交PR #7054
#7054 fixed