Skip to main content
Glama
ukonduru91

Spark History Server MCP

by ukonduru91

Spark History Server MCP (TypeScript)

LLM に Spark History Server への読み取りアクセスを提供し、Spark 作業の退屈な部分(ジョブが失敗した理由の特定、遅いジョブが時間を費やしている場所の特定)を任せられるようにします。

これは kubeflow/mcp-apache-spark-history-server の TypeScript 移植版であり、Python オリジナルとレスポンス単位で検証されています(PARITY.md を参照)。移植に加えて、根本原因分析とパフォーマンスチューニングのためのエキスパートワークフローに生のツールを変える エージェントスキル を2つ同梱しています。

                    ┌──────────────────┐
  data engineer ──▶ │  LLM client      │   Claude Code / Claude Desktop / any MCP client
                    │  + skills        │   ← skills/ supply the method
                    └────────┬─────────┘
                             │ MCP (stdio or streamable-http)
                    ┌────────▼─────────┐
                    │  this server     │   17 tools, 2 prompts
                    └────────┬─────────┘
                             │ HTTP  GET /api/v1/...
                    ┌────────▼─────────┐
                    │ Spark History    │   your existing one, or the bundled demo
                    │ Server           │
                    └────────┬─────────┘
                             │ reads
                    ┌────────▼─────────┐
                    │ event logs       │   s3://…, hdfs://…, file://…
                    └──────────────────┘

このサーバーは History Server の REST API に対して GET リクエストのみを発行します。何も変更することはできません。


目次

  1. クイックスタート

  2. Spark History Server を指定する

  3. LLM クライアントを接続する

  4. スキルのインストール

  5. ツール

  6. 仕組み

  7. デプロイ

  8. トラブルシューティング

  9. 開発


Related MCP server: Spark EventLog MCP Server

1. クイックスタート

オプション A — Docker(Docker 以外のインストールは不要)

サンプルのイベントログとこの MCP を読み込んだ Spark History Server を起動します:

git clone https://github.com/ukonduru91/spark-history-mcp.git
cd spark-history-mcp
docker compose up --build

Spark History Server UI

http://localhost:18080

Spark History REST API

http://localhost:18080/api/v1/applications

MCP エンドポイント

http://localhost:18888/mcp

同梱のログには、正常なパイプラインと意図的に失敗させたジョブが含まれているため、独自のクラスターを指定する前に、ツールが実際に何かを表示できます。

History Server のみを実行する場合:

./start_local_spark_history.sh          # macOS / Linux / Git Bash
.\start_local_spark_history.ps1         # Windows PowerShell

オプション B — ソースから

Node.js 20+ が必要です(22 推奨)。

git clone https://github.com/ukonduru91/spark-history-mcp.git
cd spark-history-mcp
npm install
npm run build
npm start

動作確認

node scripts/mcp-cli.mjs list-tools
node scripts/mcp-cli.mjs call list_applications '{"limit": 5}'

アプリケーションが返ってくれば、接続されています。


2. Spark History Server を指定する

これが唯一設定が必要な項目です。 優先度の高い順に3つの方法があります。環境変数は .env ファイルより優先され、.env ファイルは YAML より優先されます。

a. 環境変数(コンテナと CI に最適)

ネストには 二重 アンダースコアを使用します。以下の LOCAL はサーバーに付ける任意の名前です:

export SHS_SERVERS__LOCAL__URL=http://spark-history.internal:18080
export SHS_SERVERS__LOCAL__DEFAULT=true

b. YAML 設定ファイル

サーバーは次の順序でファイルを探します:

  1. --config または $SHS_MCP_CONFIG で指定されたパス

  2. 作業ディレクトリの ./config.yaml

  3. ~/.config/spark-mcp/config.yaml

servers:
  prod:
    url: "https://spark-history.company.com:18080"
    default: true          # used when a tool call omits `server`
    verify_ssl: true
    ssl_ca_cert: "/etc/ssl/custom-ca/ca-bundle.pem"   # private CA
    timeout: 30            # seconds
    auth:
      username: admin
      password: ${SPARK_PASSWORD}   # see the note below
      # token: <bearer token>       # or a bearer token instead

  staging:
    url: "https://spark-history-staging.company.com:18080"

シークレットについて: YAML の値はリテラルです — ${SPARK_PASSWORD}展開されません。認証情報は環境変数(SHS_SERVERS__PROD__AUTH__PASSWORD)に保持してください。これらはファイルより優先されます。これはアップストリームプロジェクトの動作と一致します。

c. .env ファイル

(a) と同じ変数名で、作業ディレクトリの .env から読み取ります。

複数サーバー

必要な数だけ設定できます。ツールはオプションの server 引数を受け取ります。省略された場合、サーバーはそのアプリケーションを持つ設定済み History Server を 自動検出 し、それを使用します(5分間キャッシュされます)。したがって、エンジニアはどのクラスターで実行されたかを知らなくても、アプリケーション ID について質問できます。

すべての設定

設定

環境変数

デフォルト

意味

servers.<n>.url

SHS_SERVERS__<N>__URL

http://localhost:18080

History Server のベース URL

servers.<n>.default

SHS_SERVERS__<N>__DEFAULT

false

server が指定されていない場合に使用

servers.<n>.auth.username

SHS_SERVERS__<N>__AUTH__USERNAME

基本認証

servers.<n>.auth.password

SHS_SERVERS__<N>__AUTH__PASSWORD

基本認証

servers.<n>.auth.token

SHS_SERVERS__<N>__AUTH__TOKEN

ベアラートークン

servers.<n>.verify_ssl

SHS_SERVERS__<N>__VERIFY_SSL

true

TLS 検証

servers.<n>.ssl_ca_cert

SHS_SERVERS__<N>__SSL_CA_CERT

プライベート CA 用の PEM バンドル

servers.<n>.timeout

SHS_SERVERS__<N>__TIMEOUT

30

リクエストタイムアウト(秒)

servers.<n>.use_proxy

SHS_SERVERS__<N>__USE_PROXY

false

socks5h://localhost:8157 経由でルーティング

servers.<n>.include_plan_description

SHS_SERVERS__<N>__INCLUDE_PLAN_DESCRIPTION

false

get_sql_execution のプランテキストのデフォルト

mcp.transport

SHS_MCP__TRANSPORT

streamable-http

stdio または streamable-http

mcp.address

SHS_MCP__ADDRESS

localhost

HTTP のバインドアドレス

mcp.port

SHS_MCP__PORT

18888

HTTP のバインドポート

mcp.debug

SHS_MCP__DEBUG

false

詳細ログ

単一アンダースコアの変数(SHS_MCP_PORT)も引き続き機能しますが、アップストリームと同様に非推奨の警告がログに記録されます。

ルーティングできない History Server に到達する

SSH トンネルと use_proxy: true を組み合わせることで、一般的なロックダウンされたクラスターのケースをカバーできます:

ssh -D 8157 -N user@bastion    # SOCKS5 proxy on :8157

3. LLM クライアントを接続する

stdio(Claude Code、Claude Desktop、ほとんどのクライアント)

{
  "mcpServers": {
    "spark-history": {
      "command": "node",
      "args": ["/absolute/path/to/spark-history-mcp/dist/index.js"],
      "env": {
        "SHS_MCP__TRANSPORT": "stdio",
        "SHS_SERVERS__PROD__URL": "https://spark-history.company.com:18080",
        "SHS_SERVERS__PROD__DEFAULT": "true"
      }
    }
  }
}

Claude Code ユーザーは同じことを1行で行えます:

claude mcp add spark-history \
  --env SHS_MCP__TRANSPORT=stdio \
  --env SHS_SERVERS__PROD__URL=https://spark-history.company.com:18080 \
  --env SHS_SERVERS__PROD__DEFAULT=true \
  -- node /absolute/path/to/spark-history-mcp/dist/index.js

streamable-http(チームで共有する1つのサーバー)

一度実行して、全員をそこに向けます:

SHS_MCP__TRANSPORT=streamable-http SHS_MCP__ADDRESS=0.0.0.0 npm start

クライアントは http://<host>:18888/mcp に接続します。サーバーは読み取り専用ですが、認証もありません。通常の内部イングレスの背後に配置し、ブラウザから到達可能な場合は DNS リバインディング保護を有効にしてください:

mcp:
  transport_security:
    enable_dns_rebinding_protection: true
    allowed_hosts: ["spark-mcp.internal:*"]
    allowed_origins: ["https://spark-mcp.internal"]

4. スキルのインストール

ツールはモデルにデータへのアクセスを提供します。スキルは方法論を提供します — 証拠を収集する順序、ノイズから発見を分離するしきい値、そしてデータで確認していない原因を挙げてはならないというルールです。

# per project
mkdir -p .claude/skills
cp -r skills/spark-rca skills/spark-optimization .claude/skills/

# or for every project
mkdir -p ~/.claude/skills
cp -r skills/spark-rca skills/spark-optimization ~/.claude/skills/

スキル

対象

トリガー

spark-rca

失敗、強制終了、またはハングしたジョブ

「なぜ失敗したのか」、スタックトレース、アプリ ID、「OOM」、「スタック」

spark-optimization

遅い、高コスト、または劣化したジョブ

「なぜ遅いのか」、「チューニング」、「以前は20分かかった」、「コスト削減」

通常の質問から自動的にトリガーされるため、コマンドを覚える必要はありません:

「午前2時のロードがまた失敗しました、app_1724… — 見てもらえますか?」

各スキルの内容と、チーム独自の知識で拡張する方法については、skills/README.md を参照してください。


5. ツール

17個すべてが src/tools/tools.ts にあります。JSON スキーマは src/schemas/generated.ts にあります。node scripts/mcp-cli.mjs list-tools を実行すると、引数とともに確認できます。

検索

ツール

戻り値

list_applications

アプリケーション。ステータスと日付でフィルタリング可能、または app_id で1件取得

list_jobs

アプリケーションのジョブ。デフォルトでは失敗が先頭。sort_byduration / failed-tasks / id

list_stages

ステージ。同じ並べ替えオプション、オプションのサマリーメトリクス

list_executors

エグゼキューター。デフォルトはアクティブ、include_inactive で全履歴

list_sql_executions

厳選された SQL 実行サマリー。説明でフィルタリング可能

詳細調査

ツール

戻り値

get_stage

1つのステージ。指定した分位数でのタスクごとのメトリクス分布

list_stage_task_failures

タスクごとの例外とスタックトレース — 根本原因が存在する場所

get_sql_execution

1つのクエリ: ヘッダー、物理プラン、ノードごとのメトリクス、ジョブ、ステージ

get_environment

ランタイムバージョン、Spark/システム/Hadoop プロパティ、クラスパス — section でフィルタリング

get_executor_summary

アプリケーションの集計エグゼキューター メトリクス

get_executor_thread_dump

JVM スレッドダンプ — 実行中アプリケーションのみ

診断

ツール

戻り値

get_job_bottlenecks

最も遅いステージとジョブ、スピル、GC プレッシャー、利用率、推奨事項

get_resource_usage_timeline

エグゼキューターの追加/削除とステージのタイムラインサマリー

2つの実行の比較

ツール

戻り値

compare_job_environments

設定の差分 — 2つの実行間で何が変わったか

compare_job_performance

リソースと期間の差分

compare_sql_executions

2つのクエリのメトリクス差分、オプションのプラン構造差分

compare_stages

ステージのメトリクスとタスク分位数を並べて表示

プロンプト

investigate_failure(app_id, server?)compare_applications(app_a, app_b, server?, context?) — アップストリームプロジェクトからの対話型ウォークスルー。エンジニアが分析を任せる代わりに自分で操作したい場合に使用します。


6. 仕組み

ツール呼び出しは /api/v1/... に対する1つ以上の GET になり、JSON は Python オリジナルが整形したのとまったく同じ形で返されます。

src/
  index.ts                 CLI entry, transport selection (stdio | streamable-http)
  config/config.ts         YAML + .env + SHS_* resolution and precedence
  core/
    app.ts                 MCP request handlers; maps results to content blocks
    validation.ts          pydantic-compatible argument validation and messages
    json.ts                Python-compatible JSON rendering
    pyfloat.ts             int/float fidelity across the JSON round-trip
    pyrepr.ts              Python repr() for validation messages
    errors.ts              error text shaping
  api/
    httpClient.ts          HTTP transport, ApiException taxonomy, auth, TLS, SOCKS
    sparkClient.ts         Spark REST facade: pagination, attempts, status filters
  models/
    generated.ts           model shapes, generated from the upstream OpenAPI models
    deserialize.ts         from_dict / model_dump equivalents
    mcpTypes.ts            curated LLM-facing output models
  tools/tools.ts           the 17 tools
  prompts/prompts.ts       the 2 prompts
  schemas/generated.ts     tool + prompt catalogue (names, descriptions, schemas)

変更を計画している場合に知っておく価値のある3つの詳細:

  • models/generated.tsschemas/generated.ts は生成されますtools/gen_models.pytools/gen_schemas.py によって、アップストリームの Python プロジェクトから生成されます。手動編集ではなく再生成してください — これにより、カタログとレスポンスの形状がオリジナルと同一に保たれます。

  • 低レベルの Server API が使用され、McpServer は使用されません。結果の形状が FastMCP のものと一致する必要があるためです: リスト要素ごとに1つのテキストブロック、structuredContent は Python シグネチャが具体的な戻り値の型を宣言したツールのみ。

  • アプリケーションの自動検出により、ツールは server を省略できます。ApplicationDiscovery は各設定済みサーバーをプローブしてアプリケーション ID を探し、回答を5分間キャッシュします。


7. デプロイ

Docker

docker build -t spark-history-mcp .
docker run -p 18888:18888 \
  -e SHS_SERVERS__PROD__URL=https://spark-history.company.com:18080 \
  -e SHS_SERVERS__PROD__DEFAULT=true \
  -e SHS_MCP__ADDRESS=0.0.0.0 \
  spark-history-mcp

Kubernetes

通常のDeploymentとして、URLをenvに、認証情報をSecretから指定して実行します:

env:
  - name: SHS_MCP__TRANSPORT
    value: streamable-http
  - name: SHS_MCP__ADDRESS
    value: "0.0.0.0"
  - name: SHS_SERVERS__PROD__URL
    value: http://spark-history-server.spark.svc.cluster.local:18080
  - name: SHS_SERVERS__PROD__DEFAULT
    value: "true"
  - name: SHS_SERVERS__PROD__AUTH__TOKEN
    valueFrom:
      secretKeyRef: { name: spark-history-auth, key: token }

このプロセスは5分間のディスカバリーキャッシュ以外はステートレスなので、調整なしで水平スケールできます。


8. トラブルシューティング

症状

原因と対処

connect ECONNREFUSED

URLまたはポートが間違っているか、History Serverが停止しています。同じホストから curl $URL/api/v1/applications を確認してください

Application '<id>' not found on any server

そのIDが設定済みのサーバーにないか、イベントログがまだ取得されていません — spark.history.fs.update.interval がスキャンを制御します

No Spark server named 'x' is configured

server 引数が servers: のキーと一致しません

404 … No tasks reported metrics for N / 0 yet

タスクが完了する前に失敗したステージに対するSpark自身の応答です。ツールの問題ではありません — 代わりにタスクの例外を確認してください

get_executor_thread_dump errors on a finished app

想定どおりです:History Serverはスレッドダンプを保持しません。アプリの実行中のみ機能します

Empty list_applications

spark.history.fs.logDirectory がジョブが実際にイベントログを書き込む場所を指していること、およびジョブで spark.eventLog.enabled=true になっていることを確認してください

Very large responses

lengthlimitsection で絞り込んでください。get_stage(with_summaries=false) の方がはるかに小さくなります

emr_cluster_arn … not included in this TypeScript port

EMR persistent-UI認証は移植されていません。代わりに直接到達可能なURLを指定してください

詳細ログには SHS_MCP__DEBUG=true を設定してください。


9. 開発

npm install
npm run build        # compile to dist/
npm run dev          # run from source, no build step
npm test             # unit tests
npm run typecheck    # tsc --noEmit

実装間のパリティテストは parity/ にあります — このサーバーとPython版オリジナルに対して同じMCP呼び出しを実行し、すべてのレスポンスを差分比較します。PARITY.md に結果と残っている正確な差分が記録されています。

アップストリームから移植されていないもの

アップストリームモジュール

ステータス

api/emr_persistent_ui_client.py

移植されていません — emr_cluster_arn で設定されたサーバーは説明付きエラーで即座に失敗します

tools/aws_troubleshooting.py

移植されていません — AWSホストのMCPエンドポイントへのプロキシで、AWS認証情報がある場合のみ登録されます

api/spark_html_client.py

移植されていません — ツール呼び出しのないPlaywrightスクリーンショットヘルパー


ライセンス

アップストリームプロジェクトと同様にApache-2.0です。

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI assistants to interact with Delta Lake tables stored in MinIO through Spark using natural language queries. Provides read-oriented data operations on Delta Lake tables through the Model Context Protocol.
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables comprehensive analysis of Apache Spark event logs from S3, HTTP, or local sources, providing performance metrics, resource monitoring, shuffle analysis, and automated optimization recommendations with interactive HTML reports.
    MIT
  • F
    license
    Not graded
    quality
    Not graded
    maintenance
    Exposes Spark History Server metrics and metadata as tools for LLM-based analysis of Spark applications. It enables deep optimization of Spark jobs by providing access to job summaries, stage details, SQL execution plans, and executor performance.
  • A
    license
    Not graded
    quality
    A
    maintenance
    Exposes Spark History Server data as tools for AI agents, enabling natural language querying of Spark applications, jobs, stages, and performance metrics.
    189
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • The grounded data layer for any LLM: governed SQL, metrics, lineage and catalog over your data.

  • Enable language models to perform advanced AI-powered web scraping with enterprise-grade reliabili…

  • LLM chat, text summarization and AI image generation

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ukonduru91/spark-history-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server