Skip to main content
Glama
Databricks MCP Server

Databricks MCP Server

by samhavens

Databricks MCP Server - Working Version

A fixed version of the Databricks MCP Server that properly works with Claude Code and other MCP clients.

πŸ”§ What Was Fixed

This is a working fork of the original Databricks MCP server that fixes critical issues preventing it from working with Claude Code and other MCP clients.

Original Repository: https://github.com/JustTryAI/databricks-mcp-server

The Problems

  1. Asyncio event loop conflict: Original server used asyncio.run() inside MCP tool functions, causing asyncio.run() cannot be called from a running event loop errors when used with Claude Code (which already runs in an async context)

  2. Command spawning issues: Claude Code's MCP client can only spawn single executables, not commands with arguments like databricks-mcp start

  3. SQL API issues: Byte limit too high (100MB vs 25MB max), no API endpoint fallback for different Databricks workspace configurations

The Solutions

  1. Fixed async patterns: Created simple_databricks_mcp_server.py that follows the working iPython MCP pattern - changed all tools to use async def with await instead of asyncio.run()

  2. Simplified CLI: Modified the CLI to default to starting the server when no command is provided, eliminating the need for wrapper scripts

  3. SQL API improvements:

    • Reduced byte_limit from 100MB to 25MB (Databricks maximum allowed)

    • Added API endpoint fallback: tries /statements first, then /statements/execute

    • Better error logging when SQL APIs fail

Related MCP server: Databricks MCP Server

πŸš€ Quick Start for Claude Code Users

  1. Install directly from GitHub:

uv tool install git+https://github.com/samhavens/databricks-mcp-server.git

Or clone and install locally:

git clone https://github.com/samhavens/databricks-mcp-server.git
cd databricks-mcp-server
uv tool install --editable .
  1. Configure credentials:

cp .env.example .env
# Edit .env with your Databricks host and token
  1. Add to Claude Code:

claude mcp add databricks "databricks-mcp"
  1. Test it works:

> list all databricks clusters

Why no arguments needed?

The CLI now defaults to starting the server when no command is provided, making it compatible with Claude Code's MCP client (which can only spawn single executables without arguments).


About This MCP Server

A Model Completion Protocol (MCP) server for Databricks that provides access to Databricks functionality via the MCP protocol. This allows LLM-powered tools to interact with Databricks clusters, jobs, notebooks, and more.

Features

  • MCP Protocol Support: Implements the MCP protocol to allow LLMs to interact with Databricks

  • Databricks API Integration: Provides access to Databricks REST API functionality

  • Tool Registration: Exposes Databricks functionality as MCP tools

  • Async Support: Built with asyncio for efficient operation

Available Tools

The Databricks MCP Server exposes 20 comprehensive tools across all major Databricks functionality areas:

Cluster Management (5 tools)

  • list_clusters: List all Databricks clusters with status and configuration details

  • create_cluster: Create a new Databricks cluster with specified configuration

  • terminate_cluster: Terminate a Databricks cluster

  • get_cluster: Get detailed information about a specific Databricks cluster

  • start_cluster: Start a terminated Databricks cluster

Job Management (4 tools)

  • list_jobs: List Databricks jobs with advanced pagination, creator filtering, and run status tracking

  • list_job_runs: List recent job runs with detailed execution status, duration, and result information

  • run_job: Execute a Databricks job with optional parameters

  • create_job: Create a new job to run a notebook (supports serverless compute by default)

Notebook Management (3 tools)

  • list_notebooks: List notebooks in a workspace directory with metadata

  • export_notebook: Export a notebook from the workspace in various formats (Jupyter, Python, etc.)

  • create_notebook: Create a new notebook in the workspace with specified content and language

File System (4 tools)

  • list_files: List files and directories in DBFS paths with size and modification details

  • upload_file_to_volume: Upload files to Unity Catalog volumes with progress tracking and large file support

  • upload_file_to_dbfs: Upload files to DBFS with chunked upload for large files

  • list_volume_files: List files and directories in Unity Catalog volumes with detailed metadata

SQL Execution (3 tools)

  • execute_sql: Execute SQL statement and wait for completion (blocking) - perfect for quick queries

  • execute_sql_nonblocking: Start SQL execution and return immediately with statement_id for long-running queries

  • get_sql_status: Monitor and retrieve results of non-blocking SQL executions by statement_id

Enhanced Features

Advanced Job Management

  • Pagination support: list_jobs includes pagination with configurable limits and offsets

  • Creator filtering: Filter jobs by creator email (case-insensitive)

  • Run status integration: Automatically includes latest run status and execution duration

  • Duration calculations: Real-time tracking of job execution times

Unity Catalog Integration

  • Volume operations: Full support for Unity Catalog volumes using Databricks SDK

  • Large file handling: Optimized upload with progress tracking for multi-GB files

  • Path validation: Automatic validation of volume paths and permissions

Non-blocking SQL Execution

  • Asynchronous execution: Start long-running SQL queries without blocking

  • Status monitoring: Real-time status tracking with detailed error reporting

  • Result retrieval: Fetch results when queries complete successfully

Key Features

Serverless Compute Support

The create_job tool supports serverless compute by default, eliminating the need for cluster management:

# Serverless execution (default - no cluster needed)
mcp__databricks__create_job(
    job_name="My Data Pipeline",
    notebook_path="/Users/your.email@company.com/MyNotebook",
    timeout_seconds=3600,
    parameters={"param1": "value1"}
)

# Or explicitly specify serverless
mcp__databricks__create_job(
    job_name="My Pipeline",
    notebook_path="/path/to/notebook",
    use_serverless=True  # Default
)

# Still supports cluster-based execution
mcp__databricks__create_job(
    job_name="My Pipeline",
    notebook_path="/path/to/notebook", 
    use_serverless=False,
    cluster_id="your-cluster-id"
)

Benefits of serverless:

  • No cluster creation permissions required

  • Auto-scaling compute resources

  • Cost-efficient - pay only for execution time

  • Faster job startup

Installation

Prerequisites

  • Python 3.10 or higher

  • uv package manager (recommended for MCP servers)

Setup

  1. Install uv if you don't have it already:

    # MacOS/Linux
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
    # Windows (in PowerShell)
    irm https://astral.sh/uv/install.ps1 | iex

    Restart your terminal after installation.

  2. Clone the repository:

    git clone https://github.com/samhavens/databricks-mcp-server.git
    cd databricks-mcp-server
  3. Set up the project with uv:

    # Create and activate virtual environment
    uv venv
    
    # On Windows
    .\.venv\Scripts\activate
    
    # On Linux/Mac
    source .venv/bin/activate
    
    # Install dependencies in development mode
    uv pip install -e .
    
    # Install development dependencies
    uv pip install -e ".[dev]"
  4. Set up environment variables:

    # Windows
    set DATABRICKS_HOST=https://your-databricks-instance.azuredatabricks.net
    set DATABRICKS_TOKEN=your-personal-access-token
    
    # Linux/Mac
    export DATABRICKS_HOST=https://your-databricks-instance.azuredatabricks.net
    export DATABRICKS_TOKEN=your-personal-access-token

    You can also create an .env file based on the .env.example template.

Usage with Claude Code

The MCP server is automatically started by Claude Code when needed. No manual server startup is required.

After installation and configuration:

  1. Start using Databricks tools in Claude Code:

    > list all databricks clusters
    > create a job to run my notebook
    > execute SQL: SHOW CATALOGS
  2. Check available tools:

    databricks-mcp list-tools

Querying Databricks Resources

You can test the MCP server tools directly or use them through Claude Code once installed.

Project Structure

databricks-mcp-server/
β”œβ”€β”€ src/                                      # Source code
β”‚   β”œβ”€β”€ __init__.py                           # Makes src a package
β”‚   β”œβ”€β”€ __main__.py                           # Main entry point for the package
β”‚   β”œβ”€β”€ api/                                  # Databricks API clients
β”‚   β”‚   β”œβ”€β”€ clusters.py                       # Cluster management APIs
β”‚   β”‚   β”œβ”€β”€ dbfs.py                          # DBFS file system APIs
β”‚   β”‚   β”œβ”€β”€ jobs.py                          # Job management APIs
β”‚   β”‚   β”œβ”€β”€ notebooks.py                     # Notebook workspace APIs
β”‚   β”‚   └── sql.py                           # SQL execution APIs
β”‚   β”œβ”€β”€ core/                                # Core functionality
β”‚   β”‚   β”œβ”€β”€ config.py                        # Configuration management
β”‚   β”‚   β”œβ”€β”€ auth.py                          # Authentication
β”‚   β”‚   └── utils.py                         # Utility functions
β”‚   β”œβ”€β”€ server/                              # Server implementation
β”‚   β”‚   └── simple_databricks_mcp_server.py  # Main MCP server
β”‚   └── cli/                                 # Command-line interface
β”‚       └── commands.py                      # CLI commands
β”œβ”€β”€ tests/                                   # Test directory
β”‚   β”œβ”€β”€ test_clusters.py                     # Unit tests for API functions
β”‚   β”œβ”€β”€ test_direct.py                       # Integration tests
β”‚   β”œβ”€β”€ test_tools.py                        # MCP tool tests
β”‚   └── test_validation.py                   # Import/schema validation tests
└── pyproject.toml                           # Project configuration

Development

Linting

The project includes optional linting tools for code quality:

# Run linters (if installed in dev dependencies)
uv run pylint src/ tests/
uv run flake8 src/ tests/
uv run mypy src/

Testing

The project uses pytest for testing with async support. Tests are automatically configured to run with pytest-asyncio.

# Run all tests
uv run pytest tests/ -v

# Run specific test files
uv run pytest tests/test_clusters.py -v
uv run pytest tests/test_direct.py -v
uv run pytest tests/test_tools.py -v

# Run with coverage report (if coverage is installed)
uv run pytest --cov=src tests/ --cov-report=term-missing

Test Status: βœ… 12 passed, 5 skipped (intentionally disabled)

Test Types:

  • Unit tests (test_clusters.py): Test API functions with mocks

  • Integration tests (test_direct.py, test_tools.py): Test MCP tools directly (requires Databricks credentials)

  • Validation tests (test_validation.py): Test import and schema validation

Note: Integration tests will show errors if Databricks credentials are not configured, but this is expected behavior.

Documentation

  • API documentation is generated using Sphinx and can be found in the docs/api directory

  • All code includes Google-style docstrings

  • See the examples/ directory for usage examples

Examples

Volume Upload Operations

Upload a local file to Unity Catalog volume:

# Upload dataset to Unity Catalog volume
mcp__databricks__upload_file_to_volume(
    local_file_path='./data/large_dataset.json',
    volume_path='/Volumes/catalog/schema/volume/large_dataset.json',
    overwrite=True
)

# List files in the volume to verify
mcp__databricks__list_volume_files(
    volume_path='/Volumes/catalog/schema/volume/'
)

Upload to DBFS for temporary processing:

# Upload script to DBFS 
mcp__databricks__upload_file_to_dbfs(
    local_file_path='./scripts/analysis.py',
    dbfs_path='/tmp/analysis.py',
    overwrite=True  
)

Non-blocking SQL Execution

Start long-running query and monitor progress:

# Start a long-running query (non-blocking)
statement_result = mcp__databricks__execute_sql_nonblocking(
    statement="SELECT COUNT(*) FROM large_table GROUP BY category",
    warehouse_id="your-warehouse-id"
)
statement_id = statement_result['statement_id']

# Check status periodically
status = mcp__databricks__get_sql_status(statement_id=statement_id)
print(f"Status: {status['state']}")  # PENDING, RUNNING, SUCCEEDED, FAILED

# When complete, retrieve results
if status['state'] == 'SUCCEEDED':
    results = status['result']

Advanced Job Management

List jobs with filtering and pagination:

# List jobs created by specific user with pagination
jobs = mcp__databricks__list_jobs(
    limit=25,
    offset=0,
    created_by='user@company.com',
    include_run_status=True  # Include latest run info
)

# Get detailed run history for a specific job
runs = mcp__databricks__list_job_runs(
    job_id=12345,
    limit=10
)

For more examples, check the examples/ directory:

# Run example scripts with uv
uv run examples/direct_usage.py
uv run examples/mcp_client_usage.py

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Ensure your code follows the project's coding standards

  2. Add tests for any new functionality

  3. Update documentation as necessary

  4. Verify all tests pass before submitting

πŸ” Technical Details

The key fix was changing from:

@mcp.tool()
def list_clusters() -> str:
    result = asyncio.run(clusters.list_clusters())  # ❌ Breaks in async context
    return json.dumps(result)

To:

@mcp.tool()
async def list_clusters() -> str:
    result = await clusters.list_clusters()  # βœ… Works in async context
    return json.dumps(result)

This pattern was applied to all 20 MCP tools in the server.

πŸ—οΈ Implementation Architecture

SDK vs REST API Approach

The MCP server uses a hybrid implementation approach optimized for reliability and performance:

Databricks SDK (Preferred)

Used for: Volume operations, authentication, and core workspace interactions

  • Benefits: Automatic authentication, better error handling, type safety

  • Tools using SDK: upload_file_to_volume, list_volume_files, authentication layer

  • Authentication: Automatically discovers credentials from environment, CLI config, or instance metadata

REST API (Legacy)

Used for: SQL execution, some job operations

  • Benefits: Direct control over API calls, established patterns

  • Tools using REST: execute_sql, execute_sql_nonblocking, get_sql_status

  • Authentication: Uses manual token-based authentication

Migration Status

  • βœ… Volume operations: Migrated to SDK (fixes 404 errors from REST)

  • πŸ”„ In progress: Additional tools being evaluated for SDK migration

  • πŸ“ Future: Plan to migrate remaining tools for consistency

Recommendation: New tools should use the Databricks SDK for better maintainability and error handling.

πŸ“ Original Repository

Based on: https://github.com/JustTryAI/databricks-mcp-server

πŸ› Issues Fixed

  • βœ… asyncio.run() cannot be called from a running event loop

  • βœ… spawn databricks-mcp start ENOENT (command with arguments not supported)

  • βœ… MCP server connection failures with Claude Code

  • βœ… Proper async/await patterns for MCP tools

  • βœ… SQL execution byte limit issues (100MB β†’ 25MB)

  • βœ… SQL API endpoint compatibility across different Databricks workspaces

  • βœ… Better error handling and logging for SQL operations

License

This project is licensed under the MIT License - see the LICENSE file for details.

Available Tools

19 tools
create_clusterC

Create a new Databricks cluster

Inputs: cluster_name (required), spark_version (required), node_type_id (required), num_workers.

create_jobB

Create a new Databricks job to run a notebook (uses serverless by default)

Inputs: job_name (required), notebook_path (required), timeout_seconds, parameters, +2 more.

create_notebookC

Create a new notebook in the Databricks workspace

Inputs: path (required), content (required), language, overwrite.

execute_sqlB

Execute a SQL statement and wait for completion (blocking)

Inputs: statement (required), warehouse_id (required), catalog, schema_name.

execute_sql_nonblockingB

Start SQL statement execution and return immediately with statement_id (non-blocking)

Inputs: statement (required), warehouse_id (required), catalog, schema_name.

export_notebookC

Export a notebook from the workspace

Inputs: path (required), format.

get_clusterC

Get information about a specific Databricks cluster

Inputs: cluster_id (required).

get_sql_statusC

Get the status and results of a SQL statement by statement_id

Inputs: statement_id (required).

list_clustersB

List all Databricks clusters

Inputs: no named parameters.

list_filesC

List files and directories in DBFS

Inputs: dbfs_path.

list_job_runsA

List recent job runs with detailed status and duration information.

Args:
    job_id: Specific job ID to list runs for (optional, omit to see runs across all jobs)
    limit: Number of runs to return (default: 10, most recent first)

Returns:
    JSON with runs array. Each run includes state (RUNNING/SUCCESS/FAILED), result_state, 
    duration_minutes for completed runs, current_duration_minutes for running jobs.

Inputs: job_id, limit.

list_jobsA

List Databricks jobs with pagination and filtering.

Args:
    limit: Number of jobs to return (default: 25, keeps response under token limits)
    offset: Starting position for pagination (default: 0, use pagination_info.next_offset for next page)
    created_by: Filter by creator email (e.g. 'user@company.com'), case-insensitive, optional
    include_run_status: Include latest run status and duration (default: true, set false for faster response)

Returns:
    JSON with jobs array and pagination_info. Each job includes latest_run with state, duration_minutes, etc.
    Use pagination_info.next_offset for next page. Total jobs shown in pagination_info.total_jobs.

Inputs: limit, offset, created_by, include_run_status.

list_notebooksC

List notebooks in a workspace directory

Inputs: path (required).

list_volume_filesA
List files and directories in a Unity Catalog volume.

Args:
    volume_path: Volume path to list (e.g. '/Volumes/catalog/schema/volume/directory')

Returns:
    JSON with directory listing including file names, sizes, and modification times.
    
Example:
    # List files in volume directory
    files = list_volume_files('/Volumes/kbqa/stark_mas_eval/stark_raw_data/')
    
Note: Returns detailed file information including sizes for managing large datasets.

Inputs: volume_path (required).

run_jobD

Run a Databricks job

Inputs: job_id (required), notebook_params.

start_clusterB

Start a terminated Databricks cluster

Inputs: cluster_id (required).

terminate_clusterC

Terminate a Databricks cluster

Inputs: cluster_id (required).

upload_file_to_dbfsA
Upload a local file to Databricks File System (DBFS).

Args:
    local_file_path: Path to local file (e.g. './data/notebook.py')
    dbfs_path: DBFS path (e.g. '/tmp/uploaded/notebook.py')
    overwrite: Whether to overwrite existing file (default: True)

Returns:
    JSON with upload results including success status, file size, and upload time.
    
Example:
    # Upload script to DBFS
    result = upload_file_to_dbfs(
        local_file_path='./scripts/analysis.py',
        dbfs_path='/tmp/analysis.py',
        overwrite=True
    )
    
Note: For large files (>10MB), uses chunked upload with proper retry logic.
DBFS is good for temporary files, scripts, and smaller datasets.

Inputs: local_file_path (required), dbfs_path (required), overwrite.

upload_file_to_volumeA
Upload a local file to a Databricks Unity Catalog volume.

Args:
    local_file_path: Path to local file (e.g. './data/products.json')
    volume_path: Full volume path (e.g. '/Volumes/catalog/schema/volume/file.json')
    overwrite: Whether to overwrite existing file (default: False)

Returns:
    JSON with upload results including success status, file size in MB, and upload time.
    
Example:
    # Upload large dataset to volume
    result = upload_file_to_volume(
        local_file_path='./stark_export/products_full.json',
        volume_path='/Volumes/kbqa/stark_mas_eval/stark_raw_data/products_full.json',
        overwrite=True
    )
    
Note: Handles large files (multi-GB) with progress tracking and proper error handling.
Perfect for uploading extracted datasets to Unity Catalog volumes for processing.

Inputs: local_file_path (required), volume_path (required), overwrite.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 19 tools

    Disambiguation5/5

    Every tool has a clearly distinct purpose targeting specific Databricks resources and actions. There is no ambiguity: create_* tools create resources, list_* tools list resources, execute_sql vs execute_sql_nonblocking handle different execution modes, and upload_file_to_dbfs vs upload_file_to_volume target different storage systems. The descriptions reinforce these distinctions.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern with snake_case throughout. Verbs like create, list, get, execute, run, start, terminate, export, and upload are used predictably with appropriate nouns (cluster, job, notebook, sql, files, etc.). There are no deviations in naming conventions.

    Tool Count4/5

    With 19 tools, the count is slightly high but reasonable for a comprehensive Databricks interface covering clusters, jobs, notebooks, SQL execution, and file management. It includes core operations for each domain without being excessive, though some tools like list_job_runs and list_jobs could potentially be consolidated to reduce count.

    Completeness5/5

    The tool surface provides complete CRUD/lifecycle coverage for Databricks domains: clusters (create/get/list/start/terminate), jobs (create/list/run with detailed run tracking), notebooks (create/list/export), SQL execution (blocking/non-blocking with status check), and file management (list/upload for both DBFS and Unity Catalog volumes). There are no obvious gaps that would cause agent failures.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      A server that implements the Model Completion Protocol (MCP) to allow LLMs to interact with Databricks resources including clusters, jobs, notebooks, and SQL execution through natural language.
      11
      50
      MIT
    • F
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables AI assistants like Claude to interact with Databricks workspaces through secure OAuth authentication. Supports custom prompts, tools for workspace management, and SQL query execution via a deployable MCP server on Databricks Apps.
      -
    • A
      license
      C
      quality
      D
      maintenance
      A read-only MCP server that enables users to query Databricks SQL, browse metadata, and monitor Delta Lake tables. It also supports tracking Databricks Jobs, DLT Pipelines, and cluster metrics through natural language interfaces.
      25
      4
      MIT