MetaTrader 5 MCP Server & Distrobox Automation
About
A MCP-Server to control Metatrader5 for EA optimization
Details
- Author
- chymian
- GitHub stars
- 27
- Downloads
- 983
- Categories
- Productivity
Jump to
- MetaTrader 5 setup and launch via Wine in Distrobox.
- Flask REST API for programmatic EA optimization.
- MCP server for unified trading and optimization interface.
- Automated HTML and Markdown optimization reports.
- Git version control for all code and configuration.
Create the Distrobox container with distrobox-assemble create --file src/mt5.ini -R and enter it with distrobox-enter mt5. The Flask API starts automatically and is accessible at http://localhost:5000. Use the MCP server (src/mt5-server.ts) to trigger optimizations and generate reports. Results are saved to ~/mt5-dev/result/manual/tuning/.
MetaTrader 5 MCP Server & Distrobox Automation
This project provides a fully automated workflow for running, optimizing, and documenting MetaTrader 5 (MT5) Expert Advisors (EAs) using a Distrobox container, a Flask REST API, and an MCP server.
---
Features
- MetaTrader 5 in Wine/Distrobox: Automated setup and launch.
- Flask REST API: Programmatic optimization of EAs, with endpoints for running, monitoring, and saving results.
- MCP Server: Unified interface for trading, optimization, and result retrieval.
- Automated Documentation: Optimization results are saved as clear HTML and Markdown reports for each EA.
- Git Version Control: All code and configuration are versioned from the start.
---
Quickstart
1. Distrobox Container Setup
To assemble and enter the Distrobox container, run the following commands from the project root:
distrobox-assemble create --file src/mt5.ini -R
distrobox-enter mt5
- See src/mt5.ini for a complete, automated Distrobox config.
- On container creation, the following are installed and configured:
- Wine, MT5, Python3, pip, Flask, MetaTrader5, pandas, jinja2, git, and all required tools.
- The Flask API is started automatically.
- A git repository is initialized and all files are committed.
2. Flask REST API
- Located at src/mt5_flask_api.py.
- The API is accessible from the host at http://localhost:5000 (port 5000 is published by default; see src/mt5.ini).
- Example: test the API from your host system with:
curl http://localhost:5000/optimization_status/some-id
- Endpoints:
-
POST /optimize: Start an optimization run.-
GET /optimization_status/<id>: Check optimization status.-
GET /optimization_results/<id>: Get results.-
POST /save_results: Save results as HTML/Markdown/CSV/JSON.- Results are saved to
~/mt5-dev/result/manual/tuning/<EA_NAME>_tuning.html and .md.
3. MCP Server
- See src/mt5-server.ts for the MCP server implementation.
- Tools include:
- Trading operations (get_account_info, create_order, etc.)
- Optimization operations (run_optimization, get_optimization_status, get_optimization_results, save_optimization_results)
4. Usage Example
- Start the container (Distrobox will run all setup and start the Flask API).
- Use the MCP server to trigger optimizations and generate reports.
- Open the HTML/Markdown reports in ~/mt5-dev/result/manual/tuning/ for a clear overview.
---
Working Directory & Configuration
By default, all logs, data, results, and outputs are stored in ~/mt5-dev for portability and consistency.
To override any configuration value for your local development, copy src/mt5.ini to src/mt5-dev.ini and customize as needed.
The src/mt5-dev.ini file is ignored by git and will not be tracked or pushed.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



