envdoc
Officialby tarkeebdev
README.md
<div align="center">
# π± envdoc
**Find missing, unused and misspelled environment variables β before they break your app.**
*A CLI for you, an **MCP server for your AI agent**.*
[](https://pypi.org/project/envdoc/)
[](https://www.python.org/)
[](#-mcp-server-for-ai-agents)
[](#-tests)
[](LICENSE)
*Zero dependencies. Installs in one second. Works in your terminal **and** in your AI agent.*
</div>
---
## 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:
```console
$ 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`.
---
## β¨ 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
```bash
pip install envdoc
```
Or from source:
```bash
git clone https://github.com/tarkeebdev/envdoc.git
cd envdoc && pip install .
```
Requires Python 3.9+. No other dependencies.
---
## π Usage
```bash
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**
```bash
claude mcp add envdoc -- envdoc mcp
```
**Claude Desktop / any MCP client** β add to your MCP config:
```json
{
"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
```bash
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
```bash
envdoc fix # preview (dry run)
envdoc fix --apply # write the changes
```
```console
$ 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`:
```dotenv
# Used by the ops team's cron job only β envdoc:ignore
CRON_TOKEN=abc123
```
β¦or pass `--ignore CRON_TOKEN`.
---
## π§ͺ Tests
```bash
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**
```yaml
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install envdoc
- run: envdoc --strict
```
**Git hook (pre-commit)**
```yaml
# .pre-commit-config.yaml
- repo: local
hooks:
- id: envdoc
name: envdoc
entry: envdoc --strict
language: system
pass_filenames: false
```
---
## πΊοΈ Roadmap
- [x] `fix` mode β auto-correct detected typos, append missing keys
- [x] 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](LICENSE) Β© tarkeebdev
<div align="center">
<sub>Built for developers <b>and the agents working alongside them</b> who are tired of <code>KeyError: 'DATABASE_URL'</code></sub>
</div>
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues