Databricks MCP协议服务器

一个为Databricks提供的模型完成协议(MCP)服务器,通过MCP协议实现对Databricks集群、作业、笔记本等功能的访问,使LLM驱动的工具能够与Databricks交互。

  • by JustTryAI
  • Python
  • 本地部署
  • 50 星标
  • 更新于
在 GitHub 查看 JustTryAI/databricks-mcp-server

使用说明

_CHMCP服务器

一个用于copula的模型完成协议(MCP)服务器,通过MCP协议提供对copula功能的访问。这允许LLM驱动的工具与ViewModel集群、作业、笔记本电脑等进行交互。

特性

  • MCP协议支持:实现MCP协议,以允许LLM与Databricks交互
  • Databricks API集成:提供对Databricks REST API功能的访问
  • 工具注册:将copula功能作为MCP工具公开
  • 异步支持:内置asyncio以实现高效运行

可用工具

AppDMCP服务器公开了以下工具:

  • list_cluster:列出所有copula集群
  • create_cluster:创建一个新的copula集群
  • terminate_cluster:终止copula集群
  • get_cluster:获取有关特定copula集群的信息
  • start_cluster:启动已终止的copula集群
  • list_jobs列出所有 Databricks 工作
  • run_job:运行copula作业
  • list_notebooks:列出工作区目录中的笔记本
  • export_notebook:从工作区导出笔记本
  • 列表文件:列出DBFS路径中的文件和目录
  • execute_sql:执行SQL语句

安装

先决条件

  • Python 3.10或更高版本
  • uv 包管理器(建议用于MCP服务器)

设置

  1. 安装 uv 如果你还没有:

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

    安装后重新启动终端。

  2. 克隆存储库:

    git clone https://github.com/JustTryAI/databricks-mcp-server.git
    cd databricks-mcp-server
    
  3. 通过以下方式设置项目 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. 设置环境变量:

    # 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
    

    您还可以创建 .env 文件基于 .env.example 模板。

运行MCP服务器

要启动MCP服务器,请运行:

# Windows
.\start_mcp_server.ps1

# Linux/Mac
./start_mcp_server.sh

这些包装器脚本将执行位于 scripts 目录。服务器将启动并准备接受MCP协议连接。

您还可以直接从脚本目录运行服务器脚本:

# Windows
.\scripts\start_mcp_server.ps1

# Linux/Mac
./scripts/start_mcp_server.sh

查询copula资源

该存储库包含实用程序脚本,用于快速查看copula资源:

# View all clusters
uv run scripts/show_clusters.py

# View all notebooks
uv run scripts/show_notebooks.py

项目结构

databricks-mcp-server/
├── src/                             # Source code
│   ├── __init__.py                  # Makes src a package
│   ├── __main__.py                  # Main entry point for the package
│   ├── main.py                      # Entry point for the MCP server
│   ├── api/                         # Databricks API clients
│   ├── core/                        # Core functionality
│   ├── server/                      # Server implementation
│   │   ├── databricks_mcp_server.py # Main MCP server
│   │   └── app.py                   # FastAPI app for tests
│   └── cli/                         # Command-line interface
├── tests/                           # Test directory
├── scripts/                         # Helper scripts
│   ├── start_mcp_server.ps1         # Server startup script (Windows)
│   ├── run_tests.ps1                # Test runner script
│   ├── show_clusters.py             # Script to show clusters
│   └── show_notebooks.py            # Script to show notebooks
├── examples/                        # Example usage
├── docs/                            # Documentation
└── pyproject.toml                   # Project configuration

看 project_structure.md 查看项目结构的更详细视图。

发展

代码规范

  • Python代码遵循PEP 8风格指南,最大行长为100个字符
  • 使用4个空格进行缩进(无制表符)
  • 字符串使用双引号
  • 所有类、方法和函数都应该有谷歌风格的文档字符串
  • 除测试外,所有代码都需要类型提示

代码检查

该项目使用以下linting工具:

# Run all linters
uv run pylint src/ tests/
uv run flake8 src/ tests/
uv run mypy src/

测试

该项目使用pytest进行测试。要运行测试,请执行以下操作:

# Run all tests with our convenient script
.\scripts\run_tests.ps1

# Run with coverage report
.\scripts\run_tests.ps1 -Coverage

# Run specific tests with verbose output
.\scripts\run_tests.ps1 -Verbose -Coverage tests/test_clusters.py

您还可以直接使用pytest运行测试:

# Run all tests
uv run pytest tests/

# Run with coverage report
uv run pytest --cov=src tests/ --cov-report=term-missing

该项目的目标是代码覆盖率至少达到80%。

文档

  • API文档是使用Sphinx生成的,可以在 docs/api 目录
  • 所有代码都包含谷歌风格的文档字符串
  • 请参阅 examples/ 使用示例目录

例子

检查 examples/ 使用示例目录。要运行示例,请执行以下操作:

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

贡献

欢迎投稿!请随时提交拉取请求。

  1. 确保你的代码遵循项目的编码标准
  2. 为任何新功能添加测试
  3. 必要时更新文档
  4. 提交前验证所有测试是否通过

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。