Skip to main content
Glama

delete_file

Remove files from your codebase using this MCP server tool. Specify the file path to delete it and maintain project organization.

Instructions

Deletes a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • Core handler function for the 'delete_file' tool. Validates the path, moves the file to a timestamped trash directory instead of permanent deletion, and returns a confirmation message.
    async def delete_file(self, path: str) -> str: path = await self.validate_path(path) if not path.is_file(): return f"Path not found: {path}" # Create trash directory trash_dir = path.parent / ".mcp_server_code_assist_trash" trash_dir.mkdir(exist_ok=True) # Move file to trash with timestamp to avoid conflicts from datetime import datetime timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") trash_path = trash_dir / f"{path.name}_{timestamp}" path.rename(trash_path) return f"Moved file to trash: {trash_path}"
  • Pydantic model defining the input schema for the delete_file tool, requiring a 'path' parameter.
    class FileDelete(BaseModel): path: str | Path
  • Registers the 'delete_file' tool in the MCP server with name, description, and input schema.
    Tool( name=CodeAssistTools.DELETE_FILE, description="Deletes a file", inputSchema=FileDelete.model_json_schema(), ),
  • Enum constant defining the tool name 'delete_file'.
    DELETE_FILE = "delete_file"
  • MCP server tool call handler that invokes the delete_file method on file_tools instance.
    case CodeAssistTools.DELETE_FILE: model = FileDelete(path=arguments["path"]) result = await file_tools.delete_file(model.path) return [TextContent(type="text", text=result)]

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/abhishekbhakat/mcp_server_code_assist'

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