Skip to content

feat: add support for custom environment variable expansion#539

Merged
gocamille merged 24 commits intomainfrom
camille/env-var-expansion
Jan 9, 2026
Merged

feat: add support for custom environment variable expansion#539
gocamille merged 24 commits intomainfrom
camille/env-var-expansion

Conversation

@gocamille
Copy link
Copy Markdown
Contributor

Summary

This PR adds support for ${env.VAR_NAME} syntax in configuration files, allowing users to reference custom environment variables without being limited to the APOLLO_MCP_* naming convention.

Closes #454.

Changes

  • runtime/env_expansion.rs (new module) - parser for variable expansion

  • runtime.rs (modified) - integrates expansion into the read_config() function

  • config-file.mdx - updated docs with syntax, escaping, and special characters handling

  • Note The APOLLO_MCP_* environment variable(s) will still take precedence over expanded custom config values (no breaking change).

@apollo-librarian
Copy link
Copy Markdown
Contributor

apollo-librarian Bot commented Jan 7, 2026

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 1 changed, 0 removed
* (developer-tools)/apollo-mcp-server/(latest)/config-file.mdx

Build ID: a7e05f447a36fe36d782297e
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/a7e05f447a36fe36d782297e

Comment thread crates/apollo-mcp-server/src/runtime/env_expansion.rs Outdated
@gocamille gocamille force-pushed the camille/env-var-expansion branch from 824a742 to e6fcaf0 Compare January 7, 2026 17:31
@gocamille gocamille marked this pull request as ready for review January 7, 2026 17:32
@gocamille gocamille requested a review from a team as a code owner January 7, 2026 17:32
@gocamille gocamille requested a review from DaleSeo January 7, 2026 17:32
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 7, 2026

Changeset file missing for PR

All changes should include an associated changeset file.
Please refer to README for more information on generating changesets.

Copy link
Copy Markdown
Member

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gocamille, for implementing this so cleanly with solid tests! I believe this should meet the customer's request. However, I wanted to mention that most features in Apollo MCP Server have been following Router's patterns since they've been refined and tested over several years. This approach also ensures a consistent experience across Apollo products.

As I was reviewing this, I took a look at how Apollo Router implements the same functionality: https://github.com/apollographql/router/blob/dev/apollo-router/src/configuration/expansion.rs

Here are a couple of differences worth noting:

  • Router performs type coercion during expansion. Environment variables that contain true or 10 can be converted to YAML booleans or numbers. The current implementation only does string substitution before YAML parsing, which is simpler but requires users to be careful about how values are interpreted.
  • Architecturally, Router's expansion module is part of the library and available to crate consumers, while this implementation is limited to the binary's runtime module. That works for now, but it's something to keep in mind if we expect other consumers to want this functionality.

This isn't blocking anything, just flagging it for consideration.

}

#[test]
fn it_prioritizes_apollo_mcp_env_over_expanded_vars() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are really helpful to understand the precedence behavior!

Comment thread crates/apollo-mcp-server/src/env_expansion.rs Outdated
Comment thread crates/apollo-mcp-server/src/runtime/env_expansion.rs Outdated
Comment thread crates/apollo-mcp-server/src/runtime/env_expansion.rs Outdated
Comment thread crates/apollo-mcp-server/src/runtime/env_expansion.rs Outdated
Comment thread .changeset/feat_feat_env_var_expansion.md
Comment thread .changeset/feat_feat_env_var_expansion.md Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 8, 2026

Changeset file missing for PR

All changes should include an associated changeset file.
Please use knope document-change to create a changeset. (installation instructions: https://knope.tech/installation/)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 9, 2026

Changeset file missing for PR

All changes should include an associated changeset file.
Please use knope document-change to create a changeset. (installation instructions: https://knope.tech/installation/)

Co-authored-by: Dale Seo <5466341+DaleSeo@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 9, 2026

Changeset file missing for PR

All changes should include an associated changeset file.
Please use knope document-change to create a changeset. (installation instructions: https://knope.tech/installation/)

@gocamille
Copy link
Copy Markdown
Contributor Author

gocamille commented Jan 9, 2026

Thank you so much for your thorough review @DaleSeo ! I appreciated the insight on achieving logical parity with our long-standing Router features, that makes sense! I did take that suggestion and updated the core expand_env_vars function to leverage the well-supported shellexpand library, which is the same library used by Router. As you pointed out, we now have parity on the range of features this expansion module covers:

  • The MCP server now performs type coercion during expansion with shellexpand, like apollo router (a09f08c);
  • Default variable expansion has also been implemented (5ba738b); and
  • The expansion module here is now part of the library so it's available to crate consumers who want this functionality.

This PR is only targeting a very narrow band of features for environment variable expansion, but we could look into adding the following in the future to achieve parity with apollo-router (and consider other ways we'd want to extend it), including:

  • File expansion
  • Prefix support
  • Expansion modes
  • An override system
  • Developer mode defaults

@gocamille gocamille requested a review from DaleSeo January 9, 2026 05:45
Copy link
Copy Markdown
Member

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvements! 🎉

Comment thread .changeset/feat_env_var_expansion.md Outdated
@@ -0,0 +1,15 @@
### feat: add support for custom environment variable expansion - @gocamille PR #539

## Summary
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use #### here instead? I'm concerned that this might break the structure when we add it to the changelog.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point -- I'll update this!

@gocamille gocamille enabled auto-merge January 9, 2026 18:48
@gocamille gocamille merged commit dd26b17 into main Jan 9, 2026
10 checks passed
@gocamille gocamille deleted the camille/env-var-expansion branch January 9, 2026 18:49
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.

Allow Custom Environment Variable Mapping in Apollo MCP Server

3 participants