Skip to main content
Glama
Preston-Harrison

Filesystem MCP Server

delete_file

Remove files from the filesystem by specifying their path. This tool helps manage storage by deleting unnecessary files within allowed directories.

Instructions

Delete a file from the filesystem.

Args: path (str): File path to delete (absolute or relative to allowed directories)

Returns: str: Success message with deleted file path, or error message if failed

Note: - Path must be within allowed directory roots - Fails if file doesn't exist or cannot be deleted

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • main.py:234-254 (handler)
    The main handler function for the 'delete_file' tool. It is registered via the @mcp.tool decorator. Resolves the path using _resolve to ensure it's within allowed directories, deletes the file using unlink(), and returns a success message or human-readable error.
    @mcp.tool
    def delete_file(path: str) -> str:
        """Delete a file from the filesystem.
    
        Args:
            path (str): File path to delete (absolute or relative to allowed directories)
    
        Returns:
            str: Success message with deleted file path, or error message if failed
    
        Note:
            - Path must be within allowed directory roots
            - Fails if file doesn't exist or cannot be deleted
        """
        try:
            rp = _resolve(path)
            rp.unlink()
            return f"Deleted {rp}"
        except Exception as e:
            return _human_error(e, "deleting file")

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/Preston-Harrison/fs-mcp-py'

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