fix: preserve PATHEXT for stdio mcp servers on windows#5822
fix: preserve PATHEXT for stdio mcp servers on windows#5822XXXxx7258 wants to merge 2 commits intoAstrBotDevs:masterfrom
Conversation
fix: preserve PATHEXT for stdio mcp servers on windows
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue on Windows where uvx commands failed to locate executables like git.exe when launching stdio MCP servers, due to the PATHEXT environment variable not being correctly inherited by subprocesses. The changes introduce a mechanism to ensure PATHEXT is preserved, thereby improving the reliability of command execution within the AstrBot environment on Windows. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - 我已经审阅了你的更改,一切看起来都很棒!
让我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进后续的审查。
Original comment in English
Hey - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request addresses an issue on Windows where PATHEXT was not being preserved for stdio MCP servers. The change introduces a new helper function, _prepare_stdio_env, to correctly propagate PATHEXT from the parent process to the subprocess environment, without overriding user-configured values. The implementation is clean and includes comprehensive unit tests for various scenarios. The changes are well-executed and effectively resolve the issue.
There was a problem hiding this comment.
Pull request overview
This PR fixes a Windows-specific MCP stdio startup issue where PATHEXT is not inherited into the stdio subprocess environment (notably impacting uvx --from git+... resolving git.exe). It adds a small config-preparation helper to preserve PATHEXT from the parent process when the user hasn’t explicitly set it.
Changes:
- Add
_prepare_stdio_envto injectPATHEXTinto stdio MCP server config on Windows when available. - Apply
_prepare_stdio_envright before constructingmcp.StdioServerParameters(...). - Add unit tests covering Windows/non-Windows behavior and user override preservation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
astrbot/core/agent/mcp_client.py |
Preserves PATHEXT for Windows stdio MCP subprocesses without overriding user-provided env. |
tests/unit/test_mcp_client.py |
Adds unit tests validating PATHEXT injection/merge behavior and non-Windows no-op behavior. |
Fix #5820
Modifications / 改动点
改动 "astrbot/core/agent/mcp_client.py"
当Windows 下启动 stdio MCP 服务时,如果用户没有显式传 env.PATHEXT,AstrBot 会从父进程补上 PATHEXT,避免 uvx --from git+... 无法解析 git.exe。用户自己配置的 PATHEXT 不会被覆盖。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
确保 Windows stdio MCP 子进程继承可执行文件解析设置,并为这一新行为添加测试覆盖。
Bug Fixes:
PATHEXT环境变量,防止命令解析失败,同时尊重用户自定义覆盖。Tests:
PATHEXT传递、环境变量合并、用户自定义PATHEXT的保留,以及在非 Windows 平台上对 stdio MCP 配置的不进行任何操作(no-op)行为。Original summary in English
Summary by Sourcery
Ensure Windows stdio MCP subprocesses inherit executable resolution settings and add coverage for the new behavior.
Bug Fixes:
Tests: