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
Visit Server

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured