Commit Graph

59 Commits

Author SHA1 Message Date
kaffa
eebb1ca8df feat: Add bulk operations, wildcard support, and stability improvements
1. Add timeout to HAProxy response wait
   - Use select() for non-blocking recv with 30s timeout
   - Prevents indefinite blocking on slow/hung HAProxy

2. Log warnings for failed server clears
   - haproxy_remove_domain now logs warnings instead of silent pass
   - Helps debugging without breaking cleanup flow

3. Add HAPROXY_CONTAINER environment variable
   - Container name now configurable (default: "haproxy")
   - Used in reload_haproxy() and haproxy_check_config()

4. Add haproxy_add_servers() for bulk operations
   - Add multiple servers in single call
   - Accepts JSON array of server configs
   - More efficient than multiple haproxy_add_server calls

5. Add wildcard domain support in haproxy_list_domains()
   - New include_wildcards parameter (default: false)
   - Shows .domain entries with (wildcard) label when enabled

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:43:05 +00:00
kaffa
4c4ec24848 refactor: Improve stability and add IPv6 support
1. Fix order: Save to disk FIRST, then update HAProxy
   - Prevents inconsistency if HAProxy update succeeds but disk write fails
   - Data is preserved correctly on restart

2. Add IPv6 support
   - Use Python ipaddress module instead of regex
   - Now accepts both IPv4 and IPv6 addresses

3. Extract atomic_write_file() helper
   - Eliminates duplicated code in save_map_file, save_servers_config, haproxy_save_state
   - Single source of truth for atomic file operations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:38:00 +00:00
kaffa
f17b02fddf fix: Auto-restore servers after haproxy_reload
haproxy_reload now automatically restores server configurations from
servers.json after a successful reload, preventing service disruption.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:32:03 +00:00
kaffa
85b4e9b4ed docs: Improve MCP tool docstrings with examples and usage guidance
- haproxy_add_domain: Explain pool backend, link to haproxy_add_server
- haproxy_add_server: Clarify slots 1-10 for load balancing, add examples
- haproxy_remove_server: Add usage example
- haproxy_list_servers: Explain output format with example
- haproxy_list_domains: Add output format example
- haproxy_health: Describe JSON structure and monitoring use case
- haproxy_domain_health: Explain status values (healthy/degraded/down)
- haproxy_set_server_state: Document ready/drain/maint with examples
- haproxy_set_server_weight: Explain weight ratio and soft disable
- haproxy_get_server_health: Clarify vs haproxy_domain_health
- haproxy_get_connections: Add usage examples

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:21:03 +00:00
kaffa
d51e982f7c docs: Update CLAUDE.md with health checks and environment variables
- Add Environment Variables table with all configurable options
- Add Health Check section with haproxy_health and haproxy_domain_health examples
- Update MCP Tools count from 17 to 19
- Add new Health Check tools section
- Update server.py description (line count and tool count)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:10:42 +00:00
kaffa
28df45900c Add health check endpoints and environment variable configuration
New features:
- haproxy_health: System-level health check (MCP, HAProxy, config files)
- haproxy_domain_health: Domain-specific health check with server status

Environment variables support:
- MCP_HOST, MCP_PORT: MCP server binding
- HAPROXY_HOST, HAPROXY_PORT: HAProxy Runtime API connection
- HAPROXY_STATE_FILE, HAPROXY_MAP_FILE, HAPROXY_SERVERS_FILE: File paths
- HAPROXY_POOL_COUNT, HAPROXY_MAX_SLOTS: Pool configuration
- LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 13:07:22 +00:00
kaffa
61dd4a69fc Improve code quality based on code review
Major improvements:
- Atomic file writes using temp file + rename pattern
- Structured logging with logging module (replaces print)
- StateField class for HAProxy state field indices
- Helper function get_backend_and_prefix() to reduce duplication
- Consistent exception chaining with 'from e'
- Proper fd/temp_path tracking to prevent resource leaks
- Added IOError handling in server management functions

Technical changes:
- save_map_file, save_servers_config, haproxy_save_state now use
  atomic writes with tempfile.mkstemp() + os.rename()
- Standardized on 'set server state ready' (was 'enable server')
- All magic numbers for state parsing replaced with StateField class

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 12:48:49 +00:00
kaffa
196374e70c Simplify backend configuration to HTTP only
Remove SSL/QUIC backend templates - all backends now use HTTP only
with SSL termination at HAProxy frontend. This improves performance
(~33% faster than HTTPS backends based on benchmarks).

Changes:
- server.py: Remove https_port parameter from all functions
- haproxy.cfg: Remove ssl/h3 server templates from pool backends
- CLAUDE.md: Update docs for HTTP-only backends and acme.sh

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 12:34:47 +00:00
root
432154c850 Initial commit: HAProxy MCP Server
- Zero-reload domain management with map-based routing
- 100 pool backends with 10 server slots each
- Runtime API integration for dynamic configuration
- Auto-restore servers from persistent config on startup
- 17 MCP tools for domain/server management

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 11:37:06 +00:00