X Tutup
Skip to content

fix: preserve PATHEXT for stdio mcp servers on windows#5822

Open
XXXxx7258 wants to merge 2 commits intoAstrBotDevs:masterfrom
XXXxx7258:master
Open

fix: preserve PATHEXT for stdio mcp servers on windows#5822
XXXxx7258 wants to merge 2 commits intoAstrBotDevs:masterfrom
XXXxx7258:master

Conversation

@XXXxx7258
Copy link
Contributor

@XXXxx7258 XXXxx7258 commented Mar 7, 2026

Fix #5820

Modifications / 改动点

改动 "astrbot/core/agent/mcp_client.py"
当Windows 下启动 stdio MCP 服务时,如果用户没有显式传 env.PATHEXT,AstrBot 会从父进程补上 PATHEXT,避免 uvx --from git+... 无法解析 git.exe。用户自己配置的 PATHEXT 不会被覆盖。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

image

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

确保 Windows stdio MCP 子进程继承可执行文件解析设置,并为这一新行为添加测试覆盖。

Bug Fixes:

  • 在父进程已设置的情况下,为 Windows stdio MCP 服务器保留 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:

  • Preserve the PATHEXT environment variable for Windows stdio MCP servers when it is set on the parent process, preventing command resolution failures while respecting user overrides.

Tests:

  • Add unit tests verifying PATHEXT propagation, environment merging, user-defined PATHEXT preservation, and no-op behavior on non-Windows platforms for stdio MCP configuration.

Copilot AI review requested due to automatic review settings March 7, 2026 06:50
@auto-assign auto-assign bot requested review from Fridemn and Soulter March 7, 2026 06:50
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 7, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Windows PATHEXT handling: Implemented logic to automatically propagate the PATHEXT environment variable from the parent process to stdio MCP server subprocesses on Windows, ensuring executables like git.exe are discoverable. This behavior is conditional on the PATHEXT not being explicitly set by the user, preventing accidental overwrites.
Changelog
  • astrbot/core/agent/mcp_client.py
    • Imported 'os' and 'sys' modules for platform detection and environment variable access.
    • Introduced '_prepare_stdio_env' function to conditionally add the system's PATHEXT to the subprocess environment on Windows.
    • Applied '_prepare_stdio_env' to the configuration for StdioServerParameters.
  • tests/unit/test_mcp_client.py
    • Added a new test file to validate the '_prepare_stdio_env' function's behavior.
    • Included tests for PATHEXT addition, merging with existing environment variables, respecting user-defined PATHEXT, and ensuring no changes on non-Windows platforms.
Activity
  • The author provided screenshots and test results to demonstrate the fix.
  • The author confirmed that this is not a breaking change.
  • The author verified that no new dependencies were introduced.
  • The author confirmed the absence of malicious code.
  • The author indicated that the changes have been well-tested.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我已经审阅了你的更改,一切看起来都很棒!


Sourcery 对开源项目是免费的——如果你喜欢我们的审查结果,请考虑分享给更多人 ✨
让我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进后续的审查。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Mar 7, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_env to inject PATHEXT into stdio MCP server config on Windows when available.
  • Apply _prepare_stdio_env right before constructing mcp.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Windows 下 MCP Stdio 模式未继承 PATHEXT,导致 uvx --from git+... 无法找到 git.exe

2 participants

X Tutup