Propagate parent env to MCP server subprocess #23

Merged
archeious merged 1 commit from fix/mcp-env-propagation into main 2026-04-08 21:32:11 +00:00
Collaborator

Closes Issue #18

Change

  • cli/main.py: pass env=os.environ.copy() to StdioServerParameters so the spawned MCP server inherits the CLI's environment. Without this, vars like MARCHWARDEN_MODEL set on the CLI process were silently dropped before reaching the researcher.
  • scripts/docker-test.sh:
    • Forward MARCHWARDEN_MODEL into the ask container if set on the host
    • Detect a non-TTY parent and drop -it flags so non-interactive ask runs don't fail with the input device is not a TTY (needed when invoking from automation/agents)

Out of scope

A more conservative env-passing strategy (whitelist MARCHWARDEN_* plus specific keys instead of copying everything) — noted in Issue #18 as a future hardening.

88/88 tests still passing.

Closes Issue #18 ## Change - `cli/main.py`: pass `env=os.environ.copy()` to `StdioServerParameters` so the spawned MCP server inherits the CLI's environment. Without this, vars like `MARCHWARDEN_MODEL` set on the CLI process were silently dropped before reaching the researcher. - `scripts/docker-test.sh`: - Forward `MARCHWARDEN_MODEL` into the `ask` container if set on the host - Detect a non-TTY parent and drop `-it` flags so non-interactive `ask` runs don't fail with `the input device is not a TTY` (needed when invoking from automation/agents) ## Out of scope A more conservative env-passing strategy (whitelist `MARCHWARDEN_*` plus specific keys instead of copying everything) — noted in Issue #18 as a future hardening. 88/88 tests still passing.
claude-code added 1 commit 2026-04-08 21:31:23 +00:00
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) <noreply@anthropic.com>
archeious approved these changes 2026-04-08 21:32:06 +00:00
archeious merged commit 8293cbfb68 into main 2026-04-08 21:32:11 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: archeious/marchwarden#23
No description provided.