Skip to content

Commit d0146bd

Browse files
DoctorReidclaudeglm-5.2
committed
fix(tools): start_mcp_server 健壮性(.env -PathType Leaf + LASTEXITCODE 检查)
CodeRabbit 增量 review 2 条: - .env 用 Test-Path -PathType Leaf(排除 .env 是目录的边界,目录会让 uv 失败)。 - cmd /c 后检查 $LASTEXITCODE 非零则 exit(ErrorActionPreference 对原生命令无效,非零退出码不进 catch,否则启动失败仍报成功)。 Co-Authored-By: Claude Code <noreply@anthropic.com> Co-Authored-By: glm-5.2 <noreply@bigmodel.cn>
1 parent ec6d7a4 commit d0146bd

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

tools/mcp/start_mcp_server.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ Write-Host ""
4141
# Switch to project root
4242
Set-Location $ProjectRoot
4343

44-
# --env-file 仅在 .env 存在时传(缺失时 uv 会在启动前失败,导致开机自启起不来)
45-
$EnvArg = if (Test-Path ".env") { "--env-file .env" } else { "" }
44+
# --env-file 仅在 .env 是普通文件时传(目录或缺失都不传;缺失时 uv 启动失败导致自启起不来)
45+
$EnvArg = if (Test-Path ".env" -PathType Leaf) { "--env-file .env" } else { "" }
4646
try {
4747
# Redirect via cmd /c: merge stdout/stderr into one file as raw bytes (matches
4848
# daemon subprocess.Popen(stdout=file, stderr=STDOUT); avoids PS native-redirect encoding issues)
4949
cmd /c "uv run $EnvArg python -m zzz_od.backend.entry.server --host $HostName --port $Port > `"$LogPath`" 2>&1"
50+
# cmd /c 的非零退出码不会触发 catch(ErrorActionPreference 对原生命令无效),手动检查避免启动失败仍报成功
51+
if ($LASTEXITCODE -ne 0) {
52+
Write-Host "[ERROR] Main MCP Server exited with code $LASTEXITCODE" -ForegroundColor Red
53+
exit $LASTEXITCODE
54+
}
5055
} catch {
5156
Write-Host "[ERROR] Main MCP Server failed to start: $_" -ForegroundColor Red
5257
exit 1

0 commit comments

Comments
 (0)