diff --git a/src/commands/mcp/install.rs b/src/commands/mcp/install.rs index e120b5d5d..a0b45ff0e 100644 --- a/src/commands/mcp/install.rs +++ b/src/commands/mcp/install.rs @@ -1,5 +1,5 @@ use super::*; -use crate::commands::skills::resolve_tools; +use crate::{commands::skills::resolve_tools, consts::RAILWAY_API_TOKEN_ENV}; use serde_json::{Value as JsonValue, json}; use std::path::{Path, PathBuf}; @@ -171,6 +171,10 @@ fn codex_mcp_configured(path: &Path, remote: bool) -> bool { .is_some_and(|entry| { if remote { entry.get("url").and_then(toml::Value::as_str) == Some(REMOTE_MCP_URL) + && entry + .get("bearer_token_env_var") + .and_then(toml::Value::as_str) + == Some(RAILWAY_API_TOKEN_ENV) } else { entry.get("command").and_then(toml::Value::as_str) == Some("railway") && entry @@ -328,6 +332,10 @@ fn write_codex_toml(path: &Path, remote: bool) -> Result<()> { "url".to_string(), toml::Value::String(REMOTE_MCP_URL.to_string()), ); + railway.insert( + "bearer_token_env_var".to_string(), + toml::Value::String(RAILWAY_API_TOKEN_ENV.to_string()), + ); } else { railway.insert( "command".to_string(), @@ -511,6 +519,7 @@ mod tests { r#" [mcp_servers.railway] url = "https://mcp.railway.com" + bearer_token_env_var = "RAILWAY_API_TOKEN" "#, ) .unwrap(); @@ -519,6 +528,23 @@ mod tests { assert!(!mcp_configured_for_slug(home.path(), "codex", false)); } + #[test] + fn treats_codex_remote_without_bearer_env_as_incomplete() { + let home = tempfile::tempdir().unwrap(); + let path = home.path().join(".codex").join("config.toml"); + std::fs::create_dir_all(path.parent().unwrap()).unwrap(); + std::fs::write( + &path, + r#" + [mcp_servers.railway] + url = "https://mcp.railway.com" + "#, + ) + .unwrap(); + + assert!(!mcp_configured_for_slug(home.path(), "codex", true)); + } + #[test] fn writes_codex_remote_mcp() { let home = tempfile::tempdir().unwrap(); @@ -538,6 +564,12 @@ mod tests { railway.get("url").and_then(toml::Value::as_str), Some("https://mcp.railway.com") ); + assert_eq!( + railway + .get("bearer_token_env_var") + .and_then(toml::Value::as_str), + Some("RAILWAY_API_TOKEN") + ); assert!(railway.get("command").is_none()); assert!(railway.get("args").is_none()); }