From ab8d342596aaddc5e9c54ef80144907cd4e9dfb2 Mon Sep 17 00:00:00 2001 From: GuDaStudio Date: Mon, 10 Nov 2025 12:45:01 +0800 Subject: [PATCH] =?UTF-8?q?v0.4.2=EF=BC=9A=E4=BF=AE=E5=A4=8DWindows?= =?UTF-8?q?=E4=B8=8B=E7=BC=96=E7=A0=81bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/codexmcp/server.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/codexmcp/server.py b/src/codexmcp/server.py index 290b7af..c499b54 100644 --- a/src/codexmcp/server.py +++ b/src/codexmcp/server.py @@ -13,6 +13,7 @@ from typing import Annotated, Any, Dict, Generator, Literal, Optional from mcp.server.fastmcp import FastMCP from pydantic import BeforeValidator, Field +import shutil mcp = FastMCP("Codex MCP Server-from guda.studio") @@ -35,11 +36,11 @@ def run_shell_command(cmd: list[str]) -> Generator[str, None, None]: """ # On Windows, codex is exposed via a *.cmd shim. Use cmd.exe with /s so # user prompts containing quotes/newlines aren't reinterpreted as shell syntax. - if os.name == "nt": - quoted_cmd = subprocess.list2cmdline(cmd) - popen_cmd = ["cmd", "/d", "/s", "/c", quoted_cmd] - else: - popen_cmd = cmd + popen_cmd = cmd + + codex_path = shutil.which('codex') or None # 替换运行路径 + if codex_path is not None: + popen_cmd[0] = codex_path process = subprocess.Popen( popen_cmd, @@ -48,7 +49,7 @@ def run_shell_command(cmd: list[str]) -> Generator[str, None, None]: stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, - bufsize=1, + encoding='utf-8', ) output_queue: queue.Queue[str] = queue.Queue()