MetaTrader 5 MCP Server & Distrobox Automation
LocalAbout MetaTrader 5 MCP Server & Distrobox Automation
An MCP server that controls MetaTrader 5 to run and optimize Expert Advisors, combined with a Distrobox container, a Flask REST API and generated reports. It suits users who want to automate EA optimization and document the results.
Key features
- 01Automated MT5 setup in a Distrobox container
- 02Flask REST API for starting and monitoring optimizations
- 03MCP server exposing trading and optimization functions
- 04HTML and Markdown optimization reports
- 05Git version control for code and configuration
Use cases
- 01Automating Expert Advisor parameter optimization
- 02Retrieving optimization results through an MCP client
- 03Generating optimization reports for multiple EAs
MCP support
The project provides a TypeScript MCP server that exposes tools such as account info, order creation, and optimization run, status and result retrieval to MCP clients.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMetaTrader 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.inifor 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.htmland.md.
3. MCP Server
- See
src/mt5-server.tsfor 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.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.