Skip to main content
Glama

clean_project

Clear project directories to prepare for rebuilding by removing unnecessary files and optionally creating backups. Designed for use with Android application reverse engineering via the Apktool MCP Server.

Instructions

Clean a project directory to prepare for rebuilding.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
backupNo
project_dirYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'clean_project' tool. It cleans build artifacts from an APKTool project directory (build, dist, temp dirs and temp/log files), optionally backing them up first. Validates input path, computes sizes freed, and returns detailed results.
    @mcp.tool()
    async def clean_project(project_dir: str, backup: bool = True) -> Dict:
        """
        Clean a project directory to prepare for rebuilding with enhanced backup support.
        
        Args:
            project_dir: Path to the APKTool project directory
            backup: Whether to create a backup of build directories before cleaning
            
        Returns:
            Dictionary with operation results and cleanup details
        """
        # Input validation
        path_validation = ValidationUtils.validate_path(project_dir, must_exist=True)
        if not path_validation["valid"]:
            return {"success": False, "error": path_validation["error"]}
        
        try:
            dirs_to_clean = ["build", "dist", "temp"]
            files_to_clean = ["*.tmp", "*.log"]
            cleaned_dirs = []
            cleaned_files = []
            backed_up = []
            
            # Clean directories
            for dir_name in dirs_to_clean:
                dir_path = os.path.join(project_dir, dir_name)
                if os.path.exists(dir_path):
                    if backup:
                        # Create backup
                        backup_path = f"{dir_path}_backup_{int(time.time())}"
                        shutil.copytree(dir_path, backup_path)
                        backed_up.append({
                            "original": dir_path,
                            "backup": backup_path,
                            "type": "directory"
                        })
                    
                    # Calculate size before removal
                    dir_size = 0
                    file_count = 0
                    for root, dirs, files in os.walk(dir_path):
                        for file in files:
                            file_path = os.path.join(root, file)
                            try:
                                dir_size += os.path.getsize(file_path)
                                file_count += 1
                            except:
                                pass
                    
                    # Remove directory
                    shutil.rmtree(dir_path)
                    cleaned_dirs.append({
                        "path": dir_path,
                        "size_freed": dir_size,
                        "files_removed": file_count
                    })
            
            # Clean specific files
            import glob
            for pattern in files_to_clean:
                pattern_path = os.path.join(project_dir, pattern)
                for file_path in glob.glob(pattern_path):
                    if os.path.isfile(file_path):
                        file_size = os.path.getsize(file_path)
                        
                        if backup:
                            backup_path = f"{file_path}.bak.{int(time.time())}"
                            shutil.copy2(file_path, backup_path)
                            backed_up.append({
                                "original": file_path,
                                "backup": backup_path,
                                "type": "file"
                            })
                        
                        os.remove(file_path)
                        cleaned_files.append({
                            "path": file_path,
                            "size": file_size
                        })
            
            total_size_freed = sum(d["size_freed"] for d in cleaned_dirs) + sum(f["size"] for f in cleaned_files)
            total_files_removed = sum(d["files_removed"] for d in cleaned_dirs) + len(cleaned_files)
            
            return {
                "success": True,
                "cleaned_directories": cleaned_dirs,
                "cleaned_files": cleaned_files,
                "backed_up_items": backed_up,
                "total_size_freed": total_size_freed,
                "total_files_removed": total_files_removed,
                "backup_created": len(backed_up) > 0
            }
            
        except Exception as e:
            logger.error(f"Error cleaning project: {str(e)}")
            return {
                "success": False,
                "error": f"Failed to clean project: {str(e)}"
            }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the high-level purpose. It doesn't disclose what 'clean' entails (e.g., deleting files, resetting configurations), whether it's destructive, what permissions are needed, or any side effects. The mention of 'backup' in the schema hints at potential data loss, but the description doesn't elaborate on this behavioral risk.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It's front-loaded with the core action and purpose, making it easy to scan. Every element ('clean,' 'project directory,' 'prepare for rebuilding') earns its place by contributing essential context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but with an output schema), the description is minimally adequate but incomplete. The output schema may cover return values, but the description lacks details on behavior, parameters, and usage context. It meets a baseline for a simple tool but doesn't fully address the gaps left by missing annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but adds no parameter information. It doesn't explain what 'project_dir' should be (e.g., path format, existence requirements) or the implications of the 'backup' parameter (e.g., what gets backed up, where). The description fails to provide meaning beyond the bare schema fields.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('clean') and target ('project directory') with a specific purpose ('to prepare for rebuilding'). It distinguishes from siblings like 'build_apk' or 'modify_resource_file' by focusing on preparation rather than building or modification. However, it doesn't explicitly differentiate from potential cleanup operations in other tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal guidance by implying usage 'to prepare for rebuilding,' but offers no explicit when-to-use rules, prerequisites, or alternatives. It doesn't specify whether this should be used before 'build_apk' or instead of manual cleanup, nor does it mention any exclusions or conditions for use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/zinja-coder/apktool-mcp-server'

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