File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,20 @@ impl McpServerConfig {
3232 }
3333
3434 pub async fn save_to_file ( & self , os : & Os , path : impl AsRef < Path > ) -> eyre:: Result < ( ) > {
35- let json = serde_json :: to_string_pretty ( self ) ?;
35+ let json = self . to_non_transparent_json_pretty ( ) ?;
3636 os. fs . write ( path. as_ref ( ) , json) . await ?;
3737 Ok ( ( ) )
3838 }
39+
40+ /// Because we had annotated [McpServerConfig] with transparent, when writing the config alone
41+ /// to its legacy location (as opposed to writing it along with its agent config), we would
42+ /// need to call this function to stringify it otherwise we would be writing only the inner
43+ /// hashmap.
44+ fn to_non_transparent_json_pretty ( & self ) -> eyre:: Result < String > {
45+ let transparent_json = serde_json:: to_value ( self ) ?;
46+ let non_transparent_json = serde_json:: json!( {
47+ "mcpServers" : transparent_json
48+ } ) ;
49+ Ok ( serde_json:: to_string_pretty ( & non_transparent_json) ?)
50+ }
3951}
Original file line number Diff line number Diff line change @@ -159,8 +159,7 @@ impl AddArgs {
159159 } ) ) ?;
160160
161161 mcp_servers. mcp_servers . insert ( self . name . clone ( ) , tool) ;
162- let json = serde_json:: to_string_pretty ( & mcp_servers) ?;
163- os. fs . write ( & global_config_path, json) . await ?;
162+ mcp_servers. save_to_file ( os, & global_config_path) . await ?;
164163 writeln ! (
165164 output,
166165 "✓ Added MCP server '{}' to global config in {}\n " ,
@@ -220,8 +219,7 @@ impl RemoveArgs {
220219
221220 match config. mcp_servers . remove ( & self . name ) {
222221 Some ( _) => {
223- let json = serde_json:: to_string_pretty ( & config) ?;
224- os. fs . write ( & global_config_path, json) . await ?;
222+ config. save_to_file ( os, & global_config_path) . await ?;
225223 writeln ! (
226224 output,
227225 "\n ✓ Removed MCP server '{}' from global config (path {})\n " ,
You can’t perform that action at this time.
0 commit comments