delete_file
Remove files securely from specified directories using the Filesystem MCP Server. Input the file path within allowed roots to delete it and receive a success or error message.
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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- main.py:234-253 (handler)The delete_file tool handler, decorated with @mcp.tool for registration. It resolves the input path to ensure it's within allowed directories, deletes the file using Path.unlink(), and returns a success message or a human-readable error via _human_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")