How lecoeurdelest/zap-mcp-server works
1. What this repository is
- This is a Python MCP server that exposes OWASP ZAP reconnaissance capabilities to an AI agent.
- The server sits between an MCP client such as Cursor/Claude and a running ZAP daemon.
2. Primary runtime boundary
- The agent talks to src/zap_mcp/server.py over stdio using MCP.
- The MCP server talks outward to ZAP over HTTP REST API.
- ZAP itself is run as a separate Dockerized headless daemon via docker-compose.yml.
3. Top-level package layout
- src/zap_mcp/tools/ contains the MCP-facing capabilities: health, spidering, site tree, endpoint inspection, alerts, scans.
- src/zap_mcp/core/ contains reusable execution logic for ZAP interaction and policy enforcement.
- src/zap_mcp/models/ contains typed request/response/error schemas.
- src/zap_mcp/db/ contains persistence for scan history and recovery.
- src/zap_mcp/config.py centralizes environment-driven settings.
4. Tool layer as the public API
- The tool modules are the functional surface exposed to the AI agent:
- health.py for daemon liveness
- spider.py for crawl execution
- site_tree.py for structured site mapping and search
- endpoint.py for single endpoint inspection
- alerts.py for passive findings
- scans.py for listing/recovering scan state
- These tools are the main diagram entry points on the MCP-server side.
5. Core execution and policy layer
- core/zap_client.py is the integration point to ZAP’s REST API.
- core/scope.py enforces target restrictions, especially the ALLOWED_SCAN_DOMAINS boundary mentioned in the README.
- core/filters.py likely shapes or reduces ZAP output before it is returned to the agent.
- core/lock.py indicates serialized access to ZAP operations, which matters because scanning and polling are stateful and likely not safe to run fully concurrently.
6. Persistence and recovery
- db/store.py provides local persistence under the data/ directory.
- The README’s zap_list_scans tool and the presence of a DB layer imply the server tracks scan history, status, and recovery metadata across runs.
- This persistence boundary is separate from ZAP itself; it lets the MCP server remember scan state even if the daemon or server restarts.
7. Data model boundary
- models/inputs.py defines the accepted parameters for tools.
- models/outputs.py defines the response payloads returned to the MCP client.
- models/errors.py standardizes failures so tool behavior is predictable for agent consumption.
- This keeps the MCP surface typed and stable even if ZAP’s raw responses vary.
8. Security and scope control
- The repo is explicitly built for reconnaissance of target web applications, not arbitrary scanning.
- Scope control is a first-class architectural concern: environment config, core/scope.py, and the README’s ALLOWED_SCAN_DOMAINS all point to a domain allowlist boundary.
- This is the main guardrail between agent intent and unsafe external scanning.
9. Operational flow for a typical scan
- The agent invokes a tool over MCP.
- The tool validates inputs and scope, then calls the core ZAP client.
- ZAP performs the action asynchronously or with polling handled internally.
- Results are filtered/normalized, optionally persisted, and returned as structured outputs to the agent.
10. Deployment and local development
- docker-compose.yml starts ZAP as a service, while the MCP server runs separately in the Python environment.
- .env.example and config.py define the configuration contract: API key, base URL, and allowed domains.
- pyproject.toml and the README show a standard Python packaging workflow with ruff and pytest.
11. Testing boundaries
- tests/test_filters.py and tests/test_scope.py cover the policy/shaping layer.
- tests/test_db/test_store.py covers persistence behavior.
- tests/test_tools/ indicates integration-like validation of the exposed MCP tools.
- The test structure mirrors the architecture: core policy, storage, and tool-facing behavior.
12. How to draw the architecture diagram
- Show three major zones: AI agent/MCP client, Python MCP server, and ZAP daemon.
- Inside the server, show separate boxes for tools, core ZAP integration/policy, and local persistence.
- Draw the main flow as: agent → MCP tools → scope/lock/filter logic → ZAP API → normalized results → agent, with an optional side path to the local data store for scan history/recovery.
Main entry points: tools Tools API · core Core layer · server.py MCP server · store.py Persistence
Components 26
MCP client
AI agent using the server over stdio/MCP
- AI agent · Cursor/Claude-style caller that invokes tools over MCP
Python MCP server
Tool surface plus execution and policy layers
- MCP server · Bridges MCP requests to internal tool execution
src/zap_mcp/server.py - Tools API · Public MCP capabilities exposed to the agent
src/zap_mcp/tools - Health · Daemon liveness and readiness checks
src/zap_mcp/tools/health.py - Spider · Crawl execution and polling
src/zap_mcp/tools/spider.py - Site tree · Structured site mapping and search
src/zap_mcp/tools/site_tree.py - Endpoint · Single endpoint inspection
src/zap_mcp/tools/endpoint.py - Alerts · Passive findings retrieval
src/zap_mcp/tools/alerts.py - Scans · Scan listing and recovery operations
src/zap_mcp/tools/scans.py - Core layer · Shared ZAP client, scope, filtering, and locking
src/zap_mcp/core - ZAP client · Integration point for ZAP's HTTP API
src/zap_mcp/core/zap_client.py - Scope guard · Domain allowlist and target restriction enforcement
src/zap_mcp/core/scope.py - Filters · Shapes and reduces ZAP output for agent consumption
src/zap_mcp/core/filters.py - Lock · Serializes stateful ZAP operations
src/zap_mcp/core/lock.py - Models · Typed inputs, outputs, and errors for the MCP surface
src/zap_mcp/models - Inputs · Accepted tool parameters
src/zap_mcp/models/inputs.py - Outputs · Structured responses returned to the client
src/zap_mcp/models/outputs.py - Errors · Standardized failure payloads
src/zap_mcp/models/errors.py
ZAP daemon
Headless OWASP ZAP service exposed over HTTP REST
- ZAP compose · Docker Compose definition for the headless daemon
docker-compose.yml - ZAP daemon · Headless OWASP ZAP instance queried by the server
Local state
Persistence and configuration used by the server
- Persistence · Scan history and recovery metadata
src/zap_mcp/db/store.py - Config · Environment-driven API, scope, and runtime settings
src/zap_mcp/config.py
Tests
Validation boundaries mirroring the main subsystems
- Tool tests · Integration-style validation of exposed tools
tests/test_tools - Scope tests · Policy boundary checks for allowed targets
tests/test_scope.py - Filter tests · Output shaping and reduction checks
tests/test_filters.py - Store tests · Persistence and recovery behavior checks
tests/test_db/test_store.py
Connections 23
- AI agent → MCP server: MCP stdio · Agent sends tool requests to the server
- MCP server → Tools API: dispatches · Server exposes the tool surface
- Tools API → Health: exposes · Health check capability
- Tools API → Spider: exposes · Spidering capability
- Tools API → Site tree: exposes · Site tree and search capability
- Tools API → Endpoint: exposes · Endpoint inspection capability
- Tools API → Alerts: exposes · Alert retrieval capability
- Tools API → Scans: exposes · Scan state and recovery capability
- Tools API → Models: uses · Tools validate and return typed payloads
- Tools API → Core layer: delegates · Tool logic relies on shared execution policy
- Core layer → ZAP client: wraps · Central REST adapter to ZAP
- Core layer → Scope guard: enforces · Restricts targets to allowed domains
- Core layer → Filters: normalizes · Reduces and reshapes ZAP responses
- Core layer → Lock: serializes · Prevents unsafe concurrent ZAP operations
- ZAP client → ZAP daemon: HTTP REST · Issues API calls to the running ZAP service
- Tools API → Persistence: persists · Stores scan history and recovery metadata
- Persistence → Config: reads settings · Uses configured data path and runtime settings
- MCP server → Config: loads · Reads environment-driven configuration
- ZAP compose → ZAP daemon: starts · Defines the headless ZAP runtime
- Tool tests → Tools API: covers · Validates the public tool surface
- Scope tests → Scope guard: covers · Validates allowlist and scope behavior
- Filter tests → Filters: covers · Validates response shaping
- Store tests → Persistence: covers · Validates persistence behavior