alpha-forge-mcp
OfficialThe alpha-forge-mcp server exposes the AlphaForge quantitative trading CLI to AI agents via the Model Context Protocol (MCP), enabling a full quant strategy development pipeline from data fetching to TradingView export.
Strategy Management
List, retrieve, and register trading strategies using their JSON definitions (
list_strategies,get_strategy,save_strategy)Apply optimization results to create optimized strategy variants (
apply_optimization)
Backtesting & Results
Fetch and cache historical OHLCV market data (
fetch_data)Run backtests on historical data (
run_backtest)List and retrieve saved backtest results with metrics and trade data (
list_results,get_result)
Optimization & Validation
Optimize strategy parameters using Optuna TPE for metrics like Sharpe, Sortino, Calmar, Win Rate, etc. (
run_optimize)Run walk-forward optimization for out-of-sample robustness (
run_walk_forward)Run Monte Carlo simulations to assess ruin probability, equity percentiles, and drawdown distribution (
run_monte_carlo)
Export & Diagnostics
Generate TradingView Pine Script v6 from strategies (
generate_pinescript)Check system readiness and authentication status (
forge_status)Get metadata for technical indicators like RSI, MACD (
get_indicator)
Journals & Exploration
Review strategy development history via journals (
list_journals,get_journal)View the optimization coverage map of explored vs. untried parameter combinations (
exploration_status)
Key Design Features
All tools return a uniform error envelope (
{ok, data, error}) for predictable error handlingRead-only tools are also exposed as MCP resources (
forge://...URIs) for@-mention accessLong-running tools (backtesting, optimization, data fetching) report progress notifications
Built-in MCP prompts (
backtest_and_review,optimize_and_verify) for guided workflows
Generates Pine Script v6 source code from AlphaForge strategies for use on TradingView.
Exports AlphaForge strategies to TradingView Pine v6 format for charting and automated trading.
alpha-forge-mcp
The MCP server for AlphaForge — the agent-native quant CLI: write strategies in JSON, optimize with Optuna TPE, validate with walk-forward, export to TradingView Pine v6. This server lets your AI agent drive the whole pipeline over MCP. → Try AlphaForge free
A Model Context Protocol (MCP) server that exposes the
AlphaForge alpha-forge CLI to AI coding agents — Claude Code, Cursor, Codex, and any
MCP-capable client — over stdio.
It is a thin open-source wrapper: it shells out to the (commercial, closed-source)
alpha-forge binary with --json and returns the parsed result. The MCP server itself
contains no core logic — alpha-forge plus a valid license are required for anything to
actually run.
Tools
Tool | What it does | Underlying command |
| List registered strategies |
|
| Full JSON of one strategy |
|
| List saved backtest results |
|
| Metrics of one result (heavy arrays folded into counts by default; |
|
| Run a backtest ( |
|
| Optimize parameters (Optuna) |
|
| Apply an optimization result file to a strategy |
|
| Walk-forward (out-of-sample) optimization |
|
| Monte Carlo from a saved result |
|
| Fetch & cache historical OHLCV (prereq for |
|
| Register a strategy from its JSON body |
|
| Generate Pine Script v6 source |
|
| Report capabilities/prerequisites (doctor + version) |
|
| List strategies that have a journal |
|
| Full journal (snapshots, runs, tags, notes) of one strategy |
|
| Strategy-exploration coverage map (explored vs. untried) |
|
| Metadata for one technical indicator |
|
save_strategy takes the strategy-definition JSON body as a string (not a file path,
which is more agent-friendly); it is written to a temp file before strategy save.
fetch_data exposes only period because the CLI has no --start/--end. forge_status
is read-only and never fails when the binary is missing — it returns binary_found: false
so a client can triage prerequisites before doing anything else.
run_optimize saves the result by default (save=true) so its saved_path can be passed
to apply_optimization, which applies the optimized parameters and saves
<strategy_id>_optimized (it runs non-interactively with --yes). get_indicator returns
indicator metadata only (description, parameters, output) — the CLI has no
compute-over-symbol command, so it does not calculate the indicator on price data.
journal/explore reads are exposed read-first; write-oriented and ml/pairs commands are not
exposed yet.
The metric argument of run_optimize / run_walk_forward is a constrained enum
(sharpe_ratio (default), sortino_ratio, calmar_ratio, total_return_pct, cagr_pct,
profit_factor, win_rate_pct, expectancy_pct, omega_ratio) so clients can pick a
valid optimization target without guessing. This enum is intentionally narrower than the
alpha-forge CLI's --metric, which accepts a wider set — it is curated to the
bigger-is-better metrics that make sense as an optimization objective. trials defaults to
200 (the optimizer default). Each tool's description states its prerequisite (e.g.
run_backtest needs fetch_data first; apply_optimization needs a run_optimize(save=true)
result) and its follow-up.
Every argument also carries an inputSchema description, plus examples and
constraints where they help: symbol shows exchange notation (AAPL, ^VIX, CL=F,
USDJPY=X, BTC-USD), start / end advertise the YYYY-MM-DD pattern (format: date),
trials / windows / simulations carry minimum: 1, and save_strategy(json_body) /
apply_optimization(result_file) spell out "JSON body, not a path" vs "path, not inline
JSON". Malformed arguments are rejected at the MCP boundary by schema validation.
The text-only (non---json) CLI wrappers return structured fields rather than only
prose: apply_optimization adds applied_strategy_id (<strategy_id>_optimized, ready to
pass to generate_pinescript), save_strategy returns the registered strategy_id, and
fetch_data returns the fetched row count as rows (the raw output text is always kept).
Server instructions & long-running jobs
The server advertises instructions (surfaced in the MCP initialize response) describing
the end-to-end workflow — forge_status → fetch_data → run_backtest → run_optimize
→ run_walk_forward → apply_optimization → generate_pinescript — so an agent knows
which tools to call and in what order.
The run/fetch/save/apply tools are long-running (run_backtest up to 300 s, run_optimize
/ run_walk_forward up to 600 s, others bounded by the default timeout — stated in each
tool's description). They report progress to capable clients via MCP progress
notifications (a start → complete bracket; the underlying alpha-forge subprocess does
not expose intermediate progress) and run the blocking call off the event loop so the
server stays responsive. The timeout is enforced by alpha-forge; on expiry the tool
returns the timeout error code, which is safe to retry.
All tools carry MCP tool annotations (readOnlyHint for the read tools — the list/
get lookups, generate_pinescript, forge_status, list_journals, get_journal,
exploration_status, and get_indicator; openWorldHint for the run/write tools —
run_backtest / run_optimize / run_walk_forward / run_monte_carlo, plus
fetch_data (fetches external market data), save_strategy and apply_optimization
(write to the DB)) and return structured output — structuredContent with an object
outputSchema — alongside the text result.
Error envelope
Every tool returns a uniform error envelope as its (always-successful) result rather than raising, so an agent can branch on the failure category mechanically instead of parsing free text:
Success:
{"ok": true, "data": { ...alpha-forge JSON... }, "error": null}Failure:
{"ok": false, "data": null, "error": {"code": "<category>", "message": "<summary>", "detail": "<raw context>"}}
error.code is the machine-readable failure category — e.g. forge_not_found (binary
missing → guide setup), authentication_required (run alpha-forge system auth login),
freemium_blocked (premium-only feature → stop), strategy_not_found, timeout (safe to
retry), bad_output, execution_failed. error.message is a one-line summary; error.detail
carries the raw context (forge stderr or the de-decorated freemium panel body, including the
upgrade URL) when there is any, otherwise null. The outputSchema reflects this ok /
data / error shape.
Related MCP server: FinClaw
Resources
Read-only data is also exposed as MCP resources, so clients such as Claude Code can
reference them by @-mention without an explicit tool call. They delegate to the same
alpha-forge commands as the read tools and return application/json.
Resource URI | Payload |
| All registered strategies |
| One strategy definition |
| All saved backtest results |
| Metrics & trades of one result |
| All strategies that have a journal |
| Full journal (snapshots, runs, tags, notes) of one strategy |
| Strategy-exploration coverage map (default goal) |
| Metadata for one technical indicator |
These mirror the read tools list_journals / get_journal / exploration_status /
get_indicator. There is no forge://indicators collection resource because the CLI's
indicator list is not wrapped as a tool/client method yet (only get_indicator is).
Prompts
Reusable workflows are exposed as MCP prompts (surfaced as
/mcp__alpha-forge__<name> slash commands in Claude Code):
Prompt | Arguments | What it does |
|
| Run a backtest, then review the key metrics and red flags |
|
| Optimize with Optuna, then check the result for overfitting |
Streamable HTTP transport, RBAC, rate limiting, and audit logging are planned for a later release.
Prerequisites
The
alpha-forgebinary must be installed and on yourPATH(or setALPHA_FORGE_BIN).You must be authenticated: run
alpha-forge system auth loginonce.Python 3.11+ (only needed if not using
uvx).
Install & run
The recommended way is via uvx — no manual install needed;
your IDE launches it on demand.
uvx alpha-forge-mcp # starts the stdio MCP serverOr install explicitly:
pip install alpha-forge-mcp
alpha-forge-mcpClaude Code
The easiest way is the claude mcp add command (user scope — available in every project):
claude mcp add --scope user alpha-forge -- uvx alpha-forge-mcpAlternatively, add the server to a project-scoped .mcp.json at the repository root
(checked in and shared with your team):
{
"mcpServers": {
"alpha-forge": { "command": "uvx", "args": ["alpha-forge-mcp"] }
}
}Note: Claude Code does not read
~/.claude/mcp.json. User-scoped servers are stored in~/.claude.json(managed byclaude mcp add); project-scoped servers live in.mcp.jsonat the project root.
Cursor / Codex
Use the same command / args in the client's MCP server configuration:
{
"mcpServers": {
"alpha-forge": { "command": "uvx", "args": ["alpha-forge-mcp"] }
}
}If alpha-forge is installed at a non-standard location, pass it via env:
{
"mcpServers": {
"alpha-forge": {
"command": "uvx",
"args": ["alpha-forge-mcp"],
"env": { "ALPHA_FORGE_BIN": "/path/to/alpha-forge" }
}
}
}Troubleshooting
forge_not_found— ensurealpha-forge(or legacyforge) is onPATH, or setALPHA_FORGE_BIN=/path/to/alpha-forge.authentication_required— runalpha-forge system auth login. The MCP server does not store credentials; it relies onalpha-forge's own auth.
Development
uv sync --extra dev
uv run pytest
uv run ruff check .Forge binary discovery order: ALPHA_FORGE_BIN → PATH (forge, alpha-forge) → OS
default install paths.
License
Available Tools
17 toolsapply_optimizationA
Apply an optimization result file to a strategy, saving <strategy_id>_optimized.
Prerequisite: run_optimize(save=true) — result_file is its `saved_path`. Runs
non-interactively (--yes). Returns {result_file, strategy_id, output}. Follow up by
generating Pine Script for `<strategy_id>_optimized`. Reports progress to capable
clients; has an execution timeout.
Inputs: result_file (required), strategy_id (required). Returns: ok, data, error
exploration_statusARead-onlyIdempotent
Show the strategy-exploration coverage map (explored vs. untried combos).
Optional `goal` filters by exploration goal; defaults to the "default" goal.
Inputs: goal. Returns: ok, data, error
fetch_dataA
Fetch & cache historical OHLCV for symbol (prerequisite for run_backtest).
period is e.g. 1y / 5y / 6m / 30d / max (defaults to 1y). Returns {symbol, period,
output}. The CLI has no --start/--end, so only period is exposed. Run this before
run_backtest. Reports progress to capable clients; has an execution timeout.
Inputs: symbol (required), period. Returns: ok, data, error
forge_statusARead-onlyIdempotent
Report alpha-forge capabilities/prerequisites before use (doctor + version).
Read-only triage: returns {binary_found, version, authenticated, plan, doctor, error}.
Never fails when the binary is missing — returns binary_found=false instead.
Inputs: no named parameters. Returns: ok, data, error
generate_pinescriptBRead-onlyIdempotent
Generate TradingView Pine Script v6 for a strategy. Returns {strategy_id, pinescript}.
Inputs: strategy_id (required), with_webhook. Returns: ok, data, error
get_indicatorARead-onlyIdempotent
Get metadata for a technical indicator (description, parameters, output, example).
`indicator` is the indicator name (e.g. RSI, MACD). This is metadata only — the CLI
has no compute-over-symbol command — so it does not run a calculation on price data.
Inputs: indicator (required). Returns: ok, data, error
get_journalARead-onlyIdempotent
Get the full journal (snapshots, runs, tags, notes) for a strategy_id.
Inputs: strategy_id (required). Returns: ok, data, error
get_resultARead-onlyIdempotent
Get metrics and trades for a saved backtest result (result_id = strategy_id or run_id).
Inputs: result_id (required). Returns: ok, data, error
get_strategyARead-onlyIdempotent
Get the full JSON definition of a registered strategy by its strategy_id.
Inputs: strategy_id (required). Returns: ok, data, error
list_journalsARead-onlyIdempotent
List strategies that have a journal (history of snapshots and runs).
Inputs: no named parameters. Returns: ok, data, error
list_resultsARead-onlyIdempotent
List saved backtest results, optionally filtered by strategy_id.
Inputs: strategy_id. Returns: ok, data, error
list_strategiesARead-onlyIdempotent
List all registered AlphaForge strategies (strategy_id, name, version, timeframe).
Inputs: no named parameters. Returns: ok, data, error
run_backtestA
Run a backtest for symbol with a registered strategy. Optional dates are YYYY-MM-DD.
Prerequisite: call `fetch_data` for the symbol first so the OHLCV cache exists.
Long-running: up to a 300-second timeout; reports progress to capable clients.
Inputs: symbol (required), strategy_id (required), end, start. Returns: ok, data, error
run_monte_carloA
Run a Monte Carlo simulation from a saved backtest result (resamples its trades).
Prerequisite: a saved result (run_backtest/run_optimize with save) — result_id =
strategy_id or run_id. simulations defaults to 1000. Returns ruin probability, equity
percentiles, and drawdown distribution for risk assessment.
Long-running: reports progress to capable clients; has an execution timeout.
Inputs: result_id (required), simulations. Returns: ok, data, error
run_optimizeA
Optimize strategy parameters with Optuna for symbol. metric defaults to sharpe_ratio.
save defaults to true so the result JSON is persisted (with `saved_path` in the
response) and can be fed to `apply_optimization`; pass save=false to skip saving.
Long-running: up to a 600-second timeout; reports progress to capable clients.
Inputs: symbol (required), strategy_id (required), save, metric, +1 more. Returns: ok, data, error
run_walk_forwardA
Run walk-forward optimization for symbol (out-of-sample robustness check).
windows defaults to 5, metric to sharpe_ratio. Run it after run_optimize to compare
in-sample vs out-of-sample behaviour (the optimize_and_verify workflow).
Long-running: up to a 600-second timeout; reports progress to capable clients.
Inputs: symbol (required), strategy_id (required), metric, windows. Returns: ok, data, error
save_strategyA
Register a strategy from its JSON body (not a file path; agent-friendly).
Pass the full strategy-definition JSON as a string; it is validated as a JSON object
and written to a temp file before `strategy save`. Returns {output}. A registered
strategy is the prerequisite for run_backtest/run_optimize. Reports progress to
capable clients; has an execution timeout.
Inputs: json_body (required). Returns: ok, data, error
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 17 tools
Most tools have distinct purposes. run_optimize and run_walk_forward both optimize but are differentiated by description (single vs. walk-forward). get_result, get_strategy, and get_journal serve different retrieval needs. Minor overlap but clear descriptions guide selection.
Tools predominantly follow verb_noun pattern with underscores (e.g., run_backtest, get_strategy). One tool, exploration_status, uses noun_noun, breaking the pattern slightly. Overall consistent and readable.
17 tools are well-scoped for a quantitative backtesting platform, covering data fetching, strategy management, backtesting, optimization, Monte Carlo, walk-forward, and results. Each tool has a clear role without bloat.
The tool surface covers the full lifecycle from data fetch to strategy registration, backtesting, optimization, and result analysis. Minor gaps like missing delete/update tools for strategies or results, but core workflows are intact.
Maintenance
Related MCP Connectors
MCP server for OpenMM — exposes market data, account, trading, and strategy tools to AI agents
MCP server exposing the Backtest360 engine API as tools for AI agents.
Trading MCP server for AI agents, with live market data, account reads and controlled execution.
Official Intrinio MCP server. US stock prices, options and fundamentals for AI agents.
Related MCP Servers
- AlicenseBqualityAmaintenanceMCP server that lets AI agents directly control and interact with the TradingView desktop app via 88 chart-control tools, enabling automated chart reading, Pine Script compilation, strategy optimization, and replay control.11347 npm60MIT
- AlicenseNot gradedqualityDmaintenanceMCP server that provides AI agents with financial tools including real-time quotes, backtesting, technical analysis, and multi-exchange data via a simple CLI interface.2MIT
- FlicenseNot gradedqualityDmaintenanceEnables quant research, strategy generation, backtesting, and paper trading from natural language prompts, integrating with AI agents via an MCP server.24-
- AlicenseBqualityDmaintenanceLocal-first MCP server for building and running reproducible Backtrader strategies offline, with tools to inspect datasets, manage drafts, and execute backtests via controlled subprocess runs. It supports multiple hosts including Claude, Codex, OpenCode, and OpenClaw through stdio.301MIT