Skip to main content
Glama
itshare4u

Agent Knowledge MCP

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/itshare4u/AgentKnowledgeMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server