Summary
In metatrader-mcp-server v0.5.1, the get_account_type() function returns incorrect values because the mapping between MT5's trade_mode integer and the returned string is rotated by one position. The most concerning consequence: demo accounts are reported as "real", which inverts the safety-critical signal that downstream code typically uses to gate live trading.
Reproduction
- Connect to any MT5 demo account (verified with XS Fintech demo, login on
XSFintech-DEMO server, MT5 title bar shows "デモ口座" / DEMO).
- Call the
get_account_info MCP tool.
- Inspect the
account_type field in the response.
Expected: "demo"
Actual: "real"
Independently verified via direct Python: mt5.account_info().trade_mode returns 0 (= ACCOUNT_TRADE_MODE_DEMO per MetaTrader 5 documentation), confirming the underlying MT5 value is correct and the bug is purely in the mapping.
Root cause
In metatrader_client/account/get_account_type.py (lines 14–20), the mapping is:
if trade_mode == 0:
return "real"
elif trade_mode == 1:
return "demo"
elif trade_mode == 2:
return "contest"
The correct mapping per MT5's ENUM_ACCOUNT_TRADE_MODE is:
trade_mode value |
Constant |
Should return |
| 0 |
ACCOUNT_TRADE_MODE_DEMO |
"demo" |
| 1 |
ACCOUNT_TRADE_MODE_CONTEST |
"contest" |
| 2 |
ACCOUNT_TRADE_MODE_REAL |
"real" |
A secondary inconsistency exists in metatrader_client/account/get_account_info.py line 12 docstring, which documents the same wrong premise (0-real, 1-demo, 2-contest). This consistent error across at least two locations suggests the misunderstanding is repository-wide rather than isolated to one function.
The MCP tool get_account_info reaches the buggy mapping via:
metatrader_openapi/routers/accounts.py (account_info endpoint) → client.account.get_trade_statistics() → get_account_type(). The docstring in get_account_info.py is unused by this path but documents the same incorrect ordering.
Suggested fix
Swap the return values in get_account_type.py to match MT5's actual enum, and update the docstring in get_account_info.py accordingly.
Impact
Any caller using account_type to gate live-vs-demo behavior (e.g., "only place real orders if account_type == 'real'") will do the opposite of intended. Trading bots are the obvious risk surface — a strategy designed to fire on a genuine demo account for testing will refuse to fire there, while strategies meant to execute only on live will fire on what the system believes is a real account but is actually demo (or vice versa depending on logic direction). Even safety patterns like if account_type != 'real': abort() invert silently.
Flagging now so other users don't trip the same wire.
Environment
metatrader-mcp-server 0.5.1 (PyPI)
- Python 3.12.10 on Windows 11
- MT5 terminal 5.0.0.5833
MetaTrader5 package 5.0.5735
Summary
In
metatrader-mcp-serverv0.5.1, theget_account_type()function returns incorrect values because the mapping between MT5'strade_modeinteger and the returned string is rotated by one position. The most concerning consequence: demo accounts are reported as"real", which inverts the safety-critical signal that downstream code typically uses to gate live trading.Reproduction
XSFintech-DEMOserver, MT5 title bar shows "デモ口座" / DEMO).get_account_infoMCP tool.account_typefield in the response.Expected:
"demo"Actual:
"real"Independently verified via direct Python:
mt5.account_info().trade_modereturns0(=ACCOUNT_TRADE_MODE_DEMOper MetaTrader 5 documentation), confirming the underlying MT5 value is correct and the bug is purely in the mapping.Root cause
In
metatrader_client/account/get_account_type.py(lines 14–20), the mapping is:The correct mapping per MT5's
ENUM_ACCOUNT_TRADE_MODEis:trade_modevalueACCOUNT_TRADE_MODE_DEMO"demo"ACCOUNT_TRADE_MODE_CONTEST"contest"ACCOUNT_TRADE_MODE_REAL"real"A secondary inconsistency exists in
metatrader_client/account/get_account_info.pyline 12 docstring, which documents the same wrong premise (0-real, 1-demo, 2-contest). This consistent error across at least two locations suggests the misunderstanding is repository-wide rather than isolated to one function.The MCP tool
get_account_inforeaches the buggy mapping via:metatrader_openapi/routers/accounts.py(account_info endpoint) →client.account.get_trade_statistics()→get_account_type(). The docstring inget_account_info.pyis unused by this path but documents the same incorrect ordering.Suggested fix
Swap the return values in
get_account_type.pyto match MT5's actual enum, and update the docstring inget_account_info.pyaccordingly.Impact
Any caller using
account_typeto gate live-vs-demo behavior (e.g., "only place real orders ifaccount_type == 'real'") will do the opposite of intended. Trading bots are the obvious risk surface — a strategy designed to fire on a genuine demo account for testing will refuse to fire there, while strategies meant to execute only on live will fire on what the system believes is a real account but is actually demo (or vice versa depending on logic direction). Even safety patterns likeif account_type != 'real': abort()invert silently.Flagging now so other users don't trip the same wire.
Environment
metatrader-mcp-server0.5.1 (PyPI)MetaTrader5package 5.0.5735