Shadowjoin

io.github.harsh-chandak由 GitHub 帳號 harsh-chandak 發布v0.3.2更新於 Oct 24, 2026

Measure the matches your exact join is silently dropping, and get the rule that fixes each.

已驗證STDIO僅桌面資料庫資料與分析

概覽

AI 產生的概覽

本機 MCP 伺服器,用來量測精確合併默默漏掉多少筆對應、解釋漏掉的原因,並建議可找回對應的正規化規則。

可以做什麼
量測兩個已設定資料來源之間的合併,回報漏失對應的下限,並附上可人工核對的樣本配對。解釋未對應的項目,區分機械性的正規化缺口與需要別名表的語意性缺口。建議正規化規則與貪婪規則組合,並在過度正規化導致找回更少時提出警告。比較多次執行,驗證所提修正是否真的改善合併。列出可用的正規化規則。
適用情境
適合管線依姓名、電子郵件、SKU 或公司名稱合併兩個資料來源,且懷疑有默默漏失的情況;也適合需要可重複、可在 CI 檢查的量測,而非臨時探索性 SQL 的場景,或用來判斷是否需要真正的實體解析函式庫。
執行需求
透過 npx 在本機執行(需要 Node.js;SQLite 需 Node 22.5+)。需要環境變數 SHADOWJOIN_CONFIG 指向設定檔的絕對路徑,檔案中列出資料來源及其連線字串。Postgres 與 MySQL 轉接器需要選用的 pg 或 mysql2 同儕套件;MCP 伺服器需要 Model Context Protocol SDK 同儕套件。對所掃描的資料來源需有讀取權限。
安裝前請注意
執行時會把合併鍵值讀入記憶體;去識別化只對樣本輸出做雜湊,並不能讓鍵不可見,受監管資料建議在副本上執行。連線字串存放在設定檔中,應使用唯讀角色;若該角色對目標資料表有寫入權限,它會拒絕執行。找回的對應可能有誤或有歧義,回報的數字是下限而非估計值。它只做量測,不會修改資料。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Shadowjoin,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

shadowjoin

Measure the matches your exact join is silently dropping.

Your pipeline joins two sources on a name, an email, a SKU, a company. It matches what matches. Everything else just... isn't there. No error, no exception, no alert — the query returns, the dashboard renders, and a quarter of the rows that should have matched quietly don't.

shadowjoin runs a shadow matcher alongside your real join key and tells you how many matches you are losing, which normalization rule would recover each one, and — if you have any ground truth at all — proves the recoveries are real.

npx shadowjoin scan \  --left  customers.csv   --left-key  company_name \  --right crm_export.csv  --right-key account_name

[shadowjoin measuring a country-name join: 205 of 249 matched exactly, which looks fine, while five real matches were being dropped including Vietnam, spelled Viet Nam by the UN]

Fourteen seconds, no sound. Every figure in it is verbatim CLI output from the committed example below — higher-resolution version.

The progress output above is real: shadowjoin shows what it is doing while it works. All of it is suppressed automatically when stdout is not a terminal, so piping to a file, to jq, or running in CI produces byte-identical output to before — and there is no postinstall script, because a tool you point at a production database has no business running code at install time.

What it found on public data

Joining the S&P 500 constituent list against NYSE + Nasdaq listings on company name. Both files carry ticker symbols, so every recovered match can be checked rather than believed:

  left rows 503   right rows 6,709
  exact join matches                1   0.2%  recovered by shadow join        428   85.09%  still unexplained                74
  LOWER BOUND ON LOST MATCHES: 85.09% of left rows  verified against ground truth: 419 correct, 1 wrong, 8 ambiguous  (precision 99.76%)
  rules worth adopting, in order (greedy by marginal recovery):  1.  strip security/listing boilerplate (common stock, ADS, ...)   +68       68  2.  strip corporate suffixes (inc, corp, ltd, plc, gmbh ...)     +319      387  3.  strip punctuation                                             +33      420  4.  sort tokens (order-insensitive match)                          +4      424  5.  remove all whitespace                                          +1      425

The exact join found one match. There were four hundred and twenty-eight, and 419 of them are confirmed correct by ticker.

Reproduce it yourself — the data ships with the repo:

bash
git clone https://github.com/harsh-chandak/shadowjoin && cd shadowjoinnpm install && npm run buildnode dist/cli.js scan \  --left  examples/sp500.csv    --left-key  Security --left-id Symbol --left-truth Symbol \  --right examples/listings.json --right-key name    --right-id symbol --right-truth symbol

A join you would actually ship

The example above is deliberately unflattering — a short index name against a full security description. Here is the realistic case.

Unicode CLDR country names (what your UI displays) joined to UN official country names (what your reference data uses), on the country name, with ISO 3166 alpha-3 as ground truth. That is a join people write every week.

  exact join matches              205 / 249   82.33%  recovered by shadow join          5          2.01%   precision 100%  still unexplained                39
  rules worth adopting:  1.  & -> and                 +4  2.  remove all whitespace    +1

It looks healthy. 82% matched, no errors, nobody investigating. And it is silently dropping Antigua & Barbuda, Trinidad & Tobago, São Tomé & Príncipe, Turks & Caicos Islands and Vietnam — the last one because the UN spells it Viet Nam.

Two things this example shows that the first one does not:

Applying every rule finds nothing. The full rule set recovers zero here; the two-rule subset recovers five. Over-normalization collapses keys that should stay distinct, and shadowjoin names the better subset instead of letting you assume more rules is better.

It separates mechanical misses from semantic ones. The 39 it cannot explain are not normalization problems at all:

  Vatican City    vs  Holy See  North Korea     vs  Democratic People's Republic of Korea  Cape Verde      vs  Cabo Verde  Bosnia          vs  Bosnia and Herzegovina  Hong Kong       vs  China, Hong Kong Special Administrative Region

No string transform recovers those. They need an alias table or a real entity resolution library. Knowing which of your misses are mechanical and which are semantic is the difference between a one-line fix and a project.

bash
node dist/cli.js scan \  --left  examples/countries_ui.csv        --left-key  country --left-truth  iso3 \  --right examples/countries_reference.csv --right-key country --right-truth iso3

That particular join is deliberately unflattering — a short index name against a full security description. It is a worked example of the measurement, not a claim that anyone ships that join. Point it at your own data to get a figure that means something about you.

The number is a floor, not an estimate

You cannot compute recall without labels. The entity-resolution literature calls the metric pair completeness, and it assumes an oracle you do not have in production.

So shadowjoin reports a lower bound: matches the shadow matcher found that exact matching missed. The shadow matcher has unknown recall of its own, so the true loss is at least this large and may be larger. Every figure ships with sample pairs so a human can verify them by hand, and when ground truth is available on both sides, the report carries a precision figure too.

This is deliberately the weaker claim. It is also the one that survives being questioned.

Why not just ask an LLM to check?

For a one-off look at a small table, do that — it is faster and this tool is redundant. It stops working when:

  • You need the same number twice. An agent writes different SQL every run, so you cannot tell whether the pipeline changed or the query did.
  • You need rules nobody thought of. Asked "is this join lossy," an agent tries lower() and trim(). It does not systematically try NFKD folding, diacritics, leading zeros, corporate suffixes, token reordering or listing boilerplate. The exhaustive rule set is the product.
  • You need it in CI. --max-loss exits non-zero. "Ask Claude" has no exit code.
  • Exploratory SQL on production is expensive. This does hash joins on precomputed keys, under a statement timeout, in a read-only transaction.

Install

bash
npm install shadowjoin      # or run it with npx, no install

Zero runtime dependencies. pg and @modelcontextprotocol/sdk are optional peers, pulled in only if you use the Postgres adapter or the MCP server.

Use it

CLI

bash
# CSV or JSON, no database involvednpx shadowjoin scan --left a.csv --left-key name --right b.json --right-key title
# with ground truth on both sides, so recoveries are verifiednpx shadowjoin scan \  --left  a.csv --left-key  name  --left-truth  customer_id \  --right b.csv --right-key title --right-truth customer_id
# straight at Postgresnpx shadowjoin scan \  --left  'postgres://ro@host/db' --left-table  orders    --left-key  customer_name \  --right 'postgres://ro@host/db' --right-table customers --right-key name
# in CI: fail the build if the floor climbs above 2%npx shadowjoin scan --left a.csv --left-key name --right b.csv --right-key name --max-loss 2
# MySQL and SQLite work the same waynpx shadowjoin scan \  --left  'mysql://ro@host/db' --left-table  accounts --left-key  company_name \  --right ./reference.sqlite   --right-table vendors  --right-key name
npx shadowjoin rules     # list the normalization rules

Sources: CSV, JSON, Postgres, MySQL and SQLite. SQLite uses Node's built-in node:sqlite (Node 22.5+), so it needs nothing installed; Postgres and MySQL need pg or mysql2, which are optional peers.

Anything else works through the library in three lines, because the core takes two arrays rather than a connection:

js
import { scan } from "shadowjoin";const [rows] = await anyDriver.query("SELECT id, company_name FROM accounts");const left = rows.map((r) => ({ id: String(r.id), key: r.company_name }));scan(left, right);

Library

js
import { scan, normalize, rulesByIds, toSql } from "shadowjoin";
const report = scan(leftRows, rightRows);        // rows are { id, key, truth? }console.log(report.lowerBoundLossPct, report.stack);
// adopt the recommended rules in your own pipelineconst rules = rulesByIds(report.stack.map((s) => s.rule));const key = (value) => normalize(value, rules);toSql("company_name", rules);                     // the same thing as Postgres SQL

Claude Code plugin (easiest)

One command installs the skill and the MCP server together, and prompts for your config path:

bash
claude plugin marketplace add harsh-chandak/shadowjoinclaude plugin install shadowjoin@harsh-chandak

Also listed in the official MCP registry as io.github.harsh-chandak/shadowjoin.

MCP server

Lets an agent measure a join, look at real examples, propose a fix, and then prove the fix worked — a loop it cannot fake, because the measurement is not something it writes.

json
{  "mcpServers": {    "shadowjoin": {      "command": "npx",      "args": ["-y", "-p", "shadowjoin", "-p", "@modelcontextprotocol/sdk", "shadowjoin-mcp"],      "env": { "SHADOWJOIN_CONFIG": "/abs/path/to/shadowjoin.config.json" }    }  }}
json
{  "sources": {    "prod":  { "type": "postgres", "connectionString": "postgres://shadowjoin_ro@host/db" },    "crm":   { "type": "csv",      "path": "./crm_export.csv" }  }}

Tools: scan_join, explain_misses, suggest_normalization, compare_runs.

Two things this MCP server deliberately does not have:

  1. No tool that executes arbitrary SQL. An agent can name a configured source, a table and a column. That is the entire surface.
  2. No tool that accepts a connection string. Credentials live in your config file and never enter a tool call, because tool calls end up in transcripts.

Pointing it at a real database

shadowjoin opens a READ ONLY transaction with statement_timeout, lock_timeout and idle_in_transaction_session_timeout set, and it refuses to run if the role it connected with can write to the table it is about to read.

Give it a role that makes trust unnecessary:

sql
CREATE ROLE shadowjoin_ro LOGIN PASSWORD 'xxx';GRANT CONNECT ON DATABASE yourdb TO shadowjoin_ro;GRANT USAGE  ON SCHEMA public    TO shadowjoin_ro;GRANT SELECT ON public.orders, public.customers TO shadowjoin_ro;

Point it at a replica where you can.

It makes no outbound network connection except to the source you give it. No telemetry, not even opt-out. Check the imports — there are three dependencies and none of them is an HTTP client.

Limits

Read these before quoting a number from it.

  • The figure is a floor. The shadow matcher's own recall is unknown. True loss is at least this, possibly more.
  • Recoveries can be wrong. In the bundled example, 1 of 428 was contradicted by ground truth and 8 were ambiguous — mostly share classes, where stripping "Class A" merges genuinely different securities. Ambiguous matches need a tie-breaker, not a normalization rule. Always read samplePairs.
  • Per-rule counts overlap and will not sum to the total. Each is measured independently against the exact baseline, deliberately, so the numbers are not an artifact of the order rules happen to run in. Use stack — the greedy ordering — to decide what to actually adopt.
  • More rules is not better. Applying every rule can recover fewer matches than the best subset, because over-normalization merges keys that should stay apart. shadowjoin warns when this happens and names the better subset.
  • It reads your join keys, so those values are in memory while it runs. --redact hashes them in sample output and server-side normalization keeps whole rows in the database, but neither makes the keys invisible. For regulated data, run it on a replica inside your own environment.
  • It does not write, fix or migrate anything. It measures.
  • unaccent in emitted SQL needs the Postgres extension of the same name.

Prior art

Blocking recall — pair completeness — is well established in the entity-resolution literature, along with its companions pairs quality and reduction ratio:

Those papers assume a labelled gold standard. shadowjoin's contribution is not the metric — it is computing a defensible version of it against a live pipeline with no labels at all, and reporting it as a bound rather than a point estimate.

For doing the matching rather than measuring what yours misses, use Splink, Dedupe or recordlinkage. shadowjoin is complementary: it tells you whether you need them.

License

MIT © Harsh N. Chandak

來源:README.md,提交 adf3faf

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

2
  1. v0.3.2最新Oct 17, 2026
  2. v0.3.1Oct 11, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分