MetaTrader MCP Server 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: The AI understands your request and executes it on MetaTrader
Add this skill
npx mdskills install ariadng/metatrader-mcp-serverComprehensive MCP bridge to MetaTrader 5 with excellent setup docs and wide AI integration
1<div align="center">2 <h1>MetaTrader MCP Server</h1>3</div>45<br />67<div align="center">89[](https://pypi.org/project/metatrader-mcp-server/)10[](https://www.python.org/downloads/)11[](https://opensource.org/licenses/MIT)1213**Let AI assistants trade for you using natural language**1415[Features](#-features) • [Quick Start](#-quick-start) • [Documentation](#-documentation) • [Examples](#-usage-examples) • [Support](#-getting-help)16171819</div>2021<br />2223---2425## 🌟 What is This?2627**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:2829> "Show me my account balance"30> "Buy 0.01 lots of EUR/USD"31> "Close all profitable positions"3233The AI understands your request and executes it on MetaTrader 5 automatically.3435### How It Works3637```38You → AI Assistant → MCP Server → MetaTrader 5 → Your Trades39```4041## ✨ Features4243- **🗣️ Natural Language Trading** - Talk to AI in plain English to execute trades44- **🤖 Multi-AI Support** - Works with Claude Desktop, ChatGPT (via Open WebUI), and more45- **📊 Full Market Access** - Get real-time prices, historical data, and symbol information46- **💼 Complete Account Control** - Check balance, equity, margin, and trading statistics47- **⚡ Order Management** - Place, modify, and close orders with simple commands48- **🔒 Secure** - All credentials stay on your machine49- **🌐 Flexible Interfaces** - Use as MCP server or REST API50- **📖 Well Documented** - Comprehensive guides and examples5152## 🎯 Who Is This For?5354- **Traders** who want to automate their trading using AI55- **Developers** building trading bots or analysis tools56- **Analysts** who need quick access to market data57- **Anyone** interested in combining AI with financial markets5859## ⚠️ Important Disclaimer6061**Please read this carefully:**6263Trading 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.6465By using this software, you acknowledge that:66- You understand the risks of financial trading67- You are responsible for all trades executed through this system68- You will not hold the developers liable for any outcomes69- You are using this software at your own risk7071**This is not financial advice. Always trade responsibly.**7273---7475## 📋 Prerequisites7677Before you begin, make sure you have:78791. **Python 3.10 or higher** - [Download here](https://www.python.org/downloads/)802. **MetaTrader 5 terminal** - [Download here](https://www.metatrader5.com/en/download)813. **MT5 Trading Account** - Demo or live account credentials82 - Login number83 - Password84 - Server name (e.g., "MetaQuotes-Demo")8586## 🚀 Quick Start8788### Step 1: Install the Package8990Open your terminal or command prompt and run:9192```bash93pip install metatrader-mcp-server94```9596### Step 2: Enable Algorithmic Trading97981. Open MetaTrader 5992. Go to `Tools` → `Options`1003. Click the `Expert Advisors` tab1014. Check the box for `Allow algorithmic trading`1025. Click `OK`103104### Step 3: Choose Your Interface105106Pick one based on how you want to use it:107108#### Option A: Use with Claude Desktop (Recommended for beginners)1091101. Find your Claude Desktop config file:111 - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`112 - **Mac**: `~/Library/Application Support/Claude/claude_desktop_config.json`1131142. Open the file and add this configuration:115116```json117{118 "mcpServers": {119 "metatrader": {120 "command": "metatrader-mcp-server",121 "args": [122 "--login", "YOUR_MT5_LOGIN",123 "--password", "YOUR_MT5_PASSWORD",124 "--server", "YOUR_MT5_SERVER"125 ]126 }127 }128}129```130131**Optional: Specify Custom MT5 Terminal Path**132133If your MT5 terminal is installed in a non-standard location, add the `--path` argument:134135```json136{137 "mcpServers": {138 "metatrader": {139 "command": "metatrader-mcp-server",140 "args": [141 "--login", "YOUR_MT5_LOGIN",142 "--password", "YOUR_MT5_PASSWORD",143 "--server", "YOUR_MT5_SERVER",144 "--path", "C:\\Program Files\\MetaTrader 5\\terminal64.exe"145 ]146 }147 }148}149```1501513. Replace `YOUR_MT5_LOGIN`, `YOUR_MT5_PASSWORD`, and `YOUR_MT5_SERVER` with your actual credentials1521534. Restart Claude Desktop1541555. Start chatting! Try: *"What's my account balance?"*156157#### Option B: Use with Open WebUI (For ChatGPT and other LLMs)1581591. Start the HTTP server:160161```bash162metatrader-http-server --login YOUR_LOGIN --password YOUR_PASSWORD --server YOUR_SERVER --host 0.0.0.0 --port 8000163```164165**Optional: Specify Custom MT5 Terminal Path**166167If your MT5 terminal is installed in a non-standard location, add the `--path` argument:168169```bash170metatrader-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 8000171```1721732. Open your browser to `http://localhost:8000/docs` to see the API documentation1741753. In Open WebUI:176 - Go to **Settings** → **Tools**177 - Click **Add Tool Server**178 - Enter `http://localhost:8000`179 - Save1801814. Now you can use trading tools in your Open WebUI chats!182183---184185## 💡 Usage Examples186187### With Claude Desktop188189Once configured, you can chat naturally:190191**Check Your Account:**192> You: "Show me my account information"193>194> Claude: *Returns balance, equity, margin, leverage, etc.*195196**Get Market Data:**197> You: "What's the current price of EUR/USD?"198>199> Claude: *Shows bid, ask, and spread*200201**Place a Trade:**202> You: "Buy 0.01 lots of GBP/USD with stop loss at 1.2500 and take profit at 1.2700"203>204> Claude: *Executes the trade and confirms*205206**Manage Positions:**207> You: "Close all my losing positions"208>209> Claude: *Closes positions and reports results*210211**Analyze History:**212> You: "Show me all my trades from last week for EUR/USD"213>214> Claude: *Returns trade history as a table*215216### With HTTP API217218```bash219# Get account info220curl http://localhost:8000/api/v1/account/info221222# Get current price223curl "http://localhost:8000/api/v1/market/price?symbol_name=EURUSD"224225# Place a market order226curl -X POST http://localhost:8000/api/v1/order/market \227 -H "Content-Type: application/json" \228 -d '{229 "symbol": "EURUSD",230 "volume": 0.01,231 "type": "BUY",232 "stop_loss": 1.0990,233 "take_profit": 1.1010234 }'235236# Get all open positions237curl http://localhost:8000/api/v1/positions238239# Close a specific position240curl -X DELETE http://localhost:8000/api/v1/positions/12345241```242243### As a Python Library244245```python246from metatrader_client import MT5Client247248# Connect to MT5249config = {250 "login": 12345678,251 "password": "your_password",252 "server": "MetaQuotes-Demo"253}254client = MT5Client(config)255client.connect()256257# Get account statistics258stats = client.account.get_trade_statistics()259print(f"Balance: ${stats['balance']}")260print(f"Equity: ${stats['equity']}")261262# Get current price263price = client.market.get_symbol_price("EURUSD")264print(f"EUR/USD Bid: {price['bid']}, Ask: {price['ask']}")265266# Place a market order267result = client.order.place_market_order(268 type="BUY",269 symbol="EURUSD",270 volume=0.01,271 stop_loss=1.0990,272 take_profit=1.1010273)274print(result['message'])275276# Close all positions277client.order.close_all_positions()278279# Disconnect280client.disconnect()281```282283---284285## 📚 Available Operations286287### Account Management288- `get_account_info` - Get balance, equity, profit, margin level, leverage, currency289290### Market Data291- `get_symbols` - List all available trading symbols292- `get_symbol_price` - Get current bid/ask price for a symbol293- `get_candles_latest` - Get recent price candles (OHLCV data)294- `get_candles_by_date` - Get historical candles for a date range295- `get_symbol_info` - Get detailed symbol information296297### Order Execution298- `place_market_order` - Execute instant BUY/SELL orders299- `place_pending_order` - Place limit/stop orders for future execution300- `modify_position` - Update stop loss or take profit301- `modify_pending_order` - Modify pending order parameters302303### Position Management304- `get_all_positions` - View all open positions305- `get_positions_by_symbol` - Filter positions by trading pair306- `get_positions_by_id` - Get specific position details307- `close_position` - Close a specific position308- `close_all_positions` - Close all open positions309- `close_all_positions_by_symbol` - Close all positions for a symbol310- `close_all_profitable_positions` - Close only winning trades311- `close_all_losing_positions` - Close only losing trades312313### Pending Orders314- `get_all_pending_orders` - List all pending orders315- `get_pending_orders_by_symbol` - Filter pending orders by symbol316- `cancel_pending_order` - Cancel a specific pending order317- `cancel_all_pending_orders` - Cancel all pending orders318- `cancel_pending_orders_by_symbol` - Cancel pending orders for a symbol319320### Trading History321- `get_deals` - Get historical completed trades322- `get_orders` - Get historical order records323324---325326## 🔧 Advanced Configuration327328### Using Environment Variables329330Instead of putting credentials in the command line, create a `.env` file:331332```env333LOGIN=12345678334PASSWORD=your_password335SERVER=MetaQuotes-Demo336337# Optional: Specify custom MT5 terminal path (auto-detected if not provided)338# PATH=C:\Program Files\MetaTrader 5\terminal64.exe339```340341Then start the server without arguments:342343```bash344metatrader-http-server345```346347The server will automatically load credentials from the `.env` file.348349### Custom Port and Host350351```bash352metatrader-http-server --host 127.0.0.1 --port 9000353```354355### Connection Parameters356357The MT5 client supports additional configuration:358359```python360config = {361 "login": 12345678,362 "password": "your_password",363 "server": "MetaQuotes-Demo",364 "path": None, # Path to MT5 terminal executable (default: auto-detect)365 "timeout": 60000, # Connection timeout in milliseconds (default: 60000)366 "portable": False, # Use portable mode (default: False)367 "max_retries": 3, # Maximum connection retry attempts (default: 3)368 "backoff_factor": 1.5, # Delay multiplier between retries (default: 1.5)369 "cooldown_time": 2.0, # Seconds to wait between connections (default: 2.0)370 "debug": True # Enable debug logging (default: False)371}372```373374**Configuration Options:**375376- **login** (int, required): Your MT5 account login number377- **password** (str, required): Your MT5 account password378- **server** (str, required): MT5 server name (e.g., "MetaQuotes-Demo")379- **path** (str, optional): Full path to the MT5 terminal executable. If not specified, the client will automatically search standard installation directories380- **timeout** (int, optional): Connection timeout in milliseconds. Default: 60000 (60 seconds)381- **portable** (bool, optional): Enable portable mode for the MT5 terminal. Default: False382- **max_retries** (int, optional): Maximum number of connection retry attempts. Default: 3383- **backoff_factor** (float, optional): Exponential backoff factor for retry delays. Default: 1.5384- **cooldown_time** (float, optional): Minimum time in seconds between connection attempts. Default: 2.0385- **debug** (bool, optional): Enable detailed debug logging for troubleshooting. Default: False386387---388389## 🗺️ Roadmap390391| Feature | Status |392|---------|--------|393| MetaTrader 5 Connection | ✅ Complete |394| Python Client Library | ✅ Complete |395| MCP Server | ✅ Complete |396| Claude Desktop Integration | ✅ Complete |397| HTTP/REST API Server | ✅ Complete |398| Open WebUI Integration | ✅ Complete |399| OpenAPI Documentation | ✅ Complete |400| PyPI Package | ✅ Published |401| Google ADK Integration | 🚧 In Progress |402| WebSocket Support | 📋 Planned |403| Docker Container | 📋 Planned |404405---406407## 🛠️ Development408409### Setting Up Development Environment410411```bash412# Clone the repository413git clone https://github.com/ariadng/metatrader-mcp-server.git414cd metatrader-mcp-server415416# Install in development mode417pip install -e .418419# Install development dependencies420pip install pytest python-dotenv421422# Run tests423pytest tests/424```425426### Project Structure427428```429metatrader-mcp-server/430├── src/431│ ├── metatrader_client/ # Core MT5 client library432│ │ ├── account/ # Account operations433│ │ ├── connection/ # Connection management434│ │ ├── history/ # Historical data435│ │ ├── market/ # Market data436│ │ ├── order/ # Order execution437│ │ └── types/ # Type definitions438│ ├── metatrader_mcp/ # MCP server implementation439│ └── metatrader_openapi/ # HTTP/REST API server440├── tests/ # Test suite441├── docs/ # Documentation442└── pyproject.toml # Project configuration443```444445---446447## 🤝 Contributing448449Contributions are welcome! Here's how you can help:4504511. **Report Bugs** - [Open an issue](https://github.com/ariadng/metatrader-mcp-server/issues)4522. **Suggest Features** - Share your ideas in issues4533. **Submit Pull Requests** - Fix bugs or add features4544. **Improve Documentation** - Help make docs clearer4555. **Share Examples** - Show how you're using it456457### Contribution Guidelines458459- Fork the repository460- Create a feature branch (`git checkout -b feature/amazing-feature`)461- Make your changes462- Write or update tests463- Ensure tests pass (`pytest`)464- Commit your changes (`git commit -m 'Add amazing feature'`)465- Push to the branch (`git push origin feature/amazing-feature`)466- Open a Pull Request467468---469470## 📖 Documentation471472- **[Developer Documentation](docs/README.md)** - Detailed technical docs473- **[API Reference](docs/api-reference.md)** - Complete API documentation474- **[Examples](docs/examples/)** - Code examples and tutorials475- **[Roadmap](docs/roadmap/version-checklist.md)** - Feature development timeline476477---478479## 🆘 Getting Help480481- **Issues**: [GitHub Issues](https://github.com/ariadng/metatrader-mcp-server/issues)482- **Discussions**: [GitHub Discussions](https://github.com/ariadng/metatrader-mcp-server/discussions)483- **LinkedIn**: [Connect with me](https://linkedin.com/in/ariadhanang)484485### Common Issues486487**"Connection failed"**488- Ensure MT5 terminal is running489- Check that algorithmic trading is enabled490- Verify your login credentials are correct491492**"Module not found"**493- Make sure you've installed the package: `pip install metatrader-mcp-server`494- Check your Python version is 3.10 or higher495496**"Order execution failed"**497- Verify the symbol exists on your broker498- Check that the market is open499- Ensure you have sufficient margin500501---502503## 📝 License504505This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.506507---508509## 🙏 Acknowledgments510511- Built with [FastMCP](https://github.com/jlowin/fastmcp) for MCP protocol support512- Uses [MetaTrader5](https://pypi.org/project/MetaTrader5/) Python package513- Powered by [FastAPI](https://fastapi.tiangolo.com/) for the REST API514515---516517## 📊 Project Stats518519- **Version**: 0.2.9520- **Python**: 3.10+521- **License**: MIT522- **Status**: Active Development523524---525526<div align="center">527528**Made with ❤️ by [Aria Dhanang](https://github.com/ariadng)**529530⭐ Star this repo if you find it useful!531532[PyPI](https://pypi.org/project/metatrader-mcp-server/) • [GitHub](https://github.com/ariadng/metatrader-mcp-server) • [Issues](https://github.com/ariadng/metatrader-mcp-server/issues)533534</div>535
Full transparency — inspect the skill content before installing.