This guide provides detailed instructions for configuring HAProxy to expose both the Runtime API and the Statistics page, which are required for the HAProxy MCP Server to function properly.
Table of Contents
Runtime API Configuration
HAProxy's Runtime API allows for dynamic configuration changes and monitoring without restarting the service. The HAProxy MCP Server requires access to this API to function properly.
TCP Socket Mode
To expose the Runtime API over a TCP socket, add the following to your haproxy.cfg:
global
# Other global settings...
# Runtime API configuration
stats socket ipv4@0.0.0.0:9999 level admin
# OR for more secure setup, bind to localhost only
# stats socket ipv4@127.0.0.1:9999 level admin
For HAProxy 2.0 and later, you can also use:
global
# Other global settings...
# Runtime API with HTTP wrapper
stats socket ipv4@0.0.0.0:9999 level admin expose-fd listeners
# Enable prometheus-exporter on the stats socket
stats socket ipv4@0.0.0.0:9999 level admin expose-fd listeners
Unix Socket Mode
For Unix socket mode, which provides better security as it's file-system based:
global
# Other global settings...
# Runtime API configuration using Unix socket
stats socket /var/run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
Ensure that the directory exists and has proper permissions: