mcp-builder: repeated -e/--env and -H/--header flags in evaluation.py silently drop all but the last value
Summary
skills/mcp-builder/scripts/evaluation.py declares -e/--env and -H/--header as
nargs="+" options with argparse's default store action, so when a user repeats
the flag — which the skill's own guide tells them to do — the later occurrence
replaces the earlier one. The first value is discarded silently: no warning, no
error, non-zero exit.
The guide documents the repeated form twice:
skills/mcp-builder/reference/evaluation.md:440-446python scripts/evaluation.py \ -t stdio \ -c python \ -a my_mcp_server.py \ -e API_KEY=abc123 \ -e DEBUG=true \ evaluation.xmlskills/mcp-builder/reference/evaluation.md:454-459python scripts/evaluation.py \ -t sse \ -u https://example.com/mcp \ -H "Authorization: Bearer token123" \ -H "X-Custom-Header: value" \ evaluation.xml
What actually happens
Lines 329 and 333 of evaluation.py on main:
stdio_group.add_argument("-e", "--env", nargs="+", help="Environment variables in KEY=VALUE format (stdio only)")
remote_group.add_argument("-H", "--header", nargs="+", dest="headers", help="HTTP headers in 'Key: Value' format (sse/http only)")store + nargs="+" means args.env is assigned, not extended, on every
occurrence. parse_env_vars() / parse_headers() (lines 275-307) then only ever
see the last one.
Reproduced against the shipped argparse block, with only anthropic and
connections stubbed (this box has no API key and neither dependency installed, so
create_connection()'s arguments are the observable output). Run against
origin/main's bytes:
CASE 1: two -e, as reference/evaluation.md:440-446 tells you to write it
env={'DEBUG': 'true'} <- API_KEY=abc123 silently gone
headers=None
CASE 2: two -H, as reference/evaluation.md:454-459 tells you to write it
env=None
headers={'X-Custom-Header': 'value'} <- Authorization silently gone
CASE 4: one -e carrying two values, plus a second -e
env={'C': '3'} <- 2 of 3 pairs lostThe consequences are the ones that matter:
- stdio: the MCP server the harness launches never receives
API_KEY. The evaluation runs, every task fails or returnsNOT_FOUND, and the report blames the server under test for a credential that was dropped by the harness. - sse/http: the request carries no
Authorizationheader, so a protected server answers 401 — and the header the user typed is nowhere in the output.
Nothing in parse_headers()/parse_env_vars() reports the loss; both only warn
about values that are malformed, and API_KEY=abc123 is well-formed.
Proposed fix
action="extend" on both declarations (Python 3.8+; this file already requires
3.10+, e.g. -> str | None at line 79):
stdio_group.add_argument("-e", "--env", action="extend", nargs="+", help="Environment variables in KEY=VALUE format (stdio only)")
remote_group.add_argument("-H", "--header", action="extend", nargs="+", dest="headers", help="HTTP headers in 'Key: Value' format (sse/http only)")extend is strictly additive: the single-occurrence form that works today
(-e A=1 B=2) keeps working, and the documented repeated form starts accumulating
instead of overwriting. Measured on the branch:
CASE 1: env={'API_KEY': 'abc123', 'DEBUG': 'true'} headers=None
CASE 2: env=None headers={'Authorization': 'Bearer token123', 'X-Custom-Header': 'value'}
CASE 3 (regression, one -e two values): env={'API_KEY': 'abc123', 'DEBUG': 'true'} identical to main
CASE 4: env={'A': '1', 'B': '2', 'C': '3'}
CASE 5 (regression, no -e/-H at all): env=None headers=None identical to mainpython -m py_compile passes on both origin/main's bytes and the branch.
Deliberately out of scope
-a/--args(line 328) carries the samestore+nargs="+"declaration and has the same overwrite behaviour, but no documented usage repeats-a, so it is left alone rather than bundled on speculation.- Separately measured, also not fixed here because the minimal repair is prose: 4 of
the 6
python scripts/evaluation.py ...command lines inreference/evaluation.md(lines 431, 440, 454, 467) exit witherror: the following arguments are required: eval_filebefore reaching any of this code. Anargs="+"option that appears last consumes the trailing positional (evaluation.xml) as one of its own values; the two that do parse (lines 522 and- are exactly the two whose final option is
-o, which takes a single value and therefore leaves the operand for the positional. That needs the operand moved first or a--separator in the docs, which is a documentation change — filed here only for completeness, and it is why the reproductions above place the XML file first.
- are exactly the two whose final option is
Duplicate check
Open PRs were enumerated with their changed-file lists at 2026-09-28 01:17Z (961
open); re-checked now, the open set is 962 and the only addition is #1894, which
changes one file (web-artifacts-builder/scripts/init-artifact.sh).
Of that set, 24 touch skills/mcp-builder/scripts/evaluation.py (#657 #747 #1321
#1377 #1386 #1397 #1588 #1602 #1674 #1676 #1683 #1690 #1720 #1724 #1780 #1837 #1838
#1839 #1840 #1841 #1842 #1843 #1844 #1845) — all 24 were confirmed OPEN again
immediately before filing, and all 24 patches were re-downloaded this round with no
errors. They were grepped for any added or removed line naming the two options or
the two parse helpers:
- Only #747 rewrites these declarations, and it is a pure line-wrap reformat —
it keeps
nargs="+"and adds noaction=, so the overwrite behaviour survives it unchanged:- stdio_group.add_argument("-e", "--env", nargs="+", help="...") + "-e", "--env", nargs="+", help="..." - remote_group.add_argument("-H", "--header", nargs="+", dest="headers", ...) + "-H", + "--header", - No PR touches
parse_headers()orparse_env_vars().
Source: anthropics/skills