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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
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
- src/mcp_server_code_assist/server.py:95-99 (registration)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(), ),
- src/mcp_server_code_assist/server.py:21-21 (registration)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)]