Litmus

Litmus

An MCP server that lets an AI agent backtest, risk-check, and audit trading strategies, determining if a strategy is overfit or actually works.

Category
访问服务器

README

🧪 Litmus

An MCP server that lets an AI agent backtest, risk-check, and audit trading strategies — the litmus test for whether your edge is real.

Point Claude (or Cursor, or any MCP client) at Litmus and ask: "Is this Freqtrade strategy overfit, or does it actually work?" — and get a real answer, backed by a backtest, a walk-forward analysis, and a static audit of the code. The model does the talking; Litmus does the maths.

<!-- Replace with a real screen recording: Claude calling audit_strategy on a broken strategy and getting a FAIL verdict. The GIF is the pitch — record it before launch. --> Litmus auditing a flawed strategy


Why

Most trading tools help you build strategies. Litmus exists to tell you the truth about them. A backtest is easy to fake without realising it — a stop-loss that never triggers, a feature that peeks at the next candle, a "high-frequency" idea that a polling framework can't actually run. Litmus catches those before they cost you money, and it does it from inside the AI agent you're already chatting with.

It's built on FastMCP, the standard framework for MCP servers. The server is free and open source; you only ever pay for your own model usage, because the inference runs in your client, not here.

Tools

Tool What it does
fetch_ohlcv Pull historical candles from any exchange via ccxt. Returns a dataset_id the other tools reuse.
backtest_strategy Backtest a built-in strategy net of fees and slippage. Returns net return vs buy & hold, Sharpe, drawdown, win rate, profit factor, expectancy.
walk_forward Optimise in-sample, measure out-of-sample, fold by fold. A big gap = overfit, not profitable. Returns a plain-language verdict.
risk_metrics Sharpe, Sortino, volatility, max drawdown, Calmar, VaR & CVaR (95% / 99%) from an equity curve or returns.
monte_carlo Project the range of futures a strategy implies (Box-Muller), with probability of loss and projected drawdowns.
audit_strategy The differentiator. Statically audits Freqtrade-style code for lookahead bias, cosmetic stop-losses, impossible timeframes, missing informative_pairs(), and oversized hyperopt surfaces. The code is parsed, never run.

Install

Requires Python 3.10+. Using uv (recommended):

git clone https://github.com/Spectrexf/litmus-mcp.git
cd litmus-mcp
uv venv && uv pip install -r requirements.txt

Or with pip:

pip install -r requirements.txt

Try it with no LLM

The MCP Inspector calls your tools directly, so you can test everything before wiring up a model:

fastmcp dev server.py

Connect to Claude Desktop

fastmcp install server.py

That patches your Claude Desktop config automatically. To do it by hand instead, add this to claude_desktop_config.json:

{
  "mcpServers": {
    "litmus": {
      "command": "python",
      "args": ["/absolute/path/to/litmus-mcp/server.py"]
    }
  }
}

Restart Claude Desktop and Litmus's tools appear.

Example prompts

Once connected, just talk to your agent:

  • "Audit this strategy for me" → paste a Freqtrade strategy, Litmus runs audit_strategy and returns a PASS/WARN/FAIL verdict with line numbers.
  • "Backtest a 20/50 moving-average cross on BTC/USDT daily and tell me if it beats buy and hold after costs."
  • "Is this strategy overfit?" → Litmus runs walk_forward and reports in-sample vs out-of-sample.
  • "Run a Monte Carlo on these returns — what's my probability of a losing year?"

See the audit catch real flaws

examples/flawed_strategy.py is a deliberately broken strategy. Feed its contents to audit_strategy and Litmus reports four blocking issues and two warnings: a sub-minute timeframe, a cosmetic stoploss = -0.99, two kinds of lookahead bias, a missing informative_pairs(), and a 10-parameter hyperopt surface.

Built-in strategies

So the agent can backtest without you writing a strategy class:

  • ma_cross — moving-average crossover. Params: fast, slow.
  • rsi_reversion — buy oversold, exit overbought. Params: period, lower, upper.
  • breakout — enter on N-bar high breakout. Params: lookback.

How it works

Plain Python, organised into small engine classes that the MCP tools delegate to:

server.py        FastMCP app — the 6 tools
market_data.py   MarketData    — ccxt wrapper (lazy-imported)
backtester.py    Backtester    — vectorised backtest + walk-forward, costs included
risk.py          RiskAnalyzer  — metrics + Monte Carlo (Box-Muller)
auditor.py       StrategyAuditor — AST-based static analysis

Fetched candles are cached server-side and referenced by dataset_id, so a 500-candle series never has to travel through the model's context twice.

Roadmap

  • [ ] Config auditor: catch shared-SQLite-DB collisions and other multi-bot Freqtrade footguns
  • [ ] More lookahead patterns (resampling leaks, .iloc[-1] misuse)
  • [ ] Custom strategy upload, not just built-ins
  • [ ] Equity-curve charts rendered inline via MCP Apps
  • [ ] Expose a strategy library as MCP resources

Contributing

Issues and PRs welcome — especially new audit rules. If you've been burned by a backtest that lied, encode the lesson here.

License

MIT © Adrián Llaca Mayo

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选