Building CLIs for AI Agents Cheat Sheet
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
A single-page index of quick back-links to every page in this sub-section, grouped the same way as the sub-section itself — handy for jumping straight to the topic you need instead of paging through the full navigation.
The downloadable PDF is a separate, single A4 page meant for printing. It states the version baseline this sub-section targets — Python 3.12 with Typer 0.27.2, Java 21 with picocli 4.7.7, Node.js 24 with commander 15.0.0, Cobra v1.10.2, clap 4.6.7, swift-argument-parser 1.8.2, System.CommandLine 2.0.12, FastMCP 4.0.10, Spring AI 2.0.1 and the MCP specification revision 2026-07-28, all checked on 2026-09-30 — and covers:
-
the design rules;
-
the exit-code table of the
docsctlrunning example; -
the streams rule (data on stdout, messages on stderr);
-
the TTY and colour rules;
-
the configuration precedence;
-
the JSON output contract;
-
the agent-ergonomics rules;
-
the safety pattern (dry-run, confirmation, idempotency);
-
CLI versus MCP;
-
the wrapping snippets (Python, TypeScript and Spring AI);
-
the injection-defence rules;
-
the frameworks-per-language table;
-
the packaging table;
-
the testing checklist.
Start here — Building CLIs for AI Agents and Agent-Readiness Checklist.
Fundamentals — CLI Design Fundamentals, Streams & Exit Codes, TTY, Colour & Interactivity and Configuration & Auth.
Designing for agents — Machine-Readable Output, Agent Ergonomics, Safety & Idempotency, Self-Describing Help and CLI vs. MCP.
Frameworks by language — Python CLI Frameworks, Java CLI Frameworks, Node.js CLI Frameworks, Go & Rust CLI Frameworks, Swift & .NET CLI Frameworks and TUIs vs. CLIs.
Integration — Wrapping a CLI as an MCP Server, Wrapping a CLI as an Agent Tool and Security.
Shipping — Packaging & Distribution, Testing CLIs and Documenting CLIs.
A short worked example that combines three of the rules above: data on stdout and messages on stderr, a JSON document with a schemaVersion, and a usage error that exits with code 2. The docsctl function below is a stand-in that mimics the running example so the snippet can be run as it is; the consumer discards stderr and reads only the JSON.
docsctl() {
if [ "$1" != search ] || [ -z "$2" ]; then
echo "docsctl: usage: docsctl search QUERY" >&2
return 2
fi
echo "searching for $2" >&2
printf '{"schemaVersion":1,"results":[{"id":"irurueta-algebra::matrix-inversion.adoc"}]}\n'
}
docsctl search matrix 2>/dev/null | python3 -c 'import json,sys; print(json.load(sys.stdin)["results"][0]["id"])'
docsctl search 2>/dev/null
echo "exit code: $?"
irurueta-algebra::matrix-inversion.adoc
exit code: 2
References
The PDF summarizes these official pages; each is cited in full on the page listed above that covers it, and in Building CLIs for AI Agents' bibliography.
Guidelines and standards
Agents and MCP
Security
Frameworks, packaging and testing