databricks-readonly-mcp
Read-only MCP server for Databricks, exposing Unity Catalog browsing and SQL execution with robust write protection via SQL AST analysis.
README
databricks-readonly-mcp
A Model Context Protocol (MCP) server that gives an LLM read-only access to Databricks. It exposes Unity Catalog browsing and SQL execution as tools, with two layers of defence against accidental writes:
- In-process AST guard. Every SQL statement is parsed with
sqlglotand rejected unless its root and entire tree are read-only (SELECT/WITH/SHOW/DESCRIBE/EXPLAIN/ set-operations).INSERT,UPDATE,DELETE,MERGE,DROP,CREATE,ALTER,TRUNCATE,USE,SET,GRANT,COPY,REFRESH,OPTIMIZE,VACUUM— all rejected before the HTTP call is made. CTE-wrapped writes (e.g.WITH x AS (DELETE …) SELECT * FROM x) are caught by a deep tree walk. - Read-only Databricks principal (recommended). Run the server under a
service principal or PAT that has only
USE CATALOG/USE SCHEMA/SELECTgrants. See Read-only principal below.
Transport is stdio only.
Install
pip install -e .
# or once published:
# uvx databricks-readonly-mcp
Configure
Create ~/.databricks-mcp/config.yaml (or point DATABRICKS_MCP_CONFIG at a
custom path). Two auth methods are supported per profile:
databricks_cli (recommended)
Delegates to a profile in ~/.databrickscfg via the Databricks SDK. Host
and credentials (PAT or OAuth U2M) come from there, and the SDK refreshes
OAuth tokens automatically. Set up once with the Databricks CLI:
databricks auth login --host https://your-workspace.cloud.databricks.com \
--profile ciq-beta
Then reference it in the MCP config:
default_profile: beta
profiles:
beta:
warehouse_name: esm_etl_wh # or warehouse_id: bd6e1945574f6d03
default_catalog: client_catalog
max_rows: 1000
auth:
method: databricks_cli
cli_profile: ciq-beta # name in ~/.databrickscfg
No tokens in YAML, no env vars. Good for laptops / interactive use.
Warehouse selection is one of (highest precedence first):
| Field | Behavior |
|---|---|
warehouse_id |
Pin a specific warehouse. No lookup; fastest startup. |
http_path |
/sql/1.0/warehouses/<id> — the <id> is used as warehouse_id. |
warehouse_name |
Resolved at startup via /api/2.0/sql/warehouses. Case-insensitive; must match exactly one. |
| (omit all) | Auto-pick: succeeds only if exactly one warehouse is visible to your principal. |
If you don't know which warehouse to pin, list them with:
databricks-readonly-mcp --profile beta --list-warehouses
Or pick one interactively (prompts on TTY, prints a YAML snippet to paste):
databricks-readonly-mcp --profile beta --pick-warehouse
Both modes run as one-shot CLI commands and exit; they don't start the MCP server.
token (for CI, headless servers)
Reads a PAT from the env var named in token_env. host must be set:
profiles:
prod:
host: https://your-prod-workspace.cloud.databricks.com
warehouse_id: prodwarehouseid
auth:
method: token
token_env: DATABRICKS_TOKEN_PROD # name of the env var; NOT the token
default_catalog: client_catalog
max_rows: 1000
See examples/config.example.yaml for a
complete template.
Profile selection precedence: --profile flag > DATABRICKS_MCP_PROFILE env
var > default_profile in the config.
Run
databricks-readonly-mcp --profile beta
# or
python -m databricks_mcp --profile beta
Wire into Claude Code / Claude Desktop
Add to your mcpServers config (e.g. ~/.claude.json):
When using auth.method: databricks_cli (recommended), no env block is
needed — credentials come from ~/.databrickscfg:
{
"mcpServers": {
"databricks": {
"command": "databricks-readonly-mcp",
"args": ["--profile", "beta"]
}
}
}
With auth.method: token, supply the env var:
{
"mcpServers": {
"databricks": {
"command": "databricks-readonly-mcp",
"args": ["--profile", "prod"],
"env": { "DATABRICKS_TOKEN_PROD": "dapi…" }
}
}
}
Restart Claude Code; the tools appear under the databricks server in /mcp.
Tools
| Tool | Args | Returns |
|---|---|---|
list_catalogs |
— | {catalogs: [{name, comment, owner, catalog_type}]} |
list_schemas |
catalog |
{schemas: [{name, full_name, comment, owner}]} |
list_tables |
catalog, schema |
{tables: [{name, full_name, table_type, data_source_format, comment}]} |
describe_table |
full_name |
{full_name, table_type, columns: […], properties} |
run_sql |
query, row_limit? |
{columns, rows, row_count, truncated, statement_id, execution_time_ms} <br/> Returns {error: "ReadOnlyViolation", message} when blocked. |
row_limit is always clamped to the profile's max_rows.
Read-only principal (recommended)
The AST guard is robust but software. Put a second wall up at the data plane by giving the server a principal that cannot write, even if asked to:
-- Run as a workspace admin once, per environment.
GRANT USE CATALOG ON CATALOG client_catalog TO `databricks-mcp-readonly`;
GRANT USE SCHEMA ON ALL SCHEMAS IN CATALOG client_catalog TO `databricks-mcp-readonly`;
GRANT SELECT ON ALL TABLES IN CATALOG client_catalog TO `databricks-mcp-readonly`;
GRANT CAN USE ON WAREHOUSE <warehouse_id> TO `databricks-mcp-readonly`;
-- explicitly: no MODIFY, no CREATE, no ALL PRIVILEGES, no warehouse mgmt.
Don't point this MCP at a PAT for a user that has broader grants. The guard catches the obvious cases, but a parser bug in any combination AST-allow-listing + over-privileged principal is the weakest configuration.
Development
python -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]'
pytest
Layout
src/databricks_mcp/
server.py stdio entrypoint, CLI parsing, FastMCP setup
tools.py tool functions registered onto FastMCP
client.py DatabricksReadClient — Statement API + Unity Catalog REST
sql_guard.py assert_readonly: sqlglot AST allow-list
config.py YAML loader, profile resolution
errors.py typed exceptions
tests/ pytest suite (sql_guard, config, client, tools)
Out of scope (v1)
- Job / cluster / warehouse management tools — not exposed.
- HTTP / SSE transport — stdio only.
- Multi-statement bodies, transactions — refused.
- Anything that writes, anywhere — refused.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。