π€ Connect AI agents to Apache Spark History Server for intelligent job analysis and performance monitoring
Transform your Spark infrastructure monitoring with AI! This Model Context Protocol (MCP) server enables AI agents to analyze job performance, identify bottlenecks, and provide intelligent insights from your Spark History Server data.
β¨ Now featuring SparkInsight-inspired intelligent analysis tools for auto-scaling optimization, data skew detection, failure analysis, and comprehensive performance insights!
Spark History Server MCP bridges AI agents with your existing Apache Spark infrastructure, enabling:
- π Query job details through natural language
- π Analyze performance metrics across applications
- π Compare multiple jobs to identify regressions
- π¨ Investigate failures with detailed error analysis
- π Generate insights from historical execution data
πΊ See it in action:
graph TB
A[π€ AI Agent/LLM] --> F[π‘ MCP Client]
B[π¦ LlamaIndex Agent] --> F
C[π LangGraph] --> F
D[οΏ½οΈ Claudep Desktop] --> F
E[π οΈ Amazon Q CLI] --> F
F --> G[β‘ Spark History MCP Server]
G --> H[π₯ Prod Spark History Server]
G --> I[π₯ Staging Spark History Server]
G --> J[π₯ Dev Spark History Server]
H --> K[π Prod Event Logs]
I --> L[π Staging Event Logs]
J --> M[π Dev Event Logs]
π Components:
- π₯ Spark History Server: Your existing infrastructure serving Spark event data
- β‘ MCP Server: This project - provides MCP tools for querying Spark data
- π€ AI Agents: LangChain, custom agents, or any MCP-compatible client
The server supports dual-mode operation:
- π€ MCP Server Mode (default) - For AI agents and LLM integration
- π₯οΈ CLI Mode (new!) - Direct command-line interface for human users
- π₯ Existing Spark History Server (running and accessible)
- π Python 3.12+
- β‘ uv package manager
git clone https://github.com/DeepDiagnostix-AI/mcp-apache-spark-history-server.git
cd mcp-apache-spark-history-server
# Install Task (if not already installed)
brew install go-task # macOS, see https://taskfile.dev/installation/ for others
# Setup and start testing
task start-spark-bg # Start Spark History Server with sample data (default Spark 3.5.5)
# Or specify a different Spark version:
# task start-spark-bg spark_version=3.5.2
task start-mcp-bg # Start MCP Server
# Optional: Opens MCP Inspector on http://localhost:6274 for interactive testing
# Requires Node.js: 22.7.5+ (Check https://github.com/modelcontextprotocol/inspector for latest requirements)
task start-inspector-bg # Start MCP Inspector
# When done, run `task stop-all`Direct command-line interface for human users - no MCP client required!
# Clone and install
git clone https://github.com/DeepDiagnostix-AI/mcp-apache-spark-history-server.git
cd mcp-apache-spark-history-server
uv sync
# Try CLI commands immediately
uv run spark-mcp --cli apps list --limit 5
uv run spark-mcp --cli --help# List applications with beautiful formatting
uv run spark-mcp --cli apps list --limit 10 --format table
# Get comprehensive insights
uv run spark-mcp --cli analyze insights app-20231201-123456
# Compare applications (new stateful approach)
uv run spark-mcp --cli apps compare "ETL Pipeline" # Auto-compare last 2 matching
uv run spark-mcp --cli apps compare app1 app2 # Compare specific IDs
uv run spark-mcp --cli apps compare app1 app2 --all # Show all executor metrics
# Interactive configuration
uv run spark-mcp --cli config init --interactive
# Test server connectivity
uv run spark-mcp --cli server test- Human (default): Beautiful tables and panels with colors
- JSON: Machine-readable for scripting
- Table: Simple tabular format
π See CLI-README.md for complete CLI documentation π MCP Tools Reference (responses + samples)
If you just want to run the MCP server without cloning the repository:
# Run with uv without installing the module
uvx --from mcp-apache-spark-history-server spark-mcp
# OR run with pip and python. Use of venv is highly encouraged.
python3 -m venv spark-mcp && source spark-mcp/bin/activate
pip install mcp-apache-spark-history-server
python3 -m spark_history_mcp.core.main
# Deactivate venv
deactivateThe repository includes real Spark event logs for testing:
spark-bcec39f6201b42b9925124595baad260- β Successful ETL jobspark-110be3a8424d4a2789cb88134418217b- π Data processing jobspark-cc4d115f011443d787f03a71a476a745- π Multi-stage analytics job
See TESTING.md for using them.
Edit config.yaml for your Spark History Server:
servers:
local:
default: true
url: "http://your-spark-history-server:18080"
auth: # optional
username: "user"
password: "pass"
mcp:
transports:
- streamable-http # streamable-http or stdio.
port: "18888"
debug: trueThis MCP server has been significantly enhanced with advanced capabilities far beyond the original forked functionality:
- 18 original tools β 50+ current tools (3x growth)
- Comprehensive comparison suite with 8 advanced tools for cross-application analysis
- Timeline-based analysis with intelligent interval merging and executor-focused comparisons
- 5 AI-powered analysis tools inspired by SparkInsight for intelligent performance optimization
- Auto-scaling recommendations based on workload pattern analysis
- Data skew detection with actionable optimization suggestions
- Failure analysis with root cause identification
- Executor utilization tracking for resource optimization
- 16 structured prompts for systematic Spark analysis
- Domain expertise encoded into reusable templates
- Tailored analysis for different audiences (technical vs executive)
- Consistent methodology across performance investigations
- Executor timeline comparisons at both application and stage levels
- Simplified output focus removing noise from memory/CPU metrics
- Intelligent interval merging for cleaner analysis
- Resource allocation pattern tracking over time
- Multi-dimensional comparisons: resources, executors, jobs, stages
- Comprehensive performance analysis with stage-level deep dives
- Significance filtering to highlight meaningful differences
- Actionable recommendations for optimization
Tools marked with π represent major additions beyond the original fork functionality.
Note: These tools are subject to change as we scale and improve the performance of the MCP server.
The MCP server provides 50+ specialized tools and 16 intelligent prompts organized by analysis patterns. LLMs can intelligently select and combine these tools and prompts based on user queries:
Basic application metadata and overview
| π§ Tool | π Description |
|---|---|
get_application |
π Get detailed information about a specific Spark application including status, resource usage, duration, and attempt details |
list_applications π |
π Enhanced application discovery - Advanced filtering by status, dates, limits, and flexible name matching (exact, contains, regex patterns) |
Job-level performance analysis and identification
| π§ Tool | π Description |
|---|---|
list_jobs |
π Get a list of all jobs for a Spark application with optional status filtering |
list_slowest_jobs |
β±οΈ Get the N slowest jobs for a Spark application (excludes running jobs by default) |
Stage-level performance deep dive and task metrics
| π§ Tool | π Description |
|---|---|
list_stages |
β‘ Get a list of all stages for a Spark application with optional status filtering and summaries |
list_slowest_stages |
π Get the N slowest stages for a Spark application (excludes running stages by default) |
get_stage |
π― Get information about a specific stage with optional attempt ID and summary metrics |
get_stage_task_summary |
π Get statistical distributions of task metrics for a specific stage (execution times, memory usage, I/O metrics) |
Resource utilization, executor performance, and allocation tracking
| π§ Tool | π Description |
|---|---|
list_executors |
π₯οΈ Get executor information with optional inactive executor inclusion |
get_executor |
π Get information about a specific executor including resource allocation, task statistics, and performance metrics |
get_executor_summary |
π Aggregates metrics across all executors (memory usage, disk usage, task counts, performance metrics) |
get_resource_usage_timeline |
π Get chronological view of resource allocation and usage patterns including executor additions/removals |
Spark configuration, environment variables, and runtime settings
| π§ Tool | π Description |
|---|---|
get_environment |
βοΈ Get comprehensive Spark runtime configuration including JVM info, Spark properties, system properties, and classpath |
SQL performance analysis and execution plan comparison
| π§ Tool | π Description |
|---|---|
list_slowest_sql_queries |
π Get the top N slowest SQL queries for an application with detailed execution metrics |
compare_sql_execution_plans |
π Compare SQL execution plans between two Spark jobs, analyzing logical/physical plans and execution metrics |
Intelligent bottleneck identification and performance recommendations
| π§ Tool | π Description |
|---|---|
get_job_bottlenecks |
π¨ Identify performance bottlenecks by analyzing stages, tasks, and executors with actionable recommendations |
Cross-application comparison for regression detection and optimization
| π§ Tool | π Description |
|---|---|
compare_job_environments |
βοΈ Compare Spark environment configurations between two jobs to identify differences in properties and settings |
compare_job_performance |
π Compare performance metrics between two Spark jobs including execution times, resource usage, and task distribution |
compare_app_resources π |
π° Compare resource allocation and configuration patterns between applications focusing on executor setup and utilization efficiency |
compare_app_executors π |
π₯οΈ Compare executor-level performance metrics including memory usage, GC performance, and task completion patterns |
compare_app_jobs π |
π Compare job-level performance metrics focusing on job counts, durations, success rates, and parallelism patterns |
compare_app_stages_aggregated π |
β‘ Compare overall stage performance patterns, I/O volumes, and shuffle operations without individual stage details |
compare_app_performance π |
π― Ultimate performance comparison - Multi-dimensional analysis covering resources, jobs, executors, and stages with intelligent filtering and actionable recommendations |
Advanced timeline analysis with simplified executor-focused output and interval merging
| π§ Tool | π Description |
|---|---|
compare_app_executor_timeline π |
π Advanced timeline comparison - Analyze executor allocation patterns across entire application lifecycle with intelligent interval merging and noise reduction |
compare_stage_executor_timeline π |
π Stage-level timeline analysis - Compare executor patterns during specific stages with consolidated intervals and simplified executor-focused output |
| π§ Tool | π Description |
|---|---|
compare_stages π |
β‘ Compare specific stages between two applications focusing on significant performance differences only |
AI-powered analysis tools inspired by SparkInsight for intelligent performance optimization
| π§ Tool | π Description |
|---|---|
analyze_auto_scaling π |
π Analyze workload patterns and provide intelligent auto-scaling recommendations for dynamic allocation |
analyze_shuffle_skew π |
π Detect and analyze data skew in shuffle operations with actionable optimization suggestions |
analyze_failed_tasks π |
π¨ Investigate task failures to identify patterns, problematic executors, and root causes |
analyze_executor_utilization π |
π Track executor utilization over time to identify over/under-provisioning and optimization opportunities |
get_application_insights π |
π§ Comprehensive SparkInsight analysis - Runs all analyzers to provide complete performance overview and recommendations |
Reusable templates that guide AI agents in structured Spark analysis
The MCP server provides 16 intelligent prompts organized by analysis type. These prompts help AI agents ask better questions and generate more structured, comprehensive analyses:
| π¬ Prompt | π Description |
|---|---|
analyze_slow_application |
π Generate structured analysis framework for slow-running Spark applications with baseline comparison |
investigate_stage_bottlenecks |
β‘ Create detailed prompt for investigating stage-level performance bottlenecks and task-level issues |
diagnose_resource_issues |
π Generate systematic resource utilization diagnosis across memory, CPU, disk, and network dimensions |
compare_job_performance |
π Structure comprehensive performance comparison between two Spark applications |
| π¬ Prompt | π Description |
|---|---|
investigate_failures |
π¨ Systematic investigation framework for application failures, task errors, and reliability issues |
examine_memory_issues |
π§ Detailed memory problem diagnosis including heap, off-heap, GC pressure, and spill analysis |
diagnose_shuffle_problems |
π Comprehensive shuffle operation diagnosis focusing on skew, performance, and data movement issues |
identify_configuration_issues |
βοΈ Systematic configuration assessment and optimization opportunity identification |
| π¬ Prompt | π Description |
|---|---|
suggest_autoscaling_config |
π Generate auto-scaling configuration recommendations with cost-performance optimization |
optimize_resource_allocation |
π‘ Comprehensive resource allocation optimization across executors, memory, and CPU dimensions |
improve_query_performance |
π SQL query and data processing performance optimization with execution plan analysis |
reduce_data_skew |
βοΈ Comprehensive data skew reduction strategies including preprocessing and runtime solutions |
| π¬ Prompt | π Description |
|---|---|
generate_performance_report |
π Create comprehensive performance reports tailored for different audiences (executive/technical) |
create_executive_summary |
π Generate high-level executive summaries focused on business impact and strategic recommendations |
summarize_trends |
π Analyze trends and patterns across multiple Spark applications over time |
benchmark_comparison |
π― Compare application performance against internal benchmarks, industry standards, or historical data |
Query Pattern Examples:
Basic Analysis:
- "Why is my job slow?" β
get_job_bottlenecks+list_slowest_stages+get_executor_summary - "Compare today vs yesterday" β
compare_job_performance+compare_job_environments - "What's wrong with stage 5?" β
get_stage+get_stage_task_summary - "Show me resource usage over time" β
get_resource_usage_timeline+get_executor_summary - "Find my slowest SQL queries" β
list_slowest_sql_queries+compare_sql_execution_plans
Timeline & Resource Analysis:
- "How do executor patterns differ between apps?" β
compare_app_executor_timeline(simplified executor-focused comparison) - "Compare stage resource allocation over time" β
compare_stage_executor_timeline(merged interval analysis) - "Analyze resource allocation efficiency" β
compare_app_resources+compare_app_executors - "Track executor scaling differences" β
compare_app_executor_timeline+analyze_auto_scaling
Comprehensive Analysis with Prompts:
- "Thoroughly analyze my slow application" β
analyze_slow_applicationprompt β structured analysis using multiple tools - "Generate a performance report for executives" β
generate_performance_reportprompt β comprehensive business-focused analysis - "Help me optimize auto-scaling configuration" β
suggest_autoscaling_configprompt β detailed optimization strategy - "Investigate memory issues systematically" β
examine_memory_issuesprompt β structured memory diagnosis - "Create executive summary of app performance" β
create_executive_summaryprompt β high-level business impact analysis
Advanced Analysis:
- "Analyze my app performance with insights" β
get_application_insights(comprehensive SparkInsight analysis) - "Why are my tasks failing?" β
investigate_failuresprompt β systematic failure investigation - "Check for data skew issues" β
reduce_data_skewprompt β comprehensive skew mitigation strategy - "Compare multiple applications over time" β
summarize_trendsprompt β trend analysis across apps
Intelligent Prompts provide:
- Structured Frameworks: Guide AI agents through systematic analysis approaches
- Domain Expertise: Encode Spark performance knowledge into reusable templates
- Tool Recommendations: Suggest optimal MCP tool sequences for different scenarios
- Consistent Analysis: Ensure comprehensive coverage of key performance areas
- Tailored Output: Generate analysis appropriate for different audiences (technical, executive)
Example: Using the analyze_slow_application prompt:
User: "My Spark job app-12345 is running slower than expected"
AI Agent: Uses analyze_slow_application("app-12345") prompt
Result: Structured investigation covering:
β’ Application performance baseline comparison
β’ Bottleneck identification using get_job_bottlenecks
β’ Resource utilization analysis via analyze_executor_utilization
β’ Data skew detection with analyze_shuffle_skew
β’ Configuration review and optimization recommendations
The timeline comparison tools have been enhanced with major improvements for cleaner analysis:
- Executor-Only Metrics: Timeline comparisons now focus exclusively on executor count differences, removing memory and CPU noise
- Streamlined Data: Cleaner output makes it easier to identify meaningful resource allocation patterns
- Reduced Complexity: Simplified comparison data structure improves readability and analysis speed
- Consecutive Consolidation: Adjacent time intervals with identical executor counts are automatically merged
- Duration Tracking: Merged intervals include
duration_intervalsshowing how many original intervals were consolidated - Noise Reduction: Significantly reduces output size while preserving all critical information
- Dual Metrics: Shows both
original_intervalsandmerged_intervalscounts for transparency - Improved Insights: Summary statistics calculated on merged data provide more meaningful analysis
- Better Tracking: Clear visibility into the effectiveness of interval consolidation
compare_stage_executor_timeline- Stage-level timeline comparison with merged intervalscompare_app_executor_timeline- Application-level timeline comparison with simplified output
These improvements make timeline analysis more focused and actionable while maintaining full backward compatibility.
The MCP server now includes intelligent analysis capabilities inspired by SparkInsight! See the SparkInsight Integration Guide for:
- π Auto-scaling optimization recommendations
- π Data skew detection and mitigation strategies
- π¨ Failure analysis with root cause identification
- π Executor utilization optimization insights
- π§ Comprehensive analysis combining all insights
If you are an existing AWS user looking to analyze your Spark Applications, we provide detailed setup guides for:
- AWS Glue Users - Connect to Glue Spark History Server
- Amazon EMR Users - Use EMR Persistent UI for Spark analysis
These guides provide step-by-step instructions for setting up the Spark History Server MCP with your AWS services.
Deploy using Kubernetes with Helm:
β οΈ Work in Progress: We are still testing and will soon publish the container image and Helm registry to GitHub for easy deployment.
# π¦ Deploy with Helm
helm install spark-history-mcp ./deploy/kubernetes/helm/spark-history-mcp/
# π― Production configuration
helm install spark-history-mcp ./deploy/kubernetes/helm/spark-history-mcp/ \
--set replicaCount=3 \
--set autoscaling.enabled=true \
--set monitoring.enabled=trueπ See deploy/kubernetes/helm/ for complete deployment manifests and configuration options.
Setup multiple Spark history servers in the config.yaml and choose which server you want the LLM to interact with for each query.
servers:
production:
default: true
url: "http://prod-spark-history:18080"
auth:
username: "user"
password: "pass"
staging:
url: "http://staging-spark-history:18080"π User Query: "Can you get application <app_id> using production server?"
π€ AI Tool Request:
{
"app_id": "<app_id>",
"server": "production"
}π€ AI Tool Response:
{
"id": "<app_id>>",
"name": "app_name",
"coresGranted": null,
"maxCores": null,
"coresPerExecutor": null,
"memoryPerExecutorMB": null,
"attempts": [
{
"attemptId": null,
"startTime": "2023-09-06T04:44:37.006000Z",
"endTime": "2023-09-06T04:45:40.431000Z",
"lastUpdated": "2023-09-06T04:45:42Z",
"duration": 63425,
"sparkUser": "spark",
"appSparkVersion": "3.3.0",
"completed": true
}
]
}SHS_MCP_PORT - Port for MCP server (default: 18888)
SHS_MCP_DEBUG - Enable debug mode (default: false)
SHS_MCP_ADDRESS - Address for MCP server (default: localhost)
SHS_MCP_TRANSPORT - MCP transport mode (default: streamable-http)
SHS_SERVERS_*_URL - URL for a specific server
SHS_SERVERS_*_AUTH_USERNAME - Username for a specific server
SHS_SERVERS_*_AUTH_PASSWORD - Password for a specific server
SHS_SERVERS_*_AUTH_TOKEN - Token for a specific server
SHS_SERVERS_*_VERIFY_SSL - Whether to verify SSL for a specific server (true/false)
SHS_SERVERS_*_TIMEOUT - HTTP request timeout in seconds for a specific server (default: 30)
SHS_SERVERS_*_EMR_CLUSTER_ARN - EMR cluster ARN for a specific server
| Integration | Transport | Best For |
|---|---|---|
| Local Testing | HTTP | Development, testing tools |
| Claude Desktop | STDIO | Interactive analysis |
| Amazon Q CLI | STDIO | Command-line automation |
| Kiro | HTTP | IDE integration, code-centric analysis |
| LangGraph | HTTP | Multi-agent workflows |
| Strands Agents | HTTP | Multi-agent workflows |
π€ AI Query: "Why is my ETL job running slower than usual?"
π MCP Actions:
β
Analyze application metrics
β
Compare with historical performance
β
Identify bottleneck stages
β
Generate optimization recommendations
π€ AI Query: "What caused job 42 to fail?"
π MCP Actions:
β
Examine failed tasks and error messages
β
Review executor logs and resource usage
β
Identify root cause and suggest fixes
π€ AI Query: "Compare today's batch job with yesterday's run"
π MCP Actions:
β
Compare execution times and resource usage
β
Identify performance deltas
β
Highlight configuration differences
Check CONTRIBUTING.md for full guidelines on contributions
Apache License 2.0 - see LICENSE file for details.
This project is built for use with Apache Sparkβ’ History Server. Not affiliated with or endorsed by the Apache Software Foundation.
π₯ Connect your Spark infrastructure to AI agents
π Get Started | π οΈ View Tools | π§ͺ Test Now | π€ Contribute
Built by the community, for the community π

