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 {
32
32
}
33
33
34
34
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 ( ) ?;
36
36
os. fs . write ( path. as_ref ( ) , json) . await ?;
37
37
Ok ( ( ) )
38
38
}
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
+ }
39
51
}
Original file line number Diff line number Diff line change @@ -159,8 +159,7 @@ impl AddArgs {
159
159
} ) ) ?;
160
160
161
161
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 ?;
164
163
writeln ! (
165
164
output,
166
165
"✓ Added MCP server '{}' to global config in {}\n " ,
@@ -220,8 +219,7 @@ impl RemoveArgs {
220
219
221
220
match config. mcp_servers . remove ( & self . name ) {
222
221
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 ?;
225
223
writeln ! (
226
224
output,
227
225
"\n ✓ Removed MCP server '{}' from global config (path {})\n " ,
You can’t perform that action at this time.
0 commit comments