Skip to main content
Glama

delete_file

Delete files with policy enforcement and optional backup, ensuring safe file removal within configured boundaries.

Instructions

Delete a single file after policy checks and optional pre-delete backup.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
ctxNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core implementation of the delete_file tool. Validates path policy, checks file exists, refuses directories, performs optional backup, uses os.remove() to delete the file, and returns a result message.
    def delete_file(path: str, ctx: Context | None = None) -> str:
        """Delete a single file after policy checks and optional pre-delete backup."""
        context_tokens = activate_runtime_context(ctx)
        path = str(pathlib.Path(WORKSPACE_ROOT) / path) if not os.path.isabs(path) else path
    
        try:
            refresh_policy_if_changed()
            path_check = check_path_policy(path, tool="delete_file")
            if path_check:
                result = PolicyResult(allowed=False, reason=path_check[0], decision_tier="blocked", matched_rule=path_check[1])
            else:
                result = PolicyResult(allowed=True, reason="allowed", decision_tier="allowed", matched_rule=None)
    
            if result.allowed:
                if not os.path.exists(path):
                    append_log_entry(build_log_entry("delete_file", result, path=path, error="file not found"))
                    return f"Error: file not found: {path}"
    
                if os.path.isdir(path):
                    result = PolicyResult(
                        allowed=False,
                        reason=f"'{path}' is a directory  -  delete_file only removes individual files. Use execute_command for directory operations (note: bulk/recursive deletions are also subject to policy).",
                        decision_tier="blocked",
                        matched_rule=None,
                    )
    
            log_entry = build_log_entry("delete_file", result, path=path)
            if not result.allowed:
                append_log_entry(log_entry)
                return f"[POLICY BLOCK] {result.reason}"
    
            backup_enabled = bool(POLICY.get("audit", {}).get("backup_enabled", True))
            backup_location = backup_paths([path]) if backup_enabled else ""
            if backup_location:
                log_entry["backup_location"] = backup_location
    
            append_log_entry(log_entry)
    
            try:
                os.remove(path)
            except OSError as e:
                return f"Error deleting file: {e}"
    
            return f"Successfully deleted {path}. " + (
                f"Backup saved to {backup_location}  -  the file can be recovered from there."
                if backup_location
                else "No content-change backup was needed."
            )
        finally:
            reset_runtime_context(context_tokens)
  • src/server.py:21-31 (registration)
    The MCP server registers delete_file as a tool via mcp.tool()(delete_file) in a loop over the tool list.
    for tool in [
        server_info,
        restore_backup,
        execute_command,
        read_file,
        write_file,
        edit_file,
        delete_file,
        list_directory,
    ]:
        mcp.tool()(tool)
  • Re-exports delete_file from file_tools module in the package's __init__.py.
    from .file_tools import delete_file, edit_file, list_directory, read_file, write_file
    from .restore_tools import restore_backup
    
    __all__ = [
        "server_info",
        "execute_command",
        "read_file",
        "write_file",
        "edit_file",
        "delete_file",
        "list_directory",
        "restore_backup",
    ]
  • Lists delete_file as one of the AIRG MCP tools in the config manager.
    AIRG_MCP_TOOLS = [
        "server_info",
        "restore_backup",
        "execute_command",
        "read_file",
        "write_file",
        "edit_file",
        "delete_file",
        "list_directory",
    ]
  • Maps the 'Delete' action from codex/AirG to the MCP tool name 'mcp__ai-runtime-guard__delete_file'.
        "Delete": "mcp__ai-runtime-guard__delete_file",
    }
Behavior3/5

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

Description adds context about policy checks and optional backup beyond the name, but lacks details on permissions, irreversibility, or error handling. Without annotations, more behavioral disclosure would be helpful.

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

Conciseness4/5

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

Single sentence, front-loaded with key information. Not verbose, but could incorporate more details without being wordy.

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?

Description covers primary purpose and a safety feature (backup), but lacks return value, error cases, and interaction with siblings. Given the complexity of deletion, more completeness would aid agent selection.

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?

With 0% schema description coverage, the description should explain parameters. It implies 'path' is the file to delete but does not describe 'ctx' or any format constraints. The description adds minimal value over the schema.

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

Purpose5/5

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

Description clearly states verb 'delete', resource 'a single file', and additional context 'after policy checks and optional pre-delete backup'. This distinguishes it from siblings like read_file or restore_backup.

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

Usage Guidelines3/5

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

Description implies tool is for deletion with safety features but does not explicitly state when to use versus alternatives like write_file or restore_backup. No exclusions or when-not guidance.

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

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/runtimeguard/ai-runtime-guard'

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