HAProxy MCP Server
Last updated
Was this helpful?
Last updated
Was this helpful?
A Model Context Protocol (MCP) server for HAProxy implemented in Go, leveraging HAProxy Runtime API and mcp-go.
The HAProxy MCP Server provides a standardized way for LLMs to interact with HAProxy's runtime API via the Model Context Protocol (MCP). This enables LLMs to perform HAProxy administration tasks, monitor server status, manage backend servers, and analyze traffic patterns, all through natural language interfaces.
Full HAProxy Runtime API Support: Comprehensive coverage of HAProxy's runtime API commands
Context-Aware Operations: All operations support proper timeout and cancellation handling
Stats Page Integration: Support for HAProxy's web-based statistics page for enhanced metrics and visualization
Secure Authentication: Support for secure connections to HAProxy runtime API
Multiple Transport Options: Supports both stdio and HTTP transports for flexibility in different environments
Enterprise Ready: Designed for production use in enterprise environments
Docker Support: Pre-built Docker images for easy deployment
To use this server with MCP-compatible LLMs, configure the assistant with the following connection details:
When using only the stats page functionality, there's no need to define Runtime API parameters like host and port. You can use both Runtime API and Stats Page simultaneously for complementary capabilities, or use only one of them based on your environment's constraints.
The HAProxy MCP Server exposes tools that map directly to HAProxy's Runtime API commands, organized into the following categories:
Statistics & Process Info: Retrieve statistics, server information, and manage counters
Topology Discovery: List frontends, backends, server states, and configuration details
Dynamic Pool Management: Add, remove, enable/disable servers and adjust their properties
Session Control: View and manage active sessions
Maps & ACLs: Manage HAProxy maps and ACL files
Health Checks & Agents: Control health checks and agent-based monitoring
Miscellaneous: View errors, run echo tests, and get help information
The server can be configured using the following environment variables:
HAPROXY_HOST
Host of the HAProxy instance (TCP4 mode only)
127.0.0.1
HAPROXY_PORT
Port for the HAProxy Runtime API (TCP4 mode only)
9999
HAPROXY_RUNTIME_MODE
Connection mode: "tcp4" or "unix"
tcp4
HAPROXY_RUNTIME_SOCKET
Socket path (Unix mode only)
/var/run/haproxy/admin.sock
HAPROXY_RUNTIME_URL
Direct URL to Runtime API (optional, overrides other runtime settings)
HAPROXY_RUNTIME_TIMEOUT
Timeout for runtime API operations in seconds
10
HAPROXY_STATS_ENABLED
Enable HAProxy stats page support
true
HAPROXY_STATS_URL
URL to HAProxy stats page (e.g., http://localhost:8404/stats)
http://127.0.0.1:8404/stats
HAPROXY_STATS_TIMEOUT
Timeout for stats page operations in seconds
5
MCP_TRANSPORT
MCP transport method (stdio/http)
stdio
MCP_PORT
Port for HTTP transport (when using http)
8080
LOG_LEVEL
Logging level (debug/info/warn/error)
info
Note: You can use the Runtime API (TCP4 or Unix socket mode), the Stats API, or both simultaneously. At least one must be properly configured for the server to function.
Authentication: Connect to HAProxy's Runtime API using secure methods
Network Security: When using TCP4 mode, restrict connectivity to the Runtime API port
Unix Socket Permissions: When using Unix socket mode, ensure proper socket file permissions
Input Validation: All inputs are validated to prevent injection attacks
You can test the HAProxy MCP server locally in several ways:
Build and run the server directly with environment variables:
You can test specific MCP tools with JSON-RPC calls:
The HAProxy MCP Server includes several technical improvements designed for reliability and robustness:
Context-Aware Operations: All API calls support context-based timeout and cancellation, allowing graceful termination of long-running operations.
Fallback Mechanisms: Automatic fallback to socat if direct connection fails, ensuring compatibility across different HAProxy deployments.
Unified Socket Handling: Common code for both TCP and Unix socket connections, reducing duplication and improving maintainability.
Resilient Connection Management: Dynamic buffer management for large responses and proper resource cleanup with deadline handling.
Comprehensive Error Handling: Structured error handling and logging for easier troubleshooting.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Download the latest binary for your platform from the .
Note: For detailed instructions on how to configure HAProxy to expose the Runtime API and Statistics page, see the .
For a complete list of all supported tools with their inputs, outputs, and corresponding HAProxy Runtime API commands, see the documentation.
For comprehensive security best practices and configuration examples, see the .