Skip to content

Commit fc1c6d1

Browse files
authored
Merge pull request #211 from apollographql/GT-317
2 parents 3264533 + 8771b2c commit fc1c6d1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

crates/apollo-mcp-server/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ struct Args {
3838

3939
#[tokio::main]
4040
async fn main() -> anyhow::Result<()> {
41-
let config: runtime::Config = Args::parse()
42-
.config
43-
.map(runtime::read_config)
44-
.transpose()?
45-
.unwrap_or_default();
41+
let config: runtime::Config = match Args::parse().config {
42+
Some(config_path) => runtime::read_config(config_path)?,
43+
None => runtime::read_config_from_env().unwrap_or_default(),
44+
};
4645

4746
let mut env_filter = EnvFilter::from_default_env().add_directive(config.logging.level.into());
4847

crates/apollo-mcp-server/src/runtime.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ pub use schema_source::SchemaSource;
2626
/// Separator to use when drilling down into nested options in the env figment
2727
const ENV_NESTED_SEPARATOR: &str = "__";
2828

29+
/// Read configuration from environment variables only (when no config file is provided)
30+
#[allow(clippy::result_large_err)]
31+
pub fn read_config_from_env() -> Result<Config, figment::Error> {
32+
Figment::new()
33+
.join(apollo_common_env())
34+
.join(Env::prefixed("APOLLO_MCP_").split(ENV_NESTED_SEPARATOR))
35+
.extract()
36+
}
37+
2938
/// Read in a config from a YAML file, filling in any missing values from the environment
3039
#[allow(clippy::result_large_err)]
3140
pub fn read_config(yaml_path: impl AsRef<Path>) -> Result<Config, figment::Error> {

0 commit comments

Comments
 (0)