Skip to content

fix(config): expand env vars in MCP HTTP/SSE headers (#365) - #367

Merged
Million-mo merged 3 commits into
wolf1069b:mainfrom
Million-mo:fix/mcp-headers-expandvars
Aug 11, 2026
Merged

fix(config): expand env vars in MCP HTTP/SSE headers (#365)#367
Million-mo merged 3 commits into
wolf1069b:mainfrom
Million-mo:fix/mcp-headers-expandvars

Conversation

@Million-mo

Copy link
Copy Markdown
Collaborator

What

MCP HTTP/SSE header values now support ${VAR} environment variable expansion before the transport is created. Previously a header like Authorization: Bearer ${API_TOKEN} was sent to the MCP server as a literal string, causing 401 Unauthorized for authenticated servers and forcing users to hard-code credentials in YAML.

Why

Fixes #365. The expansion mirrors the existing ${VAR} support already present for skill mcp.json companion files (wolfharness.skills.skill._expand_env_vars_in_value).

Changes

  • src/wolfharness_config/mcp_server.py: add _expand_headers() helper; use it in SSEMCPServerConfig.to_transport() and StreamableHTTPMCPServerConfig.to_transport()
  • src/wolfharness/mcp_server/session_pool.py: apply the same expansion in _create_transport() (a separate transport-construction path that does not route through to_transport())
  • Tests: reproductions for both transports × both construction paths (4 new unit tests)
  • Changelog: unreleased entry

Verification

  • ruff check / ruff format pass (also validated by pre-commit)
  • 43 tests pass in tests/config/test_mcp_server_config.py + tests/mcp_server/test_session_pool.py
  • Manual: curl against a /mcp endpoint with Bearer token resolves 401 → successful MCP initialize

Notes

os.path.expandvars leaves unresolved placeholders as-is (no error) — unmatched env var names silently pass through, so a typo'd variable will still send the literal and fail at auth. This matches the existing skill mcp.json behavior.

Million-mo and others added 3 commits August 11, 2026 14:47
Expand ${VAR} placeholders in SSEMCPServerConfig and
StreamableHTTPMCPServerConfig header values via os.path.expandvars
before transport construction, in both to_transport() and the session
pool's _create_transport(). Without this, authenticated MCP servers
receiving 'Bearer ${TOKEN}' literals fail with 401.

Resolves wolf1069b#365.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
…1069b#365)

Add reproductions verifying ${VAR} expansion in to_transport() and
_create_transport() for both SSE and streamable-http transports.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@Million-mo
Million-mo merged commit 04d8eb4 into wolf1069b:main Aug 11, 2026
12 of 13 checks passed
@Million-mo
Million-mo deleted the fix/mcp-headers-expandvars branch August 12, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP HTTP/SSE headers do not expand environment variables, causing auth headers to be sent as literals

1 participant