reset_config
Restore config.json to default settings by resetting it from config.default.json, ensuring a clean configuration state for the Agent Knowledge MCP server.
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 core handler implementation for the 'reset_config' tool. This FastMCP tool function resets the config.json to defaults from config.default.json, creates a timestamped backup of the existing config, reloads the configuration, reinitializes security and Elasticsearch components, and returns a detailed status report.@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")
- src/main_server.py:80-81 (registration)The admin_server_app (containing the reset_config tool) is mounted into the main FastMCP app, making the reset_config tool available in the main server.app.mount(admin_server_app)
- src/main_server.py:104-105 (registration)Documentation/print statement listing available tools from the admin server, including reset_config.print(" βοΈ Admin Server (admin_*) - Configuration and system management") print(" ββ Tools: get_config, update_config, server_status, server_upgrade, setup_elasticsearch, elasticsearch_status, validate_config, reset_config, reload_config")
- src/admin/admin_server.py:1352-1353 (registration)CLI print statement in admin_server.py listing the reset_config tool among available tools.print("βοΈ Tools: get_config, update_config, validate_config, reload_config, setup_elasticsearch, elasticsearch_status, server_status, server_upgrade, ask_user_advice, reset_config") print("π― Admin-only server - Tools for system management and configuration")