BunkerWeb MCP

by bunkerity

Not rated
GitHub

About

Official MCP server for managing BunkerWeb deployments from AI assistants, including instances, services, configuration, bans, plugins, jobs, and cache.

Details

Author
bunkerity
Categories
Cloud Service, Infrastructure

Setup

Install BunkerWeb MCP in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/bunkerity/bunkerweb-mcp

Follow the installation instructions in the repository README, then restart your MCP client.

A production-ready MCP server that exposes BunkerWeb's internal API to large language models via a constrained tool interface. The server provides both HTTP (for testing) and WebSocket (for MCP clients) JSON-RPC endpoints, strict input validation, and a resilient async client with retries.

# Install the package git clone https://github.com/bunkerity/bunkerweb-mcp.git cd bunkerweb-mcp # For demo/testing you do not need to change anything # Configure environment cp .env.example .env # Edit .env to set BUNKERWEB_BASE_URL # Launch BunkerWeb Stack docker compose up -d # If you launch Claude in this repo, it will automatically read the .mcp.json file with mcp server url. # You can then just launch Claude claude > List all BunkerWeb instances > List my BunkerWeb services > Review @config://global for security improvements # To connect to a remote BunkerWeb MCP server, # use BunkerWeb itself to protect the service with TLS: claude mcp add --transport http bunkerweb http://remote-ip:8080/mcp/ claude mcp add --transport http bunkerweb https://your-domain.com/mcp/

- 43 built-in API tools, plus optional semantic search
- πŸ” AI-powered semantic search in BunkerWeb Documentationvia remote search service (optional, configurable)
- MCP resourcesfor read-only data access (global config, job logs, active bans, instance status)
- Multiple transports: Stdio (for Claude Code), HTTP, WebSocket
- Official MCP SDK integrationwith FastMCP for compliant clients (Claude Code, VS Code, Claude Desktop)
- Robust async clientwith retry/backoff and typed Pydantic models
- Prompt catalogproviding contextual guidance for each tool
- FastAPI appexposing/rpcHTTP and/wsWebSocket JSON-RPC endpoints (legacy)
- CLI entry point(bunkerweb-mcp) for easy integration
- Comprehensive documentationincluding CLAUDE.md with BunkerWeb expertise
- Optional authenticationvia shared-secret token or API bearer token
- Structured JSON loggingwith metrics for observability
- Unit testswith mocked HTTP transport
- Docker and Kubernetesdeployment manifests
- ⚑ Performance optimizations(Sprint 2):

- Caching layerwith configurable TTLs for read-only operations
- Optional rate limitingto protect against request floods
- Multi-worker supportfor high-traffic deployments
- Load testing suitewith Locust for performance validation

- Access to a BunkerWeb API (tested with BunkerWeb 1.6.13 and current 1.6.14~rc1 development code; defaulthttp://localhost:8888)

# Clone the repository git clone https://github.com/bunkerity/bunkerweb-mcp.git cd bunkerweb-mcp # Create virtual environment python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate # Install in development mode pip install -e ".[dev]" # Or install from requirements pip install -r requirements.txt # Configure environment cp .env.example .env

Update.envwith your API base URL and either a token or basic credentials if required.

The repository includes aCLAUDE.mdfile that provides Claude Code with comprehensive BunkerWeb expertise and best practices. This file is automatically loaded when working in this repository with Claude Code, giving the assistant context about:

- BunkerWeb architecture and components
- Security module configuration (ModSecurity, Antibot, etc.)
- Common operational workflows
- Troubleshooting guidelines
- Best practices for production deployments

All settings are configurable via environment variables (see.env.example):

The compose file launches a BunkerWeb 1.6.13 demo stack and connects the MCP server to its API.

uvicorn bunkerweb_mcp.main:app --host 0.0.0.0 --port 8080
docker build -t bunkerweb-mcp . docker run --rm -p 8080:8080 --env-file .env bunkerweb-mcp

Deploy to Kubernetes with BunkerWeb ingress controller integration:

# Quick deployment kubectl apply -f deploy/kubernetes/namespace.yaml kubectl apply -f deploy/kubernetes/secret.yaml # Edit credentials first kubectl apply -f deploy/kubernetes/configmap.yaml kubectl apply -f deploy/kubernetes/deployment.yaml kubectl apply -f deploy/kubernetes/service.yaml # Optional: External access via BunkerWeb ingress kubectl apply -f deploy/kubernetes/ingress.yaml # Optional: Autoscaling and monitoring kubectl apply -f deploy/kubernetes/hpa.yaml kubectl apply -f deploy/kubernetes/servicemonitor.yaml # Verify deployment kubectl get pods -n bunkerweb kubectl logs -n bunkerweb -l app=mcp-bunkerweb --tail=100 -f

- BunkerWeb ingress controller with ModSecurity WAF and Antibot protection
- Horizontal Pod Autoscaler (2-10 replicas based on CPU/memory)
- Prometheus metrics and OpenTelemetry tracing
- Health checks with/healthand/readyendpoints
- Configurable via ConfigMap and Secrets

For detailed deployment instructions, troubleshooting, and configuration options, seedeploy/kubernetes/README.md.

If you installed the package locally (pip install -e .), Claude Code and VS Code can launch the server as a subprocess via stdio, without Docker.

Configuration examples for Claude Code, VS Code, and Claude Desktop are in the dedicated section:MCP integration > Stdio Transport.

Important: use theabsolute pathto the virtualenv binary incommand(get it withwhich bunkerweb-mcp). Relative commands can fail because MCP clients do not inherit your shell PATH.

The server supports multiple transport protocols for MCP clients:

Stdio Transport (Recommended for Claude Code and VS Code)

{ "mcpServers": { "bunkerweb": { "type": "stdio", "command": "/path/to/your/.venv/bin/bunkerweb-mcp", "env": { "BUNKERWEB_BASE_URL": "http://<bunkerweb-api-host>:8888", "BUNKERWEB_API_TOKEN": "your-api-token-here" } } } }
{ "servers": { "bunkerweb": { "type": "stdio", "command": "/path/to/your/.venv/bin/bunkerweb-mcp", "env": { "BUNKERWEB_BASE_URL": "http://<bunkerweb-api-host>:8888", "BUNKERWEB_API_TOKEN": "your-api-token-here" } } } }

Adaptcommandto your actual virtualenv path (which bunkerweb-mcpafter activating it) and setBUNKERWEB_BASE_URLto your BunkerWeb API address.

ForClaude Desktop, add the same block to yourclaude_desktop_config.json(macOS:~/Library/Application Support/Claude/claude_desktop_config.json, Linux:~/.config/Claude/claude_desktop_config.json) β€” thetypefield can be omitted as Desktop defaults to stdio:

{ "mcpServers": { "bunkerweb": { "command": "/path/to/your/.venv/bin/bunkerweb-mcp", "env": { "BUNKERWEB_BASE_URL": "http://<bunkerweb-api-host>:8888", "BUNKERWEB_API_TOKEN": "your-api-token-here" } } } }

Verify the server is detected by Claude Code:

claude mcp list # bunkerweb: /path/to/your/.venv/bin/bunkerweb-mcp (stdio)

Note: The stdio transport runs the server as a subprocess communicating via stdin/stdout β€” no port, no Docker required.

Point MCP-compatible clients at the streamable HTTP endpoint:

- Transport: Streamable HTTP
- URL:http://localhost:8080/mcp

{ "mcpServers": { "bunkerweb": { "url": "http://localhost:8080/mcp", "transport": "http" } } }

Legacy JSON-RPC transports remain available for existing workflows:

- HTTP:/rpcendpoint
- WebSocket:/wsendpoint

Use theBUNKERWEB_WEBSOCKET_TOKENvalue when a client requires authentication; the same secret protects all transports.

The server exposes read-only resources that can be referenced in Claude Code conversations using the@syntax:

> Review @config://global and suggest security hardening improvements > Check @bans://active for any suspicious patterns

The MCP server uses an AI-powered semantic search tool for BunkerWeb documentation via a remote search service.

⚠️ IMPORTANT: The search functionality has been externalized to a separate service for better scalability and reduced image size.It is not yet available to the public

# Enable or disable search SEARCH_MODE=disabled # 'remote' or 'disabled' # Search service URL SEARCH_API_URL=https://search.example.com # Request timeout SEARCH_TIMEOUT=10.0

The includeddocker-compose.ymldisables search because no search container is bundled. To use a deployed search service, setSEARCH_MODE=remoteand provide itsSEARCH_API_URL.

Query the/toolsendpoint for JSON descriptors. Available tools include:

- search_bunkerweb_docs: Semantic search across BunkerWeb documentation (query,limit,category)

- ping: Check API reachability
- health: Read the API health probe
- list_instances: List registered BunkerWeb instances
- reload_instances: Reload configuration across all instances (testflag supported)
- reload_instance: Reload a specific instance (hostname, optionaltest)

- list_bans: Retrieve active bans
- ban_ip: Ban one or multiple IPs (bansarray withip,exp,reason,service)
- unban_ip: Remove bans (bansarray withip, optionalservice)

- list_services: List services (with_draftsflag)
- get_service: Fetch details for a specific service (service,full,methods,with_drafts)
- delete_service: Delete a service (service)

And 32 more built-in tools covering authentication, configs, plugins, jobs, and cache management.

Each descriptor now carries apromptfield sourced from the prompt catalog. MCP clients can surface these short instructions to keep assistant answers consistent across tools.

The package ships withbunkerweb_mcp/data/tool_prompts.json, a curated set of guidance strings keyed by tool name. At startup the catalog is loaded once and injected into tool descriptors as well as every RPC/WebSocket response. Override the location withBUNKERWEB_PROMPT_CATALOGif you need custom wording.

curl -X POST http://localhost:8080/rpc \ -H "Content-Type: application/json" \ -H "X-MCP-Token: $BUNKERWEB_WEBSOCKET_TOKEN" \ -d '{"id":"1","tool":"list_instances","params":{}}
echo '{"id":"ping-1","tool":"ping","params":{}}' \ | websocat -H "Sec-WebSocket-Protocol: json" ws://localhost:8080/ws?token=$BUNKERWEB_WEBSOCKET_TOKEN
pip install -r requirements-dev.txt pytest
src/bunkerweb_mcp/ β”œβ”€ main.py # FastAPI app + JSON-RPC endpoints β”œβ”€ cli.py # CLI entry point for stdio mode β”œβ”€ mcp_adapter.py # MCP server integration β”œβ”€ client.py # Resilient async client for BunkerWeb β”œβ”€ tools/ # MCP tools with strict validation β”œβ”€ config.py # Environment-driven settings β”œβ”€ prompt_catalog.py # Prompt loading helpers β”œβ”€ exceptions.py # Domain-specific exceptions β”œβ”€ search_client.py # Lightweight HTTP client for search service β”œβ”€ schemas/ # Pydantic models for requests/responses └─ utils/logging.py # Structured logging helpers src/bunkerweb_mcp/data/ └─ tool_prompts.json # Default tool prompts exposed to MCP clients

The MCP server includes comprehensive observability features:

Metrics are exposed atGET /metricsin Prometheus format:

- mcp_tool_calls_total{tool_name, status}- Total tool calls by status
- mcp_tool_duration_seconds- Tool execution duration histogram
- mcp_active_websockets- Active WebSocket connections
- bunkerweb_api_requests_total{endpoint, method, status}- BunkerWeb API requests
- bunkerweb_api_errors_total{endpoint, error_type}- API errors
- mcp_cache_hits_total{cache_type}- Cache hits
- mcp_cache_misses_total{cache_type}- Cache misses
- mcp_search_queries_total{mode, status}- Search queries

Distributed tracing with automatic instrumentation:

# Configure tracing via environment variables OTEL_TRACING_ENABLED=true OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4317

- HTTP requests (FastAPI)
- Outgoing API calls (httpx)
- Tool executions

View traces in Jaeger UI athttp://localhost:16686

Liveness probe- Checks if the server is running:

curl http://localhost:8080/health # Response: {"status": "healthy", "timestamp": "..."}

Readiness probe- Checks if the server can handle requests:

curl http://localhost:8080/ready # Response: {"status": "ready", "checks": {"bunkerweb_api": true, "search_service": true}, "timestamp": "..."}
livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 10 periodSeconds: 30 readinessProbe: httpGet: path: /ready port: 8080 initialDelaySeconds: 5 periodSeconds: 10

Start the full observability stack (Prometheus, Grafana, Jaeger):

docker-compose -f docker-compose.monitoring.yml up -d

- Prometheus:http://localhost:9090
- Grafana:
http://localhost:3000(admin/admin)
- Jaeger UI:
http://localhost:16686
- Tool Calls Rate
- Tool Success Rate
- Active WebSockets
- Tool Latency (P50/P95/P99)
- BunkerWeb API Errors
- Cache Hit Rate
- BunkerWeb API Latency
- Search Results Count

Import fromdeploy/grafana/dashboards/mcp-bunkerweb.json

Pre-configured Prometheus alerts indeploy/prometheus/alerts.yml:

- High tool error rate (>10%)
- High latency (P95 > 5s)
- BunkerWeb API errors
- Low cache hit rate (<30%)
- Service health issues

Logs are emitted as single-line JSON for ingestion by log processors. Eachtool_calllog carries ametricsobject with the tool name andduration_secondsfor latency tracking. AdjustBUNKERWEB_LOG_LEVELas needed.

Seedocs/OBSERVABILITY.mdfor the complete observability guide.

The MCP server includes several performance optimizations introduced in Sprint 2:

Enabled by default- Caches read-only API operations to reduce latency and load on BunkerWeb API.

# Configure in .env CACHE_ENABLED=true # Default: true

Cache TTLs(configured insrc/bunkerweb_mcp/cache.py):

- list_services: 300s (5 minutes)
- global_config: 600s (10 minutes)
- list_instances: 60s (1 minute)
- list_bans: 30s (30 seconds)

No reviews yet β€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.