Skip to main content
Glama

dockerlint-mcp, The Hard Way

Build an MCP server that lets an AI lint Dockerfiles and compose files without Docker. Start from "what is a Dockerfile, grammatically?" and end with a tested stdio server. No hadolint, no daemon, no framework doing the hard part for you.

At the end you will have built a small version of dockerlint-mcp yourself, and you will understand the three things most lint tools get wrong: parsing (regexes over raw text lie), rule design (findings need a line number and a concrete fix, and must never leak secrets), and domain rules that look like something familiar but are not (.dockerignore is not .gitignore).

Why This Exists

Most "linter" tutorials are a list of regexes. That breaks the first time someone writes

RUN apt-get update \
    # pin the mirror
    && apt-get install -y curl

or RUN echo "apt-get update", or a heredoc. A linter an AI relies on has to be right about structure first, and quiet when the file is fine: every false positive teaches the model to ignore you.

Related MCP server: dockerfile-audit-mcp

Who This Is For

  • Developers who built a hello-world MCP server and want a real one

  • Anyone who writes Dockerfiles and wants to know why the usual advice is the usual advice

  • Anyone curious how a Dockerfile is actually tokenized

Prerequisites: Python and a rough idea of what docker build does. No Docker installation is needed; nothing here ever runs a container.

pip install -r requirements.txt
python verify.py          # runs every module and checks it

Modules

#

Module

What You'll Build

01

Dockerfile Grammar

A parser: continuations with comments inside, directives, heredocs, JSON vs shell form, flags, stages, ARG expansion

02

Building a Rule Engine

@rule, findings with a fix, shell-command splitting, ignore comments, a disable flag, a false-positive guard

03

Cache-Order Analysis

Which instructions make layers, size hints, and why COPY . . before pip install is slow

04

Compose Analysis

yaml.safe_load, getting line numbers back, privileged / docker.sock / secrets / open ports

05

Dockerignore Matching

Docker's glob rules, root anchoring, **, negation, and checking the ignore file against your COPYs

06

Fix Previews

Safe automatic fixes as a unified diff, verified by re-linting, never written

07

MCP Wrapper and Testing

A sandboxed stdio server, ToolError at the boundary, and a test that launches it for real

The code lives in minilint/, one file per module, and grows as you go. Each module has a main.py that exercises that stage and checks its own claims with assert; verify.py runs them all.

Design rules that run through every module

  1. Parse, then judge. Rules look at parsed commands, never at raw text.

  2. Every finding has a line number and a concrete fix. "Consider improving caching" is not a finding.

  3. Never echo a secret. Report the variable name; the value stays out of the model's context.

  4. Stay quiet on good files. A false-positive corpus is part of the test suite.

  5. Static means static. Nothing is built, run, pulled or written.

  6. Fail loudly and usefully. Errors say what to do next.

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    C
    maintenance
    Enables agents to validate Dockerfiles for build-breaking syntax errors, risky patterns like root users and secrets in ENV/ARG, and cache-order problems, returning every finding with its line and a fix. It also verifies referenced container images against public registries, reporting tag existence, digests to pin, supported platforms, last rebuild time, and end-of-life status with an upgrade tag.
    2
    1
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables users to audit Dockerfiles for container-security anti-patterns, including missing USER, baked-in secrets, curl | sh / wget | bash, unpinned base images, and ADD with remote URLs. It parses Dockerfile structure to return risk levels and actionable fixes.
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Exposes a Dockerfile auditing engine to AI assistants, letting them scan a Dockerfile for the 32 deterministic layer-aware rules, print a stage/layer map showing what each layer adds or deletes, explain any rule's rationale and fix, and list available rules. Findings include file:line evidence so agents can surface and triage image-safety issues directly in Claude Code, Cursor, or Cline.
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables users to analyze Dockerfiles without a Docker daemon or build, ranking layer sizes biggest first and surfacing deterministic waste flags. It also validates supplied layer sizes against the number of layer-producing instructions.
    MIT