PySpark MCP Server
A server implementation of MCP for Apache Spark that provides query plans and catalog information to AI systems for query optimization and data discovery.
README
hi# PySpark MCP Server
Description
PySpark MCP Server is a lightweight server implementation of Model Context Protocol (MCP) for Apache Spark.
The primary purpose of this MCP server is to facilitate query optimization using AI systems. It provides both logical and physical query plans from Spark to AI systems for analysis, along with additional query plan information. Furthermore, the server exposes catalog and table information, enabling data discovery capabilities in data lakes powered by Spark.
Quick Start
Installation
pip install pyspark-mcp
Running the Server
After installation, use the pyspark-mcp command to start the server:
pyspark-mcp --master "local[*]" --host 127.0.0.1 --port 8090
The CLI automatically handles spark-submit configuration. All standard spark-submit options are supported:
# With additional Spark configuration
pyspark-mcp --master "local[*]" --conf spark.driver.memory=4g
# YARN cluster mode
pyspark-mcp --master yarn --deploy-mode client --num-executors 4
# With additional JARs
pyspark-mcp --master "local[*]" --jars /path/to/connector.jar
# Preview the spark-submit command without running
pyspark-mcp --master "local[*]" --dry-run
# With GraphFrames package
pyspark-mcp --master "local[*]" --packages io.graphframes:graphframes-spark3_2.12:0.10.1
CLI Options
| Option | Default | Description |
|---|---|---|
--master |
local[*] |
Spark master URL |
--host |
127.0.0.1 |
MCP server host address |
--port |
8090 |
MCP server port number |
--spark-submit |
spark-submit |
Path to spark-submit executable |
--dry-run |
- | Print command without executing |
All spark-submit options (--conf, --jars, --packages, --executor-memory, etc.) are passed through automatically.
Adding the running MCP to the Claude-code
# Must run one server on a different port per Claude instance
claude mcp add --transport http pyspark-mcp http://127.0.0.1:8090/mcp
Dependencies
- Python >=3.11,<4.0
- fastmcp >= 2.10.6
- loguru
- pyspark >= 3.5
Bundled MCP tools
The following tools are included in the PySpark MCP Server:
| MCP Tool | Description |
|---|---|
| Get the version of PySpark | Get the version number from the current PySpark Session |
| Get Analyzed Plan of the query | Extracts an analyzed logical plan from the provided SQL query |
| Get Optimized Plan of the query | Extracts an optimized logical plan from the provided SQL query |
| Get size estimation for the query results | Extracts a size and units from the query plan explain |
| Get tables from the query plan | Extracts all the tables (relations) from the query plan explain |
| Get the current Spark Catalog | Get the catalog that is the default one for the current SparkSession |
| Check does database exist | Check if the database with a given name exists in the current Catalog |
| Get the current default database | Get the current default database from the default Catalog |
| List all the databases in the current catalog | List all the available databases from the current Catalog |
| List available catalogs | List all the catalogs available in the current SparkSession |
| List tables in the current catalog | List all the available tables in the current Spark Catalog |
| Get a comment of the table | Extract comment of the table or returns an empty string |
| Get table schema | Get the spark schema of the table in the catalog |
| Returns a schema of the result of the SQL query | Run query, get the result, get the schema of the result and return a JSON-value of the schema |
| Read first N lines of the text file | Read the first N lines of the file as a plain text. Useful to determine the format |
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.