clear_history
Remove all operation history for a specific session in the CSV Editor server to maintain clean session data and streamline processing workflows.
Instructions
Clear all operation history for a session.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes |
Implementation Reference
- src/csv_editor/server.py:534-540 (registration)Registers the 'clear_history' MCP tool with @mcp.tool decorator. Thin wrapper that delegates to the implementation in history_operations.py.@mcp.tool async def clear_history( session_id: str, ctx: Context = None ) -> Dict[str, Any]: """Clear all operation history for a session.""" return await _clear_history(session_id, ctx)
- Primary handler function for the clear_history tool. Retrieves the CSV session and invokes the history_manager.clear_history() method.async def clear_history( session_id: str, ctx: Context = None ) -> Dict[str, Any]: """ Clear all operation history for a session. Args: session_id: Session identifier ctx: FastMCP context Returns: Dict with success status """ try: manager = get_session_manager() session = manager.get_session(session_id) if not session: return OperationResult( success=False, message="Session not found", error=f"No session with ID: {session_id}" ).model_dump() if not session.history_manager: return OperationResult( success=False, message="History is not enabled for this session", error="History management is disabled" ).model_dump() if ctx: await ctx.info(f"Clearing history for session {session_id}") session.history_manager.clear_history() return OperationResult( success=True, message="History cleared successfully", session_id=session_id ).model_dump() except Exception as e: logger.error(f"Error clearing history: {str(e)}") if ctx: await ctx.error(f"Failed to clear history: {str(e)}") return OperationResult( success=False, message="Failed to clear history", error=str(e) ).model_dump()
- Core HistoryManager method that clears in-memory history structures and deletes persistent storage files for snapshots and history.def clear_history(self): """Clear all history.""" self.history.clear() self.redo_stack.clear() self.current_index = -1 # Clean up files if self.storage_type != HistoryStorage.MEMORY: # Remove history file for ext in ["json", "pkl"]: history_file = self._get_history_file_path(ext) if os.path.exists(history_file): os.remove(history_file) # Remove snapshot files snapshot_dir = os.path.join(self.history_dir, "snapshots", self.session_id) if os.path.exists(snapshot_dir): import shutil shutil.rmtree(snapshot_dir) logger.info(f"Cleared history for session {self.session_id}")