home / mcp / qmt-mcp server

QMT-MCP Server

QMT-MCP 模块化量化交易助手

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "guangxiangdebizi-qmt-mcp": {
      "url": "http://127.0.0.1:8000/sse",
      "headers": {
        "QMT_PATH": "C:\\QMT\\userdata_mini",
        "QUANTMCP_HOST": "127.0.0.1",
        "QUANTMCP_PORT": "8000",
        "QUANTMCP_TRANSPORT": "sse"
      }
    }
  }
}

You operate QMT-MCP, a modular quantitative trading MCP server that connects an AI assistant with your XTQuant/QMT trading client to generate strategies, execute trades in real time, and analyze backtests. This server emphasizes a clean modular design, seamless MCP integration, and built-in risk controls to help you manage automated trading workflows.

How to use

You connect an MCP-enabled client to the QMT-MCP server to generate strategies, place trades, and run backtests. The server exposes an MCP interface over HTTP (SSE) for remote clients and can also be started as a local process for direct interaction. Start the server, then point your MCP client to the provided endpoints. You can place orders, generate moving-average strategies, and save custom strategies, all through the MCP interface.

How to install

Prerequisites: ensure you have Python 3.8 or newer installed on your system. You also need a Windows environment for the XTQuant/QMT client as it is currently supported there.

1. Install Python dependencies from the requirements file.

2. Configure environment variables to connect to XTQuant/QMT and set server options in a .env file.

3. Start the MCP server using its main entry point script.

Configuration and runtime details

Environment and runtime configuration are provided via a .env file and the server startup script. The environment controls where the MCP server listens, how it connects to the QMT client, and various risk and strategy defaults.

# MCP server binding
QUANTMCP_HOST=127.0.0.1
QUANTMCP_PORT=8000
QUANTMCP_TRANSPORT=sse

# QMT交易客户端配置
QMT_PATH=你的QMT安装路径\userdata_mini
QMT_SESSION_ID=你的会话ID
QMT_ACCOUNT_ID=你的交易账户ID

# 策略保存目录
QMT_STRATEGY_DIR=你的QMT策略目录\mpython

# 风险控制
MAX_ORDER_VALUE=100000.0
MAX_POSITION_VALUE=500000.0
MIN_ORDER_QUANTITY=100
MARKET_ORDER_SPREAD=0.1

# 策略默认参数
DEFAULT_SYMBOL=000001.SZ
DEFAULT_START_DATE=20240101
DEFAULT_END_DATE=20241201
DEFAULT_SHORT_PERIOD=5
DEFAULT_LONG_PERIOD=20

# 日志
LOG_LEVEL=INFO
LOG_FILE=logs/quantmcp.log

MCP connection options

MCP clients can connect via the SSE endpoint for direct, zero-dependency access once the server is running.

{
  "mcpServers": {
    "qmt-mcp": {
      "type": "http",
      "url": "http://127.0.0.1:8000/sse",
      "args": []
    }
  }
}

Tools and capabilities

You can access a set of MCP tools to perform common tasks. The server provides a trading tool to place and cancel orders, and a strategy tool to generate moving-average strategies or save custom strategy code.

Example workflows

- Generate a simple moving-average strategy for a stock and run a backtest over a specified period.

- Place a buy order for a specified symbol when a strategy signal occurs, then monitor performance and risk metrics.

Backtesting and performance

The server includes backtesting that reports total and annualized returns, maximum drawdown, volatility, Sharpe ratio, and trading statistics such as hit rate and average P/L per trade.

risk and safety

Built-in risk controls include per-order value limits, per-position value limits, minimum order quantities, and price spread protection for market orders. Strategy-level safeguards and system health monitoring are also in place.

Available tools

place_order

Execute a stock trade with specified symbol, quantity, price, and direction via the MCP interface.

cancel_order

Cancel a previously placed order by its identifier.

save_qmt_strategy

Save a custom QMT strategy script with a given name and code.

generate_ma_strategy

Generate a moving-average based strategy for a target symbol with specified short and long periods.