Configure Memory Optimization
configure_memory_optimizationConfigure memory file path, toggle auto-optimization, and adjust token growth threshold to control memory optimization behavior.
Instructions
Configure memory optimization settings for auto-optimization behavior.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| memory_file | No | ||
| auto_optimize | No | ||
| token_growth_threshold | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The main handler function for the 'configure_memory_optimization' tool. It updates memory file frontmatter settings (autoOptimize, tokenGrowthThreshold), removes deprecated fields, and writes a backup.
def configure_memory_optimization( memory_file: Annotated[Optional[str], "Path to memory file to configure"] = None, auto_optimize: Annotated[Optional[bool], "Enable/disable auto-optimization"] = None, token_growth_threshold: Annotated[Optional[float], "Token growth threshold (e.g., 1.20 = 20% growth)"] = None, ) -> str: """Configure memory optimization settings.""" if read_only: return "Error: Server is running in read-only mode" try: # Determine which file to configure if memory_file: file_path = Path(memory_file) if not file_path.exists(): return f"Error: Memory file not found: {memory_file}" else: # Use default user memory file user_memory_path = instruction_manager.get_memory_file_path() if not user_memory_path.exists(): return "Error: No user memory file found to configure" file_path = user_memory_path # Read current frontmatter from ..simple_file_ops import parse_frontmatter_file, write_frontmatter_file frontmatter, content = parse_frontmatter_file(file_path) # Update settings updated_settings = [] if auto_optimize is not None: frontmatter["autoOptimize"] = auto_optimize updated_settings.append(f"auto_optimize: {auto_optimize}") if token_growth_threshold is not None: if token_growth_threshold < 1.0: return "Error: token_growth_threshold must be >= 1.0 (e.g., 1.20 = 20% growth)" frontmatter["tokenGrowthThreshold"] = token_growth_threshold growth_percent = int((token_growth_threshold - 1.0) * 100) updated_settings.append(f"token_growth_threshold: {token_growth_threshold} ({growth_percent}% growth)") # Remove deprecated fields if they exist deprecated_removed = [] for old_field in ["sizeThreshold", "entryThreshold", "timeThreshold"]: if old_field in frontmatter: frontmatter.pop(old_field) deprecated_removed.append(old_field) if not updated_settings and not deprecated_removed: return "No settings provided to update. Available options: auto_optimize, token_growth_threshold" # Write updated frontmatter success = write_frontmatter_file(file_path, frontmatter, content, create_backup=True) if success: message = "ā Memory optimization settings updated:\n" for setting in updated_settings: message += f"⢠{setting}\n" if deprecated_removed: message += "\nš§¹ Removed deprecated settings: " + ", ".join(deprecated_removed) + "\n" message += "\nš¾ Backup created for safety" return message else: return "ā Failed to update memory optimization settings" except Exception as e: return f"Error configuring memory optimization: {str(e)}" - src/mode_manager_mcp/tools/memory_tools.py:162-180 (registration)Registration decorator for the tool via @app.tool, defining name, description, tags, annotations (parameters, title), and metadata.
@app.tool( name="configure_memory_optimization", description="Configure memory optimization settings for auto-optimization behavior.", tags={"public", "memory"}, annotations={ "idempotentHint": False, "readOnlyHint": False, "title": "Configure Memory Optimization", "parameters": { "memory_file": "Optional path to specific memory file. If not provided, will configure the user's main memory file.", "auto_optimize": "Enable or disable automatic optimization. True/False.", "token_growth_threshold": "Token growth multiplier for triggering optimization (e.g., 1.20 = 20% growth). Must be >= 1.0.", }, "returns": "Returns confirmation of updated settings.", }, meta={ "category": "memory", }, ) - src/mode_manager_mcp/tools/memory_tools.py:12-18 (registration)The register_memory_tools() function that retrieves the server registry and app instance used to register tools.
def register_memory_tools() -> None: """Register all memory optimization tools with the server.""" registry = get_server_registry() app = registry.app instruction_manager = registry.instruction_manager read_only = registry.read_only - The parse_frontmatter_file helper used within the handler to read and parse YAML frontmatter from memory files.
def parse_frontmatter_file(file_path: Union[str, Path]) -> Tuple[Dict[str, Any], str]: """ Parse a file with YAML frontmatter. Args: file_path: Path to the file Returns: Tuple of (frontmatter_dict, content_string) Raises: FileOperationError: If file cannot be parsed """ try: with open(file_path, "r", encoding="utf-8") as f: content = f.read() except Exception as e: raise FileOperationError(f"Could not read file {file_path}: {e}") return parse_frontmatter(content)