MetaTrader MCP Server

by ariadng

612 1.3k downloads Not rated yet MIT

About

A Python-based MCP server that allows AI LLMs to execute trades on the MetaTrader 5 platform.

Details

License
MIT

Explore

- 🗣️ Natural Language Trading - Talk to AI in plain English to execute trades
- 🤖 Multi-AI Support - Works with Claude Desktop, ChatGPT (via Open WebUI), and more
- 📊 Full Market Access - Get real-time prices, historical data, and symbol information
- 💼 Complete Account Control - Check balance, equity, margin, and trading statistics
- ⚡ Order Management - Place, modify, and close orders with simple commands
- 🔒 Secure - All credentials stay on your machine
- 🌐 Flexible Interfaces - Use as MCP server, REST API, or WebSocket stream
- 📖 Well Documented - Comprehensive guides and examples

Once installed, invoke with /trading or just ask trading-related questions naturally:

/trading
> Show me my account dashboard
> Buy 0.1 lots of EURUSD with SL at 1.0800
> Close all profitable positions
> Show me GBPUSD H4 candles

---

Before you begin, make sure you have:

1. Python 3.10 or higher - Download here
2. MetaTrader 5 terminal - Download here
3. MT5 Trading Account - Demo or live account credentials
- Login number
- Password
- Server name (e.g., "MetaQuotes-Demo")

Open your terminal or command prompt and run:

pip install metatrader-mcp-server

Option 1: Symlink (recommended)

Create a symlink from the standard Claude Code skills directory to claude-skill/:

cd metatrader-mcp-server
mkdir -p .claude
ln -s ../claude-skill .claude/skills

The skill will be auto-discovered and available as /trading.

Option 2: Copy

Copy the skill files into the Claude Code skills directory:

cd metatrader-mcp-server
mkdir -p .claude/skills
cp -r claude-skill/trading .claude/skills/trading

For Claude Desktop, copy the skill to the global Claude skills directory:


Instead of putting credentials in the command line, create a .env file:

env
LOGIN=12345678
PASSWORD=your_password
SERVER=MetaQuotes-Demo

The MCP server supports multiple transport modes:

| Flag | Env Var | Default | Description |
|------|---------|---------|-------------|
| --transport | MCP_TRANSPORT | sse | Transport type: sse, stdio, streamable-http |
| --host | MCP_HOST | 0.0.0.0 | Host to bind (SSE/HTTP only) |
| --port | MCP_PORT | 8080 | Port to bind (SSE/HTTP only) |

CLI flags take precedence over environment variables, which take precedence over defaults.

```bash

pip install -e .

pip install pytest python-dotenv

- Issues: GitHub Issues
- Discussions: GitHub Discussions
- LinkedIn: Connect with me

<div align="center">
<h1>MetaTrader MCP Server</h1>
</div>

<br />

<div align="center">

PyPI version
Python 3.10+
License: MIT

Let AI assistants trade for you using natural language

MetaTrader MCP Server

</div>

<br />

---

📑 Table of Contents

- What is This?
- Features
- Who Is This For?
- Important Disclaimer
- Prerequisites
- Quick Start
- Trading Assistant Skill
- Usage Examples
- Available Operations
- WebSocket Quote Server
- Advanced Configuration
- Roadmap
- Development
- Contributing
- Documentation
- Getting Help
- License

---

🌟 What is This?

MetaTrader MCP Server is a bridge that connects AI assistants (like Claude, ChatGPT) to the MetaTrader 5 trading platform. Instead of clicking buttons, you can simply tell your AI assistant what to do:

> "Show me my account balance"
> "Buy 0.01 lots of EUR/USD"
> "Close all profitable positions"

The AI understands your request and executes it on MetaTrader 5 automatically.

How It Works

You → AI Assistant → MCP Server → MetaTrader 5 → Your Trades

✨ Features

- 🗣️ Natural Language Trading - Talk to AI in plain English to execute trades
- 🤖 Multi-AI Support - Works with Claude Desktop, ChatGPT (via Open WebUI), and more
- 📊 Full Market Access - Get real-time prices, historical data, and symbol information
- 💼 Complete Account Control - Check balance, equity, margin, and trading statistics
- ⚡ Order Management - Place, modify, and close orders with simple commands
- 🔒 Secure - All credentials stay on your machine
- 🌐 Flexible Interfaces - Use as MCP server, REST API, or WebSocket stream
- 📖 Well Documented - Comprehensive guides and examples

🎯 Who Is This For?

- Traders who want to automate their trading using AI
- Developers building trading bots or analysis tools
- Analysts who need quick access to market data
- Anyone interested in combining AI with financial markets

⚠️ Important Disclaimer

Please read this carefully:

Trading financial instruments involves significant risk of loss. This software is provided as-is, and the developers accept no liability for any trading losses, gains, or consequences of using this software.

By using this software, you acknowledge that:
- You understand the risks of financial trading
- You are responsible for all trades executed through this system
- You will not hold the developers liable for any outcomes
- You are using this software at your own risk

This is not financial advice. Always trade responsibly.

---

📋 Prerequisites

Before you begin, make sure you have:

1. Python 3.10 or higher - Download here
2. MetaTrader 5 terminal - Download here
3. MT5 Trading Account - Demo or live account credentials
- Login number
- Password
- Server name (e.g., "MetaQuotes-Demo")

🚀 Quick Start

Step 1: Install the Package

Open your terminal or command prompt and run:

pip install metatrader-mcp-server

Step 2: Enable Algorithmic Trading

1. Open MetaTrader 5
2. Go to Tools → Options
3. Click the Expert Advisors tab
4. Check the box for Allow algorithmic trading
5. Click OK

Step 3: Choose Your Interface

Pick one based on how you want to use it:

Option A: Use with Claude Desktop (Local STDIO)

1. Find your Claude Desktop config file:
- Windows: %APPDATA%\Claude\claude_desktop_config.json
- Mac: ~/Library/Application Support/Claude/claude_desktop_config.json

2. Open the file and add this configuration:

{
  "mcpServers": {
    "metatrader": {
      "command": "metatrader-mcp-server",
      "args": [
        "--login",     "YOUR_MT5_LOGIN",
        "--password",  "YOUR_MT5_PASSWORD",
        "--server",    "YOUR_MT5_SERVER",
        "--transport", "stdio"
      ]
    }
  }
}

Optional: Specify Custom MT5 Terminal Path

If your MT5 terminal is installed in a non-standard location, add the --path argument:

{
  "mcpServers": {
    "metatrader": {
      "command": "metatrader-mcp-server",
      "args": [
        "--login",     "YOUR_MT5_LOGIN",
        "--password",  "YOUR_MT5_PASSWORD",
        "--server",    "YOUR_MT5_SERVER",
        "--transport", "stdio",
        "--path",      "C:\\Program Files\\MetaTrader 5\\terminal64.exe"
      ]
    }
  }
}

3. Replace YOUR_MT5_LOGIN, YOUR_MT5_PASSWORD, and YOUR_MT5_SERVER with your actual credentials

4. Restart Claude Desktop

5. Start chatting! Try: "What's my account balance?"

Option B: Use with Open WebUI (For ChatGPT and other LLMs)

1. Start the HTTP server:

metatrader-http-server --login YOUR_LOGIN --password YOUR_PASSWORD --server YOUR_SERVER --host 0.0.0.0 --port 8000

Optional: Specify Custom MT5 Terminal Path

If your MT5 terminal is installed in a non-standard location, add the --path argument:

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

2. Open your browser to http://localhost:8000/docs to see the API documentation

3. In Open WebUI:
- Go to Settings → Tools
- Click Add Tool Server
- Enter http://localhost:8000
- Save

4. Now you can use trading tools in your Open WebUI chats!

Option C: Real-Time Quotes via WebSocket

Stream live tick data (bid, ask, spread, volume) over WebSocket for dashboards, bots, or monitoring:

metatrader-quote-server --login YOUR_LOGIN --password YOUR_PASSWORD --server YOUR_SERVER

Connect with any WebSocket client:

websocat ws://localhost:8765

You'll receive a connected message followed by continuous tick updates as JSON. See WebSocket Quote Server for full details.

Option D: Remote MCP Server (SSE)

Run the MCP server on a Windows VPS (where MT5 is installed) and connect to it remotely from Claude Desktop or Claude Code.

Server-side (on the Windows VPS):

metatrader-mcp-server --login YOUR_LOGIN --password YOUR_PASSWORD --server YOUR_SERVER

This starts the SSE server on 0.0.0.0:8080 by default. Customize with --host and --port:

metatrader-mcp-server --login YOUR_LOGIN --password YOUR_PASSWORD --server YOUR_SERVER --host 127.0.0.1 --port 9000

Client-side (Claude Desktop config on your local machine):

{
  "mcpServers": {
    "metatrader": {
      "url": "http://VPS_IP:8080/sse"
    }
  }
}

Replace VPS_IP with your server's IP address.

> Security Warning: The MCP protocol does not include authentication. When exposing the SSE server over a network, use a firewall to restrict access by IP, or place it behind a reverse proxy with authentication, or use an SSH tunnel.

---

🤖 Trading Assistant Skill (Claude Code / Claude Desktop)

A pre-built Trading Terminal Assistant skill is included in the claude-skill/ directory. It provides Claude with structured knowledge about all 32 trading tools, output formatting, and MetaTrader 5 domain expertise.

Installing for Claude Code

Option 1: Symlink (recommended)

…

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.

Videos about MetaTrader MCP Server

Relevant YouTube tutorials, setups, and demos