MCP Server
Overview
The MCP server lives under mcp_server/ and exposes Prowler capabilities through FastMCP. mcp_server/…/main.py is the CLI entrypoint registered as prowler-mcp in mcp_server/pyproject.toml; it parses --transport stdio|http, --host, and --port, falls back to PROWLER_MCP_TRANSPORT_MODE when no transport is passed, then runs the root server in stdio or stateless HTTP mode. mcp_server/…/server.py builds the root FastMCP("prowler-mcp-server"), installs SharedFailureMiddleware, mounts three child servers, exposes GET /health, and exports app = prowler_mcp_server.http_app(stateless_http=True) for uvicorn deployments.
The three mounted namespaces are the public routing surface. mcp_server/…/server.py is mounted as prowler_hub_* and uses unauthenticated sync httpx.Clients for https://hub.prowler.com/api and raw files from raw.githubusercontent.com/prowler-cloud/prowler; it lists/searches checks and compliance frameworks, resolves providers/services, and fetches check code or fixer files. mcp_server/…/server.py is mounted as prowler_docs_* and wraps ProwlerDocsSearchEngine from prowler_documentation/search_engine.py, which calls Mintlify search at https://leaves.mintlify.com/api/search/prowler and retrieves markdown from https://docs.prowler.com/{path}.md. mcp_server/…/server.py is mounted as prowler_*; it imports load_all_tools() from prowler_app/…/tool_loader.py, which imports every module in prowler_app/tools, discovers concrete BaseTool subclasses from that package prefix, instantiates them, and calls each instance's inherited registration method.
Prowler App tools share the same lifecycle and request path. mcp_server/…/base.py registers every public async method as a tool and derives MCP annotations from the method name plus each class's read_only_tools or destructive_tools. Each tool instance receives the singleton ProwlerAPIClient from prowler_app/…/api_client.py, which owns one httpx.AsyncClient, authenticates through ProwlerAppAuth in prowler_app/…/auth.py, builds JSON:API requests against API_BASE_URL (default https://api.prowler.com/api/v1), parses JSON bodies, normalizes filter parameters, validates pagination and two-day date ranges, polls background tasks, and allowlists external fetches to raw.githubusercontent.com. App tool modules cover findings (findings.py), finding groups (finding_groups.py), resources (resources.py), providers (providers.py), scans (scans.py), muting (muting.py), compliance (compliance.py), attack paths (attack_paths.py), integrations (integrations.py), users (users.py), and roles (roles.py). Responses are transformed through matching Pydantic models under prowler_app/models, with MinimalSerializerMixin in models/base.py dropping empty fields before returning data to MCP clients.
Authentication is transport-sensitive. In stdio mode, ProwlerAppAuth reads PROWLER_API_KEY, falling back to legacy PROWLER_APP_API_KEY, and requires the key to start with pk_; missing or malformed keys make ProwlerAPIClient construction fail while the app tool loader logs and skips the affected tools. In HTTP mode, ProwlerAppAuth.authenticate() reads the request-scoped Authorization header via FastMCP, requires Bearer <token>, accepts either pk_ API keys or JWTs, and checks JWT exp before using the token. API-key requests are sent to Prowler as Authorization: Api-Key ...; JWT requests are sent as Authorization: Bearer ....
Error handling is centralized in mcp_server/…/errors.py. The root server installs SharedFailureMiddleware, while root and sub-servers all set mask_error_details=True. App API errors are converted into ProwlerAPIError, ProwlerAPIUnreachable, or ProwlerAPIInvalidResponse in ProwlerAPIClient; Hub and Docs use parse_json_response() for upstream JSON decode failures. The middleware turns recognized failures into actionable ToolError messages and leaves protocol errors untouched. Tool-specific not-found or partial-outcome messages are raised directly as ToolError where the tool has context the shared classifier cannot know.
Runtime packaging is in mcp_server/Dockerfile and mcp_server/entrypoint.sh. The Docker build uses uv with uv.lock and pyproject.toml, installs into /app/.venv, runs as non-root UID 1001 on Alpine Python 3.13, removes pip from the final image, and defaults to /app/entrypoint.sh main. The entrypoint dispatches main|cli to prowler-mcp and uvicorn|asgi to uvicorn prowler_mcp_server.server:app after forcing PROWLER_MCP_TRANSPORT_MODE=http. The package itself requires Python >=3.12, pins FastMCP and httpx in pyproject.toml, and documents local/hosted usage, required outbound hosts, and tool prefixes in mcp_server/README.md.
Tests under mcp_server/tests mirror this architecture. tests/conftest.py pins fake environment values before imports, blocks real socket connections, patches the ProwlerAPIClient singleton in place for app tools, replaces Hub and Docs module-level sync clients with mock transports, and lazily imports the root server because importing it registers every tool. tests/test_server.py verifies every sub-server contributes namespaced tools, descriptions, and MCP annotations; tests/test_health.py guards the IETF-style /health response and its release version. Area-specific tests under tests/prowler_app, tests/prowler_hub, tests/prowler_documentation, and tests/lib validate request shaping, model transformations, auth, URL encoding, and error classification.
Coupling
- If mcp_server/…/server.py changes namespaces or mount behavior, update the tool names documented in mcp_server/README.md and the namespace assertions in mcp_server/…/test_server.py; clients rely on
prowler_*,prowler_hub_*, andprowler_docs_*prefixes. - If a new Prowler App tool module is added under
mcp_server/prowler_mcp_server/prowler_app/tools, make its tools public async methods on aBaseToolsubclass and return model-shaped data fromprowler_app/models;load_all_tools()only auto-registers concreteBaseToolsubclasses whose__module__starts with the configured tools package. - If a tool builds URL paths from caller-controlled IDs, use
url_path()from mcp_server/…/urls.py or equivalent segment encoding; Hub code uses it for Prowler Hub routes, while app tools that interpolate paths must preserve the same path-segment safety expectations. - If
PROWLER_MCP_TRANSPORT_MODE,API_BASE_URL, or API key handling changes in prowler_app/…/auth.py, update mcp_server/pyproject.toml pytest-env values and mcp_server/…/conftest.py; auth defaults are evaluated at import time and tool registration can silently collapse when construction fails. - If adding a destructive or non-mutating write-like tool, update
BaseTool.read_only_toolsordestructive_toolson the owning class and adjust mcp_server/…/test_server.py; MCP clients use these annotations to decide whether user confirmation is needed. - If API responses or JSON:API relationships change, update the corresponding
prowler_app/models/*from_api_response()methods with the tool implementation; tools intentionally return LLM-optimized models rather than raw API JSON. - If Docker or ASGI startup changes, keep
mcp_server/Dockerfile, mcp_server/entrypoint.sh, and main.py transport behavior aligned: CLI HTTP usesprowler_mcp_server.run(..., stateless_http=True), while uvicorn servesprowler_mcp_server.server:appand the entrypoint sets HTTP mode for request-scoped auth.
Risks
- mcp_server/…/server.py, prowler_app/…/tool_loader.py, and prowler_app/…/auth.py: importing the app server constructs every tool, and stdio auth is read during
ProwlerAPIClientconstruction. If the environment lacks a validPROWLER_API_KEY,load_all_tools()logs construction failures and theprowler_*namespace can mount with no tools rather than failing startup; mcp_server/…/conftest.py and tests/test_server.py explicitly guard this. - mcp_server/…/api_client.py and mcp_server/…/errors.py: retrying after
ProwlerAPIUnreachableorProwlerAPIInvalidResponsecan duplicate writes because the request outcome is unknown. Tool code that catches these errors or returns error dicts instead of raising will bypass the shared classifier and make failures look like successful MCP results. - mcp_server/…/providers.py:
delete_provider()starts an asynchronous destructive deletion and may returnstatus='in_progress'after polling times out. Retrying the delete while that task is running can race with provider, scan, finding, and resource cleanup; callers should checkprowler_search_providersfirst. - mcp_server/…/muting.py:
set_mutelist(),create_mute_rule(), andupdate_mute_rule()can hide findings, and deleting mute rules or mutelists does not unmute already muted findings. Incorrect annotation or messaging here causes clients and users to underestimate irreversible suppression.