Skip to content

feat: support ${VAR} environment variable interpolation in headers#10

Open
mrmodolo wants to merge 1 commit intoagoda-com:mainfrom
mrmodolo:feat/env-var-interpolation
Open

feat: support ${VAR} environment variable interpolation in headers#10
mrmodolo wants to merge 1 commit intoagoda-com:mainfrom
mrmodolo:feat/env-var-interpolation

Conversation

@mrmodolo
Copy link

Problem

Header values like X-Target-Headers and X-Target-URL require hardcoded secrets and environment-specific URLs, making it difficult to version-control MCP client configurations.

Solution

Expand ${VAR_NAME} references in header values using os.environ at request time. Applied to the three headers that typically contain secrets or environment-specific values:

  • X-Target-URL
  • X-Target-Headers
  • X-Base-URL

Example

{
  "headers": {
    "X-Target-URL": "${MY_API_ENDPOINT}",
    "X-Target-Headers": "{\"Authorization\": \"Bearer ${MY_API_TOKEN}\"}",
    "X-Base-URL": "${MY_API_BASE_URL}"
  }
}

Design decisions

  • Unknown variables left as-is${UNDEFINED} stays literal rather than becoming empty string, making misconfiguration easy to spot.
  • Scoped to 3 headers — only headers that carry secrets/URLs are expanded. X-API-Type, X-Allow-Unsafe-Paths, etc. are not interpolated.
  • Single function, single regex — minimal surface area, ~8 lines of new code.
  • All 336 existing tests pass with no modifications.

Security note

The expansion runs server-side, so in a shared/multi-tenant deployment a client could potentially read arbitrary env vars. This matches the existing trust model (the user who configures headers already controls the server environment), but is worth noting for anyone considering multi-tenant setups.

Expand ${VAR_NAME} references in X-Target-URL, X-Target-Headers, and
X-Base-URL header values using os.environ at request time.

This allows MCP client configurations to be version-controlled without
embedding secrets or environment-specific values directly:

  "X-Target-Headers": "{\"Authorization\": \"Bearer ${MY_TOKEN\"}"

Unknown variables are left as-is for easy debugging of incomplete configs.
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.

1 participant