list_files
Retrieve and display files and directories from Databricks File System (DBFS) by specifying a path. Streamlines file management within Databricks environments.
Instructions
List files and directories in DBFS
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dbfs_path | No | / |
Implementation Reference
- The MCP tool handler for 'list_files'. Decorated with @mcp.tool(), it handles the tool execution by calling the dbfs.list_files helper and returning JSON response.@mcp.tool() async def list_files(dbfs_path: str = "/") -> str: """List files and directories in DBFS""" logger.info(f"Listing files in: {dbfs_path}") try: result = await dbfs.list_files(dbfs_path) return json.dumps(result) except Exception as e: logger.error(f"Error listing files: {str(e)}") return json.dumps({"error": str(e)})
- src/api/dbfs.py:177-191 (helper)Supporting API function that performs the actual Databricks DBFS list API call.async def list_files(dbfs_path: str) -> Dict[str, Any]: """ List files and directories in a DBFS path. Args: dbfs_path: The path to list Returns: Response containing the directory listing Raises: DatabricksAPIError: If the API request fails """ logger.info(f"Listing files in DBFS path: {dbfs_path}") return make_api_request("GET", "/api/2.0/dbfs/list", params={"path": dbfs_path})