Skip to content

Add environment variable expansion for allowedDomains config - #5

Open
npeham wants to merge 6 commits into
mainfrom
claude/wizardly-fermat-EHOaS
Open

Add environment variable expansion for allowedDomains config#5
npeham wants to merge 6 commits into
mainfrom
claude/wizardly-fermat-EHOaS

Conversation

@npeham

@npeham npeham commented Jun 6, 2026

Copy link
Copy Markdown

Summary

This PR adds support for environment variable substitution in the allowedDomains configuration across mcpSettings, actions, and registration sections. Operators can now reference environment variables using ${ENV_VAR} syntax, and if the resolved value is a comma-separated list (optionally wrapped in brackets), it is automatically expanded into multiple domains.

This allows operators to manage domain allowlists centrally via environment variables, e.g.:

MCP_ALLOWED_DOMAINS='http://internal:8080,https://secure.api.com'

Then reference it in config:

mcpSettings:
  allowedDomains:
    - '${MCP_ALLOWED_DOMAINS}'

Change Type

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Changes

  • packages/data-provider/src/config.ts:

    • Added expandAllowedDomainsEntry() helper to resolve ${ENV_VAR} references and expand comma-separated lists
    • Added stripWrappingQuotes() utility for parsing quoted domain entries
    • Created allowedDomainsSchema Zod schema with transformation logic
    • Updated configSchema to use allowedDomainsSchema for mcpSettings.allowedDomains, actions.allowedDomains, and registration.allowedDomains
  • packages/data-provider/src/config.spec.ts:

    • Added comprehensive test suite for allowedDomainsSchema covering:
      • Literal domain passthrough
      • Single environment variable resolution
      • Comma-separated list expansion
      • Bracket-wrapped and quoted list parsing
      • Combining literal entries with expanded env vars
      • Fail-closed behavior (undefined env vars remain as placeholders)
      • Empty entry filtering
      • Integration with configSchema
  • librechat.example.yaml:

    • Updated documentation to explain ${ENV_VAR} syntax and comma-separated list expansion

Testing

All new functionality is covered by unit tests in config.spec.ts. The test suite validates:

  • Environment variable resolution and expansion
  • Comma-separated list parsing with optional bracket wrapping
  • Quote stripping from individual entries
  • Fail-closed behavior when env vars are undefined
  • Integration with the main configSchema

Run tests with: cd packages/data-provider && npx jest config.spec.ts

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in complex areas of my code (JSDoc on public schema and helpers)
  • I have made pertinent documentation changes (example config updated)
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective
  • Local unit tests pass with my changes

https://claude.ai/code/session_01GmfhbeTigYTtP5Bw52Keek

claude added 3 commits June 6, 2026 13:59
Resolve ${ENV_VAR} references in mcpSettings/actions/registration
allowedDomains via a shared allowedDomainsSchema. An entry that resolves
to a comma-separated (optionally bracket-wrapped) list is expanded into
multiple domains, so the whole allowlist can live in a single env var.

Backward compatible: literal entries contain no ${} placeholders and no
commas, so they pass through unchanged.
Accept either a YAML array or a scalar string for allowedDomains so the
whole allowlist can be supplied through one env var, e.g.
allowedDomains: '${MCP_ALLOWED_DOMAINS}'. The resolved value is split on
commas (optionally bracket-wrapped) into individual domains.
@railway-app
railway-app Bot temporarily deployed to Proactive - AI Hub - Demo / feature-dev June 7, 2026 08:29 Inactive
loadCustomConfig returns the raw (pre-transform) config object, so the
allowedDomainsSchema transform never reached consumers — mcpSettings/
actions/registration allowedDomains kept their literal ${ENV_VAR}
placeholders at runtime, mirroring how mcpServers urls rely on
processMCPEnv rather than the schema transform.

Extract the resolution into a reusable resolveAllowedDomains() and apply
it where AppService builds the app config, so env references and
comma-separated list expansion actually take effect.
@railway-app
railway-app Bot temporarily deployed to Proactive - AI Hub - Demo / feature-dev June 7, 2026 10:50 Inactive
Hardens against compose-style quoted env vars (e.g.
MCP_ALLOWED_DOMAINS="http://mastra:4111") where the quotes become part
of the value. The comma-list path already stripped quotes; apply the same
to the single-value path.
@railway-app
railway-app Bot temporarily deployed to Proactive - AI Hub - Demo / feature-dev June 7, 2026 13:11 Inactive
Carry the schema-transformed mcpSettings/actions/registration from
result.data into the returned config (mirrors the existing modelSpecs
handling), so ${ENV_VAR} references in allowedDomains are resolved for
consumers. loadCustomConfig.js is plain runtime code, so this takes
effect without a package rebuild.

Revert the equivalent AppService-layer resolution (now redundant) and
make resolveAllowedDomains internal to the data-provider schema again.
@railway-app
railway-app Bot temporarily deployed to Proactive - AI Hub - Demo / feature-dev June 7, 2026 14:26 Inactive
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.

2 participants