MetaTrader 4 MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
npm install
npm run build
2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add -e "MT4_HOST=${MT4_HOST}" -e "MT4_PORT=${MT4_PORT}" metatrader-4 -- node "<FULL_PATH_TO_METATRADER_4_MCP>/dist/index.js"

Replace <FULL_PATH_TO_METATRADER_4_MCP>/dist/index.js with the actual folder you prepared in step 1.

Required:MT4_HOSTMT4_PORT
README.md

Cross-platform integration with MetaTrader 4 trading platform over network.

MCP MetaTrader 4 Server

A Model Context Protocol (MCP) server that provides cross-platform integration with MetaTrader 4 trading platform over network.

Author: 8nite (8nite@qmlab.io)

Features

  • Account Information: Get real-time account details (balance, equity, margin, etc.)
  • Market Data: Retrieve current market prices for trading symbols
  • Order Management: Place market and pending orders
  • Position Management: View and close open positions
  • Trading History: Access historical trading data
  • Backtesting: Run backtests on Expert Advisors with detailed configuration
  • Expert Advisor Management: List and manage available EAs
  • File-Based Fallback: Robust status and results tracking when API endpoints fail
  • EA Development: Remote EA creation, editing, sync, and compilation with error reporting
  • Cross-Platform: Linux MCP server connects to Windows MT4 via HTTP

Architecture

The integration uses HTTP communication between the MCP server and MT4:

  1. MCP Server (Linux - Node.js/TypeScript) - Provides tools for Claude Code
  2. HTTP Bridge (Windows - Node.js) - Converts HTTP requests to file I/O
  3. MT4 Expert Advisor (Windows - MQL4) - Handles trading operations
  4. Network Communication - JSON-based data exchange via HTTP API

Setup

1. Install MCP Server (Linux Machine - 192.168.50.X)

npm install
npm run build

2. Install HTTP Bridge (Windows Machine - 192.168.50.161)

  1. Copy the windows-server/ folder to your Windows machine
  2. Install Node.js on Windows if not already installed
  3. Navigate to the windows-server folder and run:
npm install
npm start
  1. The HTTP bridge will start on port 8080

3. Install MT4 Expert Advisor (Windows Machine)

Option A: Ultimate MCP EA (Recommended)

  1. Copy mcp/MCP_Ultimate.mq4 to your MT4 MQL4/Experts/ folder
  2. Compile the Expert Advisor in MetaEditor
  3. Attach the Expert Advisor to any chart in MT4
  4. Configure EA inputs:
    • EnableFileReporting: true (for enhanced reporting)
    • EnableBacktestTracking: true (for backtest monitoring)
    • EnableVisualMode: true (for on-chart status indicators)
    • Configure market data tracking options as needed
  5. Ensure "Allow DLL imports" is enabled in MT4 settings

Option B: Unified EA (Legacy)

  1. Copy MT4_Files/MCPBridge_Unified.mq4 to your MT4 MQL4/Experts/ folder
  2. Follow same compilation and attachment process
  3. Enhanced functionality but not as comprehensive as Ultimate version

Option C: Basic EA (Legacy)

  1. Copy MT4_Files/MCPBridge.mq4 to your MT4 MQL4/Experts/ folder
  2. Follow same compilation and attachment process
  3. Limited to basic MCP functionality without enhanced reporting

4. Configure Claude Code (Linux Machine)

Add the MCP server to your Claude Code configuration:

claude mcp add mt4-server npm run start

Or configure manually with custom IP:

MT4_HOST=192.168.50.161 MT4_PORT=8080 claude mcp add mt4-server npm run start

Or in your MCP settings:

{
  "mcpServers": {
    "mt4-server": {
      "command": "node",
      "args": ["dist/index.js"],
      "env": {
        "MT4_HOST": "192.168.50.161",
        "MT4_PORT": "8080"
      }
    }
  }
}

Usage

Once configured, you can use these tools in Claude Code:

Get Account Information

Use the get_account_info tool to see my MT4 account details

Get Market Data

Get current market data for EURUSD using get_market_data

Place Orders

Place a BUY order for 0.1 lots of EURUSD with stop loss at 1.0850 and take profit at 1.0950

View Positions

Show me all my open positions using get_positions

Close Position

Close position with ticket number 12345

Run Backtest

Run a backtest on MACD Sample Expert Advisor for EURUSD H1 from 2024-01-01 to 2024-12-31 with initial deposit 10000

List Expert Advisors

Show me all available Expert Advisors for backtesting

Get Backtest Results

Get the results from the last backtest with detailed information

Monitor Backtest Status

Check the current status of a running backtest

EA Development Workflow

List Local EAs

Show me all EAs in the active development folder

Sync EA to MT4

Upload MyStrategy EA to MetaTrader for compilation

Compile EA

Compile MyStrategy EA and show any errors or warnings

Create New EA from Template

cd ea-strategies
./develop.sh new MyNewStrategy SimpleMA_Template.mq4
./develop.sh edit MyNewStrategy

File Structure

├── src/
│   └── index.ts                    # MCP server implementation
├── mcp/                            # MCP infrastructure files
│   └── MCP_Ultimate.mq4           # Ultimate unified MCP Bridge with all features
├── strategies/                     # User trading strategies (git ignored)
│   └── [User strategy EAs]        # Custom trading strategies for pe

Tools (6)

get_account_infoRetrieve real-time account details including balance, equity, and margin.
get_market_dataRetrieve current market prices for specified trading symbols.
place_orderPlace market or pending orders on the trading platform.
get_positionsView all currently open trading positions.
close_positionClose an open position using its ticket number.
run_backtestExecute a backtest on an Expert Advisor with specific configuration.

Environment Variables

MT4_HOSTrequiredThe IP address of the Windows machine running the MT4 HTTP bridge.
MT4_PORTrequiredThe port number for the MT4 HTTP bridge.

Configuration

claude_desktop_config.json
{"mcpServers": {"mt4-server": {"command": "node", "args": ["dist/index.js"], "env": {"MT4_HOST": "192.168.50.161", "MT4_PORT": "8080"}}}}

Try it

Get current market data for EURUSD using get_market_data
Place a BUY order for 0.1 lots of EURUSD with stop loss at 1.0850 and take profit at 1.0950
Run a backtest on MACD Sample Expert Advisor for EURUSD H1 from 2024-01-01 to 2024-12-31
Show me all my open positions using get_positions
Compile MyStrategy EA and show any errors or warnings

Frequently Asked Questions

What are the key features of MetaTrader 4 MCP Server?

Real-time account information and market data retrieval. Automated order management and position tracking. Remote Expert Advisor development, synchronization, and compilation. Automated backtesting with detailed status monitoring. Cross-platform architecture connecting Linux MCP server to Windows MT4.

What can I use MetaTrader 4 MCP Server for?

Automating trading strategies by executing orders directly through Claude. Streamlining the development and testing cycle of MQL4 Expert Advisors. Monitoring trading account performance and open positions via natural language. Running historical backtests on trading strategies without manual MT4 interaction.

How do I install MetaTrader 4 MCP Server?

Install MetaTrader 4 MCP Server by running: npm install && npm run build

What MCP clients work with MetaTrader 4 MCP Server?

MetaTrader 4 MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep MetaTrader 4 MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare