Detalhes do pacote

mt5-mcp-server

afx-markets298ISC1.0.1

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

readme (leia-me)

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

  1. Clone the repository:

    git clone https://github.com/afx-markets/mt5-mcp-server.git
    cd mt5-mcp-server
    
  2. Install dependencies:

    npm install
    
  3. 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 symbols
  • count-symbols: Returns the total number of available symbols

Resources

  • configuration://symbols/count/list: Resource providing list of available symbols
  • configuration://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 authentication
  • api/auth/answer - Complete authentication challenge
  • api/symbol/list - Get list of symbols
  • api/symbol/total - Get total symbol count
  • api/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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Build and test your changes
  5. Submit a pull request

License

ISC

Support

For issues and questions, please use the GitHub Issues page.