Skip to main content
Glama

obsidian_delete_file

Delete files or directories from your Obsidian vault to remove outdated or duplicate notes. Requires explicit confirmation for this destructive operation.

Instructions

Delete a file or directory from the vault.

DESTRUCTIVE OPERATION. Requires explicit confirmation. Use carefully when
removing outdated or duplicate notes from your Zettelkasten.

Args:
    params (DeleteFileInput): Contains:
        - filepath (str): Path to file/directory to delete
        - confirm (bool): Must be True to proceed with deletion

Returns:
    str: Success or error message
    
Example:
    Delete a duplicate note after merging content into another note.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • Pydantic input model defining the parameters for the obsidian_delete_file tool: filepath (str) and confirm (bool, required for safety).
    class DeleteFileInput(BaseModel):
        """Input for deleting files."""
        model_config = ConfigDict(str_strip_whitespace=True, extra='forbid')
        
        filepath: str = Field(
            description="Path to the file or directory to delete",
            min_length=1,
            max_length=500
        )
        confirm: bool = Field(
            description="Must be set to true to confirm deletion",
            default=False
        )
  • MCP decorator registering the delete_file function as the 'obsidian_delete_file' tool with destructive operation annotations.
    @mcp.tool(
        name="obsidian_delete_file",
        annotations={
            "title": "Delete File or Directory",
            "readOnlyHint": False,
            "destructiveHint": True,
            "idempotentHint": True,
            "openWorldHint": False
        }
    )
  • The primary handler function for the obsidian_delete_file tool. Validates the confirmation parameter and invokes the ObsidianClient.delete method to perform the deletion via the Obsidian REST API.
    async def delete_file(params: DeleteFileInput) -> str:
        """Delete a file or directory from the vault.
        
        DESTRUCTIVE OPERATION. Requires explicit confirmation. Use carefully when
        removing outdated or duplicate notes from your Zettelkasten.
        
        Args:
            params (DeleteFileInput): Contains:
                - filepath (str): Path to file/directory to delete
                - confirm (bool): Must be True to proceed with deletion
        
        Returns:
            str: Success or error message
            
        Example:
            Delete a duplicate note after merging content into another note.
        """
        if not params.confirm:
            return json.dumps({
                "error": "Deletion requires explicit confirmation. Set 'confirm' to true.",
                "filepath": params.filepath,
                "success": False
            }, indent=2)
        
        try:
            await obsidian_client.delete(f"/vault/{params.filepath}")
            
            return json.dumps({
                "success": True,
                "message": f"Successfully deleted: {params.filepath}",
                "filepath": params.filepath
            }, indent=2)
            
        except ObsidianAPIError as e:
            return json.dumps({
                "error": str(e),
                "filepath": params.filepath,
                "success": False
            }, indent=2)
  • Helper method in ObsidianClient that executes the actual HTTP DELETE request to the Obsidian Local REST API endpoint for deleting vault files or directories.
    async def delete(self, endpoint: str) -> Dict[str, Any]:
        """Execute DELETE request to Obsidian API."""
        url = f"{self.base_url}{endpoint}"
        try:
            response = await self.client.delete(url)
            if response.status_code in (200, 204):
                return {"success": True, "message": "Resource deleted successfully"}
            else:
                self._handle_error(response, f"DELETE {endpoint}")
        except httpx.RequestError as e:
            raise ObsidianAPIError(
                f"Connection error for DELETE {endpoint}: {str(e)}. "
                "Ensure Obsidian is running with the Local REST API plugin enabled."
            )

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/Shepherd-Creative/obsidian-mcp'

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