@@ -4,6 +4,7 @@ import { DynamicConfigManager } from './dynamic-config-manager';
44import { ProcessManager } from '../process/manager' ;
55import { RuntimeState } from '../process/runtime-state' ;
66import { StdioToolDiscoveryManager } from './stdio-tool-discovery-manager' ;
7+ import { UnifiedToolDiscoveryManager } from './unified-tool-discovery-manager' ;
78import { MCPServerConfig } from '../process/types' ;
89import { maskUrlForLogging } from '../utils/log-masker' ;
910
@@ -24,6 +25,7 @@ export class CommandProcessor {
2425 private processManager : ProcessManager | null ;
2526 private runtimeState : RuntimeState | null ;
2627 private stdioDiscoveryManager : StdioToolDiscoveryManager | null ;
28+ private unifiedToolDiscoveryManager : UnifiedToolDiscoveryManager | null = null ;
2729 private processes : Map < string , ProcessInfo > = new Map ( ) ;
2830 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2931 private onConfigurationUpdate ?: ( config : any ) => Promise < void > ;
@@ -50,6 +52,13 @@ export class CommandProcessor {
5052 this . onConfigurationUpdate = handler ;
5153 }
5254
55+ /**
56+ * Set unified tool discovery manager for disabled tools tracking
57+ */
58+ setUnifiedToolDiscoveryManager ( manager : UnifiedToolDiscoveryManager ) : void {
59+ this . unifiedToolDiscoveryManager = manager ;
60+ }
61+
5362 /**
5463 * Resolve installation_id or server_name to actual server name
5564 */
@@ -159,9 +168,17 @@ export class CommandProcessor {
159168 }
160169
161170 /**
162- * Handle configure command - update MCP server configuration
171+ * Handle configure command - update MCP server configuration or handle specific actions
163172 */
164173 private async handleConfigureCommand ( command : SatelliteCommand ) : Promise < CommandResult > {
174+ const payload = command . payload ;
175+
176+ // Check if this is an update_tool_status action
177+ if ( payload . action === 'update_tool_status' ) {
178+ return await this . handleUpdateToolStatus ( command ) ;
179+ }
180+
181+ // Default behavior: trigger configuration refresh
165182 this . logger . info ( {
166183 operation : 'command_configure' ,
167184 command_id : command . id
@@ -174,7 +191,7 @@ export class CommandProcessor {
174191 operation : 'command_configure_trigger' ,
175192 command_id : command . id
176193 } , 'Triggering configuration update from backend' ) ;
177-
194+
178195 // This will fetch fresh config from backend and update all services
179196 await this . onConfigurationUpdate ( { } ) ;
180197 } else {
@@ -185,7 +202,7 @@ export class CommandProcessor {
185202 }
186203
187204 const currentStats = this . configManager . getStats ( ) ;
188-
205+
189206 return {
190207 command_id : command . id ,
191208 status : 'completed' ,
@@ -198,17 +215,115 @@ export class CommandProcessor {
198215 } ;
199216 } catch ( error ) {
200217 const errorMessage = error instanceof Error ? error . message : 'Unknown error' ;
201-
218+
202219 this . logger . error ( {
203220 operation : 'command_configure_failed' ,
204221 command_id : command . id ,
205222 error : errorMessage
206223 } , `Configure command failed: ${ errorMessage } ` ) ;
207-
224+
208225 throw error ; // Re-throw to be handled by main command processor
209226 }
210227 }
211228
229+ /**
230+ * Handle update_tool_status action - enable/disable a specific tool
231+ */
232+ private async handleUpdateToolStatus ( command : SatelliteCommand ) : Promise < CommandResult > {
233+ const payload = command . payload ;
234+ const { installation_id, tool_name, is_disabled, team_id, server_slug } = payload ;
235+
236+ this . logger . info ( {
237+ operation : 'update_tool_status' ,
238+ command_id : command . id ,
239+ installation_id,
240+ tool_name,
241+ is_disabled,
242+ team_id,
243+ server_slug
244+ } , `Processing update_tool_status: ${ is_disabled ? 'disabling' : 'enabling' } tool ${ tool_name } ` ) ;
245+
246+ // Validate required fields
247+ if ( ! installation_id || ! tool_name || typeof is_disabled !== 'boolean' ) {
248+ const errorMsg = 'Missing required fields: installation_id, tool_name, or is_disabled' ;
249+ this . logger . error ( {
250+ operation : 'update_tool_status_validation_failed' ,
251+ command_id : command . id ,
252+ installation_id,
253+ tool_name,
254+ is_disabled
255+ } , errorMsg ) ;
256+
257+ return {
258+ command_id : command . id ,
259+ status : 'failed' ,
260+ error : errorMsg
261+ } ;
262+ }
263+
264+ // Check if UnifiedToolDiscoveryManager is available
265+ if ( ! this . unifiedToolDiscoveryManager ) {
266+ const errorMsg = 'UnifiedToolDiscoveryManager not available - cannot update tool status' ;
267+ this . logger . error ( {
268+ operation : 'update_tool_status_no_manager' ,
269+ command_id : command . id
270+ } , errorMsg ) ;
271+
272+ return {
273+ command_id : command . id ,
274+ status : 'failed' ,
275+ error : errorMsg
276+ } ;
277+ }
278+
279+ try {
280+ // Update the tool status in the unified discovery manager
281+ this . unifiedToolDiscoveryManager . setToolDisabled (
282+ installation_id as string ,
283+ tool_name as string ,
284+ is_disabled as boolean
285+ ) ;
286+
287+ const action = is_disabled ? 'disabled' : 'enabled' ;
288+ this . logger . info ( {
289+ operation : 'update_tool_status_success' ,
290+ command_id : command . id ,
291+ installation_id,
292+ tool_name,
293+ is_disabled,
294+ team_id,
295+ server_slug
296+ } , `Tool ${ tool_name } ${ action } successfully` ) ;
297+
298+ return {
299+ command_id : command . id ,
300+ status : 'completed' ,
301+ result : {
302+ tool_name,
303+ is_disabled,
304+ message : `Tool ${ action } successfully`
305+ }
306+ } ;
307+
308+ } catch ( error ) {
309+ const errorMessage = error instanceof Error ? error . message : 'Unknown error' ;
310+
311+ this . logger . error ( {
312+ operation : 'update_tool_status_failed' ,
313+ command_id : command . id ,
314+ installation_id,
315+ tool_name,
316+ error : errorMessage
317+ } , `Failed to update tool status: ${ errorMessage } ` ) ;
318+
319+ return {
320+ command_id : command . id ,
321+ status : 'failed' ,
322+ error : errorMessage
323+ } ;
324+ }
325+ }
326+
212327 /**
213328 * Handle spawn command - dispatches to HTTP or stdio handler based on transport_type
214329 */
0 commit comments