MT5 MCP Server
A Model Context Protocol (MCP) server that provides integration with MetaTrader 5 (MT5) trading platform. This server exposes MT5 functionality through MCP tools and resources, enabling AI assistants to interact with MT5 for trading symbol information and user management.
Features
- Symbol Management: List and count available trading symbols
- User Management: Retrieve user information by login
- MT5 Authentication: Secure connection to MT5 servers with MD5-based authentication
- MCP Integration: Exposes functionality through both tools and resources for AI assistants
Requirements
- Node.js 18+
- TypeScript
- Access to a MetaTrader 5 server with manager credentials
Installation
Clone the repository:
git clone https://github.com/afx-markets/mt5-mcp-server.git cd mt5-mcp-server
Install dependencies:
npm install
Build the project:
npm run build
Configuration
The server requires the following environment variables:
Variable | Description | Default |
---|---|---|
MT5_SERVER |
MT5 server hostname | '' |
MT5_SERVER_PORT |
MT5 server port | 443 |
MT5_LOGIN |
Manager login credentials | '' |
MT5_PASSWORD |
Manager password | '' |
MT5_VERSION |
MT5 build version | '' |
Example Configuration
export MT5_SERVER="your-mt5-server.com"
export MT5_SERVER_PORT="443"
export MT5_LOGIN="your_manager_login"
export MT5_PASSWORD="your_manager_password"
export MT5_VERSION="3350"
Usage
Starting the Server
npm start
The server will start and listen for MCP connections via stdio transport.
Development Mode
For development with automatic rebuilding:
npm run dev
Available Tools and Resources
Symbol Management
Tools
list-symbols
: Returns a comma-separated list of all available trading symbolscount-symbols
: Returns the total number of available symbols
Resources
configuration://symbols/count/list
: Resource providing list of available symbolsconfiguration://symbols/count
: Resource providing symbol count information
User Management
Tools
get-user-by-login
: Retrieve user information by login ID
API Endpoints
The server connects to MT5 using the following API endpoints:
api/auth/start
- Initialize authenticationapi/auth/answer
- Complete authentication challengeapi/symbol/list
- Get list of symbolsapi/symbol/total
- Get total symbol countapi/user/get
- Get user information
Architecture
The server is built with:
- MCP SDK: Uses
@modelcontextprotocol/sdk
for Model Context Protocol implementation - MT5 Integration: Custom MT5 API client with secure authentication
- TypeScript: Full TypeScript implementation with strict typing
- Modular Design: Organized into separate modules for symbols, users, and configuration
Security
- Uses MD5-based authentication with random challenges for MT5 connections
- Maintains persistent HTTPS connections with keep-alive
- Secure credential management through environment variables
Development
Project Structure
src/
├── config.ts # Environment configuration
├── index.ts # Main server entry point
├── lib/
│ ├── mt5.ts # MT5 API client implementation
│ └── mt5-api.ts # MT5 API helper functions
├── configurationDatabases/
│ └── symbols/ # Symbol management tools
└── users/ # User management tools
Building
npm run build
Testing
Currently no tests are implemented. To add tests:
npm test
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Build and test your changes
- Submit a pull request
License
ISC
Support
For issues and questions, please use the GitHub Issues page.