Skip to main content
Glama
envdoc

envdoc

Official
by tarkeebdev

🌱 envdoc

Find missing, unused and misspelled environment variables β€” before they break your app.

A CLI for you, an MCP server for your AI agent.

PyPI Python MCP Tests License: MIT

Zero dependencies. Installs in one second. Works in your terminal and in your AI agent.


The problem

Your app reads os.environ["DATABASE_URL"]. Your .env has DATA_BASE_URL. Everything works on your machine β€” until it doesn't, on your teammate's machine, in staging, at 2 AM.

Environment variable mistakes are one of the most common β€” and most annoying β€” bugs in modern development. They're invisible until runtime, they break CI, and nobody remembers which variables are actually required.

envdoc scans your code, reads your .env, and tells you exactly what's wrong:

$ envdoc

envdoc v0.1.0
────────────────────────────────────────────────────────────
  project    C:\work\my-api
  env file   .env (3 keys)
  scanned    3 files Β· 6 vars referenced

  βœ– MISSING (5)
    API_KEY      app/main.py:4
                 ↳ typo? .env has API_KEYS
    DEBUG        app/main.py:6
                 ↳ has default in code
    PORT         app/client.js:2
    REDIS_URL    app/client.js:1
    SECRET_KEY   app/main.py:5

  β–² UNUSED (2)
    API_KEYS      .env:3
                  ↳ typo? code uses API_KEY
    LEGACY_MODE   .env:4

  βœ– 4 blocking issue(s) - the app will crash at runtime
    + 1 missing var(s) with defaults
  exit code: 1  Β·  run `envdoc example` to sync .env.example

It caught the API_KEY / API_KEYS typo both ways β€” in the code and in the .env.


Related MCP server: envdoc

✨ Features

Feature

What it does

πŸ€– MCP server

envdoc mcp β€” hands env_check / env_fix / env_example to Claude, Cursor and any MCP agent

πŸ› οΈ Auto-fix

envdoc fix --apply renames typo'd keys and appends missing ones, keeping existing values

πŸ”΄ Missing detection

Variables read by code but absent from .env β€” the #1 cause of KeyError at 2 AM

🟑 Unused detection

Dead entries cluttering your .env, with the line number where they live

πŸ”΅ Typo suggestion

Fuzzy matching links API_KEY ↔ API_KEYS and tells you it's likely a typo

βšͺ Default-aware

os.getenv("X", "0") won't fail your build β€” it has a fallback, so it's flagged but non-blocking

🧠 Code-provided vars

Understands os.environ["X"] = "1" β€” set by the app, not a required input

πŸ“ .env.example generator

envdoc example builds or merges a complete .env.example for your team

πŸšͺ Exit codes

0 clean, 1 problems β€” drop straight into CI without parsing text

πŸ“¦ JSON output

--json for dashboards, bots and custom tooling

Zero dependencies β€” pure standard library. pip install is instant, and envdoc mcp starts with no extra install step.


πŸš€ Install

pip install envdoc

Or from source:

git clone https://github.com/tarkeebdev/envdoc.git
cd envdoc && pip install .

Requires Python 3.9+. No other dependencies.


πŸ“– Usage

envdoc                    # check the current directory (default command)
envdoc check path/to/proj # check somewhere else
envdoc fix                # preview repairs (dry run)
envdoc fix --apply        # repair .env in place
envdoc example            # generate / sync .env.example
envdoc mcp                # run the MCP server on stdio
envdoc list --missing     # just the names, one per line (pipeable)
envdoc --json             # machine-readable output

Options

Flag

Available on

Meaning

--json

check, fix

Emit a JSON report

--strict

check

Also fail on unused variables

--no-color

check, fix

Disable ANSI colours (also honours NO_COLOR)

--env-file FILE

all

Pick the env file explicitly (repeatable)

--ignore VAR

all

Silence a variable (repeatable)

--exclude GLOB

all

Skip paths (repeatable)

--apply

fix

Write changes (default is a dry run)

--include-unused

fix

Also drop .env keys nothing reads

-o, --output FILE

example

Output path (default .env.example)

--force

example

Overwrite instead of merging

--with-values

example

Copy real values ⚠️ may include secrets

Exit codes

Code

Meaning

0

No blocking issues

1

Blocking issues found (--strict: any issues)

2

Usage error / path not found


πŸ€– MCP server for AI agents

This is the headline feature. Environment-variable mistakes are the #1 way an AI coding agent gets stuck: it runs the app, hits KeyError: 'DATABASE_URL', guesses, retries, burns tokens, and gives up.

envdoc mcp gives the agent a ground-truth answer instead of guesswork.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Claude / Cursor / agent β”‚ ── 1. "what's missing in this project?"
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   envdoc mcp  (stdio)    β”‚ ── 2. JSON: missing[], unused[], typo links
β”‚   β€’ env_check            β”‚ ── 3. unified diff  (dry run)
β”‚   β€’ env_fix              β”‚ ── 4. apply β†’ .env repaired
β”‚   β€’ env_example          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Connect it

Claude Code

claude mcp add envdoc -- envdoc mcp

Claude Desktop / any MCP client β€” add to your MCP config:

{
  "mcpServers": {
    "envdoc": { "command": "envdoc", "args": ["mcp"] }
  }
}

Tools it exposes

Tool

What it returns

When the agent should call it

env_check

JSON: missing[], unused[], suggestion, locations (file:line), fixable

Before running, building or deploying β€” and first when debugging a KeyError

env_fix

Plan + unified diff. apply=true writes the file

Once env_check confirms the problem

env_example

.env.example content (secrets never leak)

Scaffolding, onboarding, PRs

Try it right now

printf '%s\n' \
  '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' \
  '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"env_check","arguments":{}}}' \
  | envdoc mcp

Design notes (why it's safe for agents)

  • Dry run by default β€” env_fix returns a diff and touches nothing until you pass apply: true.

  • Renames before adds β€” a typo repair frees the key it needs; order is deterministic.

  • Never deletes on a guess β€” include_unused is opt-in, and keys that look like typos are never auto-removed.

  • Values preserved β€” renames keep the existing value and comments intact.

  • Zero dependencies β€” plain stdio JSON-RPC, so envdoc mcp starts anywhere Python does.


πŸ› οΈ Fix mode

envdoc fix            # preview (dry run)
envdoc fix --apply    # write the changes
$ envdoc fix
would fix .env:
 ! rename API_KEYS -> API_KEY   (code reads API_KEY; .env has API_KEYS)
   add DEBUG=0                  (read by the code but not configured)
 ! add REDIS_URL=               (read by the code but not configured)

--- a/.env
+++ b/.env
@@ -1,4 +1,8 @@
-API_KEYS=oops-wrong-name
+API_KEY=oops-wrong-name
+DEBUG=0
+REDIS_URL=

Notice DEBUG=0 β€” the default came from the source itself (os.getenv("DEBUG", "0")). envdoc doesn't just find the gap, it fills it with the value your code already agreed to fall back on.


πŸ”Ž What it understands

envdoc reads environment variables across 12+ language families:

Language

Syntax detected

Python

os.environ["X"], os.environ.get("X"), os.getenv("X")

JavaScript / TypeScript

process.env.X, process.env["X"]

Deno

Deno.env.get("X")

Go

os.Getenv("X")

Ruby

ENV["X"], ENV.fetch("X")

PHP

$_ENV["X"], getenv("X")

Java

System.getenv("X")

Rust

env!("X")

Vite / webpack

import.meta.env.X

Shell / Docker / YAML

$VAR, ${VAR}

It also:

  • walks the tree respecting your .gitignore

  • skips node_modules/, .venv/, dist/, binaries and assets

  • ignores OS noise (PATH, HOME, LANG, SSH_*, …) so you only see your config


🀫 Silencing a variable

Add a comment to any entry in your .env:

# Used by the ops team's cron job only β€” envdoc:ignore
CRON_TOKEN=abc123

…or pass --ignore CRON_TOKEN.


πŸ§ͺ Tests

pip install -e ".[dev]"
pytest
67 passed in 0.91s

Covers pattern extraction across all supported languages, .env parsing, fix planning (renames, adds, order, dry-run vs apply), the full MCP handshake, tool dispatch, and CLI exit codes.


πŸ”„ Drop it into CI

GitHub Actions

- uses: actions/setup-python@v5
  with:
    python-version: "3.12"
- run: pip install envdoc
- run: envdoc --strict

Git hook (pre-commit)

# .pre-commit-config.yaml
- repo: local
  hooks:
    - id: envdoc
      name: envdoc
      entry: envdoc --strict
      language: system
      pass_filenames: false

πŸ—ΊοΈ Roadmap

  • fix mode β€” auto-correct detected typos, append missing keys

  • MCP server β€” env_check / env_fix / env_example for AI agents

  • GitHub Action that comments the env_check diff on PRs

  • Support for .env.template inheritance / variable interpolation

  • Secret-scanning warnings for committed real values

  • npx-style one-liner so non-Python agents can spawn it

  • Editor integrations (VS Code diagnostics)

Contributions welcome β€” open an issue and let's talk.


πŸ“„ License

MIT Β© tarkeebdev

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Compares a project's .env file against its .env.example template to surface missing, extra, and empty keys, flag empty required variables, and produce paste-safe key inventories for tickets or sharing. Runs entirely on local files with every value redacted, so secrets are never echoed or uploaded.
      3
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables scanning a repository's source files for actual environment variable reads and diffing those names against .env.example or .env.sample. Returns a deterministic JSON report with the sync verdict, counts, and findings for used-but-undocumented, documented-but-unused, and missing-example vars, without ever reading values.
      54 npm
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables agents to diagnose environment-variable issues read-only without exposing values, including .env versus template comparison, undocumented or unused variables across source code, shape validation, secret-exposure checks, git-ignore and history checks, and safe .env.example proposals.
      6
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables coding agents to validate .env files against .env.example, detecting missing keys, type mismatches, placeholders, and undocumented entries while reporting only key names, line numbers, and issue codes so secret values never enter LLM context.
      1
      MIT