Skip to content

Commit 72341f0

Browse files
committed
Reject missing explicit MCP configs
Return an error when an explicit MCP config path is missing or is not a file. This prevents the bridge from selecting the default node instead. This commit was created with assistance from Codex.
1 parent d0d84d9 commit 72341f0

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

ldk-server-mcp/src/config.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ pub fn resolve_config(config_path: Option<String>) -> Result<ResolvedConfig, Str
2828
env_base_url.is_some() && env_api_key.is_some() && env_tls_cert_path.is_some();
2929

3030
let explicit_config_path = config_path.map(PathBuf::from);
31+
if let Some(path) = &explicit_config_path {
32+
if !path.is_file() {
33+
return Err(format!(
34+
"Config file '{}' does not exist or is not a file",
35+
path.display()
36+
));
37+
}
38+
}
3139
let config_path = explicit_config_path.clone().or_else(get_default_config_path);
3240
let config = match config_path {
3341
Some(ref path)
@@ -136,6 +144,7 @@ mod tests {
136144
let temp_dir = std::env::temp_dir()
137145
.join(format!("ldk-server-mcp-config-fallback-{}", std::process::id()));
138146
std::fs::create_dir_all(&temp_dir).unwrap();
147+
let (default_dir_env_var, old_default_dir) = set_default_data_dir(&temp_dir);
139148

140149
let cert_path = temp_dir.join("tls.crt");
141150
std::fs::write(&cert_path, b"test-cert").unwrap();
@@ -144,16 +153,31 @@ mod tests {
144153
std::env::set_var("LDK_API_KEY", "deadbeef");
145154
std::env::set_var("LDK_TLS_CERT_PATH", &cert_path);
146155
std::env::remove_var("LDK_BASE_URL");
147-
let resolved =
148-
resolve_config(Some(temp_dir.join("nonexistent.toml").display().to_string())).unwrap();
156+
let resolved = resolve_config(None).unwrap();
149157
std::env::remove_var("LDK_API_KEY");
150158
std::env::remove_var("LDK_TLS_CERT_PATH");
159+
restore_env_var(&default_dir_env_var, old_default_dir);
151160

152161
assert_eq!(resolved.base_url, DEFAULT_GRPC_SERVICE_ADDRESS);
153162

154163
std::fs::remove_dir_all(temp_dir).unwrap();
155164
}
156165

166+
#[test]
167+
fn resolve_config_rejects_missing_explicit_config() {
168+
let _lock = ENV_LOCK.lock().unwrap();
169+
let temp_dir = std::env::temp_dir()
170+
.join(format!("ldk-server-mcp-missing-config-{}", std::process::id()));
171+
std::fs::create_dir_all(&temp_dir).unwrap();
172+
let missing_path = temp_dir.join("missing.toml");
173+
174+
let result = resolve_config(Some(missing_path.display().to_string()));
175+
176+
std::fs::remove_dir_all(temp_dir).unwrap();
177+
let error = result.err().unwrap();
178+
assert!(error.contains(&missing_path.display().to_string()));
179+
}
180+
157181
#[test]
158182
fn resolve_config_ignores_malformed_default_config_when_env_complete() {
159183
let _lock = ENV_LOCK.lock().unwrap();

0 commit comments

Comments
 (0)