DEV Community

Cover image for Why I made my Git-wiping CLI tool readable for AI Agents (MCP)
Joel Roman
Joel Roman

Posted on

Why I made my Git-wiping CLI tool readable for AI Agents (MCP)

If you build CLI tools, you probably design them for humans. You add colored text, interactive y/N safety prompts, and maybe even some fun ASCII art to celebrate a successful execution.

I did exactly this with **commits-nuke (v1.0), a minimalist Python CLI tool I built to instantly collapse an entire Git repository’s history into a single, fresh root commit. It worked flawlessly for my own workflow.

But then I tried to hook it up to an AI agent.

The agent executed the command and immediately hung indefinitely. Why? Because it was waiting for a human to type y to confirm the destructive action, and it couldn't parse the dramatic ASCII explosion I had programmed for the success message.

Here is how I refactored the tool in v2.0 to be Model Context Protocol (MCP) and AI-agent friendly, and why you should consider doing the same for your CLIs.

The Problem with Human-First CLIs

When an LLM or an automated CI/CD pipeline runs a command, it expects two things:

  1. Non-blocking execution: No interactive prompts.
  2. Structured data: Predictable output (like JSON) to determine if the action succeeded or failed, without having to scrape standard output (stdout) with complex regex.

My v1.0 tool failed on both fronts.

Making it "Agent-Ready" (v2.0)

To fix this, I didn't want to ruin the human experience. I still wanted the safety catch and the visual feedback when I ran it in my terminal. So, I implemented a hybrid approach.

1. Decoupling the Core Logic

First, I separated the argparse CLI logic from the actual Git execution. I created a pure Python function nuke_history(message: str) -> dict that returns a structured dictionary instead of printing to the console.

This means anyone building a Python-based MCP server can just import the logic directly, bypassing the CLI entirely:

from nuke_tool.main import nuke_history

result = nuke_history("Agent reset")
if result["success"]:
    print(f"Nuked branch: {result['branch']}")
Enter fullscreen mode Exit fullscreen mode

2. The Bypass Flag (-y / --force)

I added a flag that agents can append to the command to skip the interactive confirmation prompt. This is a standard CLI convention, but it is absolutely critical for autonomous agents.

commits-nuke "Automated reset" -y
Enter fullscreen mode Exit fullscreen mode

3. Strict JSON Output (--json)

Instead of letting the LLM guess if the command worked based on the presence of an ASCII mushroom cloud, I added a --json flag. When triggered, the tool suppresses all standard human text and outputs a single, strictly formatted JSON string.

$ commits-nuke "Agent reset" -y --json
{"success": true, "branch": "main", "root_commit": "Agent reset"}
Enter fullscreen mode Exit fullscreen mode

Now, an MCP server or an AI workflow can easily parse the result:

  • Check result.success.
  • If true, proceed with the workflow using the new root_commit hash.
  • If false, read result.error and attempt a self-correction.

The Takeaway

As we move into a world where AI agents execute terminal commands via tools like the Model Context Protocol, our CLI design philosophies have to adapt. Building tools that default to a great human experience but offer strict, structured, non-blocking pathways for machines is the new standard.

If you want to see the implementation or just need a zero-dependency way to wipe your local Git history clean, cause we have all been there or maybe you have you know...a special kind of tool that can use this check out the repo:

🔗 GitHub Repo: joelromanpr/commits-nuke
📦 Install via uv: uv tool install commits-nuke

If you found this helpful or want to test the tool, dropping a ⭐️ on the repo is hugely appreciated! Let me know in the comments how you are handling AI tool integrations.

Top comments (0)