
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 分