Databricks MCP服务器

一个基于Databricks Apps的MCP服务器,允许AI助手如Claude通过安全认证接口与Databricks工作区交互。

  • by canglade629
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 canglade629/my-mcp-server

使用说明

Awesome-Databricks-MCP(可译为“卓越Databricks MCP”或根据具体语境调整,但“Awesome”在此处可能表示“极棒的”或“出色的”,“MCP”可能是一个特定项目、课程或认证的缩写,具体翻译需结合上下文)

Databricks 应用中的主机模型上下文协议(MCP)提示和工具,使像 Claude 这样的 AI 助手能够通过安全的、经过身份验证的接口与您的 Databricks 工作区进行交互。

这是什么?

此模板允许您创建一个在Databricks Apps上运行的MCP服务器。您可以:

  • 📝(便签本/记事本) 添加提示 作为简单的Markdown文件在 prompts/ 文件夹
  • 🛠️(扳手,工具) 创建工具 作为利用Databricks SDK的Python函数
  • 🔐 安全认证 通过Databricks应用程序使用OAuth
  • 🚀 表示火箭或快速上升、飞速前进等意思,可以翻译为“🚀(火箭/飞速上升/飞速前进等,根据上下文具体含义)”。不过,通常在没有具体上下文时,我们可能会直接用“🚀”这个符号来表达一种快速、有力或上升的感觉,而不直接翻译出其具体含义。但在这里,为了符合您的要求,我给出了一个可能的翻译方向。 立即部署 使您的MCP服务器可供Claude访问
  • 🖥️(电脑显示器) 网页界面 配备现代的React TypeScript前端用于MCP发现
  • 🧪 表示“实验”或“化学实验”。 全面测试 配备自动化的MCP验证工具
  • 🔄 旋转(或循环) 持续集成/持续交付(CI/CD)流水线 实现自动化测试、安全扫描和部署
  • 📊 表格 高级仪表板工具 用于构建全面的湖景仪表板
  • 🛡️ 翻译为中文是:护盾 安全特性 具备全面的注入攻击防护和输入验证功能

可以将其视为Claude与您的Databricks工作区之间的桥梁——您定义Claude能看到和能做的事情,而这个服务器处理其余的工作。

它是如何工作的

架构概述

┌─────────────┐       MCP Protocol      ┌──────────────────┐        OAuth         ┌─────────────────┐
│   Claude    │ ◄─────────────────────► │  dba-mcp-proxy   │ ◄──────────────────► │ Databricks App  │
│    CLI      │     (stdio/JSON-RPC)    │ (local process)  │    (HTTPS/SSE)      │  (MCP Server)   │
└─────────────┘                         └──────────────────┘                      └─────────────────┘
                                                ▲                                           │
                                                │                                           ▼
                                                └────────── Databricks OAuth ──────► Workspace APIs
graph TB
    subgraph "MCP Client Layer"
        A[Claude CLI] 
        B[Claude Code]
        C[Other MCP Clients]
    end
    
    subgraph "MCP Proxy Layer"
        D[dba-mcp-proxy]
        E[OAuth Authentication]
        F[Token Management]
    end
    
    subgraph "Databricks Apps Layer"
        G[FastAPI App]
        H[MCP Server]
        I[React Frontend]
    end
    
    subgraph "Tools Layer"
        J[Core Tools]
        K[SQL Operations]
        L[Unity Catalog]
        M[Dashboard Tools]
        N[Widget Tools]
        O[Jobs & Pipelines]
        P[Data Management]
        Q[Governance]
    end
    
    subgraph "Databricks Services"
        R[SQL Warehouses]
        S[Unity Catalog]
        T[Jobs & DLT]
        U[DBFS & Volumes]
        V[Workspace Files]
        W[ML & Models]
    end
    
    A --> D
    B --> D
    C --> D
    D --> E
    E --> F
    F --> G
    G --> H
    H --> J
    H --> K
    H --> L
    H --> M
    H --> N
    H --> O
    H --> P
    H --> Q
    
    J --> R
    K --> R
    L --> S
    M --> S
    N --> S
    O --> T
    P --> U
    Q --> V
    
    G --> I

组件

  1. MCP 服务器 (server/app.py): 一个集成了MCP服务器的FastAPI应用,该应用:

    • 动态加载提示信息来自 prompts/*.md 文件
    • 通过模块化工具系统将Python函数作为MCP工具暴露出来
    • 处理通过服务器发送事件(Server-Sent Events)的HTTP请求和MCP协议
    • 使用FastMCP框架实现无缝的MCP集成
  2. React 前端 (client/): 一个现代的TypeScript React应用程序,它:

    • 提供一个用于MCP发现和测试的网页界面
    • 显示可用的提示、工具和MCP配置
    • 包含用于Claude集成的复制粘贴设置命令
    • 使用TailwindCSS、Radix UI和现代React模式构建
    • 使用Vite进行快速开发和构建
  3. 提示 (prompts/): 符合MCP规范的Markdown文件,带有YAML前置内容:

    • **YAML 前置元数据(或称为YAML frontmatter)**所需的元数据,用于定义提示名称、描述和参数
    • 参数验证内置对必需参数和数据类型的验证
    • 占位符替换自动替换 ${argument} 占位符
    • 安全输入净化和验证以防止注入攻击
  4. 模块化工具系统 (server/tools/): 组织了工具模块,这些模块:

    • 将功能分解为逻辑上可管理的组件
    • 提供9个专业模块中的100多个工具
    • 提高可维护性和促进协作
    • 支持轻松添加新工具
  5. 本地代理 (dba_mcp_proxy/): 验证并代理MCP请求:

    • 自动处理Databricks的OAuth认证
    • 在克劳德的stdio协议与HTTP/SSE之间进行翻译(或转换)
    • 适用于本地开发和已部署的应用
  6. 综合测试套件 (claude_scripts/): 自动化验证工具:

    • 本地和远程MCP服务器测试
    • MCP协议合规性验证
    • OAuth认证流程测试
    • 基于Web的MCP检测器,用于交互式测试
  7. 安全特性 (server/tools/security.py): 全面的安全验证:

    • 通过模式检测防止SQL注入
    • 防止HTML/脚本注入并进行清理
    • 数据集和字段名验证
    • 小部件配置安全验证
    • 输入净化和转义处理

🎬 示例/演示

这个5分钟的视频向您展示了如何设置和使用配备Claude和/或Cursor的MCP服务器:https://www.youtube.com/watch?v=_yPtm2iH04o

快速入门

创建您自己的MCP服务器

步骤1:安装Databricks CLI并设置GitHub SSH访问

在开始之前,请确保已配置好 Databricks CLI 和 GitHub SSH 访问权限。

安装 Databricks 命令行界面 (CLI):

macOS:(可翻译为“苹果操作系统”或保持原样,因为“macOS”在中文中通常直接使用,不进行翻译)

# Using Homebrew (recommended)
brew install databricks/tap/databricks

# Using pip
pip install databricks-cli

# Verify installation
databricks --version

Windows:

# Using pip
pip install databricks-cli

# Or download from official releases
# https://github.com/databricks/databricks-cli/releases
# Download the .exe file and add to PATH

# Verify installation
databricks --version

Linux:

# Using pip
pip install databricks-cli

# Using apt (Ubuntu/Debian)
curl -fsSL https://databricks.com/install-cli.sh | bash

# Using yum (RHEL/CentOS)
curl -fsSL https://databricks.com/install-cli.sh | bash

# Verify installation
databricks --version

设置GitHub SSH访问:

macOS:

# Generate SSH key (if you don't have one)
ssh-keygen -t ed25519 -C "your-email@example.com"

# Start ssh-agent
eval "$(ssh-agent -s)"

# Add SSH key to ssh-agent
ssh-add ~/.ssh/id_ed25519

# Copy public key to clipboard
pbcopy < ~/.ssh/id_ed25519.pub

# Add to GitHub: https://github.com/settings/keys
# Click "New SSH key" and paste the copied key

Windows:

# Generate SSH key (if you don't have one)
ssh-keygen -t ed25519 -C "your-email@example.com"

# Start ssh-agent (PowerShell as Administrator)
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent

# Add SSH key to ssh-agent
ssh-add ~/.ssh/id_ed25519

# Copy public key to clipboard
Get-Content ~/.ssh/id_ed25519.pub | Set-Clipboard

# Add to GitHub: https://github.com/settings/keys
# Click "New SSH key" and paste the copied key

Linux:

# Generate SSH key (if you don't have one)
ssh-keygen -t ed25519 -C "your-email@example.com"

# Start ssh-agent
eval "$(ssh-agent -s)"

# Add SSH key to ssh-agent
ssh-add ~/.ssh/id_ed25519

# Copy public key to clipboard (if xclip is available)
xclip -sel clip < ~/.ssh/id_ed25519.pub

# Or display the key to copy manually
cat ~/.ssh/id_ed25519.pub

# Add to GitHub: https://github.com/settings/keys
# Click "New SSH key" and paste the copied key

测试GitHub SSH连接:

# Test the connection
ssh -T git@github.com

# You should see: "Hi username! You've successfully authenticated..."

使用SSH配置Git:

# Set your Git username and email
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"

# Verify SSH is working by cloning a private repo
git clone git@github.com:username/private-repo.git

步骤2:克隆仓库

# Clone your new repository
git clone https://github.com/PulkitXChadha/awesome-databricks-mcp.git
cd awesome-databricks-mcp

# Run the interactive setup
./setup.sh

这将:

  • 配置Databricks身份验证
  • 设置您的MCP服务器名称
  • 安装所有依赖项(Python + Node.js)
  • 创建你的 .env.local 文件

第三步:使用Claude进行部署

在Claude Code中运行:

/setup-mcp

这将会:

  • 将您的MCP服务器部署到Databricks应用程序
  • 配置MCP集成
  • 显示你可用的提示和工具

然后重启Claude Code以使用您的新MCP服务器。

添加到 Claude CLI

部署后,将您的MCP服务器添加到Claude中:

# Set your Databricks configuration
export DATABRICKS_HOST="https://your-workspace.cloud.databricks.com"
export DATABRICKS_APP_URL="https://your-app.databricksapps.com"  # Get this from ./app_status.sh
export SERVER_NAME="your-server-name"  # This comes from config.yaml (set during ./setup.sh)

# Add your MCP server to Claude (user-scoped)
claude mcp add $SERVER_NAME --scope user -- \
  uvx --from git+https://git@github.com/YOUR-USERNAME/your-repo.git dba-mcp-proxy \
  --databricks-host $DATABRICKS_HOST \
  --databricks-app-url $DATABRICKS_APP_URL

本地开发

# Clone and setup
git clone <your-repo>
cd <your-repo>
./setup.sh

# Start dev server (both backend and frontend)
./watch.sh

# Set your configuration for local testing
export DATABRICKS_HOST="https://your-workspace.cloud.databricks.com"
export DATABRICKS_APP_URL="http://localhost:8000"  # Local dev server

# Add to Claude for local testing
claude mcp add databricks-mcp-local --scope local -- \
  uvx --from git+https://git@github.com/YOUR-ORG/YOUR-REPO.git dba-mcp-proxy \
  --databricks-host $DATABRICKS_HOST \
  --databricks-app-url $DATABRICKS_APP_URL

本地运行

先决条件

在本地运行MCP服务器之前,请确保您已具备:

  • Python 3.11及以上版本 和 Node.js 18及以上版本 已安装
  • Databricks 命令行界面 (CLI) 配置为 databricks auth login
  • Git 用于克隆仓库
  • 紫外线 包管理器(推荐)或 pip(在Python中通常指“Python包管理工具”,用于安装和管理Python包) 对于Python依赖项
  • 面包(或“汉堡面包”,根据上下文具体指代) (建议)或 npm(Node Package Manager) 用于Node.js依赖项

分步本地设置

1. 克隆并配置

# Clone your repository
git clone https://github.com/PulkitXChadha/awesome-databricks-mcp.git
cd awesome-databricks-mcp

# Run the interactive setup script
./setup.sh

安装脚本将:

  • 使用以下方式安装Python依赖项 uv 或者 pip
  • 使用以下方式安装 Node.js 依赖项 bun 或者 npm
  • 配置您的Databricks工作区设置
  • 创建一个 .env.local 附上您的配置文件

2. 启动开发服务器

# Start both backend (FastAPI) and frontend (React) servers
./watch.sh

这个命令启动:

  • 后端FastAPI 服务器已启动 http://localhost:8000
  • 前端React 开发服务器已启动 http://localhost:3000
  • 文件监视文件更改时自动重新加载

3. 验证本地设置

打开您的浏览器并导航至:

  • 后端APIhttp://localhost:8000/docs (FastAPI Swagger UI) 翻译为中文是:http://localhost:8000/docs(FastAPI Swagger 用户界面)
  • 前端http://localhost:3000(React 应用程序)
  • **MCP 终点(或MCP端点)**http://localhost:8000/mcp/ (MCP服务器)

4. 使用 Claude CLI 进行测试

# Set environment variables for local testing
export DATABRICKS_HOST="https://your-workspace.cloud.databricks.com"
export DATABRICKS_APP_URL="http://localhost:8000"

# Add the local MCP server to Claude
claude mcp add databricks-mcp-local --scope local -- \
  uvx --from git+https://git@github.com/PulkitXChadha/awesome-databricks-mcp.git dba-mcp-proxy \
  --databricks-host $DATABRICKS_HOST \
  --databricks-app-url $DATABRICKS_APP_URL

# Test the connection
echo "What MCP prompts are available from databricks-mcp-local?" | claude

开发工作流程

做出改变

  1. 编辑提示修改文件中的 prompts/ 目录
  2. 编辑工具在相应的模块下更新函数 server/tools/
  3. 编辑前端修改React组件中的 client/src/
  4. 编辑后端更新 FastAPI 路由 server/

得益于文件监视器,所有更改都会自动重新加载 ./watch.sh。

创建新的MCP提示

所有提示均需包含YAML前置信息以符合MCP规范。请在(此处)创建一个新的Markdown文件 prompts/:

---
name: your_prompt_name
description: Brief description of what the prompt does
arguments:
  - name: warehouse_id
    description: SQL Warehouse ID for query execution
    required: true
    schema:
      type: string
      pattern: "^[a-f0-9]{16}$"
  
  - name: catalog
    description: Unity Catalog name
    required: false
    schema:
      type: string
      
mutually_exclusive:
  - [option1, option2]  # Optional: Define mutually exclusive arguments
---

# Your Prompt Title

## Configuration
- **Warehouse ID**: ${warehouse_id}
- **Catalog**: ${catalog}

Your prompt content here. Use ${argument_name} for placeholder substitution.

YAML 前置元数据提供了:

  • 结构化文档明确预期参数的定义
  • 未来的MCP合规性为FastMCP添加完整参数支持做好准备
  • 模式定义JSON Schema 已准备好进行验证
  • 参数元数据必需/可选标志及说明

注:FastMCP的当前版本不支持在提示中进行运行时参数验证, 但YAML元数据文档记录了未来兼容性的预期接口。

测试更改

# Test local MCP server directly
./claude_scripts/test_local_mcp_curl.sh

# Test with MCP proxy
./claude_scripts/test_local_mcp_proxy.sh

# Use the web-based MCP Inspector
./claude_scripts/inspect_local_mcp.sh

调试

  • 后端日志检查终端输出来自 ./watch.sh
  • 前端日志检查浏览器控制台和终端输出
  • MCP日志监控 /mcp/ 终端响应
  • 数据库查询检查Databricks工作区日志

本地与生产环境的差异

特性 本地开发 生产环境
认证 Databricks CLI 令牌 通过 Databricks 应用程序进行 OAuth
URL(统一资源定位符) http://localhost:8000 https://your-app.databricksapps.com
HTTPS 否(仅限HTTP) 是(需要HTTPS)
文件监视 是(自动重载) 否
调试模式 是 否
日志 终端输出 Databricks 应用程序日志

解决本地问题

常见问题

端口冲突:

# Check what's using port 8000
lsof -i :8000

# Kill process if needed
kill -9 <PID>

未找到依赖项:

# Reinstall Python dependencies
uv sync

# Reinstall Node.js dependencies
cd client && bun install

Databricks 认证:

# Refresh Databricks CLI credentials
databricks auth login

# Verify configuration
databricks config get

MCP连接问题:

# Test MCP endpoint directly
curl http://localhost:8000/mcp/

# Check Claude MCP configuration
claude mcp list

性能优化技巧

  • 使用 uv 而不是 pip 为了更快的Python依赖管理
  • 使用 bun 而不是 npm 为了更快地管理Node.js依赖
  • 这个(或“该”) ./watch.sh 脚本使用 uvicorn --reload 用于快速后端开发
  • 前端使用Vite实现快速热模块替换

部署

# Deploy to Databricks Apps
./deploy.sh

# Check status and get your app URL
./app_status.sh

您的MCP服务器将在 https://your-app.databricksapps.com/mcp/

这个(或“该”) app_status.sh 脚本将显示您已部署的应用程序的URL,这是您后续所需的 DATABRICKS_APP_URL 在将MCP服务器添加到Claude时设置环境变量。

认证

  • 本地开发无需认证
  • 生产代理使用您的Databricks CLI凭据自动处理OAuth

示例

与Claude一起使用

添加后,您可以在Claude中与您的MCP服务器进行交互:

Human: What prompts are available?

Claude: I can see the following prompts from your Databricks MCP server:
- build_lakeview_dashboard: Build comprehensive Lakeview dashboards with data validation
- build_ldp_pipeline: Build Lakehouse Data Pipelines for data processing
- performance_optimization: Performance optimization guidance for Databricks workloads

样本工具使用

Human: Can you execute a SQL query to show databases?

Claude: I'll execute that SQL query for you using the execute_dbsql tool.

[Executes SQL and returns results]

项目结构

├── server/                    # FastAPI backend with MCP server
│   ├── app.py                # Main application + MCP server setup
│   ├── tools/                # Modular MCP tools implementation
│   │   ├── __init__.py       # Tool registration and loading
│   │   ├── core.py           # Core and health tools (✅ Active)
│   │   ├── sql_operations.py # SQL and warehouse tools (✅ Active)
│   │   ├── unity_catalog.py  # Unity Catalog tools (✅ Active)
│   │   ├── jobs_pipelines.py # Jobs and DLT pipeline tools (✅ Active)
│   │   ├── lakeview_dashboard.py # Lakeview dashboard tools (✅ Active)
│   │   ├── data_management.py # Data and DBFS tools (🚧 Available)
│   │   ├── governance.py     # Governance and compliance tools (🚧 Available)
│   │   ├── widget_specs.py   # Widget specifications and utilities
│   │   ├── layout_optimization.py # Dashboard layout optimization
│   │   └── utils.py          # Shared utility functions
│   └── routers/              # API endpoints
├── client/                   # React TypeScript frontend
│   ├── src/                  # Source code
│   │   ├── components/       # Reusable UI components
│   │   ├── pages/            # Page components
│   │   └── fastapi_client/   # Auto-generated API client
│   ├── package.json          # Node.js dependencies
│   └── tailwind.config.js    # TailwindCSS configuration
├── prompts/                  # MCP prompts (markdown files)
│   ├── build_lakeview_dashboard.md # Comprehensive dashboard building prompt
│   ├── build_ldp_pipeline.md # Lakehouse Data Pipelines building prompt
│   └── performance_optimization.md # Performance optimization guidance
├── dba_mcp_proxy/           # MCP proxy for Claude CLI
│   └── mcp_client.py        # OAuth + proxy implementation
├── claude_scripts/          # Comprehensive testing tools
│   ├── test_local_mcp_*.sh  # Local MCP testing scripts (curl & proxy)
│   ├── test_remote_mcp_*.sh # Remote MCP testing scripts (curl & proxy)
│   ├── test_mcp_tools.py    # MCP tools testing
│   ├── test_uc_tools.py     # Unity Catalog tools testing
│   ├── inspect_local_mcp.sh # Local web-based MCP Inspector
│   ├── inspect_remote_mcp.sh # Remote web-based MCP Inspector
│   └── README.md            # Testing documentation
├── docs/                     # Documentation
│   ├── databricks_apis/      # Databricks API documentation
│   ├── architecture.md       # System architecture overview
│   ├── core-tools.md         # Core tools documentation
│   ├── unity_catalog_tools.md # Unity Catalog tools documentation
│   └── api-reference.md      # Complete API reference
├── scripts/                  # Development tools
├── .github/workflows/        # CI/CD automation
│   ├── ci.yml               # Continuous integration
│   ├── deploy.yml           # Automated deployment
│   ├── security.yml         # Security scanning
│   └── test.yml             # Automated testing
└── pyproject.toml          # Python package configuration

模块化工具系统

MCP服务器的特点包括一个 模块化工具架构 该工具将功能组织成逻辑性强、易于维护的模块。目前 5个活跃模块 装满了 88+种工具 可用的:

活跃工具模块

pie title Active MCP Tools by Module
    "Core Tools" : 1
    "SQL Operations" : 15
    "Unity Catalog" : 21
    "Jobs & Pipelines" : 19
    "Lakeview Dashboard" : 3

模块状态概览

模块 状态 工具 描述
core.py 翻译为中文是“核心.py”或保持原名(在技术文档中,文件名通常直接保留原样)。不过,如果非要翻译文件名中的非英文部分(这里“core”本身是英文,但为了符合中文表达习惯,可以理解为“核心”部分),那么可以理解为“核心模块.py”或“核心文件.py”,但最直接的翻译还是“core.py” ✅ 启用 1 基本健康检查和核心功能
sql_operations.py 翻译为中文是“SQL操作文件.py”或“SQL操作模块.py” ✅ 正在运行 ~15 SQL 仓库管理、查询执行和监控
unity_catalog.py 翻译成中文可以是“Unity目录配置文件”或“Unity目录管理脚本”,具体取决于上下文和该文件的实际用途。在这里,“unity_catalog”可能指的是与Unity(一个跨平台的游戏开发引擎)相关的目录或资源管理功能,而“.py”表示这是一个Python脚本文件。因此,一个较为通用的翻译是“Unity目录配置文件”或“Unity目录管理脚本” ✅ 活跃 ~21 目录、模式、表和元数据操作
jobs_pipelines.py 翻译为中文是:“作业管道.py” 或者更具体地,可以理解为“任务处理流水线.py”,具体翻译可能根据上下文有所调整 ✅ 正在使用 ~19 工作和DLT(分布式账本技术)管道管理
lakeview_dashboard.py 翻译为中文是:“湖景仪表盘.py”(注:这里的“lakeview”被直译为“湖景”,“dashboard”通常翻译为“仪表盘”,“.py”表示这是一个Python脚本文件) ✅ 活跃 ~3 创建并管理全面的湖景仪表盘
`data_management.py` 翻译成中文是:“数据管理.py” 🚧 可用 ~10 DBFS 操作、外部位置、存储凭据
`governance.py` 翻译成中文是:“治理.py”(或根据上下文,也可译为“管理.py”,但“治理”在技术或政策语境下更为常见) 🚧 可用 ~15 审计日志、治理规则和数据血缘

总计:88+种工具 目前在5个模块中激活了59+个(功能/项目/等)

模块化的益处

  1. 可维护性每个模块都专注于一个特定的领域
  2. 可读性较小的文件更容易浏览和调试
  3. 合作多个开发人员可以同时处理不同的模块
  4. 测试各个模块可以单独进行测试
  5. 可扩展性可以在不造成杂乱的情况下,将新工具添加到适当的模块中
  6. 文档每个模块都有明确的目的,并且可以独立进行文档记录

使用MCP构建仪表板

仪表盘工具架构

仪表板系统通过专用工具提供全面的Lakeview仪表板创建功能:

工具 用途 关键特性
创建仪表盘文件 完整仪表板创建 创建支持完整小部件的.lvdash.json文件
验证小部件字段 小部件验证 确保小部件配置与数据集模式匹配
获取聚合表达式 SQL 优化 生成优化的聚合表达式

核心能力:

  • 16+种小部件类型全面支持图表、显示、过滤器和交互元素
  • SQL 验证部署前的查询测试和模式验证
  • 网格布局系统12列响应式设计,带自动定位功能
  • 数据集优化支持多个小部件的智能查询设计
  • 生产就绪生成可部署的 .lvdash.json 文件

仪表板构建快速入门

MCP服务器提供了全面的工具,用于通过编程方式构建Lakeview和传统仪表板。您可以使用Claude中的简单命令来创建、管理和共享仪表板。

工具使用示例

创建一个完整的仪表板:

# Using create_dashboard_file tool
create_dashboard_file(
    name="Sales Dashboard",
    warehouse_id="abc123",
    datasets=[{
        "name": "Sales Data",
        "query": "SELECT product_category, revenue, order_date FROM sales_transactions WHERE revenue > 100"
    }],
    widgets=[
        {
            "type": "bar",
            "dataset": "Sales Data",
            "config": {
                "x_field": "product_category",
                "y_field": "revenue",
                "title": "Revenue by Category"
            },
            "position": {"x": 0, "y": 0, "width": 6, "height": 4}
        },
        {
            "type": "counter",
            "dataset": "Sales Data",
            "config": {
                "value_field": "revenue",
                "title": "Total Revenue"
            },
            "position": {"x": 6, "y": 0, "width": 3, "height": 2}
        }
    ],
    file_path="sales_dashboard.lvdash.json",
    validate_sql=True
)

仪表板创建结果:

{
    "success": true,
    "file_path": "sales_dashboard.lvdash.json",
    "file_size": 2048,
    "message": "Dashboard file successfully created",
    "validation_results": {
        "queries_validated": [...],
        "widget_validations": [...]
    }
}

基本仪表板创建

Human: Create a sales dashboard with revenue metrics and customer analysis

Claude: I'll create a Lakeview dashboard with revenue and customer metrics using the simplified tool architecture.

[Creates dashboard using manage_dashboard, then adds widgets with create_chart_widget and create_display_widget]

可用的小部件类型

MCP服务器支持所有主要的小部件类型,用于创建仪表板:

小部件类型 描述 使用场景
柜台 单一指标显示 关键绩效指标(KPIs)、总计、计数
桌子 表格数据展示 详细记录,列表
酒吧 条形图 对比,类别
线 折线图 随时间变化的趋势
脚 饼图 比例,分布
区域 面积图 累积趋势
散射 散点图 相关性,集群
枢轴;关键点 数据透视表 多维分析
漏斗 管道图 转化分析
盒子 箱线图 统计分布
热力图 热力图 密度可视化
Markdown 文本/文档 解释,标题

SQL查询指南

在构建仪表板时,请遵循以下SQL最佳实践:

-- Use parameterized queries for flexibility
SELECT 
    date_trunc('month', order_date) as month,
    sum(revenue) as total_revenue,
    count(distinct customer_id) as unique_customers
FROM sales
WHERE order_date >= :start_date 
  AND order_date <= :end_date
GROUP BY 1
ORDER BY 1;

-- Include proper aliasing for widget display
SELECT 
    product_name as "Product",
    sum(quantity) as "Units Sold",
    sum(revenue) as "Revenue"
FROM sales_detail
GROUP BY 1;

布局与定位

仪表板采用12列网格系统以实现响应式布局:

# Widget positioning examples
{
    "x": 0,      # Start at left edge (0-11)
    "y": 0,      # Start at top
    "width": 6,  # Half width (1-12)
    "height": 4  # Standard height (typically 2-8)
}

# Common layout patterns:
# Full width: width=12
# Half width: width=6  
# Third width: width=4
# Quarter width: width=3

常见的仪表板模式

执行仪表盘

Human: Create an executive dashboard with KPIs, trends, and department breakdowns

Claude: I'll create a comprehensive executive dashboard with:
- Top KPI counters (revenue, growth, customers)
- Revenue trend line chart
- Department performance bar chart
- Regional heat map
- Key metrics table

分析仪表板

Human: Build a customer analytics dashboard with segmentation and behavior analysis

Claude: I'll create a customer analytics dashboard featuring:
- Customer segmentation pie chart
- Cohort retention heatmap
- Purchase behavior funnel
- Customer lifetime value distribution
- Product affinity analysis

运营仪表板

Human: Create an operations dashboard for monitoring system performance

Claude: I'll build an operational dashboard with:
- Real-time metrics counters
- Performance trend lines
- Alert status table
- Resource utilization gauges
- Error log analysis

仪表盘管理

列出与发现

# Find existing dashboards
echo "List all Lakeview dashboards" | claude

# Get dashboard details
echo "Show me the configuration of dashboard-id-123" | claude

更新仪表板

# Add new widgets
echo "Add a revenue forecast widget to dashboard-id-123" | claude

# Modify existing widgets
echo "Update the sales chart to show quarterly data in dashboard-id-123" | claude

共享与权限

# Share with users
echo "Share dashboard-id-123 with user@company.com with READ access" | claude

# Share with groups
echo "Grant WRITE access to dashboard-id-123 for the analytics team" | claude

最佳实践

  1. 从简单开始从核心指标开始,逐步迭代扩展
  2. 使用一致的样式保持统一的颜色和格式
  3. 优化查询使用聚合和过滤器来提高性能
  4. 添加上下文包含用于解释的Markdown小部件
  5. 测试交互性验证过滤器和参数是否正常工作
  6. 文档数据来源注意使用了哪些表和模式

示例:完整的销售仪表板

Human: Create a comprehensive sales dashboard with revenue trends, product performance, and regional analysis

Claude: I'll create a complete sales dashboard with multiple sections:

1. **KPI Section** (top row):
   - Total Revenue counter
   - Growth Rate counter  
   - Active Customers counter
   - Average Order Value counter

2. **Trends Section** (second row):
   - Monthly Revenue line chart
   - Product Category performance bar chart

3. **Analysis Section** (third row):
   - Regional sales heatmap
   - Top Products table
   - Customer Segment pie chart

4. **Details Section** (bottom):
   - Detailed transactions table with filters
   - Markdown widget with data definitions

仪表板将具备交互性,支持日期范围过滤和钻取功能。

综合测试套件

此模板包含全面的测试工具,用于在多个层面验证MCP(多协议控制器/模块等,具体含义根据上下文确定)的功能。

测试架构

graph LR
    subgraph "Test Types"
        A[Command Line Tests]
        B[Web UI Tests]
        C[Integration Tests]
        D[Performance Tests]
    end
    
    subgraph "Test Coverage"
        E[Local MCP Server]
        F[Remote MCP Server]
        G[OAuth Authentication]
        H[MCP Protocol]
        I[Tool Discovery]
        J[Tool Execution]
    end
    
    subgraph "Test Tools"
        K[test_local_mcp_curl.sh]
        L[test_local_mcp_proxy.sh]
        M[test_remote_mcp_curl.sh]
        N[test_remote_mcp_proxy.sh]
        O[inspect_local_mcp.sh]
        P[inspect_remote_mcp.sh]
    end
    
    A --> E
    A --> F
    B --> E
    B --> F
    C --> G
    C --> H
    D --> I
    D --> J
    
    K --> E
    L --> E
    M --> F
    N --> F
    O --> E
    P --> F

快速验证

在将MCP服务器添加到Claude后,验证其是否正常工作:

# List available prompts and tools
echo "What MCP prompts are available from databricks-mcp?" | claude

# Test a specific prompt
echo "Use the build_lakeview_dashboard prompt from databricks-mcp" | claude

测试脚本

这个(或“该”) claude_scripts/ 目录包含 9款综合测试工具:

命令行测试

# Test local MCP server (requires ./watch.sh to be running)
./claude_scripts/test_local_mcp_curl.sh      # Direct HTTP/curl tests
./claude_scripts/test_local_mcp_proxy.sh     # MCP proxy client tests

# Test remote MCP server (requires Databricks auth and deployment)
./claude_scripts/test_remote_mcp_curl.sh     # OAuth + HTTP tests
./claude_scripts/test_remote_mcp_proxy.sh    # Full end-to-end MCP proxy tests

# Specialized tool testing
./claude_scripts/test_mcp_tools.py           # MCP tools validation
./claude_scripts/test_uc_tools.py            # Unity Catalog tools testing

交互式网页用户界面测试

# Launch MCP Inspector for visual testing
./claude_scripts/inspect_local_mcp.sh        # Local server web interface
./claude_scripts/inspect_remote_mcp.sh       # Remote server web interface

MCP 检查器功能:

  • 🖥️ 基于Web的交互式MCP服务器测试界面
  • 🔧 带参数输入表单的可视化工具执行
  • 📊 实时请求/响应监控
  • 🐛 协议级别的调试和错误检查
  • 📋 完整的工具和资源发现
  • 🔄 会话管理和连接状态

测试结果概要

测试 状态 备注
局部卷曲 ✅ 通过 认证及头部信息验证通过
本地代理 ✅ 通过 完全符合MCP协议
远程curl ✅ 通过 OAuth 认证及头部验证通过
远程代理 ✅ 通过 端到端OAuth + MCP正常工作

持续集成/持续交付(CI/CD)流水线

该项目现已包含用于质量保证和部署的自动化CI/CD工作流程:

持续集成

graph LR
    A[Code Push] --> B[Automated Testing]
    B --> C[Code Quality Checks]
    C --> D[Security Scanning]
    D --> E[Build Validation]
    E --> F[Test Results]
    
    subgraph "Quality Gates"
        G[Python Linting]
        H[Type Checking]
        I[Unit Tests]
        J[Integration Tests]
        K[Frontend Build]
        L[Security Scan]
    end
    
    B --> G
    B --> H
    B --> I
    B --> J
    B --> K
    D --> L

自动化工作流

  1. CI 管道(或持续集成流水线) (.github/workflows/ci.yml):

    • 在每次推送和拉取请求时运行
    • 执行全面的测试套件
    • 执行代码质量检查(使用ruff、类型检查)
    • 验证前端构建过程
    • 确保所有依赖项都已正确配置
  2. 部署流水线 (.github/workflows/deploy.yml):

    • 自动部署到Databricks应用程序
    • 环境特定的配置
    • 回滚功能
    • 部署验证
  3. 安全管道 (.github/workflows/security.yml):

    • 自动化安全扫描
    • 依赖项漏洞检查
    • 代码安全分析
    • 合规报告

质量保证

CI流水线确保:

  • 代码质量一致的格式化和代码检查
  • 类型安全TypeScript 和 Python 类型检查
  • 测试覆盖率全面测试执行
  • 安全自动化漏洞扫描
  • 演出构建时间与资源优化

高级用法

环境变量

配置在 .env.local:

DATABRICKS_HOST=https://your-workspace.cloud.databricks.com
DATABRICKS_TOKEN=your-token  # For local development
DATABRICKS_SQL_WAREHOUSE_ID=your-warehouse-id  # For SQL tools

创建复杂工具

工具可以访问完整的Databricks软件开发工具包(SDK):

@mcp_server.tool
def create_job(name: str, notebook_path: str, cluster_id: str) -> dict:
    """Create a Databricks job."""
    w = get_workspace_client()
    job = w.jobs.create(
        name=name,
        tasks=[{
            "task_key": "main",
            "notebook_task": {"notebook_path": notebook_path},
            "existing_cluster_id": cluster_id
        }]
    )
    return {"job_id": job.job_id, "run_now_url": f"{DATABRICKS_HOST}/#job/{job.job_id}"}

故障排除

  • 认证错误跑 databricks auth login 更新凭据
  • 未找到MCP确保应用程序已部署且可访问
  • 工具错误检查日志于 https://your-app.databricksapps.com/logz
  • MCP连接问题:
    • 检查Claude的日志: tail -f ~/Library/Logs/Claude/*.log
    • 验证代理是否正常工作: uvx --from git+ssh://... dba-mcp-proxy --help
    • 使用回显管道进行测试: echo "list your mcp commands" | claude
  • 缓存版本问题如果在更新后遇到缺少参数的错误:
    # Clear uvx cache for this package
    rm -rf ~/.cache/uv/git-v0/checkouts/*/
    # Or clear entire uv cache
    uv cache clean
    
  • 前端构建问题确保已安装 Node.js 依赖项:
    cd client
    bun install
    

做出贡献

  1. 为仓库创建分支(或“克隆仓库”)
  2. 添加你的提示和工具
  3. 在本地使用(以下工具/方法)进行测试 ./watch.sh
  4. 提交一个拉取请求

许可证

看 LICENSE.md(许可证文件)