tfcensus mcp
mcp runs a Model Context Protocol server on stdin and stdout, for agents such as Claude Code. Logs go to stderr. Each tool returns the JSON envelope the matching command prints with --format json:
units tfcensus report units --index <file>
inventory tfcensus report inventory --index <file>
whois tfcensus whois --index <file> <arn|id>... (no --live, no accounts)
scan_summary tfcensus report scan [--from <file>]
audit_findings tfcensus report audit --from <file>
drift_summary tfcensus report drift --from <file>The tools answer from saved files only. They never call AWS, start terragrunt or terraform, read a state, run a plan, or write a file, and move apply, rollback and mark-applied are not tools. Run the commands that collect (inventory --save-index, scan, audit, drift) yourself, and pass their output with the flags below. A tool whose file wasn't given fails with a message naming the flag. scan_summary without --scan reads the newest scan cache snapshot and applies the config's ownership rules; a snapshot older than cache.ttl comes with a warning. The files are read again on every call, so a new run is picked up without a restart.
Two prompts tell the agent which tools to call and to cite unit paths, addresses, rule IDs and ARNs: triage_drift [unit] sorts drift into revert, adopt and investigate, and explain_unmanaged [account] [type] explains the unmanaged resources of the last scan. Claude Code offers them as /mcp__tfcensus__triage_drift and /mcp__tfcensus__explain_unmanaged. Neither asks for attribute values. tfcensus has no built-in LLM call; for a summary in CI see https://tfcensus.sasskovacs.dev/guides/ai-summary.
A result over --max-result-bytes (default 50,000, Claude Code's limit for showing a result to the model) is split. The envelope then has a page field, and the agent passes page.next_cursor back to the same tool for the rest. Double-managed and unmanaged resources and high-severity findings come first. A cursor lasts 15 minutes after its last use.
Usage
tfcensus mcp [flags]Flags
| Flag | Description | Type | Default | Values | Config key | Notes |
|---|---|---|---|---|---|---|
--audit | audit JSON for audit_findings | string | ||||
--drift | drift JSON for drift_summary | string | ||||
--index | state index from tfcensus inventory --save-index, for units, inventory and whois | string | ||||
--max-result-bytes | split results larger than this many bytes of JSON into pages; 0 never splits | int | 50000 | |||
--scan | scan JSON for scan_summary (default: the newest scan cache snapshot) | string |
The global flags work with every command.
Output formats
This command ignores --format.
Exit codes
| Code | Meaning |
|---|---|
| 0 | The command finished. With --fail-on, nothing matched. |
| 1 | The command failed: a read, a write, a child process or a check failed. |
| 2 | Wrong usage: an unknown command or flag, a bad value or argument, an invalid config file, or a prompt with no terminal. |
| 130 | Interrupted by Ctrl-C (SIGINT) or a cancelled context. |
All codes are listed on the exit codes page.
Examples
tfcensus inventory --save-index ~/.cache/tfcensus/index.json.zst
claude mcp add --transport stdio --scope local tfcensus -- tfcensus mcp --index ~/.cache/tfcensus/index.json.zst
tfcensus mcp --index index.json.zst --scan scan.json --audit audit.json --drift drift.json