Skip to content
All posts
ai agentic code-review mcp

Building a Local AI Gatekeeper: Why Our Autonomous Code Reviewer Doesn't Live in CI/CD

PR reviews taking five rounds, burnt-out senior engineers acting as human spell-checkers, and why we deliberately kept the AI out of Bitbucket.

When I started my career writing C++ and porting legacy codebases, the biggest bottlenecks were usually compilers, linkers, and dependency hell. Today, as a Principal AI Engineer, the tools have changed, but the fundamental problem remains the same: how do we get out of the developers’ way and let them focus on solving actual engineering problems?

Recently, one of our product development teams hit a wall. Pull requests were dragging through four or five rounds of review. Our senior engineers were burnt out, feeling less like architects and more like highly-paid human spell checkers. They were constantly flagging the same trivial issues: missing tests, coding guideline violations, typos, and missed acceptance criteria.

We have massive user stories for technical reasons, often packing 8 to 10 acceptance criteria (ACs) into a single ticket. Even our best developers tend to miss one or two, or at least only partially implement them. We clearly needed a gatekeeper to reduce the workload on the senior devs. We needed a tool that developers could run locally to perform a brutal first round of review before a human ever looked at the code.

The immediate impulse in the industry right now is to hook an LLM directly into your Bitbucket or GitHub CI/CD pipeline. We investigated that route and explicitly decided against it.

Our tech leads — who lean conservative — were terrified of a very real psychological trap: if we integrated the AI into Bitbucket, human reviewers would inevitably start reviewing the AI’s findings instead of the actual code. They would become filters for false positives, getting lazy and missing the deeper architectural issues that the AI is blind to. We needed the AI to be a private assistant for the author, not a public critic in the repo.

The Stack and the Pivot

We started by evaluating several locally available open-weights models. At the time — before the introduction of TurboQuant to drastically reduce memory usage — we were capped at around 32B parameter models on our local hardware. They simply weren’t sharp enough for the level of rigorous analysis we needed. We ended up routing through to Codex and Claude to get the baseline intelligence required.

To win over the skeptics, our first approach was entirely stealthy. We built a CLI tool that functioned exactly like a traditional linter. The AI was completely hidden behind a Python script that orchestrated the entire process: fetching the git changeset, prompting the model, and spitting out a static HTML report. It felt familiar. It felt safe.

After that initial success, developer expectations shifted. AI-native developers want their tools embedded where they work. So, we evolved the architecture, moving away from a simple static script into a fully-fledged Model Context Protocol (MCP) server.

The MCP Server and the “Marketplace”

Building this wasn’t just API wrangling; it required unlearning how we initially treated LLMs. Early on, hallucinations were a massive problem. We made the classic mistake of letting the LLM do everything: read the git diffs, format the output, generate the HTML report. We were treating the model like a general-purpose operating system.

The fix was moving to the MCP server model. We created a robust Python script that serves as an MCP server, providing deterministic, rock-solid tools for JIRA integration, Git changeset fetching, and HTML report generation. The LLM is now strictly constrained to the one thing it does well: analyzing the logic.

More importantly, this Python MCP server now acts as an internal “marketplace” for our skills and agents. Because our tech leads are still cautious about committing AI agent configurations directly into the main code repositories, the marketplace allows developers to install specific review skills and sub-agents into their local repo with a single command-line call. They get the power of the AI locally, without polluting the central version control until the organization is fully ready.

Context window management only became a critical bottleneck when we introduced interactive review sessions. One-shot reviews were fine, but in a long session, the context would bloat and the model would lose the plot. The solution was architectural fragmentation. We split the review process into isolated skills with highly specific instructions. For example, when the agent is reviewing the code against the acceptance criteria, we explicitly do not load the testing guidelines into the context. We only feed the model exactly what it needs for the immediate operation.

Catching the Skeptic

The turning point for adoption happened during our very first demo.

Our most vocal AI-skeptic tech lead — the guy who famously declared, “I don’t want to see AI-generated code in my repo” — volunteered his own code for the trial. We ran the local gatekeeper against his PR.

The agent immediately flagged that he had completely forgotten to cover one of the acceptance criteria, and had only partially written tests for a second.

It was a huge win. The room went quiet, and we had our buy-in. In day-to-day operation, the agent mostly catches trivial, boring issues. But that is exactly the point. Sparing our team two or three rounds of mundane review cycles means our senior engineers can finally get back to focusing on design flaws, architecture, and the hard problems they were actually hired to solve.

Lessons Learned

  • AI as a Private Mentor, Not a Public Critic: Keep the initial AI review out of the central CI/CD pipeline. If the AI flags issues in the PR, reviewers will subconsciously stop reviewing the code and just review the AI’s output. Force the author to use the AI locally.
  • Constrain the LLM: Do not let the LLM handle operations that require strict determinism (like fetching code or generating reports). Use tools like an MCP server for the scaffolding, and let the LLM handle the logic analysis.
  • Context is Still Finite: Just like the 64KB page limit of 16-bit architectures, you have to be clever about how you load data. Break complex tasks down into sub-agents and only load the specific context (like testing guidelines vs. ACs) when that specific agent needs it.