MetaTrader 5 MCP Server
A Model Context Protocol (MCP) server for MetaTrader 5, allowing AI assistants to interact with the MetaTrader 5 platform for trading and market data analysis.
Features
- Connect to MetaTrader 5 terminal
- Access market data (symbols, rates, ticks)
- Place and manage trades
- Analyze trading history
- Integrate with AI assistants through the Model Context Protocol
Installation
From Source
Requirements
- uv
- Python 3.11 or higher
- MetaTrader 5 terminal installed
- MetaTrader 5 account (demo or real)
Usage
Running the Server
To run the server in development mode:
This will start the server at http://127.0.0.1:8000 by default.
You can specify a different host and port:
Installing for Claude Desktop
To install the server for Claude Desktop:
Check your claude_desktop_config.json
file. It should look something like this:
API Reference
Connection Management
initialize()
: Initialize the MT5 terminallogin(account, password, server)
: Log in to a trading accountshutdown()
: Close the connection to the MT5 terminal
Market Data Functions
get_symbols()
: Get all available symbolsget_symbols_by_group(group)
: Get symbols by groupget_symbol_info(symbol)
: Get information about a specific symbolget_symbol_info_tick(symbol)
: Get the latest tick for a symbolcopy_rates_from_pos(symbol, timeframe, start_pos, count)
: Get bars from a specific positioncopy_rates_from_date(symbol, timeframe, date_from, count)
: Get bars from a specific datecopy_rates_range(symbol, timeframe, date_from, date_to)
: Get bars within a date rangecopy_ticks_from_pos(symbol, start_pos, count)
: Get ticks from a specific positioncopy_ticks_from_date(symbol, date_from, count)
: Get ticks from a specific datecopy_ticks_range(symbol, date_from, date_to)
: Get ticks within a date range
Trading Functions
order_send(request)
: Send an order to the trade serverorder_check(request)
: Check if an order can be placed with the specified parameterspositions_get(symbol, group)
: Get open positionspositions_get_by_ticket(ticket)
: Get an open position by its ticketorders_get(symbol, group)
: Get active ordersorders_get_by_ticket(ticket)
: Get an active order by its tickethistory_orders_get(symbol, group, ticket, position, from_date, to_date)
: Get orders from historyhistory_deals_get(symbol, group, ticket, position, from_date, to_date)
: Get deals from history
Example Workflows
Connecting and Getting Market Data
Placing a Trade
Resources
The server provides the following resources to help AI assistants understand how to use the MetaTrader 5 API:
mt5://getting_started
: Basic workflow for using the MetaTrader 5 APImt5://trading_guide
: Guide for placing and managing tradesmt5://market_data_guide
: Guide for accessing and analyzing market datamt5://order_types
: Information about order typesmt5://order_filling_types
: Information about order filling typesmt5://order_time_types
: Information about order time typesmt5://trade_actions
: Information about trade request actions
Prompts
The server provides the following prompts to help AI assistants interact with users:
connect_to_mt5(account, password, server)
: Connect to MetaTrader 5 and log inanalyze_market_data(symbol, timeframe)
: Analyze market data for a specific symbolplace_trade(symbol, order_type, volume)
: Place a trade for a specific symbolmanage_positions()
: Manage open positionsanalyze_trading_history(days)
: Analyze trading history
Development
Project Structure
Building the Package
To build the package:
Or using uv:
Publishing to PyPI
To publish the package to PyPI:
Or using uv:
License
MIT
Acknowledgements
- MetaQuotes for the MetaTrader 5 platform
- FastMCP for the MCP server implementation
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 AI assistants to interact with the MetaTrader 5 trading platform for market data analysis, placing trades, and managing trading positions. Provides comprehensive access to forex and financial market operations through the Model Context Protocol.
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol server implementation that enables AI assistants to interact with the Paradex perpetual futures trading platform, allowing for retrieving market data, managing trading accounts, placing orders, and monitoring positions.Last updated -268MIT License
- -securityFlicense-qualityA Model Context Protocol server that provides stock technical analysis tools (moving averages, RSI, trade recommendations) for AI assistants to analyze stocks and offer trading signals.Last updated -
- AsecurityFlicenseAqualityTransforms AI assistants into autonomous crypto trading agents with real-time market analysis, portfolio management, and trade execution across 17+ blockchains.Last updated -321016
- AsecurityFlicenseAqualityEnables AI assistants to interact with IG Trading API for forex, indices, and commodities trading. Provides 21 tools for account management, position trading, order placement, market data analysis, and watchlist management.Last updated -21101