Let AI assistants trade for you using natural language
Features • Quick Start • Documentation • Examples • Support

🌟 What is This?
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.
How It Works
Related MCP server: Financial Datasets MCP Server
✨ Features
🗣️ Natural Language Trading - Talk to AI in plain English to execute trades
🤖 Multi-AI Support - Works with Claude Desktop, ChatGPT (via Open WebUI), and more
📊 Full Market Access - Get real-time prices, historical data, and symbol information
💼 Complete Account Control - Check balance, equity, margin, and trading statistics
⚡ Order Management - Place, modify, and close orders with simple commands
🔒 Secure - All credentials stay on your machine
🌐 Flexible Interfaces - Use as MCP server or REST API
📖 Well Documented - Comprehensive guides and examples
🎯 Who Is This For?
Traders who want to automate their trading using AI
Developers building trading bots or analysis tools
Analysts who need quick access to market data
Anyone interested in combining AI with financial markets
⚠️ Important Disclaimer
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:
You understand the risks of financial trading
You are responsible for all trades executed through this system
You will not hold the developers liable for any outcomes
You are using this software at your own risk
This is not financial advice. Always trade responsibly.
📋 Prerequisites
Before you begin, make sure you have:
Python 3.10 or higher - Download here
MetaTrader 5 terminal - Download here
MT5 Trading Account - Demo or live account credentials
Login number
Password
Server name (e.g., "MetaQuotes-Demo")
🚀 Quick Start
Step 1: Install the Package
Open your terminal or command prompt and run:
Step 2: Enable Algorithmic Trading
Open MetaTrader 5
Go to
Tools→OptionsClick the
Expert AdvisorstabCheck the box for
Allow algorithmic tradingClick
OK
Step 3: Choose Your Interface
Pick one based on how you want to use it:
Option A: Use with Claude Desktop (Recommended for beginners)
Find your Claude Desktop config file:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonMac:
~/Library/Application Support/Claude/claude_desktop_config.json
Open the file and add this configuration:
Optional: Specify Custom MT5 Terminal Path
If your MT5 terminal is installed in a non-standard location, add the --path argument:
Replace
YOUR_MT5_LOGIN,YOUR_MT5_PASSWORD, andYOUR_MT5_SERVERwith your actual credentialsRestart Claude Desktop
Start chatting! Try: "What's my account balance?"
Option B: Use with Open WebUI (For ChatGPT and other LLMs)
Start the HTTP server:
Optional: Specify Custom MT5 Terminal Path
If your MT5 terminal is installed in a non-standard location, add the --path argument:
Open your browser to
http://localhost:8000/docsto see the API documentationIn Open WebUI:
Go to Settings → Tools
Click Add Tool Server
Enter
http://localhost:8000Save
Now you can use trading tools in your Open WebUI chats!
💡 Usage Examples
With Claude Desktop
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
With HTTP API
As a Python Library
📚 Available Operations
Account Management
get_account_info- Get balance, equity, profit, margin level, leverage, currency
Market Data
get_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 information
Order Execution
place_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 parameters
Position Management
get_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 trades
Pending Orders
get_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 symbol
Trading History
get_deals- Get historical completed tradesget_orders- Get historical order records
🔧 Advanced Configuration
Using Environment Variables
Instead of putting credentials in the command line, create a .env file:
Then start the server without arguments:
The server will automatically load credentials from the .env file.
Custom Port and Host
Connection Parameters
The MT5 client supports additional configuration:
Configuration Options:
login (int, required): Your MT5 account login number
password (str, required): Your MT5 account password
server (str, required): MT5 server name (e.g., "MetaQuotes-Demo")
path (str, optional): Full path to the MT5 terminal executable. If not specified, the client will automatically search standard installation directories
timeout (int, optional): Connection timeout in milliseconds. Default: 60000 (60 seconds)
portable (bool, optional): Enable portable mode for the MT5 terminal. Default: False
max_retries (int, optional): Maximum number of connection retry attempts. Default: 3
backoff_factor (float, optional): Exponential backoff factor for retry delays. Default: 1.5
cooldown_time (float, optional): Minimum time in seconds between connection attempts. Default: 2.0
debug (bool, optional): Enable detailed debug logging for troubleshooting. Default: False
🗺️ Roadmap
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 |
🛠️ Development
Setting Up Development Environment
Project Structure
🤝 Contributing
Contributions are welcome! Here's how you can help:
Report Bugs - Open an issue
Suggest Features - Share your ideas in issues
Submit Pull Requests - Fix bugs or add features
Improve Documentation - Help make docs clearer
Share Examples - Show how you're using it
Contribution Guidelines
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Make your changes
Write or update tests
Ensure tests pass (
pytest)Commit your changes (
git commit -m 'Add amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
📖 Documentation
Developer Documentation - Detailed technical docs
API Reference - Complete API documentation
Examples - Code examples and tutorials
Roadmap - Feature development timeline
🆘 Getting Help
Issues: GitHub Issues
Discussions: GitHub Discussions
LinkedIn: Connect with me
Common Issues
"Connection failed"
Ensure MT5 terminal is running
Check that algorithmic trading is enabled
Verify your login credentials are correct
"Module not found"
Make sure you've installed the package:
pip install metatrader-mcp-serverCheck your Python version is 3.10 or higher
"Order execution failed"
Verify the symbol exists on your broker
Check that the market is open
Ensure you have sufficient margin
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
Built with FastMCP for MCP protocol support
Uses MetaTrader5 Python package
Powered by FastAPI for the REST API
📊 Project Stats
Version: 0.2.9
Python: 3.10+
License: MIT
Status: Active Development
Made with ❤️ by
⭐ Star this repo if you find it useful!