Spark SQL

io.github.aidancorrell由 GitHub 帳號 aidancorrell 發布v0.1.2更新於 Oct 24, 2026

Query Spark SQL clusters via Thrift/HiveServer2. Works with Spark, EMR, Hive, Impala.

已驗證STDIO僅桌面資料庫資料與分析

概覽

AI 產生的概覽

讓助理透過 Thrift/HiveServer2 對 Spark、EMR、Hive 或 Impala 叢集執行唯讀 SQL 查詢並檢視資料表結構。

可以做什麼
連線到相容於 HiveServer2 的端點,提供四個工具:list_databases、list_tables、describe_table 和 execute_query。查詢僅限唯讀語句(SELECT、SHOW、DESCRIBE、DESC、EXPLAIN、WITH),未設限的查詢會自動加上 LIMIT,資料庫錯誤在回傳前會先去除敏感資訊。支援 NONE、LDAP、NOSASL、CUSTOM 與 Kerberos 驗證。
適用情境
適合讓助理不必另外開啟 SQL 用戶端,就能瀏覽或查詢既有的 Spark、EMR、Hive、Impala 或 Presto 資料倉儲。適用於結構探索與臨時唯讀分析,不適合寫入或叢集管理。
執行需求
需要本機 Python 執行環境,可用 pip 安裝或以 uvx 執行。必須設定 SPARK_HOST,可選 SPARK_PORT(預設 10000)、SPARK_DATABASE、SPARK_AUTH;LDAP 需要 SPARK_USERNAME 與 SPARK_PASSWORD,Kerberos 需要有效票證。需要能連線到 Thrift 伺服器,通常經由 SSH 通道。
安裝前請注意
連線未加密且不支援 TLS/SSL,SPARK_PASSWORD 等憑證可能以明文傳輸,建議使用 SSH 通道。沒有查詢逾時,也沒有依使用者區分的存取控制,所有查詢都以設定的 Spark 使用者權限執行。SPARK_AUTH 預設為 NONE,不適合正式環境。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Spark SQL,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

Spark SQL MCP Server

An MCP server that enables AI assistants to query Spark SQL clusters via the Thrift/HiveServer2 protocol.

Works with any HiveServer2-compatible system: Apache Spark, AWS EMR, Hive, Impala, Presto.

Features

  • Query Spark SQL — Execute read-only SQL queries against your Spark cluster
  • Schema Discovery — List databases, tables, and describe table structures
  • Multiple Auth Methods — NONE, LDAP, NOSASL, CUSTOM, and Kerberos authentication
  • EMR Compatible — Works with AWS EMR clusters out of the box
  • Read-Only Enforcement — Only SELECT, SHOW, DESCRIBE, EXPLAIN, and WITH statements are allowed
  • Safety Defaults — Automatic LIMIT clause on unbounded queries, sanitized error messages

Installation

bash
pip install spark-sql-mcp-server

Or run directly with uvx:

bash
uvx spark-sql-mcp-server

Quick Start

1. Set Environment Variables

bash
export SPARK_HOST="your-emr-master-node.amazonaws.com"export SPARK_PORT="10000"        # defaultexport SPARK_DATABASE="default"  # defaultexport SPARK_AUTH="NONE"         # NONE | LDAP | KERBEROS | CUSTOM | NOSASL

2. Add to Claude Code

Global (all projects) — add to ~/.claude.json under your project's mcpServers:

json
{  "mcpServers": {    "spark-sql": {      "command": "uvx",      "args": ["spark-sql-mcp-server"],      "env": {        "SPARK_HOST": "your-emr-master-node.amazonaws.com",        "SPARK_PORT": "10000",        "SPARK_AUTH": "NONE"      }    }  }}

Project-level — add to .claude/mcp.json in your repo:

json
{  "mcpServers": {    "spark-sql": {      "command": "uvx",      "args": ["spark-sql-mcp-server"],      "env": {        "SPARK_HOST": "your-emr-master-node.amazonaws.com",        "SPARK_PORT": "10000",        "SPARK_AUTH": "NONE"      }    }  }}

3. Add to Claude Desktop

Add to your claude_desktop_config.json:

json
{  "mcpServers": {    "spark-sql": {      "command": "uvx",      "args": ["spark-sql-mcp-server"],      "env": {        "SPARK_HOST": "your-emr-master-node.amazonaws.com",        "SPARK_PORT": "10000"      }    }  }}

4. Query

Ask Claude things like:

  • "What databases are available in our Spark cluster?"
  • "Show me the schema of the sales.transactions table"
  • "Query the top 10 customers by revenue from the analytics database"

Available Tools

ToolDescription
list_databasesList all available databases
list_tablesList tables in a database
describe_tableGet table schema (columns, types)
execute_queryRun read-only SQL queries with formatted results

Authentication

No Auth (default)

bash
export SPARK_AUTH="NONE"

LDAP

bash
export SPARK_AUTH="LDAP"export SPARK_USERNAME="your-username"export SPARK_PASSWORD="your-password"

Kerberos

bash
export SPARK_AUTH="KERBEROS"export SPARK_KERBEROS_SERVICE_NAME="hive"  # default# Ensure you have a valid Kerberos ticket (kinit)

AWS EMR Setup

  1. Security Group — Allow inbound traffic on port 10000 from your IP
  2. SSH Tunnel (recommended):
    bash
    ssh -i your-key.pem -L 10000:localhost:10000 hadoop@your-emr-master
  3. Set SPARK_HOST=localhost

Development

bash
git clone https://github.com/aidancorrell/spark-sql-mcp-server.gitcd spark-sql-mcp-serverpip install -e ".[dev]"pytestruff check .

Local Testing with Docker

A Docker Compose setup provides a local Spark Thrift Server with sample data for integration testing.

bash
# Start the Spark Thrift Servercd docker && docker compose up -d
# Wait for it to be ready (takes ~30s on first start)docker logs -f spark-thrift-server  # look for "Sample data loaded."
# Run integration testspytest -m integration -v
# Tear downcd docker && docker compose down -v

The local server comes with sample tables: default.employees, default.orders, and test_db.metrics.

Unit tests run by default with pytest (integration tests are skipped unless -m integration is specified).

Using the local server with Claude Code

With the Docker Spark server running, add it to your MCP config to test the server interactively.

Global — add to ~/.claude.json under your project's mcpServers:

json
{  "spark-sql": {    "command": "uvx",    "args": ["spark-sql-mcp-server"],    "env": {      "SPARK_HOST": "localhost",      "SPARK_PORT": "10000",      "SPARK_AUTH": "NONE"    }  }}

Project-level — add to .claude/mcp.json:

json
{  "mcpServers": {    "spark-sql": {      "command": "uvx",      "args": ["spark-sql-mcp-server"],      "env": {        "SPARK_HOST": "localhost",        "SPARK_PORT": "10000",        "SPARK_AUTH": "NONE"      }    }  }}

Then start a new Claude Code session and ask it to query the sample data.

Security

Read-Only Enforcement

The execute_query tool only allows read-only SQL statements. Queries must start with one of: SELECT, SHOW, DESCRIBE, DESC, EXPLAIN, or WITH. All other statement types (DROP, INSERT, DELETE, CREATE, ALTER, SET, ADD JAR, etc.) are rejected before reaching the Spark cluster.

Error Sanitization

Database errors are sanitized before being returned to the MCP client. Internal details such as server hostnames, file paths, and stack traces are not exposed. Connection failures report only the target host/port and error type.

Credential Handling

  • Passwords are never included in log output or error messages
  • The SparkConfig object masks passwords in its string representation
  • SPARK_PASSWORD is marked as a secret in the MCP registry schema

Known Limitations

  • No TLS/SSL support — Thrift connections are unencrypted. For production use with LDAP auth, use an SSH tunnel to protect credentials in transit.
  • No query timeout — Long-running queries are not automatically cancelled. Rely on Spark cluster-level timeout configuration.
  • No per-user access control — All queries execute with the privileges of the configured Spark user. Use HiveServer2 authorization (Ranger, Sentry) to restrict access at the database level.
  • Auth mode defaults to NONE — Appropriate for local development but not for production. Set SPARK_AUTH to LDAP or KERBEROS for authenticated environments.

License

MIT

來源:README.md,提交 691cee7

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.2最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分