list_files
Browse and view files and directories stored in DBFS paths to manage Databricks data resources.
Instructions
List files and directories in a DBFS path with parameter: dbfs_path (required)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- MCP tool handler for 'list_files' that extracts dbfs_path from params, calls the dbfs.list_files helper, and returns JSON-formatted result as TextContent.async def list_files(params: Dict[str, Any]) -> List[TextContent]: logger.info(f"Listing files with params: {params}") try: result = await dbfs.list_files(params.get("dbfs_path")) return [{"text": json.dumps(result)}] except Exception as e: logger.error(f"Error listing files: {str(e)}") return [{"text": json.dumps({"error": str(e)})}]
- src/server/databricks_mcp_server.py:179-182 (registration)Registers the 'list_files' tool using the FastMCP @tool decorator with name and description specifying the required dbfs_path parameter.@self.tool( name="list_files", description="List files and directories in a DBFS path with parameter: dbfs_path (required)", )
- src/api/dbfs.py:177-191 (helper)Core helper function that performs the actual Databricks DBFS /list API request to retrieve files and directories at the given path.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})