
Leakguard Mcp
io.github.doazvjettu由 GitHub 帳號 doazvjettu 發布v0.1.1更新於 Oct 25, 2026
Static analyzer flagging lookahead bias & data leakage in ML/trading code before backtest.
概覽
一個本機 MCP 伺服器,對 Python 時間序列與交易程式碼做靜態分析,在回測執行前標記前視偏差與資料外洩。
- 可以做什麼
- 分析程式碼字串、單一檔案或符合萬用字元的路徑,回傳含嚴重等級與修正片段的發現。列出全部十條內建規則,並說明任一規則的原理與修正模式。發現結果為啟發式,分為錯誤與警告兩級,方便代理在同一輪對話中自行修正。
- 適用情境
- 適合在 AI 代理撰寫特徵工程、預測或量化策略 Python 程式碼時,於回測前找出外洩問題。也可透過隨附的命令列工具作為提交前或 CI 檢查。
- 執行需求
- 本機 Python 3.11 以上程序,從 PyPI(leakguard-mcp)或原始碼安裝,需要 uv 或 pip。透過 stdio 執行,需在 Claude Code 或 Cursor 等用戶端的 MCP 設定中配置。不需 API 金鑰、帳號或網路存取。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Leakguard Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
leakguard-mcp
[PyPI] [Python] [License: MIT] [release] [MCP registry] [glama]
Squawk for backtests. A local-first MCP server that static-analyzes agent-generated Python code and flags lookahead bias & data leakage before the backtest runs.
Works for any time-series ML code — quant trading (crypto, equities, forex, futures),
demand forecasting, energy, weather, IoT sensors — wherever a wrong .shift() or a
global normalization silently poisons your results.
- Pure source analysis (libcst) — your code never leaves the machine, no API calls.
- Heuristic, not a proof: severity tiers (🔴 error / 🟡 warning), like an aviation squawk.
- Framework-agnostic: pandas / numpy / polars, any stack.
- MCP-native (stdio): works directly inside Claude Code, Cursor, and any MCP-compatible agent.
- All 10 rules ship free — no license, no tiers, no phone-home.
[leakguard flagging three lookahead leaks in a strategy file]
Why this exists
AI agents (Claude Code, Cursor) write feature engineering and strategy code faster than humans can review it. But they introduce lookahead bias at scale — subtle time-boundary errors that backtest perfectly and fail catastrophically in live trading or production:
leakguard catches these in the same agent loop — before the backtest runs:
The agent reads the finding + fix snippet and self-corrects in one turn. No human review needed.
Install
Requirements
- Python 3.11+
- uv (recommended) or pip
From PyPI
From source
Setup with Claude Code
Add to your MCP config (~/.claude/claude_desktop_config.json or .claude/settings.json
in your project):
Or if installed via uv:
Restart Claude Code. leakguard's tools are now available to the agent.
Setup with Cursor
Add the same block under mcpServers in your Cursor MCP settings file.
MCP Tools
CLI
The same scanner is available as a CLI — handy for a pre-commit hook or CI step (exits non-zero when leakage is found):
It prints each finding with its severity, line/col, and a concrete fix snippet — the same output shown in the demo above.
Rules
All 10 rules active, no tiers:
Each finding includes a concrete fix snippet so the calling agent can self-correct immediately.
Benchmark
Measured on two labeled corpora, 49 snippets total.
Reproduce with uv run python -m benchmark.run.
Honesty note: the trading corpus was written by the tool's author — treat its numbers as regression fixtures, not independent validation. The general-ML corpus is one arm's length removed in domain (author-composed reproductions of widely documented leakage anti-patterns, not a downloaded public dataset). The corpus deliberately includes adversarial snippets the scanner is known to miss; they are counted against it.
Trading corpus — 39 snippets (23 leaky, 16 clean + hard negatives):
General-ML corpus — 10 snippets (LG003/LG004/LG010): Precision 88%, Recall 100% (TP 7 / FP 1 / FN 0).
Combined: Precision 90.4%, Recall 100% (TP 47 / FP 5 / FN 0).
Recall is 100% on this corpus — every adversarial miss exposed has since been fixed
(constant propagation, hand-rolled normalization, cv=<int>, drop-based selection).
Leak shapes not yet in the corpus are still missed — see Known Limitations below.
Known false positives (clean code that gets flagged)
- LG001: a forward-return label built with a negative shift and used only as
y— pure AST cannot distinguish a target column from a feature. - LG003: fit inside a helper defined above the split call site — line-order heuristic confuses definition order with execution order.
- LG004: shuffled splits on genuinely non-temporal data — no datetime-index inference yet.
- LG009: resampling for reporting/plotting rather than features — intent is invisible to static analysis.
Known false negatives (leak shapes not yet covered)
- LG004:
cross_val_score(...)withcvomitted (defaults to KFold). - LG005: taint through
df.loc[:, 'col'] = ...ordf.assign(col=...). - All rules: values flowing through function calls, dicts, or non-constant variables — no cross-function dataflow.
These sets are pinned in tests/test_benchmark.py: any new miss or silent fix fails the
suite until docs and corpus are updated to match.
Develop
The scanner core lives in leakguard/core/ (pure, no MCP imports); server.py and
cli.py are thin wrappers. Each rule has a fixture pair under tests/fixtures/.
Limitations (v1)
- Heuristic static analysis — catches ~90% of common patterns, not 100%.
- Single-file only — no cross-module taint tracking.
- Python only (pandas / numpy / polars).
- No runtime execution — cannot catch patterns that only emerge at runtime.
Contributions welcome: new corpus snippets (especially real bugs you've hit) strengthen the benchmark more than new rules do.
來源:README.md,提交 17e278e
工具
0版本歷史
1- v0.1.1最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分