@@ -8,7 +8,7 @@ use cortex_engine::config::find_cortex_home;
88use std:: io:: { self , BufRead , Write } ;
99
1010use super :: auth:: { get_auth_status_for_display, remove_auth_silent} ;
11- use super :: config:: { get_mcp_server, get_mcp_servers} ;
11+ use super :: config:: { get_mcp_server, get_mcp_servers, parse_config_content } ;
1212use super :: types:: {
1313 AddArgs , AddMcpSseArgs , AddMcpStreamableHttpArgs , AddMcpTransportArgs , DisableArgs , EnableArgs ,
1414 GetArgs , ListArgs , RemoveArgs , RenameArgs ,
@@ -301,8 +301,7 @@ pub(crate) async fn run_add(args: AddArgs) -> Result<()> {
301301 if config_path. exists ( ) {
302302 let content = std:: fs:: read_to_string ( & config_path)
303303 . with_context ( || format ! ( "failed to read config: {}" , config_path. display( ) ) ) ?;
304- let mut config: toml:: Value =
305- toml:: from_str ( & content) . with_context ( || "failed to parse config" ) ?;
304+ let mut config = parse_config_content ( & content, & config_path) ?;
306305
307306 if let Some ( mcp_servers) = config. get_mut ( "mcp_servers" ) . and_then ( |v| v. as_table_mut ( ) )
308307 {
@@ -576,8 +575,7 @@ pub(crate) async fn run_remove(args: RemoveArgs) -> Result<()> {
576575 . with_context ( || format ! ( "failed to read config: {}" , config_path. display( ) ) ) ?;
577576
578577 // Parse the TOML and remove the server section
579- let mut config: toml:: Value =
580- toml:: from_str ( & content) . with_context ( || "failed to parse config" ) ?;
578+ let mut config = parse_config_content ( & content, & config_path) ?;
581579
582580 if let Some ( mcp_servers) = config. get_mut ( "mcp_servers" ) . and_then ( |v| v. as_table_mut ( ) ) {
583581 mcp_servers. remove ( & name) ;
@@ -622,8 +620,7 @@ pub(crate) async fn run_enable(args: EnableArgs) -> Result<()> {
622620 let content = std:: fs:: read_to_string ( & config_path)
623621 . with_context ( || format ! ( "failed to read config: {}" , config_path. display( ) ) ) ?;
624622
625- let mut config: toml:: Value =
626- toml:: from_str ( & content) . with_context ( || "failed to parse config" ) ?;
623+ let mut config = parse_config_content ( & content, & config_path) ?;
627624
628625 if let Some ( mcp_servers) = config. get_mut ( "mcp_servers" ) . and_then ( |v| v. as_table_mut ( ) )
629626 && let Some ( server) = mcp_servers. get_mut ( & args. name )
@@ -674,8 +671,7 @@ pub(crate) async fn run_disable(args: DisableArgs) -> Result<()> {
674671 let content = std:: fs:: read_to_string ( & config_path)
675672 . with_context ( || format ! ( "failed to read config: {}" , config_path. display( ) ) ) ?;
676673
677- let mut config: toml:: Value =
678- toml:: from_str ( & content) . with_context ( || "failed to parse config" ) ?;
674+ let mut config = parse_config_content ( & content, & config_path) ?;
679675
680676 if let Some ( mcp_servers) = config. get_mut ( "mcp_servers" ) . and_then ( |v| v. as_table_mut ( ) )
681677 && let Some ( server) = mcp_servers. get_mut ( & args. name )
@@ -740,8 +736,7 @@ pub(crate) async fn run_rename(args: RenameArgs) -> Result<()> {
740736 let content = std:: fs:: read_to_string ( & config_path)
741737 . with_context ( || format ! ( "failed to read config: {}" , config_path. display( ) ) ) ?;
742738
743- let mut config: toml:: Value =
744- toml:: from_str ( & content) . with_context ( || "failed to parse config" ) ?;
739+ let mut config = parse_config_content ( & content, & config_path) ?;
745740
746741 if let Some ( mcp_servers) = config. get_mut ( "mcp_servers" ) . and_then ( |v| v. as_table_mut ( ) )
747742 && let Some ( server_config) = mcp_servers. remove ( & args. old_name )
0 commit comments