Skip to content

Commit ca82163

Browse files
author
LittleCoinCoin
committed
feat(mcp): add host configuration removal functionality
Implement remove_host_configuration() method in MCPHostConfigurationManager to enable complete host configuration cleanup. This supports the new 'hatch mcp remove host' command for removing entire host configurations. Key features: - Complete host configuration file removal - Integrated backup support with optional skip - Atomic operations with proper error handling - Returns detailed ConfigurationResult with backup information Part of Phase 3e Direct MCP Management Commands implementation.
1 parent 4e496bc commit ca82163

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

hatch/mcp_host_config/host_management.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,49 @@ def sync_environment_to_hosts(self, env_data: EnvironmentData,
307307
servers_synced=servers_synced,
308308
hosts_updated=hosts_updated
309309
)
310+
311+
def remove_host_configuration(self, hostname: str, no_backup: bool = False) -> ConfigurationResult:
312+
"""Remove entire host configuration (all MCP servers).
313+
314+
Args:
315+
hostname (str): Host identifier
316+
no_backup (bool, optional): Skip backup creation. Defaults to False.
317+
318+
Returns:
319+
ConfigurationResult: Result of the removal operation
320+
"""
321+
try:
322+
host_type = MCPHostType(hostname)
323+
strategy = self.host_registry.get_strategy(host_type)
324+
config_path = strategy.get_config_path()
325+
326+
if not config_path or not config_path.exists():
327+
return ConfigurationResult(
328+
success=True,
329+
hostname=hostname,
330+
error_message="No configuration file to remove"
331+
)
332+
333+
# Create backup if requested
334+
backup_path = None
335+
if not no_backup and self.backup_manager:
336+
backup_result = self.backup_manager.create_backup(config_path, hostname)
337+
if backup_result.success:
338+
backup_path = backup_result.backup_path
339+
340+
# Remove configuration file
341+
config_path.unlink()
342+
343+
return ConfigurationResult(
344+
success=True,
345+
hostname=hostname,
346+
backup_created=backup_path is not None,
347+
backup_path=backup_path
348+
)
349+
350+
except Exception as e:
351+
return ConfigurationResult(
352+
success=False,
353+
hostname=hostname,
354+
error_message=str(e)
355+
)

0 commit comments

Comments
 (0)