From d2e0bc778ab151b4ba6fb78eae23ca1e2997834c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E7=A9=BA?= <3103908461@qq.com> Date: Sat, 21 Mar 2026 00:27:54 +0800 Subject: [PATCH] fix: preserve PATHEXT for stdio mcp servers on windows (#5822) * fix: preserve PATHEXT for stdio mcp servers on windows * chore: delete test_mcp_client.py --------- Co-authored-by: Soulter <905617992@qq.com> --- astrbot/core/agent/mcp_client.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/astrbot/core/agent/mcp_client.py b/astrbot/core/agent/mcp_client.py index a8ff0fdb9..af969a3fa 100644 --- a/astrbot/core/agent/mcp_client.py +++ b/astrbot/core/agent/mcp_client.py @@ -1,5 +1,7 @@ import asyncio import logging +import os +import sys from contextlib import AsyncExitStack from datetime import timedelta from typing import Generic @@ -45,6 +47,22 @@ def _prepare_config(config: dict) -> dict: return config +def _prepare_stdio_env(config: dict) -> dict: + """Preserve Windows executable resolution for stdio subprocesses.""" + if sys.platform != "win32": + return config + + pathext = os.environ.get("PATHEXT") + if not pathext: + return config + + prepared = config.copy() + env = dict(prepared.get("env") or {}) + env.setdefault("PATHEXT", pathext) + prepared["env"] = env + return prepared + + async def _quick_test_mcp_connection(config: dict) -> tuple[bool, str]: """Quick test MCP server connectivity""" import aiohttp @@ -214,6 +232,7 @@ class MCPClient: ) else: + cfg = _prepare_stdio_env(cfg) server_params = mcp.StdioServerParameters( **cfg, )