Skip to main content
Glama
h-kazuki-pixel

metric-shift-mcp-server

metric-shift-mcp-server

CI

「先週から売上(予約件数)が落ちた。どこで?」に答えるMCPサーバー。

CSVを渡すと、基準期間から曜日補正つきの予測値を作り、対象期間の実績との乖離がどの属性組合せに集中しているかを特定します。

例: 「全体で12%減。うち75%は チャネル=web の減少、35%は 火曜の夜 の減少で説明できます」

完全ローカル・読み取り専用・外部送信なし・APIキー不要・機械学習の訓練不要。

⚠️ このツールがやらないこと(先に読んでください)

  • 因果関係の証明はしません。 出力は「変化がどの属性組合せに集中しているか」という相関に基づく絞り込みです。「なぜそこが減ったのか」(施策変更・障害・競合・天候など)の解釈と確認は人の仕事です。

  • 予測はしません。異常検知の常時監視もしません。1回の「比較して分解する」分析だけをします。

  • 変化が小さく(全体±2%未満)データが少ない場合、原理的に検出できません。その場合は「有意な変化なし」と答えます。

Related MCP server: MCP Tabular Data Analysis Server

クイックスタート

1. インストール

git clone https://github.com/h-kazuki-pixel/metric-shift-mcp-server.git
cd metric-shift-mcp-server
npm install
npm run build

2. Claude Desktop への登録

claude_desktop_config.json に追加:

{
  "mcpServers": {
    "metric-shift": {
      "command": "node",
      "args": ["/絶対パス/metric-shift-mcp-server/dist/index.js"]
    }
  }
}

3. 使う

Claudeにこう頼みます:

/Users/you/reservations.csv を見て。6月は普通だったのに、6/29の週から予約が減った気がする。どこで減ってるか調べて。

Claudeが metric_shift_inspect_data でデータを確認し、metric_shift_localize で要因分解します。

データの形式

ヘッダー行つきのCSV(UTF-8、BOM可)。1行=1レコード(1予約、1注文など)。

日時,チャネル,店舗,金額
2026-06-01 10:30,web,A店,1200
2026-06-01 11:00,phone,A店,800
  • 日時列: ISO 8601 / YYYY-MM-DD / YYYY/MM/DD(時刻付き可)。列は自動推定、明示指定も可

  • 非対応: 和暦、Excelシリアル値(45678のような数値)。Excelからは「日付」列を文字列形式でCSVエクスポートしてください

  • 少量データ(1,000行以下)はファイルを作らず直接渡すことも可能

ツール

metric_shift_inspect_data

分析前のデータ確認。列一覧、日時列の推定結果、日付範囲、次元(切り口)候補、指標候補を返します。

metric_shift_localize

要因分解の本体。

引数

説明

file_path / rows

CSVパス、または直接データ(排他)

measure

"count"(件数)または数値列名(合計を分析)

dimensions

切り口1〜6個。列名、または予約語 __weekday__(曜日)/ __timeband__(時間帯: 朝6-11/昼11-17/夜17-22/深夜22-6、境界は変更可)

baseline_period

基準期間(正常だった頃)。1週間以上を推奨。対象期間との重複はエラー

target_period

対象期間(変化が起きた期間)

max_candidates

原因候補の最大数(既定3)

merge_rare_categories

希少カテゴリを「その他」に自動集約(既定ON、次元ごとに上位10保持。集約された値は警告で明示)

response_format

markdown(既定)/ json

仕組み

  1. 予測値の生成: 基準期間の曜日別1日あたり平均 × 対象期間の曜日構成で、属性組合せ(葉)ごとの「本来ならこうなるはず」を作る(曜日補正つき・決定論的)

  2. 異常な葉の絞り込み: 偏差分布の knee point 法で閾値を自動決定

  3. クラスタリング: 偏差スコアのヒストグラム密度クラスタリングで「同じ原因の影響を受けた葉の群れ」を分離(ripple effect 仮説)

  4. 局在化: クラスタごとに属性組合せの空間を浅い層から探索し、GPS(汎用ポテンシャルスコア)で「その組合せが原因だとしたら観測データをどれだけうまく説明できるか」を評価。簡潔性(オッカムの剃刀)とのバランスで代表候補を選ぶ

アルゴリズムについて

本実装は以下の論文のアルゴリズムに基づく独自のTypeScript実装です(公式実装のコードは使用していません):

  • Z. Li et al., "Generic and Robust Localization of Multi-Dimensional Root Causes" (Squeeze), ISSRE 2019

  • R. Bhagwan et al., "Adtributor: Revenue Debugging in Advertising Systems", NSDI 2014(先行研究として設計時に参照)

公式実装(NetManAIOps/Squeeze)のREADMEに著者自身が記載している既知バグ2件を修正済みです:

  • バグ1(期待値の計算): 論文の定義どおり、部分集合の実測/予測の合計比で期待値を計算。さらにGPSの計算対象を「当該クラスタの葉+正常な葉」に限定し、他クラスタの異常葉による汚染を防止

  • バグ2(簡潔性重みの負値): 重み C を下限0でクリップし、負値による誤った順位付けを防止

これに加えて、原著の必要条件(「原因に属する属性組合せは子孫葉の大半が同一クラスタ内にある」)の明示的な実装、クラスタ被覆制約、兄弟候補の統合、影響量フィルタを追加しています。

小規模データへの適応(本実装の独自拡張)

Squeeze は大規模なサービス監視データ向けに設計されています。小さい店舗のデータ(週数百件)に多次元を指定すると、薄く広がった原因が葉レベルのノイズに埋もれることがあります。本実装は:

  • 疎らさの警告: 属性組合せあたりの件数が少なすぎる場合に警告し、次元削減・期間延長を提案

  • 拡散原因の安全網: 次元単体の合計レベルでも乖離を検査し、「候補には出ていないが単体で大きな乖離のある値」があれば、次元を絞った再実行を提案

制約(v0.1)

  • 次元は最大6個。inline データは最大1,000行(超える場合はCSVファイルで)

  • 期間の重複は不可。基準期間は1週間以上を推奨(曜日補正のため)

  • 時間帯の既定区切りは日本の飲食・サービス業を想定(変更可能)

  • タイムゾーン変換はしない(日時は書かれたまま解釈)

  • 祝日は考慮しない(v1.0で jp-dates 連携を予定)

セキュリティ

  • 読み取り専用。ファイルの書き込み・削除は一切しない

  • 完全ローカル動作。ネットワーク通信なし・外部送信なし

  • システム領域(/etc など)へのアクセスは拒否

ロードマップ

  • v0.1(現在): コア分析(count/数値列、file/inline、曜日補正、要因分解)

  • v0.5: 派生指標(キャンセル率など)、移動平均ベースの予測値

  • v1.0: 予約データ用プリセット、jp-dates 連携(祝日補正)

ライセンス

MIT

作者

@h-kazuki-pixel — 無人スペース運営 × AI自動化。現場で使って効果のあった自動化ツールを汎用化してOSSとして公開しています。

Available Tools

2 tools
metric_shift_inspect_dataデータ概要の確認A
Read-onlyIdempotent

分析前にデータの中身を確認する。列の一覧、日時列の推定結果、日付範囲、次元(切り口)候補、指標候補を返す。metric_shift_localize を呼ぶ前にこのツールで列名と期間を確認することを推奨。

ParametersJSON Schema
NameRequiredDescriptionDefault
rowsNoデータを直接渡す場合のオブジェクト配列(最大1000行)。file_path とは排他
file_pathNoCSVファイルの絶対パス。ヘッダー行必須。UTF-8(BOM可)。rows とは排他
datetime_columnNo日時列の名前。省略時は自動推定。対応形式: ISO 8601 / YYYY-MM-DD / YYYY/MM/DD(時刻付き可)

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare the tool as read-only, idempotent, and non-destructive, so the safety profile is well covered. The description adds valuable behavioral context by revealing that the tool performs datetime column estimation and returns dimension/metric candidates, which conveys that it does heuristic analysis rather than just raw listing. No contraindication with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two compact sentences, front-loading the core purpose and then providing practical workflow guidance. Every sentence earns its place—no fluff, no repetition of schema details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (3 optional params, no output schema, one sibling), the description covers the essential context: what it does, what it returns, and its place in the workflow. It could theoretically mention error handling or return format specifics, but the schema already handles param constraints, and the description sufficiently orients the agent for a read-only inspection tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with each parameter (rows, file_path, datetime_column) already well-documented including format constraints and mutual exclusivity. The description does not add substantive parameter-level detail beyond what the schema provides, so the baseline of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('確認する' - inspect) and clearly identifies the resource (data contents). It enumerates the concrete outputs (columns, datetime column estimation, date range, dimension/metric candidates), which precisely scopes the tool's function. It also distinguishes itself from the sibling metric_shift_localize by explicitly positioning this as the pre-check step.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description states exactly when to use the tool: before analysis and before calling metric_shift_localize. It explicitly recommends verifying column names and date range here prior to localization, giving clear workflow context. While it doesn't mention when not to use it, the recommendation is unambiguous.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

metric_shift_localize変化の要因分解A
Read-onlyIdempotent

「先週から売上(予約件数)が落ちた。どこで?」に答える。基準期間から曜日補正つきの予測値を作り、対象期間の実績との乖離がどの属性組合せ(例: 曜日=火 かつ 時間帯=夜、チャネル=web)に集中しているかを特定する。Squeeze(ISSRE 2019)アルゴリズムの独自実装。相関に基づく絞り込みであり因果の証明ではない。列名が不明な場合は先に metric_shift_inspect_data で確認すること。

ParametersJSON Schema
NameRequiredDescriptionDefault
rowsNoデータを直接渡す場合のオブジェクト配列(最大1000行)。file_path とは排他
deltaNo局在化の早期終了閾値δ(既定0.9)。通常は変更不要
measureYes分析する指標。件数なら "count"、金額などは数値列の名前(その列の合計を分析)
file_pathNoCSVファイルの絶対パス。ヘッダー行必須。UTF-8(BOM可)。rows とは排他
dimensionsYes分析の切り口(1〜6個)。列名、または予約語 __weekday__(曜日)/ __timeband__(時間帯)
target_periodYes対象期間(変化が起きた期間)
max_candidatesNo返す原因候補の最大数(既定3)
baseline_periodYes基準期間(正常だった頃)。1週間以上を推奨。対象期間と重複不可
datetime_columnNo日時列の名前。省略時は自動推定。対応形式: ISO 8601 / YYYY-MM-DD / YYYY/MM/DD(時刻付き可)
response_formatNo出力形式(既定markdown)。jsonは機械可読の全数値
timeband_boundariesNo__timeband__ の区切り時刻(既定: 朝6/昼11/夜17/深夜22)
top_n_per_dimensionNo集約時に次元ごとに保持する値の数(既定10)
merge_rare_categoriesNo希少カテゴリを「その他」に自動集約するか(既定true)。次元ごとに件数上位10を保持

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint, idempotentHint, and destructiveHint, so the safety profile is known. The description adds valuable behavioral context: the day-of-week correction, the Squeeze algorithm, and the explicit statement that results are correlation-based and not causal proof. No contradiction with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact—four sentences in Japanese—and front-loaded with the primary purpose. Each sentence adds meaningful information: the question answered, the method (prediction + deviation), the algorithm/limitation, and a practical prerequisite. No unnecessary filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (13 parameters, nested objects, no output schema), the description adequately covers the core logic and usage context. It explains what the tool does and how to interpret results, though it does not describe the output format in detail. The prerequisite hint about the sibling tool rounds out the picture.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so each parameter's meaning is well-documented in the schema. The description adds extra semantic context by giving an example attribute combination (weekday=Tue AND timeband=evening) and by clarifying the role of dimensions/reserved words, which helps the agent map the analysis concept to parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description starts with a concrete question ('Where did sales drop?') and clearly states the tool's function: build a day-of-week-adjusted prediction from the baseline and identify attribute combinations where the deviation concentrates. It explicitly names the algorithm (Squeeze) and distinguishes itself from the sibling tool by directing users to metric_shift_inspect_data when column names are unknown.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description clearly frames the usage context—localizing where a metric change occurred. It explicitly mentions using metric_shift_inspect_data first if column names are unknown, which is a concrete alternative. It also includes a caution about correlation vs. causation, but does not enumerate additional when-not-to-use scenarios.

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.

  1. 2 tool updatesv0.1.0
    • First observedmetric_shift_inspect_data
    • First observedmetric_shift_localize

TDQS

A4.4/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have clearly distinct purposes: one inspects data to provide context (columns, date ranges, candidates), while the other performs the actual shift localization. There is no overlap or ambiguity between them.

Naming Consistency5/5

Both tools follow the exact same verb_noun pattern with a consistent prefix 'metric_shift_'. The names clearly indicate action (inspect/localize) and domain, making them predictable and easy to navigate.

Tool Count4/5

With only 2 tools, the server feels slightly thin but is well-scoped for a narrow, specialized purpose: metric shift analysis. The two tools cover the entire intended workflow (inspect then localize), so the count is appropriate for the niche.

Completeness4/5

The tool surface covers the essential workflow: inspection before localization, which is explicitly recommended. Minor gaps exist (e.g., no tool for comparing periods or exporting results), but for the stated purpose of answering 'where did the metric drop?', the coverage is sufficient.

Maintenance

ActivitySlowing
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    A
    quality
    C
    maintenance
    Enables comprehensive analysis of CSV files and SQLite databases through tools for statistics, correlations, anomaly detection, pivot tables, time series analysis, visualization, and automated insights discovery.
    16
    -
  • A
    license
    B
    quality
    B
    maintenance
    Statistical analysis, forecasting, and ML for business data (Shopify, Stripe, WooCommerce, eBay, GA4, Search Console). Upload a CSV or connect live data sources — ask a question in Claude or Cursor, get an interactive HTML report
    19
    2 npm
    7
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    Superhuman data-driven science. Allows agents to upload any tabular dataset, specify a target column, and get validated predictive patterns (with p-values, effect sizes, and context from literature) that surface feature interactions and subgroup effects you'd otherwise miss. Many discoveries already made, free for open data!
    14
    7
    MIT