export_notebook
Export Databricks notebooks from the workspace in multiple formats including SOURCE, HTML, JUPYTER, and DBC for sharing or backup purposes.
Instructions
Export a notebook from the workspace with parameters: path (required), format (optional, one of: SOURCE, HTML, JUPYTER, DBC)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- src/server/databricks_mcp_server.py:157-160 (registration)Registration of the export_notebook MCP tool using @self.tool decorator@self.tool( name="export_notebook", description="Export a notebook from the workspace with parameters: path (required), format (optional, one of: SOURCE, HTML, JUPYTER, DBC)", )
- Handler function for export_notebook tool that processes params, calls notebooks.export_notebook, handles response truncation, and returns MCP TextContentasync def export_notebook(params: Dict[str, Any]) -> List[TextContent]: logger.info(f"Exporting notebook with params: {params}") try: format_type = params.get("format", "SOURCE") result = await notebooks.export_notebook(params.get("path"), format_type) # For notebooks, we might want to trim the response for readability content = result.get("content", "") if len(content) > 1000: summary = f"{content[:1000]}... [content truncated, total length: {len(content)} characters]" result["content"] = summary return [{"text": json.dumps(result)}] except Exception as e: logger.error(f"Error exporting notebook: {str(e)}") return [{"text": json.dumps({"error": str(e)})}]
- src/api/notebooks.py:57-90 (helper)Core helper function that performs the actual Databricks API call to export a notebook, including base64 decoding for certain formatsasync def export_notebook( path: str, format: str = "SOURCE", ) -> Dict[str, Any]: """ Export a notebook from the workspace. Args: path: The path of the notebook to export format: The format to export (SOURCE, HTML, JUPYTER, DBC) Returns: Response containing the notebook content Raises: DatabricksAPIError: If the API request fails """ logger.info(f"Exporting notebook from path: {path}") params = { "path": path, "format": format, } response = make_api_request("GET", "/api/2.0/workspace/export", params=params) # Optionally decode base64 content if "content" in response and format in ["SOURCE", "JUPYTER"]: try: response["decoded_content"] = base64.b64decode(response["content"]).decode("utf-8") except Exception as e: logger.warning(f"Failed to decode notebook content: {str(e)}") return response