@@ -2,7 +2,7 @@ use serde_json::{json, Value};
22use std:: path:: Path ;
33
44use super :: file_io:: { read_json_file, write_json_file} ;
5- use super :: utils:: { get_key_by_client, is_per_server_disabled_client, normalize_response_key} ;
5+ use super :: utils:: { get_key_by_client, is_per_server_disabled_client, normalize_response_key, is_cherrystudio_client } ;
66
77/// Update a disabled MCP server configuration
88pub async fn update_disabled_mcp_server (
@@ -30,6 +30,22 @@ pub async fn update_disabled_mcp_server(
3030 return normalize_response_key ( json, client) ;
3131 }
3232
33+ // cherrystudio: update mcpServers with isActived: false
34+ if is_cherrystudio_client ( client) {
35+ if !json. is_object ( ) {
36+ json = json ! ( { } ) ;
37+ }
38+ if !json. as_object ( ) . unwrap ( ) . contains_key ( key) {
39+ json[ key] = json ! ( { } ) ;
40+ }
41+ // Set config and isActived: false
42+ let mut config_with_isactived = config;
43+ config_with_isactived[ "isActived" ] = json ! ( false ) ;
44+ json[ key] [ name] = config_with_isactived;
45+ write_json_file ( path, & json) . await ?;
46+ return normalize_response_key ( json, client) ;
47+ }
48+
3349 // Default: update __disabled section
3450 if !json. is_object ( ) {
3551 json = json ! ( { } ) ;
@@ -71,6 +87,20 @@ pub async fn disable_mcp_server(path: &Path, client: &str, name: &str) -> Result
7187 return normalize_response_key ( json, client) ;
7288 }
7389
90+ // cherrystudio: set isActived: false in mcpServers
91+ if is_cherrystudio_client ( client) {
92+ if !json. as_object ( ) . unwrap ( ) . contains_key ( key)
93+ || !json[ key] . is_object ( )
94+ || !json[ key] . as_object ( ) . unwrap ( ) . contains_key ( name)
95+ {
96+ return Err ( format ! ( "Server '{}' not found in active servers" , name) ) ;
97+ }
98+ // Set isActived: false
99+ json[ key] [ name] [ "isActived" ] = json ! ( false ) ;
100+ write_json_file ( path, & json) . await ?;
101+ return normalize_response_key ( json, client) ;
102+ }
103+
74104 // Default: move to __disabled section // Check if server exists in active servers
75105 if !json. as_object ( ) . unwrap ( ) . contains_key ( key)
76106 || !json[ key] . is_object ( )
@@ -125,6 +155,38 @@ pub async fn enable_mcp_server(path: &Path, client: &str, name: &str) -> Result<
125155 return normalize_response_key ( json, client) ;
126156 }
127157
158+ // cherrystudio: set isActived: true in mcpServers, or move from __disabled if not found
159+ if is_cherrystudio_client ( client) {
160+ if json. as_object ( ) . unwrap ( ) . contains_key ( key)
161+ && json[ key] . is_object ( )
162+ && json[ key] . as_object ( ) . unwrap ( ) . contains_key ( name)
163+ {
164+ // Set isActived: true
165+ json[ key] [ name] [ "isActived" ] = json ! ( true ) ;
166+ write_json_file ( path, & json) . await ?;
167+ return normalize_response_key ( json, client) ;
168+ }
169+ // If not found in mcpServers, try to move from __disabled
170+ if json. as_object ( ) . unwrap ( ) . contains_key ( "__disabled" )
171+ && json[ "__disabled" ] . is_object ( )
172+ && json[ "__disabled" ] . as_object ( ) . unwrap ( ) . contains_key ( name)
173+ {
174+ let mut server_config = json[ "__disabled" ] [ name] . clone ( ) ;
175+ server_config[ "isActived" ] = json ! ( true ) ;
176+ json[ "__disabled" ] . as_object_mut ( ) . unwrap ( ) . remove ( name) ;
177+ if json[ "__disabled" ] . as_object ( ) . unwrap ( ) . is_empty ( ) {
178+ json. as_object_mut ( ) . unwrap ( ) . remove ( "__disabled" ) ;
179+ }
180+ if !json. as_object ( ) . unwrap ( ) . contains_key ( key) {
181+ json[ key] = json ! ( { } ) ;
182+ }
183+ json[ key] [ name] = server_config;
184+ write_json_file ( path, & json) . await ?;
185+ return normalize_response_key ( json, client) ;
186+ }
187+ return Err ( format ! ( "Server '{}' not found in active or disabled servers" , name) ) ;
188+ }
189+
128190 // Default: move from __disabled section to active
129191 // Check if server exists in disabled section
130192 if !json. as_object ( ) . unwrap ( ) . contains_key ( "__disabled" )
@@ -177,7 +239,30 @@ pub async fn list_disabled_servers(path: &Path, client: &str) -> Result<Value, S
177239 if json. is_object ( ) && json. as_object ( ) . unwrap ( ) . contains_key ( key) {
178240 if let Some ( servers_obj) = json[ key] . as_object ( ) {
179241 for ( name, server) in servers_obj {
180- if server. get ( "disabled" ) . and_then ( |v| v. as_bool ( ) ) . unwrap_or ( false ) {
242+ if server
243+ . get ( "disabled" )
244+ . and_then ( |v| v. as_bool ( ) )
245+ . unwrap_or ( false )
246+ {
247+ disabled. insert ( name. clone ( ) , server. clone ( ) ) ;
248+ }
249+ }
250+ }
251+ }
252+ return Ok ( Value :: Object ( disabled) ) ;
253+ }
254+
255+ // cherrystudio: return all mcpServers with isActived: false
256+ if is_cherrystudio_client ( client) {
257+ let mut disabled = serde_json:: Map :: new ( ) ;
258+ if json. is_object ( ) && json. as_object ( ) . unwrap ( ) . contains_key ( key) {
259+ if let Some ( servers_obj) = json[ key] . as_object ( ) {
260+ for ( name, server) in servers_obj {
261+ if server
262+ . get ( "isActived" )
263+ . and_then ( |v| v. as_bool ( ) )
264+ == Some ( false )
265+ {
181266 disabled. insert ( name. clone ( ) , server. clone ( ) ) ;
182267 }
183268 }
0 commit comments