MCP Trading Agent

MCP Trading Agent

Enables an AI agent to perform live demo trading analysis using market data, news, backtesting, breakout scanning, and persistent trading knowledge tools.

Category
访问服务器

README

MCP Trading Agent v3.0 — ICT / SMC + News Sentiment

======================================================

A production-ready MCP server exposing 13 market-data, news,

backtesting, and persistence tools to an LLM agent (Nexus v2).

The agent learns from backtests and applies those rules to

live analysis — compounding its edge over time.

Quick Start

-----------

1. Install dependencies:

pip install -r requirements.txt

2. Run the server (stdio transport for Claude Desktop / Claude Code):

python server.py

3. Or run with HTTP transport (for MCP Inspector / web):

set MCP_TRANSPORT=streamable-http

python server.py

4. Test with the MCP Inspector:

npx -y @modelcontextprotocol/inspector

# Then connect to http://localhost:8000/mcp

Claude Desktop Integration

--------------------------

Add this to your Claude Desktop config (~/.claude/config.json):

{

"mcpServers": {

"trading-agent": {

"command": "python",

"args": ["C:\Github\ai-company\mcp-trading-agent\server.py"]

}

}

}

Project Structure

-----------------

mcp-trading-agent/

├── server.py # 13 MCP tool registrations + entry point

├── config.py # ServerConfig dataclass (v2.0.0)

├── system_prompt.py # Nexus v2 persona — 7 command workflows

├── CLAUDE.md # Auto-loaded by Claude Code (same as above)

├── requirements.txt # mcp[cli], yfinance, ddgs, pandas, numpy

├── README.md # This file

├── v2_upgrade_walkthrough.md # Architecture & evolution docs

├── tools/

│ ├── market_data.py # 7 functions: OHLC, liquidity, backtest,

│ │ # intraday backtest, MTF fetch, breakout scan

│ ├── news.py # fetch_market_news (DuckDuckGo / ddgs)

│ ├── risk_reward.py # get_risk_to_reward_setup

│ └── persistence.py # HTML reports, lessons.md CRUD,

│ # sync_trading_knowledge (SHA-256 dedup)

└── data/ # Persistent state (auto-created on first run)

├── lessons.md # Knowledge base — rules learned from backtests

├── lessons.hashes # SHA-256 fingerprints for dedup sidecar

└── reports/ # HTML analysis reports (30-day auto-purge)

All 13 MCP Tools

----------------

v1 — Original (5 tools)

┌──────────────────────────────┬──────────────────────────────────────────┐

│ Tool │ Purpose │

├──────────────────────────────┼──────────────────────────────────────────┤

│ get_daily_ohlc │ Daily OHLCV candles (60-day default) │

│ get_intraday_ohlc │ Sub-daily candles (1m/5m/15m/30m/60m) │

│ identify_liquidity_pools │ Swing high/low detection (BSL / SSL) │

│ fetch_market_news │ DuckDuckGo news search (fundamental bias)│

│ get_risk_to_reward_setup │ RR ratio + quality verdict │

└──────────────────────────────┴──────────────────────────────────────────┘

v2 — Stateful / Backtest (6 tools)

┌──────────────────────────────┬──────────────────────────────────────────┐

│ Tool │ Purpose │

├──────────────────────────────┼──────────────────────────────────────────┤

│ get_historical_backtest_data │ Extended OHLCV w/ swing flags (10-500d) │

│ run_intraday_backtest │ Auto SMC scan: sweep+FVG, RR>=3, w-fwd │

│ manage_html_report │ Save HTML + auto-open browser + 30d purge│

│ read_lessons_learned │ Read lessons.md knowledge base │

│ update_lessons_learned │ Append free-form insights to lessons.md │

│ sync_trading_knowledge │ SHA-256 dedup + persist structured rules │

└──────────────────────────────┴──────────────────────────────────────────┘

v3 — Breakout Scanner (2 tools)

┌──────────────────────────────┬──────────────────────────────────────────┐

│ Tool │ Purpose │

├──────────────────────────────┼──────────────────────────────────────────┤

│ get_multi_timeframe_data │ Monthly + Weekly + Daily OHLC in one call│

│ scan_for_breakout │ 1-10 score across M/W/D timeframes │

└──────────────────────────────┴──────────────────────────────────────────┘

Agent Commands (plain-text, not slash commands)

-----------------------------------------------

Command Data Source

──────────────────────────────────────────────────────────────────

backtest [ticker] [days] get_historical_backtest_data

backtest intraday [ticker] [days] [intv] run_intraday_backtest

analyze [ticker] get_daily_ohlc + liquidity

entry [ticker] (runs analyze silently first)

intraday [ticker] get_intraday_ohlc — 1:3 RR gate

view [ticker] get_daily_ohlc — macro swing

breakout [ticker or list] get_multi_timeframe_data +

scan_for_breakout

Example session:

backtest intraday NIFTY 60 15m

→ automated SMC scan, equity curve HTML, rules saved to lessons.md

intraday NIFTY

→ live 15m analysis with 1:3 RR gate, HTML report auto-opened

breakout NIFTY, BTC, GOLD

→ D/W/M alignment matrix, conviction scores, trigger prices

analyze AAPL

→ fundamental + technical confluence, HTML report

entry AAPL

→ tight trade card: entry / SL / target / RR / verdict

Breakout Scoring (scan_for_breakout)

-------------------------------------

Scoring breakdown (10 pts max):

Monthly (3 pts): price > EMA-6, near BSL <= 5%, 2/3 months bullish

Weekly (3 pts): price > EMA-20, volatility contraction, near BSL <= 3%

Daily (4 pts): price > EMA-20, displacement candle, FVG present,

volume spike >= 1.3× 20-day avg

Conviction tiers:

8-10 HIGH (high_conviction_confirmed when M + W both BULLISH)

5-7 MODERATE (Watch and Wait)

1-4 LOW (no confluence)

Trigger price = nearest daily BSL above current price.

Supported Ticker Aliases

------------------------

NIFTY → ^NSEI, BANKNIFTY → ^NSEBANK, SENSEX → ^BSESN,

SPX → ^GSPC, SPY → SPY, QQQ → QQQ, DXY → DX-Y.NYB,

GOLD → GC=F, CRUDE → CL=F, BTC → BTC-USD, ETH → ETH-USD

Intraday Backtest — What run_intraday_backtest Returns

-------------------------------------------------------

Per-trade fields:

setup_type, direction, sweep_time, session_label, hour,

swept_level, fvg_zone, entry, stop_loss, target,

risk_pts, reward_pts, rr, atr_at_setup, is_consecutive_sweep,

outcome (WIN/LOSS/OPEN), exit_price

Aggregate stats:

win_rate_pct, avg_rr, profit_factor, max_drawdown_r,

expectancy_r, equity_curve (R-multiple list), session_breakdown

session_breakdown keys (Opening/Morning/Midday/Afternoon/Closing):

total, wins, losses, open_trades, win_rate_pct

Knowledge Persistence

---------------------

lessons.md is automatically maintained across sessions.

sync_trading_knowledge uses SHA-256 fingerprints stored in

lessons.hashes to prevent near-duplicate rules accumulating.

HTML reports older than 30 days are auto-purged by manage_html_report.

License: MIT

推荐服务器

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 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

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

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

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

官方
精选
TypeScript
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 模型以安全和受控的方式获取实时的网络信息。

官方
精选