spark-sense-ai
Provides tools for diagnosing Spark job failures and optimizing Spark performance, using error logs and source code to identify root causes and suggest fixes.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@spark-sense-aiMy Spark job failed ā can you find the root cause and suggest a fix?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
spark-sense-ai
An MCP (Model Context Protocol) server that gives AI agents ā Claude Desktop, Claude Code, Devin, or any MCP-compatible client ā two capabilities for working with Apache Spark jobs:
š“
diagnose_spark_failureā a Spark job failed; get a root cause and a concrete fix, grounded in the actual error log and the specific code that failed.š¢
optimize_spark_performanceā a Spark job succeeded but is slow or expensive; get targeted, evidence-based tuning recommendations.
Built by a data engineer with 12+ years of hands-on Apache Spark experience, to bring that same debugging instinct ā "which file is this error actually about, and why" ā into an AI-assisted workflow.
Why this exists
Spark failures are usually diagnosable from the log alone ā but reading a 200-line stack trace, matching it back to the right file in a large, multi-job codebase, and knowing which of a dozen possible causes it actually is, takes real Spark experience. This tool automates that first pass: it finds the relevant code (not the whole repository), hands it to an LLM alongside the log, and gets back a structured diagnosis you can verify and act on.
Related MCP server: Spark MCP Optimizer
What makes it different
Design choice | Why it matters |
Source-agnostic ā EMR (cluster + step ID) or a local folder | Works whether your job runs on AWS or on-prem/locally |
Provider-agnostic ā Bedrock, Anthropic, OpenAI, or none | No vendor lock-in; |
Smart file selection | Large projects run many jobs ā this tool parses the error log's stack trace (Python and Scala/Java, including mixed PySpark traces) to pull in only the specific file(s) implicated in the failure, capped at 10 files, instead of dumping an entire codebase into the prompt |
No bundled credentials, ever | Every user brings their own AWS and/or LLM credentials. Nothing here shares billing or access between users |
Sample output
Given this sample Scala error log
and its matching project files,
diagnose_spark_failure (with a provider configured) returns:
ROOT CAUSE:
CustomerHelper.validate() calls .trim() on the "email" field without
checking for null first. Records with a missing email cause a
NullPointerException, which aborts the job after 4 failed task retries.
EVIDENCE:
- Caused by: java.lang.NullPointerException: Cannot invoke "String.trim()"
because "email" is null
- at com.company.jobs.CustomerHelper$.validate(CustomerHelper.scala:22)
- Source shows: email.trim().nonEmpty with no null check beforehand
SUGGESTED FIX:
def validate(row: Row): Boolean = {
val email = Option(row.getAs[String]("email"))
email.exists(_.trim.nonEmpty)
}
CONFIDENCE: HighNotice the tool automatically pulled in CustomerHelper.scala (the file
the trace's Caused by actually points to), not the whole project or
even the top-level CustomerOrderJoin.scala entry file ā because the
stack-trace parser resolved the deepest relevant frame.
Installation
pip install spark-sense-aiInstall extras only for what you'll actually use:
pip install spark-sense-ai[aws] # for EMR source or Bedrock provider
pip install spark-sense-ai[anthropic] # for provider="anthropic"
pip install spark-sense-ai[openai] # for provider="openai"
pip install spark-sense-ai[all] # everythingprovider="none" with source_type="local" needs no extras at all
ā just the base mcp dependency.
The four ways to use it
# | Log/code source | LLM provider | Extras needed | AWS credentials needed? |
1 | EMR cluster + step | Bedrock |
| Yes ā for fetching and diagnosis |
2 | EMR cluster + step | Anthropic / OpenAI |
| Yes ā only for fetching |
3 | Local folder | None (agent reasons, e.g. inside Devin) | none | No |
4 | Local folder | Anthropic / OpenAI |
| No |
AWS credentials, when needed, are picked up automatically from your
existing setup (aws configure, an attached IAM role, or standard
AWS_* environment variables) ā never passed as a tool parameter.
Setup
Claude Desktop
Edit claude_desktop_config.json:
{
"mcpServers": {
"sparksense": {
"command": "sparksense-mcp",
"env": {
"SPARKSENSE_AWS_REGION": "ap-south-1"
}
}
}
}Claude Code
claude mcp add sparksense -- sparksense-mcpDevin
See Devin's MCP docs for
the current config method for your Devin agent mode (Cascade and Devin
Local use slightly different config locations). Point it at the
sparksense-mcp command the same way as above.
Usage examples
"My Spark job failed ā EMR cluster j-ABC123, step s-XYZ789. Use sparksense to diagnose it with Bedrock."
"Here's my local job's log at
./logs/error.logand code at./srcā diagnose the failure."
"I know it's
jobs/customer_order_join.pythat failed ā use sparksense with that as the entry point."
"Use sparksense to fetch the log at
./logs/job.logā I'll review it myself." (provider="none"ā the tool just fetches; the calling agent does the reasoning)
"My job succeeded but took 40 minutes. Use sparksense to check the execution stats for optimization opportunities."
Tool reference
diagnose_spark_failure
Parameter | Required | Notes |
| Yes |
|
| If | |
| If | |
| No | S3 URI to source code |
| If | File or folder |
| No | Local source code folder |
| No | Specific filename/relative path to use directly, skipping auto-extraction ā best when you already know which job failed |
| No (default |
|
| No | For anthropic/openai; else reads |
optimize_spark_performance
Same parameters as above, plus:
Parameter | Required | Notes |
| No | Executor memory, cores, shuffle partitions, etc. |
File selection logic (both tools)
1. job_entry_point given?
ā use ONLY that file. No auto-extraction.
2. Else, parse the error log for:
ā Python: File "<path>", line <N>
ā Scala/Java: at <package>.<Class>.<method>(<Filename>:<N>)
(handles mixed PySpark traces ā Python frames bottoming into JVM
frames ā by scanning for both patterns in the same log)
ā filters out framework/library internals (site-packages, pyspark,
org.apache.spark, scala.*, java.*, etc.)
ā fetches up to 10 matched files
3. Else, fallback: broad scan of the project folder, capped at 10 filesEnvironment variables
Variable | Default | Purpose |
|
| Region for EMR/S3/Bedrock calls |
|
| Bedrock model to use |
| ā | Used if |
| ā | Used if |
Testing
git clone https://github.com/YOUR_GITHUB_USERNAME/spark-sense-ai.git
cd spark-sense-ai
pip install -e ".[all]"
# Local source + Anthropic provider, includes Python and Scala samples
export ANTHROPIC_API_KEY="sk-ant-..."
python tests/test_local_anthropic.py
# EMR source + Bedrock provider (needs a real EMR cluster/step)
aws configure
python tests/test_emr_bedrock.py --cluster-id j-XXXXXXX --step-id s-XXXXXXXBoth scripts run a free, no-API-call sanity check first (provider="none")
before making any billed LLM calls.
Roadmap
Automatic trigger via Lambda/EventBridge on EMR/Glue job completion
Databricks as a third
source_typeStructured Spark History Server API integration
Skew detection with partition-level statistics
License
MIT ā see LICENSE.
Available Tools
2 toolsdiagnose_spark_failureARead-onlyIdempotent
Diagnose why an Apache Spark job failed.
Args: source_type: Where to fetch the log/code from - "emr" or "local". emr_cluster_id: EMR cluster ID (required if source_type="emr"). emr_step_id: EMR step ID (required if source_type="emr"). s3_project_location: Optional S3 URI to the job's source code (used only if source_type="emr"). local_log_path: Path to a local log file or folder (required if source_type="local"). local_project_path: Optional local folder containing the job's source code (used only if source_type="local"). job_entry_point: Optional filename/relative path of the specific job file that ran (e.g. "jobs/customer_order_join.py"). If given, ONLY this file is used as code context - skips auto-extraction entirely. Best used when the caller already knows which job failed. If omitted, the tool automatically parses the error log's stack trace (Python and/or Scala/Java patterns - handles mixed PySpark traces) to find the relevant file(s) in the project, up to 10 files, filtering out framework/library internals. This keeps large, multi-job projects from having their entire codebase sent to the model - only the code actually implicated by the failure is included. provider: Which LLM does the reasoning - "bedrock", "anthropic", "openai", or "none" (default). "none" returns the fetched log/code as-is, for the CALLING AGENT to diagnose itself - no LLM call is made by this tool in that case. api_key: API key for "anthropic" or "openai" providers. If omitted, reads from the ANTHROPIC_API_KEY / OPENAI_API_KEY environment variable. Not used for "bedrock" (uses locally configured AWS credentials) or "none".
Returns: A structured diagnosis (root cause, evidence, fix, confidence) if a provider is set, or the raw fetched log/code for the calling agent to analyze if provider="none".
| Name | Required | Description | Default |
|---|---|---|---|
| api_key | No | ||
| provider | No | none | |
| emr_step_id | No | ||
| source_type | Yes | ||
| emr_cluster_id | No | ||
| local_log_path | No | ||
| job_entry_point | No | ||
| local_project_path | No | ||
| s3_project_location | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
The annotations (readOnlyHint=true, idempotentHint=true, destructiveHint=false) are consistent with the description, which implies fetch-and-analyze operations with no side effects. The description adds transparency about the optional LLM call and the 'none' provider returning raw data, which is valuable context beyond the annotations. No contradictions found.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is long but well-structured, with clear sections for parameters and returns. Each piece of information serves a purpose (e.g., explaining conditional requirements, provider options, and the detection algorithm). While slightly verbose, the complexity of the tool justifies the length. It is not padded with irrelevant details.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's complexity (multiple providers, conditional parameters, return type variations), the description is exceptionally complete. It covers return values for both provider and 'none' cases, explains the code extraction logic, and provides examples. No missing information that an agent would need to call this tool correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Despite the schema having zero description coverage, the tool description explains every parameter in detail, including conditional requirements (e.g., 'required if source_type="emr"'), defaults, environment variable fallbacks, and the behavior of job_entry_point. It even includes an example and explains the auto-extraction logic. This fully compensates for the schema's lack of per-parameter descriptions.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description opens with a specific verb and object: 'Diagnose why an Apache Spark job failed.' This clearly distinguishes the tool from the sibling 'optimize_spark_performance' by focusing on failure diagnosis rather than performance tuning. The purpose is unambiguous and immediately actionable.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides thorough guidance on when to use the tool and how to configure it for different scenarios (source_type, provider, conditional parameters). It explains fallback behavior (env vars, 'none' provider) and the logic for auto-extraction. However, it does not explicitly contrast with the sibling tool, relying instead on the name difference. This is a minor gap, keeping it from a perfect score.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
optimize_spark_performanceARead-onlyIdempotent
Analyze a successful Spark job's execution log/stats and suggest performance optimizations.
Args: source_type: Where to fetch the log/code from - "emr" or "local". emr_cluster_id: EMR cluster ID (required if source_type="emr"). emr_step_id: EMR step ID (required if source_type="emr"). s3_project_location: Optional S3 URI to the job's source code. local_log_path: Path to a local log file/folder (required if source_type="local"). local_project_path: Optional local folder with source code. job_entry_point: Optional filename/relative path of the specific job file to focus on. If given, ONLY this file is used - skips auto-extraction. If omitted, the tool parses the execution log for stack-trace-like file references (Python and/or Scala/Java) to narrow down which of the project's files are relevant, up to 10 files. Useful for large, multi-job repositories. current_spark_config: Optional text describing the current Spark configuration (executor memory, cores, shuffle partitions, etc.), to ground recommendations in what's configurable. provider: "bedrock", "anthropic", "openai", or "none" (default - returns fetched content for the calling agent to analyze). api_key: API key for "anthropic"/"openai". Reads from env var if omitted. Unused for "bedrock" or "none".
Returns: A structured analysis (observations, recommendations, estimated impact) if a provider is set, or the raw fetched content for the calling agent to analyze if provider="none".
| Name | Required | Description | Default |
|---|---|---|---|
| api_key | No | ||
| provider | No | none | |
| emr_step_id | No | ||
| source_type | Yes | ||
| emr_cluster_id | No | ||
| local_log_path | No | ||
| job_entry_point | No | ||
| local_project_path | No | ||
| s3_project_location | No | ||
| current_spark_config | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations already declare readOnly, idempotent, openWorld, and non-destructive. The description adds clarity by explaining that with provider='none' it returns raw fetched content, and otherwise returns a structured analysis. There is no contradiction with annotations, and the description provides useful context on what the tool does without describing side effects.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-organized with a main purpose statement, an Args section listing each parameter with explanations, and a Returns section. It is thorough but not redundant, providing all necessary information without unnecessary verbosity.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The description explains the full behavior of the tool: what it analyzes, how it uses the parameters, and what it returns under different provider settings. Although an explicit output schema is not shown, the description clearly describes the two possible return types (structured analysis or raw content), making it complete for the agent to use correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema has 0% description coverage for its 10 parameters, but the tool description compensates fully by explaining each parameter: source_type, emr_cluster_id, emr_step_id, s3_project_location, local_log_path, local_project_path, job_entry_point, current_spark_config, provider, and api_key. It clarifies requirements (e.g., 'required if source_type=...') and optionality, making the semantics complete.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose: analyze successful Spark job logs/stats and suggest performance optimizations. It names the specific action (analyze, suggest) and resource (execution log/stats), and differentiates from the sibling tool by emphasizing 'successful' jobs, implying a contrast with failure diagnosis.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies when to use the tool (for successful jobs to get optimization suggestions) by contrasting with 'successful' and the sibling 'diagnose_spark_failure'. It also explains provider options (including 'none' for raw content) and argument dependencies. However, it does not explicitly state 'use this instead of diagnose_spark_failure when the job succeeded,' leaving the distinction implicit.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
2 tool updates
v0.1.3- First observed
diagnose_spark_failure - First observed
optimize_spark_performance
TDQS
Scored across 2 tools
The two tools have clearly distinct purposes: one diagnoses failures and the other optimizes performance. Despite sharing similar arguments, their actions and return types are unambiguously different.
Both tool names follow the consistent verb_noun pattern (diagnose_spark_failure, optimize_spark_performance), which is clear and predictable.
With only two tools, the server is slightly below the typical well-scoped range, but it is focused on a narrow domain (Spark job analysis) where these two core operations are appropriate.
The server covers the primary needs of diagnosing failures and optimizing performance. However, there may be gaps such as retrieving job metrics or listing available jobs, though these are not strictly required for the stated purpose.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.
MCP server for building and testing AI agents with multi-model experimentation and insights.
MCP server for AI dialogue using various LLM models via AceDataCloud
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server for intelligent log analysis providing semantic search, error pattern clustering, and smart error detection. It enables users to process, vectorize, and query local logs to efficiently identify issues and generate AI-powered summaries.MIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that optimizes Apache Spark code using Claude AI, providing intelligent code optimization suggestions and performance analysis.29-
- AlicenseAqualityDmaintenanceMCP server for log file analysis. Gives LLMs the ability to efficiently analyze large log files without loading them into context.7100MIT
- AlicenseAqualityCmaintenanceMCP server that reads Spark profiler files to give accurate Minecraft server tuning advice, parsing binary protobuf directly and diagnosing TPS, MSPT, GC, heap, and call-tree issues.14354MIT