Skip to main content
Glama
samhavens

Databricks MCP Server

by samhavens

export_notebook

Export notebooks from Databricks workspace in various formats for sharing, backup, or migration purposes.

Instructions

Export a notebook from the workspace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
formatNoJUPYTER

Implementation Reference

  • MCP tool handler for 'export_notebook', decorated with @mcp.tool(). Delegates to notebooks.export_notebook API, trims large content for readability, and returns JSON response.
    @mcp.tool()
    async def export_notebook(path: str, format: str = "JUPYTER") -> str:
        """Export a notebook from the workspace"""
        logger.info(f"Exporting notebook: {path} in format: {format}")
        try:
            result = await notebooks.export_notebook(path, format)
            
            # 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 json.dumps(result)
        except Exception as e:
            logger.error(f"Error exporting notebook: {str(e)}")
            return json.dumps({"error": str(e)})
  • Helper function implementing the Databricks Workspace Export API call (/api/2.0/workspace/export). Handles base64 decoding for SOURCE/JUPYTER formats.
    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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/samhavens/databricks-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server