Skip to main content
Glama

MetaTrader5 MCP Server

by emerzon

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 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.

# 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)

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,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.
time,open,high,low,close,tick_volume 2025-08-29T14:00:00,1.16945,1.17072,1.16937,1.17017,2690 2025-08-29T15:00:00,1.17017,1.17089,1.16964,1.16986,2156

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)

time,bid,ask 2025-08-29T15:30:15.123,1.16983,1.16985 2025-08-29T15:30:16.456,1.16982,1.16986

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:

{ "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

-
security - not tested
F
license - not found
-
quality - not tested

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.

  1. Features
    1. Installation
      1. Configuration
        1. Usage
          1. Starting the MCP Server
          2. Available Tools
          3. Example Usage
        2. Intelligent Symbol Search
          1. Date Inputs
            1. Quote Data Format
              1. Historical Rates (get_rates)
              2. Tick Data (get_ticks)
              3. Intelligent Column Filtering
              4. Response Format
            2. Timeframes
              1. Requirements
                1. Error Handling
                  1. Security Notes
                    1. License

                      Related MCP Servers

                      • A
                        security
                        A
                        license
                        A
                        quality
                        Provides 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 -
                        7
                        54
                        MIT License
                        • Apple
                      • A
                        security
                        F
                        license
                        A
                        quality
                        Provides 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 -
                        2
                        8
                        13
                        • Apple
                      • A
                        security
                        A
                        license
                        A
                        quality
                        Provides 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 -
                        35
                        30
                        MIT License
                      • -
                        security
                        F
                        license
                        -
                        quality
                        Enables trading and market analysis through Tiger Brokers API integration. Provides real-time market data, portfolio management, order execution, and technical analysis tools with a comprehensive web dashboard for monitoring.
                        Last updated -

                      View all related MCP servers

                      MCP directory API

                      We provide all the information about MCP servers via our MCP API.

                      curl -X GET 'https://glama.ai/api/mcp/v1/servers/emerzon/mt-data-mcp'

                      If you have feedback or need assistance with the MCP directory API, please join our Discord server