Cover image
Try Now
2025-04-13

A Model Context Protocol (MCP) server for interacting with the MetaTrader 5 trading platform. This server provides AI assistants with tools and resources to access market data, perform trading operations, and analyze trading history.

3 years

Works with Finder

2

Github Watches

1

Github Forks

6

Github Stars

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 PyPI

pip install mcp-metatrader5-server

From Source

git clone https://github.com/yourusername/mcp-metatrader5-server.git
cd mcp-metatrader5-server
pip install -e .

Requirements

  • 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:

mt5-mcp dev

This will start the server at http://127.0.0.1:8000 by default.

You can specify a different host and port:

mt5-mcp dev --host 0.0.0.0 --port 8080

Installing for Claude Desktop

To install the server for Claude Desktop:

mt5-mcp install

API Reference

Connection Management

  • initialize(): Initialize the MT5 terminal
  • login(account, password, server): Log in to a trading account
  • shutdown(): Close the connection to the MT5 terminal

Market Data Functions

  • get_symbols(): Get all available symbols
  • get_symbols_by_group(group): Get symbols by group
  • get_symbol_info(symbol): Get information about a specific symbol
  • get_symbol_info_tick(symbol): Get the latest tick for a symbol
  • copy_rates_from_pos(symbol, timeframe, start_pos, count): Get bars from a specific position
  • copy_rates_from_date(symbol, timeframe, date_from, count): Get bars from a specific date
  • copy_rates_range(symbol, timeframe, date_from, date_to): Get bars within a date range
  • copy_ticks_from_pos(symbol, start_pos, count): Get ticks from a specific position
  • copy_ticks_from_date(symbol, date_from, count): Get ticks from a specific date
  • copy_ticks_range(symbol, date_from, date_to): Get ticks within a date range

Trading Functions

  • order_send(request): Send an order to the trade server
  • order_check(request): Check if an order can be placed with the specified parameters
  • positions_get(symbol, group): Get open positions
  • positions_get_by_ticket(ticket): Get an open position by its ticket
  • orders_get(symbol, group): Get active orders
  • orders_get_by_ticket(ticket): Get an active order by its ticket
  • history_orders_get(symbol, group, ticket, position, from_date, to_date): Get orders from history
  • history_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 API
  • mt5://trading_guide: Guide for placing and managing trades
  • mt5://market_data_guide: Guide for accessing and analyzing market data
  • mt5://order_types: Information about order types
  • mt5://order_filling_types: Information about order filling types
  • mt5://order_time_types: Information about order time types
  • mt5://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 in
  • analyze_market_data(symbol, timeframe): Analyze market data for a specific symbol
  • place_trade(symbol, order_type, volume): Place a trade for a specific symbol
  • manage_positions(): Manage open positions
  • analyze_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

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • 林乔安妮
  • A fashion stylist GPT offering outfit suggestions for various scenarios.

  • https://reddgr.com
  • Delivers concise Python code and interprets non-English comments

  • 田中 楓太
  • A virtual science instructor for engaging and informative lessons.

  • ShrimpingIt
  • Micropython I2C-based manipulation of the MCP series GPIO expander, derived from Adafruit_MCP230xx

  • apappascs
  • Discover the most comprehensive and up-to-date collection of MCP servers in the market. This repository serves as a centralized hub, offering an extensive catalog of open-source and proprietary MCP servers, complete with features, documentation links, and contributors.

  • GeyserMC
  • A library for communication with a Minecraft client/server.

  • awslabs
  • AWS MCP Servers — specialized MCP servers that bring AWS best practices directly to your development workflow

  • Mintplex-Labs
  • The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, No-code agent builder, MCP compatibility, and more.

  • 1Panel-dev
  • 💬 MaxKB is an open-source AI assistant for enterprise. It seamlessly integrates RAG pipelines, supports robust workflows, and provides MCP tool-use capabilities.

  • modelcontextprotocol
  • Model Context Protocol Servers

  • open-webui
  • User-friendly AI Interface (Supports Ollama, OpenAI API, ...)

    Reviews

    5 (1)
    Avatar
    user_iRYqm6r1
    2025-04-18

    mcp-metatrader5-server by Qoyyuum is a phenomenal tool for trading automation. The integration with MetaTrader 5 is seamless, and the setup is user-friendly. Whether you're a beginner or an experienced trader, this server elevates your trading experience. For anyone serious about trading, this is a must-have. Highly recommended!