
MetaTrader 5 MCP Server
Enables AI assistants to interact with the MetaTrader 5 trading platform for market data analysis, placing trades, and managing trading positions. Provides comprehensive access to forex and financial market operations through the Model Context Protocol.
README
MetaTrader 5 MCP Server
A Model Context Protocol (MCP) server for MetaTrader 5, allowing AI assistants to interact with the MetaTrader 5 platform for trading and market data analysis.
Features
- Connect to MetaTrader 5 terminal
- Access market data (symbols, rates, ticks)
- Place and manage trades
- Analyze trading history
- Integrate with AI assistants through the Model Context Protocol
Installation
From Source
git clone https://github.com/Qoyyuum/mcp-metatrader5-server.git
cd mcp-metatrader5-server
pip install -e .
Requirements
- uv
- Python 3.11 or higher
- MetaTrader 5 terminal installed
- MetaTrader 5 account (demo or real)
Usage
Running the Server
To run the server in development mode:
uv run mt5mcp dev
This will start the server at http://127.0.0.1:8000 by default.
You can specify a different host and port:
uv run mt5mcp dev --host 0.0.0.0 --port 8080
Installing for Claude Desktop
To install the server for Claude Desktop:
git clone https://github.com/Qoyyuum/mcp-metatrader5-server
cd mcp-metatrader5-server
uv run fastmcp install src\mcp_metatrader5_server\server.py
Check your claude_desktop_config.json
file. It should look something like this:
{
"mcpServers": {
"MetaTrader 5 MCP Server": {
"command": "uv",
"args": [
"run",
"--with",
"MetaTrader5",
"--with",
"fastmcp",
"--with",
"numpy",
"--with",
"pandas",
"--with",
"pydantic",
"fastmcp",
"run",
"C:\\FULL_PATH_TO\\src\\mcp_metatrader5_server\\server.py"
]
}
}
}
API Reference
Connection Management
initialize()
: Initialize the MT5 terminallogin(account, password, server)
: Log in to a trading accountshutdown()
: Close the connection to the MT5 terminal
Market Data Functions
get_symbols()
: Get all available symbolsget_symbols_by_group(group)
: Get symbols by groupget_symbol_info(symbol)
: Get information about a specific symbolget_symbol_info_tick(symbol)
: Get the latest tick for a symbolcopy_rates_from_pos(symbol, timeframe, start_pos, count)
: Get bars from a specific positioncopy_rates_from_date(symbol, timeframe, date_from, count)
: Get bars from a specific datecopy_rates_range(symbol, timeframe, date_from, date_to)
: Get bars within a date rangecopy_ticks_from_pos(symbol, start_pos, count)
: Get ticks from a specific positioncopy_ticks_from_date(symbol, date_from, count)
: Get ticks from a specific datecopy_ticks_range(symbol, date_from, date_to)
: Get ticks within a date range
Trading Functions
order_send(request)
: Send an order to the trade serverorder_check(request)
: Check if an order can be placed with the specified parameterspositions_get(symbol, group)
: Get open positionspositions_get_by_ticket(ticket)
: Get an open position by its ticketorders_get(symbol, group)
: Get active ordersorders_get_by_ticket(ticket)
: Get an active order by its tickethistory_orders_get(symbol, group, ticket, position, from_date, to_date)
: Get orders from historyhistory_deals_get(symbol, group, ticket, position, from_date, to_date)
: Get deals from history
Example Workflows
Connecting and Getting Market Data
# Initialize MT5
initialize()
# Log in to your trading account
login(account=123456, password="your_password", server="your_server")
# Get available symbols
symbols = get_symbols()
# Get recent price data for EURUSD
rates = copy_rates_from_pos(symbol="EURUSD", timeframe=15, start_pos=0, count=100)
# Shut down the connection
shutdown()
Placing a Trade
# Initialize and log in
initialize()
login(account=123456, password="your_password", server="your_server")
# Create an order request
request = OrderRequest(
action=mt5.TRADE_ACTION_DEAL,
symbol="EURUSD",
volume=0.1,
type=mt5.ORDER_TYPE_BUY,
price=mt5.symbol_info_tick("EURUSD").ask,
deviation=20,
magic=123456,
comment="Buy order",
type_time=mt5.ORDER_TIME_GTC,
type_filling=mt5.ORDER_FILLING_IOC
)
# Send the order
result = order_send(request)
# Shut down the connection
shutdown()
Resources
The server provides the following resources to help AI assistants understand how to use the MetaTrader 5 API:
mt5://getting_started
: Basic workflow for using the MetaTrader 5 APImt5://trading_guide
: Guide for placing and managing tradesmt5://market_data_guide
: Guide for accessing and analyzing market datamt5://order_types
: Information about order typesmt5://order_filling_types
: Information about order filling typesmt5://order_time_types
: Information about order time typesmt5://trade_actions
: Information about trade request actions
Prompts
The server provides the following prompts to help AI assistants interact with users:
connect_to_mt5(account, password, server)
: Connect to MetaTrader 5 and log inanalyze_market_data(symbol, timeframe)
: Analyze market data for a specific symbolplace_trade(symbol, order_type, volume)
: Place a trade for a specific symbolmanage_positions()
: Manage open positionsanalyze_trading_history(days)
: Analyze trading history
Development
Project Structure
mcp-metatrader5-server/
├── src/
│ └── mcp_metatrader5_server/
│ ├── __init__.py
│ ├── server.py
│ ├── market_data.py
│ ├── trading.py
│ ├── main.py
│ └── cli.py
├── run.py
├── README.md
└── pyproject.toml
Building the Package
To build the package:
python -m pip install build
python -m build
Or using uv:
uv build
Publishing to PyPI
To publish the package to PyPI:
python -m pip install twine
python -m twine upload dist/*
Or using uv:
uv publish
License
MIT
Acknowledgements
- MetaQuotes for the MetaTrader 5 platform
- FastMCP for the MCP server implementation
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.