Skip to main content
All posts
Drupal Security MCP Case Study Nov 25, 2026 · 6 min read

Building a Drupal Health Monitor: Signed Agents, Deterministic Findings, and an MCP Server

How I built a fleet dashboard for Drupal maintenance retainers: an HMAC-signed agent, deterministic analysis with AI used only for prose, an MCP server for Claude, and what a security audit and a composer audit step turned up.

Article

The Problem: Maintenance Retainers Run on Spreadsheets

If you maintain Drupal sites for clients, you know the routine. A security advisory lands, and you open a dozen admin screens to find out which sites run the affected module, which are already patched, and which are still on a core release that drupal.org no longer supports. Then someone asks whether a site is ready for Drupal 12, and you start over.

I built Drupal Health Monitor to replace that routine. It is a dashboard for a whole fleet of client sites. It shows core, module and PHP versions, flags security updates and Drupal 12 blockers, tracks uptime, and writes the plain-English report you would otherwise write by hand on Friday afternoon. The code is open source on GitHub, and a live instance runs at health-monitor.tofdev.com. The dashboard itself sits behind a login because it holds operational client data.

Two Codebases, One Repository

The project is split in two on purpose:

  • hm_core is the monitor: a Drupal 11 site with custom entities for clients, sites, snapshots, findings, uptime checks and AI reports, plus the dashboard, built with Single Directory Components and HTMX.
  • hm_agent is a small module installed on each client site. It depends on core only and supports ^10.3 || ^11, so adding it to an older client never drags in a dependency tree.

The agent exposes one JSON endpoint with the site's core version, PHP version and installed modules. The monitor polls it from cron through a queue, so a slow or dead site never blocks the others.

Signed, Not Just Authenticated

An endpoint that lists every installed module is exactly what an attacker wants to scan for, so the agent does not answer anonymous requests. Each request carries an HMAC signature computed with a per-site secret, and the agent only accepts signatures inside a five-minute window. The secrets live in the Key module and in environment variables, never in config or git.

The monitor has to be careful in the other direction too. It sends signed headers to a URL that someone typed into a form, so the collector must not become a way to leak those headers or to probe internal networks. That became the focus of the security pass I describe below.

Deterministic Findings, AI Only for Prose

This was the design rule I held to most strictly: detection is plain PHP with unit tests, and the model never decides what is wrong.

The monitor fetches release data from drupal.org and compares it with each site's latest snapshot. It produces findings for security updates, unsupported versions, ordinary updates and Drupal 12 blockers, optionally including results from Upgrade Status. Findings are reconciled against the previous run, so an unchanged finding is not rewritten and does not invalidate caches. A health score from 0 to 100 summarises each site.

Only after that does the AI layer run. It receives the verified evidence and writes the client-facing summary. The effort estimate is computed in PHP from the findings, and the model only words it. If the model is wrong or unavailable, the dashboard is still correct. Reports are stored as versioned entities, so each one can be traced back to the evidence it was built from.

An MCP Server for Asking Your Fleet Questions

The part I enjoyed most is the MCP server. With it, Claude Desktop, Claude Code or any MCP client can query the fleet. I deliberately kept the surface small, with four tools:

  • list_sites returns health scores and open-finding counts.
  • get_site_findings returns the evidence for one site.
  • get_security_updates returns fleet-wide security work with the deterministic effort estimate.
  • generate_site_report creates a versioned AI report for one site.

OAuth with the client-credentials grant protects the endpoint, and it uses a dedicated Drupal role with a single scope. The broad tools that ship with the contributed MCP module are disabled, so a leaked token can read fleet status and trigger a report. That is all it can do.

The Audit: What Changed When I Read My Own Code Critically

After the feature work was done, I ran a full audit of the project, the kind you would do before handing the code to a client. The findings were not exotic. They were the ordinary gaps that appear when you build fast:

  • Redirects could leak signed headers. The collector followed HTTP redirects, so a site that redirected elsewhere would receive the signed request. Redirects are now off.
  • Unbounded response bodies. A hostile or broken site could stream gigabytes back at the worker. Responses from agents are now capped at 2 MB, and the drupal.org release feed at 5 MB, using a streaming reader that stops early.
  • Unvalidated URLs. Site base URLs are limited to http and https in the entity constraint, and the runner checks again before it sends a request.
  • Queue pile-ups. If the worker fell behind, cron kept enqueueing the same site. A per-site pending marker now stops the duplicates.
  • Orphaned data. Deleting a site left its snapshots, findings, reports and uptime rows behind, which inflated fleet totals. Deleting a site now cascades, and a client that still owns sites cannot be deleted.
  • Unbounded growth. Every check writes a snapshot and an uptime row, so a fleet grows by hundreds of rows per site per day. Retention now runs on cron: uptime rows are kept for 90 days and snapshots for 30, and each site always keeps its newest snapshot.
  • Alphabetical severity. Findings were sorted by name, which put "critical" after "high". Sorting now uses real urgency.

Each fix came with a test. The rule I follow is that a bug I only fix will come back, and a bug I fix with a failing test first will not.

The CI Step That Paid for Itself

Part of the audit was adding composer audit --locked to the GitHub Actions pipeline, next to PHPUnit, PHPStan and PHPCS. I expected it to be hygiene. Instead, it failed on the pull request that introduced it.

New advisories had been published for Twig and for Drupal core itself, including a remote code execution issue fixed in core 11.4.13. Production was a couple of patch releases behind. The pipeline caught it before I did, I updated the lockfile on the same branch, and the green build deployed the fix.

Advisories change over time, so a dependency audit that only runs when you remember it is not much of an audit. Running it on every push means a red build on an untouched branch tells you something has changed upstream.

Deployment

The monitor ships as a Docker image to Railway, with an app service, a separate cron service built from the same image, and managed MySQL. A pre-deploy script runs drush deploy, so config import and updates apply on every release. Locally, DDEV spins up the monitor and two independent demo client sites, so the whole fleet flow can be tried on one laptop. A Drupal recipe installs the monitor with demo content in one command.

What I Would Do Next

  • Notifications when a new security finding appears, so the dashboard is not the only place to learn about it.
  • An uptime trend per site, since the history is already being collected.
  • Fixing the GitHub-to-Railway trigger. It did not fire on my last merge, so I deployed that release by hand.

Try It

The source, the architecture diagram and the setup steps are in the repository, and the live instance shows the deployed result. If you maintain Drupal sites for a living, I would like to hear which check you would want on that dashboard first.