feat: Add environment variable support for HTTP MCP headers #3075
+33
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #3076
Summary
Enables
${env:VAR_NAME}
syntax in HTTP MCP server headers, extending the existing environment variable processing from stdio transport to http transport. This improves security by allowing users to avoid hardcoding sensitive tokens in configuration files.Problem
Previously, MCP configuration only supported environment variable substitution for
stdio
transport servers (via theenv
field), but not forhttp
transport servers. Users had to hardcode sensitive tokens like GitHub PATs directly in theheaders
field of their MCP configuration:This creates security risks as tokens are stored in plain text configuration files.
Solution
This PR extends the existing
substitute_env_vars()
function to process HTTP headers, enabling the same${env:VAR_NAME}
syntax that's already available for stdio transport.Usage Example
Configuration:
Environment:
Changes
Core Implementation
crates/chat-cli/src/mcp_client/client.rs
: Added environment variable processing for HTTP headers in theTransportType::Http
branchTesting
test_http_headers_env_var_processing()
substitute_env_vars()
andprocess_env_vars()
functionsBenefits
${env:VAR_NAME}
syntax as stdio transportTesting
Related
This addresses the security concern of storing sensitive tokens in MCP configuration files and provides feature parity between stdio and http transport types for environment variable support.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.