Skip to content

Commit 77d5d5c

Browse files
fix(windows): inherit all system environment variables into MCP runner for Windows (#7054)
- Merge environment variables case‑insensitively - Auto‑configure dotnet PATH and suppress console window - Keep PATHEXT inheritance (from old implementation) Replaces the minimal PATHEXT fix with a robust solution that resolves common Windows subprocess issues, especially for .NET servers. * fix(stdio): improve Windows environment setup for subprocesses - Merge environment variables case‑insensitively - Auto‑configure dotnet PATH and suppress console window - Keep PATHEXT inheritance (from old implementation) -Add `show_console` option to control `CREATE_NO_WINDOW` flag.Default remains hidden (backward compatible) but can be overridden. Replaces the minimal PATHEXT fix with a robust solution that resolves common Windows subprocess issues, especially for .NET servers. * fix(stdio): improve Windows environment setup for subprocesses 修复(标准输入输出):改进 Windows 环境设置以支持子进程 - Merge environment variables case‑insensitively - Auto‑configure dotnet PATH and suppress console window - Keep PATHEXT inheritance (from old implementation) -Add `show_console` option to control `CREATE_NO_WINDOW` flag.Default remains hidden (backward compatible) but can be overridden. Replaces the minimal PATHEXT fix with a robust solution that resolves common Windows subprocess issues, especially for .NET servers. * fix(stdio): improve Windows environment setup for subprocesses 修复(标准输入输出):改进 Windows 环境设置以支持子进程 - Merge environment variables case‑insensitively - Auto‑configure dotnet PATH and suppress console window - Keep PATHEXT inheritance (from old implementation) -Add `no_console` option to control `CREATE_NO_WINDOW` flag.Default remains hidden (backward compatible) but can be overridden. Replaces the minimal PATHEXT fix with a robust solution that resolves common Windows subprocess issues, especially for .NET servers. * fix(stdio): improve Windows environment setup for subprocesses 修复(标准输入输出):改进 Windows 环境设置以支持子进程 - Merge environment variables case‑insensitively - Auto‑configure dotnet PATH and suppress console window - Keep PATHEXT inheritance (from old implementation) -Add `no_console` option to control `CREATE_NO_WINDOW` flag.Default remains hidden (backward compatible) but can be overridden. Replaces the minimal PATHEXT fix with a robust solution that resolves common Windows subprocess issues, especially for .NET servers. * fix(windows): inherit all system environment variables for subprocesses - Merge environment variables case‑insensitively - Auto‑configure dotnet PATH and suppress console window - Keep PATHEXT inheritance (from old implementation) - No longer handle as a special case for C#. Replaces the minimal PATHEXT fix with a robust solution that resolves common Windows subprocess issues, especially for .NET servers. * chore: ruff format --------- Co-authored-by: Soulter <905617992@qq.com>
1 parent 1408a84 commit 77d5d5c

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

astrbot/core/agent/mcp_client.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,29 @@ def _prepare_stdio_env(config: dict) -> dict:
5151
"""Preserve Windows executable resolution for stdio subprocesses."""
5252
if sys.platform != "win32":
5353
return config
54-
55-
pathext = os.environ.get("PATHEXT")
56-
if not pathext:
57-
return config
58-
5954
prepared = config.copy()
6055
env = dict(prepared.get("env") or {})
61-
env.setdefault("PATHEXT", pathext)
56+
env = _merge_environment_variables(env)
6257
prepared["env"] = env
6358
return prepared
6459

6560

61+
def _merge_environment_variables(env: dict) -> dict:
62+
"""合并环境变量,处理Windows不区分大小写的情况"""
63+
merged = env.copy()
64+
65+
# 将用户环境变量转换为统一的大小写形式便于比较
66+
user_keys_lower = {k.lower(): k for k in merged.keys()}
67+
68+
for sys_key, sys_value in os.environ.items():
69+
sys_key_lower = sys_key.lower()
70+
if sys_key_lower not in user_keys_lower:
71+
# 使用系统环境变量中的原始大小写
72+
merged[sys_key] = sys_value
73+
74+
return merged
75+
76+
6677
async def _quick_test_mcp_connection(config: dict) -> tuple[bool, str]:
6778
"""Quick test MCP server connectivity"""
6879
import aiohttp

0 commit comments

Comments
 (0)