From d0a732735edacaa283cefbf5cb27e1d2b4dffd2f Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Wed, 8 Apr 2026 15:31:14 -0600 Subject: [PATCH] Propagate parent env to MCP server subprocess (#18) The mcp SDK's StdioServerParameters does not pass the parent process's environment to the spawned server by default, so env vars set on the CLI process (notably MARCHWARDEN_MODEL) were silently dropped on the way to the researcher. Pass env=os.environ.copy() to StdioServerParameters so the server sees the same environment as the CLI. Also update scripts/docker-test.sh to forward MARCHWARDEN_MODEL into the container and to detect a non-TTY parent so non-interactive `ask` invocations don't fail with "the input device is not a TTY". Co-Authored-By: Claude Opus 4.6 (1M context) --- cli/main.py | 1 + scripts/docker-test.sh | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/main.py b/cli/main.py index 4802f11..69808e8 100644 --- a/cli/main.py +++ b/cli/main.py @@ -40,6 +40,7 @@ async def call_research_tool( params = StdioServerParameters( command=sys.executable, args=["-m", "researchers.web.server"], + env=os.environ.copy(), ) async with stdio_client(params) as (read, write): async with ClientSession(read, write) as session: diff --git a/scripts/docker-test.sh b/scripts/docker-test.sh index e7cc707..d844061 100755 --- a/scripts/docker-test.sh +++ b/scripts/docker-test.sh @@ -31,7 +31,13 @@ case "$cmd" in exit 1 fi mkdir -p "$HOME/.marchwarden/traces" - docker run --rm -it \ + tty_flag="" + if [ -t 0 ] && [ -t 1 ]; then tty_flag="-it"; fi + env_flag="" + if [ -n "${MARCHWARDEN_MODEL:-}" ]; then + env_flag="-e MARCHWARDEN_MODEL=$MARCHWARDEN_MODEL" + fi + docker run --rm $tty_flag $env_flag \ -v "$ROOT:/app" \ -v "$HOME/secrets:/root/secrets:ro" \ -v "$HOME/.marchwarden:/root/.marchwarden" \ -- 2.45.2