@@ -191,7 +191,6 @@ export class MCPConfigManager {
191191 description ?: string ;
192192 } >
193193 ) : void {
194- console . log ( 'MCP config called ' , this . config , serverName , toolsInfo ) ;
195194 if ( ! this . config [ serverName ] ) {
196195 this . config [ serverName ] = { } ;
197196 }
@@ -203,7 +202,6 @@ export class MCPConfigManager {
203202 const toolName = toolInfo . name ;
204203
205204 if ( ! serverConfig [ toolName ] ) {
206- console . log ( `Creating new tool config for: ${ toolName } ` ) ;
207205 serverConfig [ toolName ] = {
208206 enabled : true ,
209207 usageCount : 0 ,
@@ -212,15 +210,13 @@ export class MCPConfigManager {
212210 } ;
213211 hasChanges = true ;
214212 } else {
215- console . log ( `Updating existing tool config for: ${ toolName } ` ) ;
216213 // Always update schema and description for existing tools
217214 let toolChanged = false ;
218215
219216 // Update schema if it's different or missing
220217 const currentSchema = JSON . stringify ( serverConfig [ toolName ] . inputSchema || null ) ;
221218 const newSchema = JSON . stringify ( toolInfo . inputSchema || null ) ;
222219 if ( currentSchema !== newSchema ) {
223- console . log ( `Updating schema for tool: ${ toolName } ` ) ;
224220 serverConfig [ toolName ] . inputSchema = toolInfo . inputSchema || null ;
225221 toolChanged = true ;
226222 }
@@ -229,7 +225,6 @@ export class MCPConfigManager {
229225 const currentDescription = serverConfig [ toolName ] . description || '' ;
230226 const newDescription = toolInfo . description || '' ;
231227 if ( currentDescription !== newDescription ) {
232- console . log ( `Updating description for tool: ${ toolName } ` ) ;
233228 serverConfig [ toolName ] . description = newDescription ;
234229 toolChanged = true ;
235230 }
@@ -241,10 +236,7 @@ export class MCPConfigManager {
241236 }
242237
243238 if ( hasChanges ) {
244- console . log ( `Saving configuration changes for server: ${ serverName } ` ) ;
245239 this . saveConfig ( ) ;
246- } else {
247- console . log ( `No changes needed for server: ${ serverName } ` ) ;
248240 }
249241 }
250242
@@ -259,4 +251,52 @@ export class MCPConfigManager {
259251
260252 return { ...serverConfig [ toolName ] } ;
261253 }
254+
255+ /**
256+ * Replace the entire tools configuration with a new set of tools
257+ * This overwrites all existing tools with only the current ones
258+ */
259+ replaceToolsConfig (
260+ toolsByServer : Record <
261+ string ,
262+ Array < {
263+ name : string ;
264+ inputSchema ?: any ;
265+ description ?: string ;
266+ } >
267+ >
268+ ) : void {
269+ // Create a new config object
270+ const newConfig : MCPToolsConfig = { } ;
271+
272+ for ( const [ serverName , toolsInfo ] of Object . entries ( toolsByServer ) ) {
273+ newConfig [ serverName ] = { } ;
274+
275+ for ( const toolInfo of toolsInfo ) {
276+ const toolName = toolInfo . name ;
277+
278+ // Check if this tool existed in the old config to preserve enabled state and usage count
279+ const oldToolState = this . config [ serverName ] ?. [ toolName ] ;
280+
281+ newConfig [ serverName ] [ toolName ] = {
282+ enabled : oldToolState ?. enabled ?? true , // Preserve enabled state or default to true
283+ usageCount : oldToolState ?. usageCount ?? 0 , // Preserve usage count or default to 0
284+ inputSchema : toolInfo . inputSchema || null ,
285+ description : toolInfo . description || '' ,
286+ } ;
287+ }
288+ }
289+
290+ // Replace the entire config
291+ this . config = newConfig ;
292+ this . saveConfig ( ) ;
293+ }
294+
295+ /**
296+ * Replace the entire configuration with a new config object
297+ */
298+ replaceConfig ( newConfig : MCPToolsConfig ) : void {
299+ this . config = newConfig ;
300+ this . saveConfig ( ) ;
301+ }
262302}
0 commit comments