reset_config
Restore configuration to default settings by overwriting the current config.json file with default values from config.default.json.
Instructions
Reset config.json to defaults from config.default.json (manual reset - overwrites current config)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/admin/admin_server.py:1222-1346 (handler)The handler function for the 'reset_config' tool. It resets the config.json file to the contents of config.default.json, creates a timestamped backup of the original config.json if it exists, reloads the configuration, reinitializes security and Elasticsearch components, and returns a detailed status message.@app.tool( description="Reset config.json to defaults from config.default.json (manual reset - overwrites current config)", tags={"admin", "config", "reset", "default", "restore"} ) async def reset_config() -> str: """Reset configuration to defaults, creating backup of current config.""" try: import shutil import time from src.config.config import load_config # Use the working config loader # Use same approach as working update_config function script_dir = Path(__file__).parent.parent # /src directory config_path = script_dir / "config.json" default_config_path = script_dir / "config.default.json" # Verify default config exists if not default_config_path.exists(): return f"ā **Default Configuration File Not Found!**\n\nšØ **Error:** Cannot find {default_config_path}\nš **Absolute Path:** {default_config_path.absolute()}\n\nš ļø **Resolution Steps:**\n 1. Verify config.default.json exists in src directory\n 2. Check if file was accidentally deleted or moved\n 3. Try reinstalling AgentKnowledgeMCP package\n\nš” **Manual Reset:** Copy config.default.json to config.json manually" # Create backup of current config if it exists backup_created = False backup_path = None backup_status = "" if config_path.exists(): try: import time timestamp = int(time.time()) backup_path = config_path.with_name(f"config.backup.{timestamp}.json") import shutil shutil.copy2(config_path, backup_path) backup_created = True backup_status = f"ā Current configuration backed up as: {backup_path.name}" except PermissionError: return "ā **Backup Creation Failed!**\n\nšØ **Error:** Insufficient permissions to create backup file\nš **Target:** config.backup.[timestamp].json\n\nš ļø **Resolution:**\n ⢠Check file system permissions for src directory\n ⢠Ensure user has write access to configuration directory\n ⢠Try running with elevated permissions if necessary\n ⢠Verify sufficient disk space for backup creation" except Exception as e: return f"ā **Backup Creation Error!**\n\nšØ **Error:** Cannot create backup of current configuration\nš **Details:** {str(e)}\n\nš” **Options:**\n ⢠Check file system permissions and disk space\n ⢠Try manual backup: copy config.json to config.backup.manual.json\n ⢠Proceed with caution if backup creation fails" else: backup_status = "ā¹ļø No existing config.json to backup" # Copy config.default.json to config.json (overwrite) try: import shutil shutil.copy2(default_config_path, config_path) except PermissionError: return "ā **Configuration Reset Failed!**\n\nšØ **Error:** Insufficient permissions to overwrite config.json\nš **Target:** config.json\n\nš ļø **Resolution:**\n ⢠Check file permissions for config.json\n ⢠Ensure user has write access to configuration file\n ⢠Try running with elevated permissions if necessary\n ⢠Verify config.json is not locked by another process" except Exception as e: return f"ā **File Copy Error!**\n\nšØ **Error:** Cannot copy default configuration\nš **Details:** {str(e)}\n\nš ļø **Manual Reset Steps:**\n 1. Copy contents of config.default.json\n 2. Paste into config.json (overwrite existing content)\n 3. Save file and try reloading configuration\n 4. Check file permissions and disk space if issues persist" # Reload configuration after reset try: config = load_config() except Exception as e: return f"ā **Configuration Reload Failed!**\n\nšØ **Error:** Reset completed but cannot load new configuration\nš **Details:** {str(e)}\n\nā ļø **Status:** config.json has been reset but system components not reinitialized\n\nš ļø **Recovery:**\n ⢠Use reload_config tool to reinitialize components\n ⢠Check config.json syntax and structure\n ⢠Verify all required configuration sections are present" # Reinitialize components with reset config component_status = [] try: init_security(config["security"]["allowed_base_directory"]) component_status.append("ā Security component reinitialized") except Exception as e: component_status.append(f"ā ļø Security initialization failed: {str(e)}") try: init_elasticsearch(config) reset_es_client() component_status.append("ā Elasticsearch components reinitialized") except Exception as e: component_status.append(f"ā ļø Elasticsearch initialization failed: {str(e)}") # Build comprehensive success message message = "š **Configuration Reset Completed Successfully!**\n\n" # Reset summary message += f"š **Reset Summary:**\n" message += f" {backup_status}\n" message += f" ā Configuration reset from config.default.json\n" message += f" š All components reinitialized with default settings\n\n" # Component reinitialization status message += f"š§ **Component Status:**\n" for status in component_status: message += f" {status}\n" message += f"\n" # Configuration details message += f"š **Current Configuration:**\n" try: message += f" š Security Base Directory: {config['security']['allowed_base_directory']}\n" message += f" š Elasticsearch: {config['elasticsearch']['host']}:{config['elasticsearch']['port']}\n" if "server" in config: server_config = config["server"] message += f" š Server: {server_config.get('name', 'AgentKnowledgeMCP')} v{server_config.get('version', '1.0.0')}\n" except Exception as e: message += f" ā ļø Configuration display error: {str(e)}\n" # Next steps guidance message += f"\nš” **Next Steps:**\n" message += f" ⢠Review reset configuration with get_config tool\n" message += f" ⢠Customize settings using update_config tool\n" message += f" ⢠Test system functionality after reset\n" if backup_created and backup_path: message += f" ⢠Previous settings available in {backup_path.name}\n" # Restore instructions if needed if backup_created and backup_path: message += f"\nš **Restore Previous Configuration (if needed):**\n" message += f" 1. Copy {backup_path.name} to config.json\n" message += f" 2. Use reload_config tool to apply restored settings\n" message += f" 3. Verify components work with restored configuration\n" message += f"\nā **System Ready:** Configuration reset complete with default settings active!" return message except ImportError as e: return f"ā Module Error: Missing required module for configuration reset\nš Details: {str(e)}\nš” Required modules: shutil (for file operations), time (for backup timestamps)" except FileNotFoundError as e: return f"ā File System Error: Required file not found during reset operation\nš Details: {str(e)}\nš” Check that both config.json and config.default.json exist in src directory" except Exception as e: return _format_admin_error(e, "reset configuration", "default configuration restore and component reinitialization")