At a Glance: MCP Servers & AI Agents for Source Code Archaeology
- Custom Builds in Hours, Not Weeks: Using structured methodologies like the BMAD framework alongside AI agents such as Claude Code, tailored analysis tools (e.g., a .NET dependency analyzer) can be built within a few hours – provided they are backed by automated tests and baseline comparisons.
- MCP Servers as Bridges to Established Tools: Through Model Context Protocol (MCP) servers, AI agents directly drive battle-tested scanners like CodeCharta and jQAssistant instead of guessing code metrics themselves.
- Clear Division of Labor Instead of Flying Blind: Deterministic tools deliver reliable measurements from source code, Git history, and bytecode; the AI agent handles correlation, prioritization, and translation into concrete refactoring recommendations.
- No Substitute for Engineering Discipline: AI drastically lowers the barrier to entry for source code archaeology, but shifts the effort toward crisp requirement definitions, tight workflow guardrails, and domain-level verification of the results.
In the previous installments of this series, we explored why source code archaeology is essential for modernization initiatives (Part 1) and surveyed the tools available on the market (Part 2). We also examined the capabilities that standard IDEs and Git already offer right out of the box (Part 3). Most recently, we compared traditional graph-based analysis with AI-assisted graph approaches (Part 4).
In this fifth and final part of our series on source code archaeology, we take the next decisive step: We show you how to build a custom analysis tool using an AI agent like Claude Code – and how to orchestrate established tools agentically via Model Context Protocol (MCP) servers.
Before the breakthrough of generative AI, reinventing existing analysis tools was widely considered an inefficient anti-pattern – the time and effort simply didn’t stack up against off-the-shelf solutions. That equation has fundamentally changed. With the help of AI agents, specialized utilities can now be built in a matter of hours. Methodologies like the BMAD framework guide the requirements analysis in a structured way, yielding sharp specifications that can then be implemented cost-effectively (by leveraging lighter, budget-friendly AI models).
That doesn’t mean established tools are obsolete – far from it. The immense value of conventional tools lies in their foundation of battle-tested, scientifically grounded metrics. They also bring a level of maturity and stability earned through years of real-world usage and comprehensive test coverage.
Below, we walk through two concrete real-world scenarios: In the first case, the goal was to automatically capture tangled dependencies within a microservice landscape, prepare them for architectural documentation, and systematically eliminate structural weak spots. We built the solution using the Claude Code AI agent. Case Study 1 covers the exact steps required and the tangible value delivered.
Case Study 2 then demonstrates how we empowered AI agents via Model Context Protocol (MCP) servers to actively drive established analysis tools like the CodeCharta CLI and jQAssistant for automated, AI-assisted software analysis. Relying on the rock-solid metrics produced by these tools allows us to draw well-founded conclusions about code quality and potential architectural flaws.
Case Study 1: A Homegrown Analysis Tool for Dependency Analysis
On a project involving a mature .NET microservice landscape, we were dealing with an architecture that was actually a distributed monolith in disguise – and we needed a custom dependency analyzer to untangle it. We had inherited this system from a previous vendor, and the connections between its microservices were a tangled web: thirteen modules were linked via 56 proxy interfaces and 28 cross-module public types, including data classes and enums. We later counted over 400 individual call sites. To bring order to the chaos and understand how the application really worked, we first had to map out who was talking to whom.
We could have used jQAssistant for this, but the project lived in the .NET ecosystem, and at that point in time, the C# plugin introduced in Part 4 wasn't available to us yet. Commercial alternatives would have required lengthy client procurement approvals. Since we initially wanted to focus strictly on inter-service connections, a full-blown static code analysis wasn't necessary anyway.
One specific mandate was to identify and eliminate microservice self-calls. To do that, we needed to pinpoint which services were calling themselves and exactly where those calls originated.
From Requirements to Dependency Analyzer with Claude Code
At first glance, the requirements seemed straightforward: Using Claude Code, we wanted to build a compact dependency analyzer that counts connections between microservices while distinguishing between outgoing and incoming dependencies. The metrics needed to be versioned so we could track progress across sprints. Additionally, the tool had to generate a report visualizing the microservices and their connections as graphs alongside a tabular breakdown of the metrics.
Under the hood, the tool doesn't parse raw source code; instead, it inspects compiled .NET assemblies directly. Leveraging the Mono.Cecil library, it analyzes the Intermediate Language (IL) code of all methods to detect calls to proxy interfaces as well as the usage of public types across module boundaries. This systematically surfaces the exact inter-service connections relevant to our investigation, revealing which methods invoke other modules and where they rely on external public types – making it possible to trace and systematically decouple them.
On this basis, the tool calculates incoming and outgoing module coupling metrics inspired by Robert C. Martin’s principles of component coupling, including each module's instability – defined as the ratio of outgoing dependencies to total (incoming plus outgoing) dependencies. This made it easy to see at a glance which modules were primarily consumed by others and which ones were heavily dependent on the rest of the system. An HTML report renders the results as an interactive dependency graph, a sortable metrics table, and a heatmap matrix, complete with expandable drill-down views showing the captured dependencies for each module pair.
The first working version of the analyzer came together in just a few hours using a lightweight language model and included a CLI, core analysis logic, a report generator, and baseline tracking. Figure 1 shows an anonymized version of the resulting report.
Guardrails: Turning a Prototype into a Reliable Measuring Instrument
That’s when the real learning began. The drill-down views of our initial runs turned up plenty of inaccurate numbers; as it turned out, our requirements weren't quite as airtight as we thought. Several iterations were required before the output matched reality. Three examples from the development process illustrate why:
- False Self-Calls: Calls originating from a shared core library were initially misclassified as self-calls. Only after mapping shared libraries specifically to their consuming modules did the picture clear up.
- Misattributed Modules: Shared libraries ending in "Shared" weren't properly mapped to their logical parent modules, skewing the coupling metrics.
- Illusory Precision: An early version of the report displayed counts for supposedly removed call sites. However, if a call was simply refactored into a helper method, the tool flagged it as a removed dependency even though the underlying connection between the services remained intact. We removed the numeric counts from the "Removed Dependencies" section while keeping the detailed list for manual review.
Rapidly standing up the prototype was only step one. To turn it into a dependable analysis tool, we added a test suite – including snapshot tests to catch any unintended shifts in the reports – and used every discrepancy we uncovered as a targeted bug-fix prompt for the AI agent. Domain-level validation proved crucial: any tool meant to guide strategic decisions must produce transparent, trustworthy results.
Baking It into the Pipeline: Measure, Don't Forget
Experience shows that analysis tools quickly gather dust if they have to be run manually. That’s why we wired the analyzer as a dedicated job right into the GitLab build pipeline: on every merge request and every push to the main branch, the analysis automatically runs against the compiled assemblies. Any new dependencies compared to the baseline trigger a specific exit code along with a detailed log of the newly introduced calls. As a result, the team has to make a conscious choice – either explicitly accept the new dependency and update the baseline, or refactor it out. The HTML report was published as a pipeline artifact on GitLab Pages and even became a regular fixture in client sprint reviews.
With that, we didn't just check off our original goal: we systematically hunted down and eliminated the self-calls, and for the first time, the team had a continuous measuring instrument that made architectural goals truly quantifiable.
Case Study 2: How Do MCP Servers Connect AI Agents to Code Analysis Tools?
Model Context Protocol (MCP) servers connect AI agents like Claude Code to external tools and data sources via a standardized interface – in our case, deterministic code analysis tools like CodeCharta and jQAssistant. This allows the agent to query their metrics directly and synthesize them into well-founded insights on code quality and architecture.
While the dependency analyzer in Case Study 1 solved a narrowly scoped problem, a second project tackled a broader question: How can MCP servers connect AI agents like Claude Code with established code analysis tools to operate them in tandem and distill their reliable metrics into a prioritized, actionable assessment of code quality and architecture?
The driving idea stems directly from what we learned in Case Study 1: AI-generated insights about code are only as good as the underlying measurements. So why not leave the measuring to mature, proven tools and let the AI handle the interpretation? Naturally, its prioritizations and recommendations still require human expert review.
A Gartner forecast highlights just how fast the industry is moving in this direction: in 2025, the average Global Fortune 500 enterprise ran fewer than 15 AI agents; by 2028, Gartner projects that number to exceed 150,000 (Gartner, 2026).
The Prototype: Architecture with the BMAD Framework and MCP Servers
For this challenge, we built a prototype that didn't grow organically from a whiteboard sketch, but was structured from day one using the BMAD framework mentioned in the introduction. We started with a Product Requirements Document and system architecture, followed by breaking work down into epics and stories – each complete with its own review findings – before writing a single line of implementation code.
The resulting tool links both CodeCharta and jQAssistant to Claude Code via MCP servers. A single CLI command runs an environment preflight check, kicks off the underlying scanners, and automatically registers the MCP servers. CodeCharta analyzes source code and Git history, while jQAssistant loads compiled classes into a Neo4j graph database to enable structured architectural queries. Claude Code orchestrates both tools through MCP and interprets their findings.
This brings the paradigm shift outlined at the beginning to life: the agent is not the measuring instrument. Established tools do the measuring; the agent prioritizes, explains, and recommends.
Automated AI Code Review Workflow: How the AI Agent Distills Findings
Once launched, the AI agent executes a structured workflow for automated, AI-assisted software analysis:
- Thresholds & Scan Validation: An interactive wizard defines project-specific thresholds (rated from CRITICAL to LOW) and checks upfront whether up-to-date scan results already exist instead of blindly re-running expensive analyses.
- 5-Dimensional Hotspot Analysis (CodeCharta): The agent correlates complexity, file size, commit history, author count, and active time spans in parallel. High complexity paired with few authors gets flagged as a bus-factor risk; long commit histories combined with high complexity point to maintenance-heavy code; and large files with high churn indicate unstable modules.
- Architectural Audit (jQAssistant & Neo4j): Querying the graph database, the agent pulls in structural findings such as god classes and cyclic dependencies.
- Prioritized HTML Report: Finally, the agent distills all metrics into a unified management and developer report complete with concrete refactoring recommendations.
The prototype is built for extensibility: additional analysis tools can be plugged in via extra MCP servers as long as they expose their output as files or through an API, allowing teams to layer in new analytical perspectives. Here, too, we ran into a challenge familiar from Case Study 1: early versions of the workflow gave the agent too much leeway for interpretation. When given overly complex instructions, it occasionally hallucinated references to scan results that didn't even exist. We streamlined the workflow and made each step crystal clear, backing the result-processing pipeline with targeted tests. Ultimately, what mattered most wasn't the number of workflow steps, but setting strict boundaries on which data sources the evaluation was allowed to use.
Takeaway: Custom Builds vs. MCP Orchestration at a Glance
AI agents like Claude Code dramatically cut the cost of custom source code archaeology, yet they don't replace solid engineering discipline. Automated tests and domain-level verification remain non-negotiable. Both case studies illustrate this principle from opposite angles: in Case Study 1, we used AI to build a custom measuring tool that simply didn't exist on the market for our tech stack – completing it in hours instead of weeks, though it only became truly reliable after disciplined iteration with tests and baseline checks. In Case Study 2, we flipped the roles: established tools handled the measurements while the AI agent orchestrated them, interpreted the metrics, and turned them into prioritized action items. In neither case do AI agents run code analysis completely autonomously; requirements, measurement logic, and recommendations still demand human expert oversight.
| Criterion | Approach 1: Building Custom Analysis Tools with AI | Approach 2: Orchestrating Existing Tools via MCP Servers |
|---|---|---|
| Use Case | A specific analytical question isn't adequately covered by off-the-shelf tools, or doesn't justify their licensing and onboarding overhead. | Findings from multiple existing analysis tools need to be combined and evaluated holistically. |
| Measuring Instrument | Custom-built analysis tool (in our example: a static .NET analyzer built with Mono.Cecil). | Established deterministic tools such as CodeCharta and jQAssistant. |
| Role of AI | Assisting development and iterating based on test feedback (e.g., via Claude Code); the analysis itself runs without an LLM. | Invoking analysis functions via MCP servers, fetching and correlating results, and deriving prioritized recommendations (e.g., with Claude Code). |
| Primary Risk | Flawed or incomplete analysis and metric logic skews the measurements. | Unsubstantiated claims or overreaching conclusions drawn from the metrics. |
| Key Safeguard | Domain-verified reference cases and tests for analysis and metric logic; baseline comparisons to track changes over time. | Validating the data supplied via MCP servers, enforcing clear workflow guardrails, and reviewing recommendations with domain experts. |
When you leave deterministic measurements to established tools and let AI agents like Claude Code do what they do best – spotting patterns, adding context, and explaining complex findings – you get a toolkit capable of backing real strategic decisions. And with that, our five-part series on Source Code Archaeology comes full circle: these validated insights empower you to prioritize legacy modernizations with confidence based on maintenance effort, change risk, and business value.
Sources & References
- Robert C. Martin: Clean Architecture: A Craftsman’s Guide to Software Structure and Design. Prentice Hall, 2017.
- Gartner: Gartner Identifies Six Steps to Manage AI Agent Sprawl. Press release, April 28, 2026. Available online at: https://www.gartner.com/en/newsroom/press-releases/2026-04-28-gartner-identifies-six-steps-to-manage-artificial-intelligence-agent-sprawl (accessed November 26, 2026).
- BMAD Method: BMAD Method Documentation. Available online at: https://docs.bmad-method.org/ (accessed November 25, 2026).
The "Source Code Archaeology" Blog Series
- Part 1: Fundamentals & Business Perspective – What source code archaeology accomplishes and why the most reliable path to modernizing legacy systems begins with understanding existing business logic and technical health.
- Part 2: The Tool Landscape – Which tools exist in the source code archaeology space and which solution fits which problem.
- Part 3: Analysis with Built-In Tools – How development teams can uncover valuable system knowledge using standard, out-of-the-box tools without extra budget.
- Part 4: Graph-Based Code Analysis – Conventional tools compared with AI-assisted code graphs, and how to get the best of both worlds.
- Part 5: Artificial Intelligence & Autonomy – From MCP servers to AI agents: Can generative AI soon take over source code archaeology completely?
More about software analysis & AI at codecentric
More articles in this subject area
Discover exciting further topics and let the codecentric world inspire you.
Blog author
Dr. Fadil Kallat
Do you still have questions? Just send me a message.
Do you still have questions? Just send me a message.