export_notebook
Export a notebook from Databricks workspace in formats like SOURCE, HTML, JUPYTER, or DBC by specifying the path. Simplifies sharing and reuse of notebook content.
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
- MCP tool handler for 'export_notebook' that extracts parameters, calls the core export function, trims large content, and returns JSON response.async 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, optionally decodes base64 content.async 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
- src/server/databricks_mcp_server.py:157-160 (registration)Registration of the 'export_notebook' tool using the @self.tool decorator, including name and parameter description (serving as schema).@self.tool( name="export_notebook", description="Export a notebook from the workspace with parameters: path (required), format (optional, one of: SOURCE, HTML, JUPYTER, DBC)", )