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 - Initialize and manage MT5 connections
- 📊 Access market data - Get symbols, rates, ticks, and historical data
- 💹 Place and manage trades - Send orders, manage positions, and track history
- 📈 Analyze trading history - Review past orders and deals
- 🤖 AI Integration - Seamlessly integrate with AI assistants through MCP
Quick Start¶
Installation¶
Running the Server¶
Claude Desktop Setup¶
Install for Claude Desktop:
Or manually configure claude_desktop_config.json:
{
"mcpServers": {
"mcp-metatrader5-server": {
"command": "uv",
"args": [
"--directory",
"C:\\path\\to\\mcp-metatrader5-server",
"run",
"mt5mcp"
]
}
}
}
Requirements¶
- uv (recommended) or pip
- Python 3.11 or higher
- MetaTrader 5 terminal installed on Windows
- MetaTrader 5 account (demo or real)
Available Tools¶
Connection Management¶
initialize(path)- Initialize the MT5 terminallogin(login, password, server)- Log in to a trading accountshutdown()- Close the connection to the MT5 terminalget_account_info()- Get trading account informationget_terminal_info()- Get terminal informationget_version()- Get MT5 version
Market Data¶
get_symbols()- Get all available symbolsget_symbols_by_group(group)- Get symbols by groupget_symbol_info(symbol)- Get symbol informationget_symbol_info_tick(symbol)- Get latest tick datacopy_rates_from_pos()- Get bars from positioncopy_rates_from_date()- Get bars from datecopy_rates_range()- Get bars in date rangecopy_ticks_from_pos()- Get ticks from positioncopy_ticks_from_date()- Get ticks from datecopy_ticks_range()- Get ticks in date range
Trading¶
order_send(request)- Send an orderorder_check(request)- Check order validitypositions_get()- Get open positionspositions_get_by_ticket(ticket)- Get position by ticketorders_get()- Get active ordersorders_get_by_ticket(ticket)- Get order by tickethistory_orders_get()- Get historical ordershistory_deals_get()- Get historical deals
Resources¶
The server provides helpful resources for AI assistants:
mt5://timeframes- Available timeframe constantsmt5://tick_flags- Tick flag constantsmt5://order_types- Order type constantsmt5://order_filling_types- Order filling type constantsmt5://order_time_types- Order time type constantsmt5://trade_actions- Trade action constants
Example Usage¶
Ask your AI assistant:
"Initialize MT5, login to my account, and show me the current price of EURUSD"
"Get the last 100 bars of GBPUSD on the 1-hour timeframe"
"Place a buy order for 0.1 lots of EURUSD at market price"
"Show me all my open positions"
Next Steps¶
- Getting Started Guide - Detailed setup and usage
- Market Data Guide - Working with market data
- Trading Guide - Placing and managing trades
- Pydantic AI Integration - Using with Pydantic AI framework
- Publishing Guide - Publishing to PyPI
License¶
MIT License - see LICENSE for details.
Acknowledgements¶
- MetaQuotes for the MetaTrader 5 platform
- FastMCP for the MCP server implementation
