Uses .env files for configuration management, allowing secure storage of MetaTrader5 broker credentials through environment variables.
Leverages pandas_ta library to provide technical indicators (SMA, EMA, RSI, MACD, Stochastic, Bollinger Bands) for market data analysis and charting.
Provides access to MetaTrader5 terminal functionality including market data retrieval, historical rates, tick data, symbol information, and real-time market streaming through Python integration.
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
- Install MetaTrader5 terminal
- Install Python dependencies:
Configuration
Copy .env.example
to .env
and configure your MetaTrader5 credentials:
Edit the .env
file with your broker credentials (optional - you can also connect without pre-configured credentials).
Usage
Starting the MCP Server
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 informationget_rates(symbol, timeframe, candles, start_datetime, end_datetime, ohlcv, ti)
- Get historical OHLCV data in CSV formatget_ticks(symbol, count, start_datetime)
- Get tick data in CSV formatget_market_depth(symbol)
- Get market depth (DOM)get_indicators()
- List supported technical indicators (dynamic from pandas_ta)
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.
Intelligent Symbol Search
The get_symbols
function uses a smart 3-tier search strategy:
Search order:
- Group name match (e.g.,
Majors
,Forex
) - Symbol name match (e.g.,
EUR
→ EURUSD, JPYEUR, ...) - 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 tocandles
). - Only
end_datetime
: returns the lastcandles
bars before the end. - Both
start_datetime
andend_datetime
: returns bars within the range (ignorescandles
).
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,open,high,low,close
, and optionally tick_volume,spread,real_volume
if meaningful.
Selecting OHLCV subset:
- Use
ohlcv
with letters from{O,H,L,C,V}
to choose columns (time is always included). - Examples:
ohlcv=OC
→ 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.
Note: spread
and real_volume
columns excluded because they contained only zeros
Tick Data (get_ticks
)
Core columns: time,bid,ask
(always included)
Optional columns: last,volume,flags
(included only if they contain meaningful data)
Note: last
, volume
, and flags
columns excluded because they contained no meaningful data
Intelligent Column Filtering
- 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:
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:
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
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
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.
Related MCP Servers
- AsecurityAlicenseAqualityProvides real-time and historical cryptocurrency market data through integration with major exchanges. This server enables LLMs like Claude to fetch current prices, analyze market trends, and access detailed trading information.Last updated -754MIT License
- AsecurityFlicenseAqualityProvides real-time cryptocurrency price data from OKX exchange through a Model Context Protocol interface, allowing access to historical candlestick data and current market prices for any trading instrument.Last updated -2813
Twelve Data MCP Serverofficial
AsecurityAlicenseAqualityProvides integration with Twelve Data API to access financial market data including historical time series, real-time quotes, and instrument metadata for stocks, forex pairs, and cryptocurrencies.Last updated -3530MIT License