by ariadng
Enables AI LLMs to execute trades on the MetaTrader 5 platform through the Model Context Protocol.
Enables large language models to interact with MetaTrader 5, allowing AI‑driven trade execution and management via a standardized MCP interface.
pip install metatrader-mcp-server.Tools → Options → Allow algorithmic trading).metatrader-mcp-server --login <YOUR_MT5_LOGIN> --password <YOUR_MT5_PASSWORD> --server <YOUR_MT5_SERVER>
This launches the MCP server and automatically starts the MT5 terminal.{
"mcpServers": {
"metatrader": {
"command": "metatrader-mcp-server",
"args": ["--login", "<YOUR_MT5_LOGIN>", "--password", "<YOUR_MT5_PASSWORD>", "--server", "<YOUR_MT5_SERVER>"]
}
}
}
metatrader-http-server --login <YOUR_MT5_LOGIN> --password <YOUR_MT5_PASSWORD> --server <YOUR_MT5_SERVER> --host 0.0.0.0 --port 8000
Then add http://localhost:8000 as a tool server in the Open WebUI settings.Q: What Python version is required? A: Python 3.10 or newer.
Q: Do I need a licensed MetaTrader 5 terminal? A: Yes, the server interacts with a locally installed MT5 client.
Q: How are credentials supplied?
A: Via command‑line arguments --login, --password, and --server when launching the server.
Q: Can I run the server on a remote machine? A: The server must be on the same host as the MT5 terminal because it launches the client locally.
Q: Is there any legal disclaimer? A: Yes – the package disclaims liability for any trading losses; users assume all risks.
Let AI assistants trade for you using natural language
Features • Quick Start • Documentation • Examples • Support

MetaTrader MCP Server is a bridge that connects AI assistants (like Claude, ChatGPT) to the MetaTrader 5 trading platform. Instead of clicking buttons, you can simply tell your AI assistant what to do:
"Show me my account balance" "Buy 0.01 lots of EUR/USD" "Close all profitable positions"
The AI understands your request and executes it on MetaTrader 5 automatically.
You → AI Assistant → MCP Server → MetaTrader 5 → Your Trades
Please read this carefully:
Trading financial instruments involves significant risk of loss. This software is provided as-is, and the developers accept no liability for any trading losses, gains, or consequences of using this software.
By using this software, you acknowledge that:
This is not financial advice. Always trade responsibly.
Before you begin, make sure you have:
Open your terminal or command prompt and run:
pip install metatrader-mcp-server
Tools → OptionsExpert Advisors tabAllow algorithmic tradingOKPick one based on how you want to use it:
Find your Claude Desktop config file:
%APPDATA%\Claude\claude_desktop_config.json~/Library/Application Support/Claude/claude_desktop_config.jsonOpen the file and add this configuration:
{
"mcpServers": {
"metatrader": {
"command": "metatrader-mcp-server",
"args": [
"--login", "YOUR_MT5_LOGIN",
"--password", "YOUR_MT5_PASSWORD",
"--server", "YOUR_MT5_SERVER"
]
}
}
}
Optional: Specify Custom MT5 Terminal Path
If your MT5 terminal is installed in a non-standard location, add the --path argument:
{
"mcpServers": {
"metatrader": {
"command": "metatrader-mcp-server",
"args": [
"--login", "YOUR_MT5_LOGIN",
"--password", "YOUR_MT5_PASSWORD",
"--server", "YOUR_MT5_SERVER",
"--path", "C:\\Program Files\\MetaTrader 5\\terminal64.exe"
]
}
}
}
Replace YOUR_MT5_LOGIN, YOUR_MT5_PASSWORD, and YOUR_MT5_SERVER with your actual credentials
Restart Claude Desktop
Start chatting! Try: "What's my account balance?"
metatrader-http-server --login YOUR_LOGIN --password YOUR_PASSWORD --server YOUR_SERVER --host 0.0.0.0 --port 8000
Optional: Specify Custom MT5 Terminal Path
If your MT5 terminal is installed in a non-standard location, add the --path argument:
metatrader-http-server --login YOUR_LOGIN --password YOUR_PASSWORD --server YOUR_SERVER --path "C:\Program Files\MetaTrader 5\terminal64.exe" --host 0.0.0.0 --port 8000
Open your browser to http://localhost:8000/docs to see the API documentation
In Open WebUI:
http://localhost:8000Now you can use trading tools in your Open WebUI chats!
Once configured, you can chat naturally:
Check Your Account:
You: "Show me my account information"
Claude: Returns balance, equity, margin, leverage, etc.
Get Market Data:
You: "What's the current price of EUR/USD?"
Claude: Shows bid, ask, and spread
Place a Trade:
You: "Buy 0.01 lots of GBP/USD with stop loss at 1.2500 and take profit at 1.2700"
Claude: Executes the trade and confirms
Manage Positions:
You: "Close all my losing positions"
Claude: Closes positions and reports results
Analyze History:
You: "Show me all my trades from last week for EUR/USD"
Claude: Returns trade history as a table
# Get account info
curl http://localhost:8000/api/v1/account/info
# Get current price
curl "http://localhost:8000/api/v1/market/price?symbol_name=EURUSD"
# Place a market order
curl -X POST http://localhost:8000/api/v1/order/market \
-H "Content-Type: application/json" \
-d '{
"symbol": "EURUSD",
"volume": 0.01,
"type": "BUY",
"stop_loss": 1.0990,
"take_profit": 1.1010
}'
# Get all open positions
curl http://localhost:8000/api/v1/positions
# Close a specific position
curl -X DELETE http://localhost:8000/api/v1/positions/12345
from metatrader_client import MT5Client
# Connect to MT5
config = {
"login": 12345678,
"password": "your_password",
"server": "MetaQuotes-Demo"
}
client = MT5Client(config)
client.connect()
# Get account statistics
stats = client.account.get_trade_statistics()
print(f"Balance: ${stats['balance']}")
print(f"Equity: ${stats['equity']}")
# Get current price
price = client.market.get_symbol_price("EURUSD")
print(f"EUR/USD Bid: {price['bid']}, Ask: {price['ask']}")
# Place a market order
result = client.order.place_market_order(
type="BUY",
symbol="EURUSD",
volume=0.01,
stop_loss=1.0990,
take_profit=1.1010
)
print(result['message'])
# Close all positions
client.order.close_all_positions()
# Disconnect
client.disconnect()
get_account_info - Get balance, equity, profit, margin level, leverage, currencyget_symbols - List all available trading symbolsget_symbol_price - Get current bid/ask price for a symbolget_candles_latest - Get recent price candles (OHLCV data)get_candles_by_date - Get historical candles for a date rangeget_symbol_info - Get detailed symbol informationplace_market_order - Execute instant BUY/SELL ordersplace_pending_order - Place limit/stop orders for future executionmodify_position - Update stop loss or take profitmodify_pending_order - Modify pending order parametersget_all_positions - View all open positionsget_positions_by_symbol - Filter positions by trading pairget_positions_by_id - Get specific position detailsclose_position - Close a specific positionclose_all_positions - Close all open positionsclose_all_positions_by_symbol - Close all positions for a symbolclose_all_profitable_positions - Close only winning tradesclose_all_losing_positions - Close only losing tradesget_all_pending_orders - List all pending ordersget_pending_orders_by_symbol - Filter pending orders by symbolcancel_pending_order - Cancel a specific pending ordercancel_all_pending_orders - Cancel all pending orderscancel_pending_orders_by_symbol - Cancel pending orders for a symbolget_deals - Get historical completed tradesget_orders - Get historical order recordsInstead of putting credentials in the command line, create a .env file:
LOGIN=12345678
PASSWORD=your_password
SERVER=MetaQuotes-Demo
# Optional: Specify custom MT5 terminal path (auto-detected if not provided)
# PATH=C:\Program Files\MetaTrader 5\terminal64.exe
Then start the server without arguments:
metatrader-http-server
The server will automatically load credentials from the .env file.
metatrader-http-server --host 127.0.0.1 --port 9000
The MT5 client supports additional configuration:
config = {
"login": 12345678,
"password": "your_password",
"server": "MetaQuotes-Demo",
"path": None, # Path to MT5 terminal executable (default: auto-detect)
"timeout": 60000, # Connection timeout in milliseconds (default: 60000)
"portable": False, # Use portable mode (default: False)
"max_retries": 3, # Maximum connection retry attempts (default: 3)
"backoff_factor": 1.5, # Delay multiplier between retries (default: 1.5)
"cooldown_time": 2.0, # Seconds to wait between connections (default: 2.0)
"debug": True # Enable debug logging (default: False)
}
Configuration Options:
| Feature | Status |
|---|---|
| MetaTrader 5 Connection | ✅ Complete |
| Python Client Library | ✅ Complete |
| MCP Server | ✅ Complete |
| Claude Desktop Integration | ✅ Complete |
| HTTP/REST API Server | ✅ Complete |
| Open WebUI Integration | ✅ Complete |
| OpenAPI Documentation | ✅ Complete |
| PyPI Package | ✅ Published |
| Google ADK Integration | 🚧 In Progress |
| WebSocket Support | 📋 Planned |
| Docker Container | 📋 Planned |
# Clone the repository
git clone https://github.com/ariadng/metatrader-mcp-server.git
cd metatrader-mcp-server
# Install in development mode
pip install -e .
# Install development dependencies
pip install pytest python-dotenv
# Run tests
pytest tests/
metatrader-mcp-server/
├── src/
│ ├── metatrader_client/ # Core MT5 client library
│ │ ├── account/ # Account operations
│ │ ├── connection/ # Connection management
│ │ ├── history/ # Historical data
│ │ ├── market/ # Market data
│ │ ├── order/ # Order execution
│ │ └── types/ # Type definitions
│ ├── metatrader_mcp/ # MCP server implementation
│ └── metatrader_openapi/ # HTTP/REST API server
├── tests/ # Test suite
├── docs/ # Documentation
└── pyproject.toml # Project configuration
Contributions are welcome! Here's how you can help:
git checkout -b feature/amazing-feature)pytest)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)"Connection failed"
"Module not found"
pip install metatrader-mcp-server"Order execution failed"
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by Aria Dhanang
⭐ Star this repo if you find it useful!
Please log in to share your review and rating for this MCP.
Explore related MCPs that share similar capabilities and solve comparable challenges
by stripe
Provides SDKs and tools to integrate Stripe's billing and API services with large language models, agent frameworks, and token‑metering for AI‑powered products and businesses.
by goat-sdk
Enables AI agents to send and receive payments, purchase goods and services, execute investment strategies, tokenize assets, and obtain financial insights by leveraging blockchains, stablecoins, and wallets.
by financial-datasets
Provides access to income statements, balance sheets, cash flow statements, stock prices, market news, and cryptocurrency data through MCP tools for AI assistants.
by alpacahq
Enables large language models to trade stocks and options, retrieve real‑time and historical market data, and manage portfolios using plain English commands through a local or remote MCP server.
by stefanoamorelli
Provides an MCP server that connects AI models to SEC EDGAR filings, enabling real‑time retrieval of company filings, financial statements, and insider‑trading data with exact XBRL precision and verifiable filing references.
by XeroAPI
Provides a bridge between the Model Context Protocol and Xero's API, enabling standardized access to Xero accounting and business features.
by kukapay
Provides a comprehensive set of cryptocurrency technical analysis indicators and ready‑to‑use trading strategies through an MCP interface, enabling AI agents and applications to generate buy, hold, or sell signals.
by kukapay
Integrates the Freqtrade cryptocurrency trading bot with MCP, exposing its REST API as tools for AI agents to perform automated trading operations.
by calvernaz
Provides access to Alpha Vantage stock market data via an MCP server, supporting stdio and HTTP streaming modes with optional OAuth 2.1 authentication.