Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix: attach stdin for docker-native MCP stdio (#3447)

宇宙的山峰a490bba83fdf
diff --git a/scripts/install.ps1 b/scripts/install.ps1
index a93d7ef5a..ce8282ef4 100644
--- a/scripts/install.ps1
+++ b/scripts/install.ps1
@@ -194,14 +194,10 @@ function Get-SharedDockerArgs {
function Add-TtyArgs {
param($ArgsList)
+ # MCP stdio always uses a pipe for stdin. Docker only forwards stdin when
+ # explicitly given -i, regardless of whether the host console is redirected.
+ $ArgsList.Add('-i')
if (-not [Console]::IsInputRedirected -and -not [Console]::IsOutputRedirected) {
- $ArgsList.Add('-it')
- return
- }
- if (-not [Console]::IsInputRedirected) {
- $ArgsList.Add('-i')
- }
- if (-not [Console]::IsOutputRedirected) {
$ArgsList.Add('-t')
}
}
diff --git a/tests/test_install/test_native_installers.py b/tests/test_install/test_native_installers.py
index fdf61eb43..e6b3e5242 100644
--- a/tests/test_install/test_native_installers.py
+++ b/tests/test_install/test_native_installers.py
@@ -647,6 +647,61 @@ def test_powershell_installer_does_not_leak_into_user_path(tmp_path: Path) -> No
_restore_user_path_entry(before)
+ os.name != "nt" or _powershell_executable() is None,
+ reason="Windows PowerShell coverage runs on Windows hosts only",
+)
+def test_powershell_mcp_wrapper_keeps_stdin_attached_for_redirected_stdio(
+ tmp_path: Path,
+) -> None:
+ """Piped MCP stdio must still pass -i to Docker even when input is redirected."""
+ powershell = _powershell_executable()
+ assert powershell is not None
+
+ home = tmp_path / "home"
+ (home / ".local").mkdir(parents=True)
+ env = _build_env(home, tmp_path)
+ env["HEADROOM_DOCKER_IMAGE"] = "headroom:test-image"
+
+ try:
+ _run(
+ [
+ powershell,
+ "-NoProfile",
+ "-ExecutionPolicy",
+ "Bypass",
+ "-File",
+ str(REPO_ROOT / "scripts" / "install.ps1"),
+ ],
+ env=env,
+ cwd=REPO_ROOT,
+ )
+ wrapper = home / ".local" / "bin" / "headroom.ps1"
+ result = subprocess.run(
+ [
+ powershell,
+ "-NoProfile",
+ "-ExecutionPolicy",
+ "Bypass",
+ "-File",
+ str(wrapper),
+ "mcp",
+ "serve",
+ ],
+ env=env,
+ input='{"jsonrpc":"2.0","id":1,"method":"initialize"}\n',
+ capture_output=True,
+ text=True,
+ check=True,
+ )
+ assert result.returncode == 0
+ mcp_call = next(call for call in _read_fake_docker_log(env) if call[:2] == ["run", "--rm"])
+ assert "-i" in mcp_call
+ assert "-t" not in mcp_call
+ finally:
+ _cleanup_fake_docker(env)
+
+
# AST-extract Ensure-PathEntry from install.ps1 and invoke it in isolation under
# a given HEADROOM_INSTALL_PATH_SCOPE, so the scope allow-list is exercised
# without running the whole installer. Parsing via the PowerShell AST (not a