Skip to content

Commit 9ac4516

Browse files
committed
Add 'path' to config
1 parent fa6e2da commit 9ac4516

10 files changed

Lines changed: 137 additions & 18 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
LOGIN=your_login_here
33
PASSWORD=your_password_here
44
SERVER=your_server_here
5+
6+
# Optional: Path to MT5 terminal executable (auto-detected if not specified)
7+
# PATH=C:\Program Files\MetaTrader 5\terminal64.exe

CLAUDE.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
MCP server enabling AI assistants to trade on MetaTrader 5 via natural language. Provides both MCP (stdio) and HTTP/REST interfaces.
66

77
**Stack**: Python 3.10+ • FastMCP • FastAPI • MetaTrader5 SDK • Pandas • Pydantic • pytest
8-
**Version**: 0.2.8 (Beta)
8+
**Version**: 0.2.9 (Beta)
99
**Repo**: https://github.com/ariadng/metatrader-mcp-server
1010

1111
---
@@ -79,7 +79,23 @@ def operation(connection, *, param: type, optional: Optional[type] = None):
7979
```python
8080
from metatrader_client import MT5Client
8181

82+
# Minimal configuration
8283
config = {"login": int(login), "password": password, "server": server}
84+
85+
# Full configuration with all available options
86+
config = {
87+
"login": int(login), # Required: MT5 account login
88+
"password": password, # Required: MT5 account password
89+
"server": server, # Required: MT5 server name
90+
"path": None, # Optional: Path to terminal executable (auto-detect if None)
91+
"timeout": 60000, # Optional: Connection timeout in ms (default: 60000)
92+
"portable": False, # Optional: Use portable mode (default: False)
93+
"max_retries": 3, # Optional: Max connection retries (default: 3)
94+
"backoff_factor": 1.5, # Optional: Retry delay multiplier (default: 1.5)
95+
"cooldown_time": 2.0, # Optional: Seconds between connections (default: 2.0)
96+
"debug": False # Optional: Enable debug logging (default: False)
97+
}
98+
8399
client = MT5Client(config)
84100
client.connect()
85101
# operations...

README.md

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ Pick one based on how you want to use it:
128128
}
129129
```
130130

131+
**Optional: Specify Custom MT5 Terminal Path**
132+
133+
If your MT5 terminal is installed in a non-standard location, add the `--path` argument:
134+
135+
```json
136+
{
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+
```
150+
131151
3. Replace `YOUR_MT5_LOGIN`, `YOUR_MT5_PASSWORD`, and `YOUR_MT5_SERVER` with your actual credentials
132152

133153
4. Restart Claude Desktop
@@ -142,6 +162,14 @@ Pick one based on how you want to use it:
142162
metatrader-http-server --login YOUR_LOGIN --password YOUR_PASSWORD --server YOUR_SERVER --host 0.0.0.0 --port 8000
143163
```
144164

165+
**Optional: Specify Custom MT5 Terminal Path**
166+
167+
If your MT5 terminal is installed in a non-standard location, add the `--path` argument:
168+
169+
```bash
170+
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
171+
```
172+
145173
2. Open your browser to `http://localhost:8000/docs` to see the API documentation
146174

147175
3. In Open WebUI:
@@ -305,6 +333,9 @@ Instead of putting credentials in the command line, create a `.env` file:
305333
LOGIN=12345678
306334
PASSWORD=your_password
307335
SERVER=MetaQuotes-Demo
336+
337+
# Optional: Specify custom MT5 terminal path (auto-detected if not provided)
338+
# PATH=C:\Program Files\MetaTrader 5\terminal64.exe
308339
```
309340

310341
Then start the server without arguments:
@@ -313,6 +344,8 @@ Then start the server without arguments:
313344
metatrader-http-server
314345
```
315346

347+
The server will automatically load credentials from the `.env` file.
348+
316349
### Custom Port and Host
317350

318351
```bash
@@ -328,14 +361,29 @@ config = {
328361
"login": 12345678,
329362
"password": "your_password",
330363
"server": "MetaQuotes-Demo",
331-
"timeout": 60000, # Connection timeout (ms)
332-
"max_retries": 3, # Retry attempts
333-
"backoff_factor": 1.5, # Delay multiplier between retries
334-
"cooldown_time": 2.0, # Seconds to wait between connections
335-
"debug": True # Enable debug logging
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)
336371
}
337372
```
338373

374+
**Configuration Options:**
375+
376+
- **login** (int, required): Your MT5 account login number
377+
- **password** (str, required): Your MT5 account password
378+
- **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 directories
380+
- **timeout** (int, optional): Connection timeout in milliseconds. Default: 60000 (60 seconds)
381+
- **portable** (bool, optional): Enable portable mode for the MT5 terminal. Default: False
382+
- **max_retries** (int, optional): Maximum number of connection retry attempts. Default: 3
383+
- **backoff_factor** (float, optional): Exponential backoff factor for retry delays. Default: 1.5
384+
- **cooldown_time** (float, optional): Minimum time in seconds between connection attempts. Default: 2.0
385+
- **debug** (bool, optional): Enable detailed debug logging for troubleshooting. Default: False
386+
339387
---
340388

341389
## 🗺️ Roadmap
@@ -468,7 +516,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
468516

469517
## 📊 Project Stats
470518

471-
- **Version**: 0.2.8
519+
- **Version**: 0.2.9
472520
- **Python**: 3.10+
473521
- **License**: MIT
474522
- **Status**: Active Development

docs/metatrader_client/README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,45 @@ from metatrader_client.client import MT5Client
3232
```python
3333
from metatrader_client.client import MT5Client
3434

35+
# Minimal configuration
3536
config = {
3637
"login": 12345678,
3738
"password": "your_password",
38-
"server": "Broker-Server",
39-
# Optional: path, timeout, portable, debug, etc.
39+
"server": "Broker-Server"
40+
}
41+
42+
# Full configuration with all available options
43+
config = {
44+
"login": 12345678, # Required: MT5 account login number
45+
"password": "your_password", # Required: MT5 account password
46+
"server": "Broker-Server", # Required: MT5 server name
47+
"path": None, # Optional: Path to terminal executable (auto-detect if None)
48+
"timeout": 60000, # Optional: Connection timeout in ms (default: 60000)
49+
"portable": False, # Optional: Use portable mode (default: False)
50+
"max_retries": 3, # Optional: Max connection retries (default: 3)
51+
"backoff_factor": 1.5, # Optional: Retry delay multiplier (default: 1.5)
52+
"cooldown_time": 2.0, # Optional: Seconds between connections (default: 2.0)
53+
"debug": False # Optional: Enable debug logging (default: False)
4054
}
4155

4256
client = MT5Client(config)
4357
```
4458

59+
### Configuration Parameters
60+
61+
| Parameter | Type | Required | Default | Description |
62+
|-----------|------|----------|---------|-------------|
63+
| `login` | int | Yes | - | Your MT5 account login number |
64+
| `password` | str | Yes | - | Your MT5 account password |
65+
| `server` | str | Yes | - | MT5 server name (e.g., "MetaQuotes-Demo") |
66+
| `path` | str | No | None | Full path to MT5 terminal executable (auto-detected if not provided) |
67+
| `timeout` | int | No | 60000 | Connection timeout in milliseconds |
68+
| `portable` | bool | No | False | Enable portable mode for MT5 terminal |
69+
| `max_retries` | int | No | 3 | Maximum number of connection retry attempts |
70+
| `backoff_factor` | float | No | 1.5 | Exponential backoff factor for retry delays |
71+
| `cooldown_time` | float | No | 2.0 | Minimum time in seconds between connection attempts |
72+
| `debug` | bool | No | False | Enable detailed debug logging for troubleshooting |
73+
4574
---
4675

4776
## Main Attributes & Methods 🧩

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "metatrader-mcp-server"
7-
version = "0.2.8"
7+
version = "0.2.9"
88
authors = [
99
{ name = "Aria Dhanang", email = "ariadng@gmail.com" },
1010
]

src/metatrader_mcp/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
@click.option("--login", required=True, type=int, help="MT5 login ID")
88
@click.option("--password", required=True, help="MT5 password")
99
@click.option("--server", required=True, help="MT5 server name")
10-
def main(login, password, server):
10+
@click.option("--path", default=None, help="Path to MT5 terminal executable (optional, auto-detected if not provided)")
11+
def main(login, password, server, path):
1112
"""Launch the MetaTrader MCP STDIO server."""
1213
load_dotenv()
1314
# override env vars if provided via CLI
1415
os.environ["login"] = str(login)
1516
os.environ["password"] = password
1617
os.environ["server"] = server
18+
if path:
19+
os.environ["path"] = path
1720
# run STDIO transport
1821
mcp.run(transport="stdio")
1922

src/metatrader_mcp/server.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ class AppContext:
2323
async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
2424

2525
try:
26-
client = init(os.getenv("login"), os.getenv("password"), os.getenv("server"))
26+
client = init(
27+
os.getenv("login"),
28+
os.getenv("password"),
29+
os.getenv("server"),
30+
os.getenv("path")
31+
)
2732
yield AppContext(client=client)
2833
finally:
2934
client.disconnect()
@@ -229,13 +234,15 @@ def cancel_pending_orders_by_symbol(ctx: Context, symbol: str) -> dict:
229234
parser.add_argument("--login", type=str, help="MT5 login")
230235
parser.add_argument("--password", type=str, help="MT5 password")
231236
parser.add_argument("--server", type=str, help="MT5 server name")
232-
237+
parser.add_argument("--path", type=str, help="Path to MT5 terminal executable (optional)")
238+
233239
args = parser.parse_args()
234240

235241
# inject into lifespan via env vars
236242
if args.login: os.environ["login"] = args.login
237243
if args.password: os.environ["password"] = args.password
238244
if args.server: os.environ["server"] = args.server
245+
if args.path: os.environ["path"] = args.path
239246

240247
# run the MCP server (must call mcp.run)
241248
mcp.run(

src/metatrader_mcp/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def init(
55
login: Optional[Union[str, int]],
66
password: Optional[str],
77
server: Optional[str],
8+
path: Optional[str] = None,
89
) -> Optional[client.MT5Client]:
910
"""
1011
Initialize MT5Client
@@ -13,17 +14,24 @@ def init(
1314
login (Optional[Union[str, int]]): Login ID
1415
password (Optional[str]): Password
1516
server (Optional[str]): Server name
17+
path (Optional[str]): Path to MT5 terminal executable (default: None for auto-detect)
1618
1719
Returns:
1820
Optional[client.MT5Client]: MT5Client instance if all parameters are provided, None otherwise
1921
"""
20-
22+
2123
if login and password and server:
22-
mt5_client = client.MT5Client(config={
24+
config = {
2325
"login": int(login),
2426
"password": password,
2527
"server": server,
26-
})
28+
}
29+
30+
# Add path to config if provided
31+
if path:
32+
config["path"] = path
33+
34+
mt5_client = client.MT5Client(config=config)
2735
mt5_client.connect()
2836
return mt5_client
2937

src/metatrader_openapi/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Settings(BaseSettings):
2222
docs_url: str = "/docs"
2323
redoc_url: str = "/redoc"
2424
title: str = "MetaTrader MCP API"
25-
version: str = "0.2.8"
25+
version: str = "0.2.9"
2626

2727
# Load from env vars prefixed with OPENAPI_
2828
model_config = SettingsConfigDict(env_prefix="OPENAPI_")

src/metatrader_openapi/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ async def lifespan(app):
2222
login = os.getenv("LOGIN", os.getenv("login"))
2323
password = os.getenv("PASSWORD", os.getenv("password"))
2424
server = os.getenv("SERVER", os.getenv("server"))
25-
client = init(login, password, server)
25+
path = os.getenv("PATH", os.getenv("path"))
26+
client = init(login, password, server, path)
2627
app.state.client = client
2728
yield
2829
if client:
@@ -62,6 +63,7 @@ def main():
6263
parser.add_argument("--login", required=True, help="MT5 login")
6364
parser.add_argument("--password", required=True, help="MT5 password")
6465
parser.add_argument("--server", required=True, help="MT5 server address")
66+
parser.add_argument("--path", default=None, help="Path to MT5 terminal executable (optional, auto-detected if not provided)")
6567
parser.add_argument("--host", default="127.0.0.1", help="Bind host")
6668
parser.add_argument("--port", type=int, default=8000, help="Bind port")
6769
args = parser.parse_args()
@@ -73,6 +75,9 @@ def main():
7375
os.environ["login"] = args.login
7476
os.environ["password"] = args.password
7577
os.environ["server"] = args.server
78+
if args.path:
79+
os.environ["PATH"] = args.path
80+
os.environ["path"] = args.path
7681

7782
uvicorn.run(
7883
"metatrader_openapi.main:app",

0 commit comments

Comments
 (0)