mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
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>
This commit is contained in:
@@ -51,18 +51,29 @@ 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)
|
||||
env = _merge_environment_variables(env)
|
||||
prepared["env"] = env
|
||||
return prepared
|
||||
|
||||
|
||||
def _merge_environment_variables(env: dict) -> dict:
|
||||
"""合并环境变量,处理Windows不区分大小写的情况"""
|
||||
merged = env.copy()
|
||||
|
||||
# 将用户环境变量转换为统一的大小写形式便于比较
|
||||
user_keys_lower = {k.lower(): k for k in merged.keys()}
|
||||
|
||||
for sys_key, sys_value in os.environ.items():
|
||||
sys_key_lower = sys_key.lower()
|
||||
if sys_key_lower not in user_keys_lower:
|
||||
# 使用系统环境变量中的原始大小写
|
||||
merged[sys_key] = sys_value
|
||||
|
||||
return merged
|
||||
|
||||
|
||||
async def _quick_test_mcp_connection(config: dict) -> tuple[bool, str]:
|
||||
"""Quick test MCP server connectivity"""
|
||||
import aiohttp
|
||||
|
||||
Reference in New Issue
Block a user