home / mcp / metatrader mcp server
Model Context Protocol (MCP) to enable AI LLMs to trade using MetaTrader platform
Configuration
View docs{
"mcpServers": {
"ariadng-metatrader-mcp-server": {
"url": "http://localhost:8000",
"headers": {
"PATH": "C:\\\\Program Files\\\\MetaTrader 5\\\\terminal64.exe",
"LOGIN": "12345678",
"SERVER": "MetaQuotes-Demo",
"PASSWORD": "your_password"
}
}
}
}You can connect AI assistants to MetaTrader 5 through a dedicated MCP server, letting you request trades, fetch market data, and manage accounts with natural language or HTTP calls. This server acts as a bridge between your AI workflows and MetaTrader 5, enabling hands-free trading automation and quick access to prices, positions, and history.
Set up the MCP server and connect your MCP client of choice to start issuing trading commands. The server exposes two primary interfaces you can use: a local MCP script (stdio) that runs on your machine and a REST API (http) you can call from web UIs or other clients.
To begin, choose your preferred interface and follow the configuration steps to point the client at MT5 credentials and the correct server endpoint. Typical workflows include checking your balance, requesting real-time prices, placing market or pending orders, and managing positions and history.
Prerequisites you need before installing: - Python 3.10 or higher - MetaTrader 5 terminal - An MT5 trading account (demo or live) with login, password, and server name.
pip install metatrader-mcp-serverEnable algorithmic trading in MT5: 1) Open MetaTrader 5 2) Tools β Options 3) Expert Advisors tab 4) Check Allow algorithmic trading 5) OK
Choose how you want to run the MCP server: - Claude Desktop integration (stdio) for interactive commands - HTTP REST API (http) for web or API-based interactions
Stdio (local) MCP server configuration for Claude Desktop: - command: metatrader-mcp-server - args: ["--login", "YOUR_MT5_LOGIN", "--password", "YOUR_MT5_PASSWORD", "--server", "YOUR_MT5_SERVER"]
HTTP (REST API) server configuration for Open WebUI or other clients: - start command: metatrader-http-server --login YOUR_LOGIN --password YOUR_PASSWORD --server YOUR_SERVER --host 0.0.0.0 --port 8000 - optional path to MT5 terminal can be added with --path "C:\\Program Files\\MetaTrader 5\\terminal64.exe"
Environment variables (for convenience): you can place credentials in a .env file with these names and then start the HTTP server without command-line arguments: - LOGIN, PASSWORD, SERVER - Optional: PATH for MT5 terminal location
Examples of common actions you can perform via the MCP server include: checking your balance, fetching current prices, placing trades, modifying orders, and querying trade history. Use natural language commands through your chosen MCP client or call the REST API directly for automated workflows.
If you see a connection error, verify that the MT5 terminal is running and that algorithmic trading is enabled in MT5. Double-check your login credentials and server name. For API issues, ensure the HTTP server is reachable at the configured host and port and that the MT5 terminal path is correct when using a custom path.
If you encounter a module or dependency error, ensure you installed the MCP package with the correct Python version (3.10+) and that you started the server with the appropriate command for your chosen interface.
Account management: get account info, balance, equity, margin, and leverage. Market data: retrieve symbol lists, current prices, and candles. Order execution: place market and pending orders, modify positions, and cancel orders. Position management: view, close, or modify open positions and filter by symbol or ID. Trading history: access deals and order history for analysis.
Retrieve balance, equity, profit, margin level, leverage, and currency for the connected MT5 account.
List all available trading symbols on the connected MT5 server.
Fetch current bid/ask prices for a specified symbol.
Obtain the most recent OHLCV candles for quick market view.
Retrieve historical completed trades from the MT5 account.
Fetch historical orders for analysis and reporting.
Execute an instant BUY or SELL order with optional stop loss and take profit.
Place limit or stop orders for future execution.
Update stop loss or take profit for an open position.
Close a specific open position.
Close all open positions.
Close only trades that are currently profitable.
Close only trades that are currently losing.
List all open positions.
Get detailed information about a specific trading symbol.