Skip to main content

spark-connect-mcp

MCP server exposing Apache Spark Connect (and Databricks Connect) via DataFrame and SQL tools for AI agents.

Install

Choose one backend — do not install both.

# OSS Spark Connect
pip install "spark-connect-mcp[spark]"

# Databricks Connect
pip install "spark-connect-mcp[databricks]"

Quick Start

Add to your Claude Code MCP config:

{
  "mcpServers": {
    "spark": {
      "command": "uvx",
      "args": ["--from", "spark-connect-mcp[databricks]", "spark-connect-mcp"]
    }
  }
}

For OSS Spark Connect, replace [databricks] with [spark].

Configuration

All connection config is set via environment variables — the MCP tools require no parameters to start a session.

OSS Spark Connect

Set SPARK_REMOTE to your Spark Connect server URL (PySpark's native env var):

export SPARK_REMOTE=sc://localhost:15002

Databricks Connect

Optionally set DATABRICKS_CONFIG_PROFILE to select a profile from ~/.databrickscfg (defaults to DEFAULT):

export DATABRICKS_CONFIG_PROFILE=my-workspace

Serverless compute is used by default inside Databricks Apps, Jobs, and notebooks — no env var needed.

Preflight Size Checks

Before executing an action tool (show, collect, count, describe, save, save_as_table), spark-connect-mcp runs a lightweight preflight check that inspects the Spark Catalyst optimized plan statistics to estimate result size without triggering a Spark job. If the estimate exceeds configurable thresholds the tool returns a warning instead of executing.

Prerequisites — making statistics available

Preflight relies on Catalyst Cost-Based Optimization (CBO) statistics. How you populate them depends on your environment:

Environment How to get statistics
Databricks UC managed tables Enable Predictive Optimization — stats are computed automatically.
External / unmanaged tables Run ANALYZE TABLE <table> COMPUTE STATISTICS FOR ALL COLUMNS.
OSS Spark Set spark.sql.cbo.enabled=true and spark.sql.cbo.planStats.enabled=true, then run ANALYZE TABLE.

Confidence tiers

The quality of the estimate depends on what statistics are present in the plan:

Tier Condition Behaviour
High Root node has sizeInBytes + rowCount, and every join node has rowCount Blocks if thresholds exceeded
Medium Root has rowCount but some join nodes are missing rowCount Uses 10× the configured thresholds before blocking
Low Root has sizeInBytes only, no rowCount Fail-open — warns but does not block
Cross-join Plan contains CartesianProduct Always warns regardless of thresholds

Threshold configuration

Set via environment variables (defaults shown):

# Maximum estimated bytes before warning (default 1 GB)
export SPARK_CONNECT_MCP_PREFLIGHT_MAX_BYTES=1073741824

# Maximum estimated rows before warning (default 10 million)
export SPARK_CONNECT_MCP_PREFLIGHT_MAX_ROWS=10000000

# Disable preflight entirely
export SPARK_CONNECT_MCP_PREFLIGHT_ENABLED=false

Per-session overrides

Use the set_preflight_threshold tool to adjust thresholds for a single session without changing env vars:

{
  "tool": "set_preflight_threshold",
  "arguments": {
    "session_id": "abc123",
    "max_bytes": 5368709120,
    "max_rows": 50000000
  }
}

Pass "enabled": false to disable preflight for that session.

The force escape hatch

Every action tool accepts a force parameter. Pass force=True to skip the preflight check entirely and execute immediately:

{
  "tool": "collect",
  "arguments": { "df_id": "df-001", "limit": 100, "force": true }
}

SQL Tool

The sql tool executes a SQL query against an active Spark session. By default it enforces read-only SQL — only SELECT, WITH...SELECT, SHOW, DESCRIBE, and EXPLAIN statements are permitted. Write operations (INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, MERGE, TRUNCATE, COPY INTO, OPTIMIZE, VACUUM, etc.) are rejected before reaching Spark.

Multi-statement SQL (e.g. SELECT 1; DROP TABLE foo) is also blocked — submit one statement at a time.

Malformed SQL that cannot be parsed is rejected fail-closed — the query is never executed.

Allowing write SQL

To permit write operations, set the escape-hatch environment variable:

export SPARK_CONNECT_MCP_ALLOW_WRITE_SQL=true

This bypasses all read-only enforcement. Intended for trusted environments where the agent needs DDL or DML access.

Status

Under active development. See issues for the roadmap.

License

Apache-2.0

Metadata

Release files for spark-connect-mcp 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spark-connect-mcp 0.2.0
File Size Uploaded Provenance
spark_connect_mcp-0.2.0.tar.gz 116.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for spark-connect-mcp 0.2.0
File Interpreter ABI Platform
spark_connect_mcp-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 140.9 kB

Release files / spark_connect_mcp-0.2.0.tar.gz

Download URL spark_connect_mcp-0.2.0.tar.gz
Size 116.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c63c5bd1dc039bc92579e38cbe1f1516befe63b72a9a56df9b57d6b263289789
BLAKE2b-256 checksum
How to use checksums
c445c98255da5003c715e3d99e35c971b08ee09edb36411af02726cca6bca53b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.

Transparency log

Release files / spark_connect_mcp-0.2.0-py3-none-any.whl

Download URL spark_connect_mcp-0.2.0-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d192827e3492152270c3439988cf493a9a913fed42bc8a342055e76afc1817f
BLAKE2b-256 checksum
How to use checksums
928a707d2adb84f5410b96228dd11187e62dec09b16275b52f7724b8d742df48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.

Transparency log

Security for spark-connect-mcp 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spark_connect_mcp-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page