Codex CLI · Setup
Backtest from Codex CLI
OpenAI's Codex CLI supports MCP via its mcp_servers config block. Point it at Bagtester and the agent gets a 14-tool backtesting surface — submit, optimize, walk-forward, compare, manage subscription.
Setup
Get an API key
Sign up at bagtester.com/sign-up. Create a key in the dashboard — it starts with bag_.
Edit your Codex config
Open ~/.codex/config.toml and add a new MCP server block:
[mcp_servers.bagtester] type = "http" url = "https://bagtester.com/api/mcp" [mcp_servers.bagtester.headers] Authorization = "Bearer bag_YOUR_KEY_HERE"
If you prefer per-project config, drop the same block into your repo's.codex/config.toml.
Verify the connection
Start a Codex session and ask:
list bagtester tools
The agent should enumerate all 14 tools.
Run a backtest
backtest an RSI mean-reversion strategy on ETHUSDT for 2024-2025
Codex writes the strategy, calls submit_strategy, and reads the structured result back. You see metrics + sparkline + share URL right in the terminal.
Tips for Codex specifically
- Use approval mode for the first run. Codex's approval mode prompts you before each MCP call so you can see the args. Switch to auto once you trust the flow.
- Bearer header goes under [mcp_servers.NAME.headers]. Codex parses this section as a string map; the leading dot in
mcp_servers.bagtester.headersmatters. - If MCP discovery fails, restart Codex. The CLI caches the MCP capability ad on startup. Re-running
codexwith the new config block re-fetches it.
Try it
Free tier: 500 credits/month. Add the block above to ~/.codex/config.toml and ask Codex to run a backtest.