MetaTrader5 MCP Server

MetaTrader5 MCP Server

Enables access to MetaTrader5 market data and trading functionality, including real-time quotes, historical OHLCV data, tick data, symbol information, and technical indicators for forex and other trading instruments.

Category
访问服务器

README

MetaTrader5 MCP Server

A Model Context Protocol (MCP) server that provides access to MetaTrader5 market data and trading functionality.

Features

  • Connect to MetaTrader5 terminal
  • Retrieve symbol information and market data
  • Get historical rates (OHLCV) for any timeframe
  • Access tick data and market depth (DOM)
  • Real-time market data streaming
  • Support for all major trading instruments

Installation

  1. Install MetaTrader5 terminal
  2. Install Python dependencies:
pip install -r requirements.txt

Configuration

Copy .env.example to .env and configure your MetaTrader5 credentials:

cp .env.example .env

Edit the .env file with your broker credentials (optional - you can also connect without pre-configured credentials).

Usage

Starting the MCP Server

python server.py

Available Tools

Market Data

  • get_symbols(search_term, limit) - Smart search for trading symbols (CSV output)
  • get_symbol_groups(search_term, limit) - Get available symbol groups (CSV output)
  • get_symbol_info(symbol) - Get detailed symbol information
  • get_rates(symbol, timeframe, candles, start_datetime, end_datetime, ohlcv, ti) - Get historical OHLCV data in CSV format
  • get_ticks(symbol, count, start_datetime) - Get tick data in CSV format
  • get_market_depth(symbol) - Get market depth (DOM)
  • get_indicators() - List indicators (CSV: name,category)
    • Indicator params + full help (JSON)

Example Usage

The server automatically connects to MetaTrader5 when any tool is called. Connection credentials can be configured via environment variables or the server will use the terminal's current login.

# Get all available symbol groups from MT5
groups = get_symbol_groups()

# Get all visible symbols (no search term)
all_symbols = get_symbols()

# Smart search: Find symbols containing "EUR" (EURUSD, JPYEUR, etc.)
eur_symbols = get_symbols(search_term="EUR", limit=20)

# Search by group: Find all major forex pairs
majors = get_symbols(search_term="Majors", limit=10)

# Limit number of results
eur_top5 = get_symbols(search_term="EUR", limit=5)

# Get symbol information
info = get_symbol_info("GBPUSD")

# Get EUR/USD hourly data
rates = get_rates("EURUSD", "H1", 100)

# Get tick data
ticks = get_ticks("EURUSD", 50)

Intelligent Symbol Search

The get_symbols function uses a smart 3-tier search strategy:

Search order:

  1. Group name match (e.g., Majors, Forex)
  2. Symbol name match (e.g., EUR → EURUSD, JPYEUR, ...)
  3. Description match (symbol or group path)

Parameters:

  • search_term: Optional search term. If omitted, lists visible symbols.
  • limit: Optional maximum number of symbols to return.

Response format:

  • CSV with header name,group,description and one row per symbol.

Date Inputs

Flexible date/time parsing powered by dateparser:

  • Accepts natural language (e.g., yesterday 14:00, 2 days ago)
  • Accepts common formats (e.g., 2025-08-29, 2025/08/29 14:30, 2025-08-29 14:30 UTC)
  • Times are interpreted and converted to UTC internally

Usage patterns for get_rates:

  • Only start_datetime: returns bars forward from the start (up to candles).
  • Only end_datetime: returns the last candles bars before the end.
  • Both start_datetime and end_datetime: returns bars within the range (ignores candles).

Quote Data Format

Historical rates and tick data are returned in compact CSV format with intelligent column filtering:

Historical Rates (get_rates)

By default returns: time,close (using ohlcv=["C"]).

Selecting OHLCV subset:

  • Use ohlcv as a list of letters from {O,H,L,C,V}; time is always included (V maps to tick_volume).
  • CLI examples: --ohlcv O C → time,open,close; --ohlcv V → time,tick_volume

Technical indicators via ti:

  • Pass a comma-separated list like: ti=sma(14),rsi(14),ema(50)
  • Supported basics: sma(length), ema(length), rsi(length), macd(fast,slow,signal), stoch(k,d,smooth), bbands(length,std)
  • Indicator columns are appended to the CSV after the requested OHLCV columns.

MCP structured payload example (preferred for programmatic clients):

  • Meaningful Data Check: Columns are included only if they have at least one non-zero value OR multiple different values
  • Space Efficiency: Empty/constant columns are automatically excluded to reduce response size
  • Consistency: Core OHLC columns (rates) and bid/ask columns (ticks) are always included

Response Format

Both functions return:

{
  "success": true,
  "symbol": "EURUSD",
  "timeframe": "H1",  // rates only
  "candles": 100,
  "csv_data": "time,open,high,low,close,tick_volume\n2025-08-29T14:00:00,1.16945,1.17072,1.16937,1.17017,2690\n..."
}

Timeframes

Supported timeframes for historical data (MetaTrader5):

  • Minutes: M1, M2, M3, M4, M5, M6, M10, M12, M15, M20, M30
  • Hours: H1, H2, H3, H4, H6, H8, H12
  • Days/Weeks/Months: D1, W1, MN1

Requirements

  • Windows OS (MetaTrader5 requirement)
  • MetaTrader5 terminal installed
  • Python 3.8+
  • Active internet connection for real-time data

Error Handling

All functions return structured responses with success/error status:

{
    "success": True/False,
    "data": {...},  # on success
    "error": "Error message"  # on failure
}

Security Notes

  • Store credentials securely in environment variables
  • Use demo accounts for testing
  • Never commit credentials to version control
  • Consider using read-only API access where possible

License

MIT License

推荐服务器

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

官方
精选