#!/usr/bin/env python3 """HAProxy MCP Server - Direct Runtime API Integration This module provides an MCP (Model Context Protocol) server for managing HAProxy configuration and runtime state. It supports dynamic domain/server management with HTTP backends (SSL termination at HAProxy frontend). Environment Variables: MCP_HOST: Host to bind MCP server (default: 0.0.0.0) MCP_PORT: Port for MCP server (default: 8000) HAPROXY_HOST: HAProxy Runtime API host (default: localhost) HAPROXY_PORT: HAProxy Runtime API port (default: 9999) HAPROXY_STATE_FILE: Path to server state file HAPROXY_MAP_FILE: Path to domains.map file HAPROXY_MAP_FILE_CONTAINER: Container path for domains.map HAPROXY_SERVERS_FILE: Path to servers.json file HAPROXY_POOL_COUNT: Number of pool backends (default: 100) HAPROXY_MAX_SLOTS: Max servers per pool (default: 10) """ from mcp.server.fastmcp import FastMCP from .config import MCP_HOST, MCP_PORT from .db import init_db from .tools import register_all_tools from .tools.configuration import startup_restore # Initialize MCP Server mcp = FastMCP("haproxy", host=MCP_HOST, port=MCP_PORT) # Register all tools register_all_tools(mcp) if __name__ == "__main__": init_db() startup_restore() mcp.run(transport="streamable-http")