# AST Cyclomatic Complexity Calculator MCP for AI Agents MCP

> AST Cyclomatic Complexity Calculator measures how hard your code is to maintain. It scans source files for logical branches and decision points to give you an exact complexity score per function. Great for catching messy code before it hits production by identifying high-risk functions that exceed your threshold.

## Overview
- **Category:** developer-tools
- **Price:** Free
- **Endpoint:** https://edge.vinkius.com/vk_preview_7bidHq5myx7zxRKoE4VCnLp62IY4gA9ZCwP8xqGB/mcp
- **Tags:** complexity, cyclomatic, refactoring, maintainability, static-analysis, javascript, typescript

## Description

Imagine reviewing a massive pull request and not knowing where the technical debt is hiding. This MCP lets your agent scan through your files to find exactly which functions are becoming too tangled to manage. You can see how much harder a function got after a recent change or pinpoint specific areas that are begging for a refactor. It's like having an automated code auditor that never gets tired of looking at nested if-statements. Since this is part of the Vinkius catalog, you just connect your preferred client and start running audits on your existing codebase immediately. No manual setup required.

## Tools

### analyze_complexity
Scans your source code to calculate the number of independent paths through each function. It gives you a clear view of how complex your logic actually is.

### compare_complexity_impact
Compares complexity scores between two different versions of your code. This helps you see if a new feature added too much unnecessary logic.

### identify_refactor_candidates
Finds specific functions that have crossed your complexity threshold. It points you directly to the parts of your code that are getting too hard to test or maintain.

## Prompt Examples

**Prompt:** 
```
How complex is this function?
```

**Response:** 
```
| Function Name | Complexity Score |
| :--- | :--- |
| `processOrder` | 12 |
| `validateUser` | 3 |

**Warning:** `processOrder` exceeds the recommended threshold of 10.
```

**Prompt:** 
```
Did my recent changes make the auth logic harder to follow?
```

**Response:** 
```
No, but there was a slight increase. 

* **Complexity Delta:** +1
* **Regression Status:** False
* **New High-Risk Functions:** 0
```

**Prompt:** 
```
Find all functions in this file that are too hard to maintain.
```

**Response:** 
```
I found 2 functions that exceed your threshold:

1. `calculateTax` (Line 45) - **Score: 15**
2. `applyDiscount` (Line 89) - **Score: 11**
```

## Capabilities

### Audit function complexity
Get a detailed breakdown of every independent path through your code.

### Spot high-risk code
Find functions that have crossed your complexity threshold.

### Track complexity regressions
See if new changes made your logic more or less complicated.

### Identify refactoring targets
Locate specific parts of your codebase that are becoming unmanageable.

## Use Cases

### Cleaning up a legacy codebase
A developer asks their agent to find the most complex functions in an old TypeScript file so they can start refactorings safely.

### Verifying PR safety
During a code review, you ask your agent to check if the new changes increased the complexity of the auth module using `compare_complexity_impact`.

### Setting up automated guardrails
You instruct your agent to scan all functions in a directory and flag anything that exceeds a complexity score of 10.

## Benefits

- Catch technical debt before it merges by using `identify_refactor_candidates` to pinpoint exactly which functions are becoming too tangled to test or maintain safely.
- Prevent logic regressions by running `compare_complexity_impact` on every major pull request to see if complexity increased.
- Get a clear view of function difficulty with `analyze_complexity` results that show the exact number of execution paths.
- Reduce testing overhead by keeping cyclomatic complexity scores low and predictable across your entire codebase.
- Automate your code reviews so you can focus on actual business logic instead of manually counting nested if-statements.

## How It Works

The bottom line is you get an automated way to keep your codebase clean and predictable.

1. Connect your AI client to the MCP via Vinkius.
2. Point your agent toward the source files you want to audit.
3. Review the complexity scores and refactor suggestions provided by your agent.

## Frequently Asked Questions

**How can I use AST Cyclomatic Complexity Calculator to improve my code reviews?**
You can ask your agent to run audits on every pull request. This allows you to see if a developer has introduced overly complex logic that will be difficult for others to maintain later.

**Can the AST Cyclomatic Complexity Calculator detect regressions in my TypeScript files?**
Yes, it is designed to compare two different versions of your code. It will tell you exactly how much the complexity changed and if a regression occurred.

**Is the AST Cyclomatic Complexity Calculator useful for large legacy projects?**
Absolutely. It helps you identify the messiest parts of an old codebase so you can prioritize which functions need refactoring first.

**Does the AST Cyclomatic Complexity Calculator work with JavaScript?**
Yes, it scans your source files for control flow keywords and logical operators to calculate complexity scores accurately.

**How do I identify which functions need refactoring using this MCP?**
You can simply ask your agent to scan a file or directory. It will flag any functions that cross the complexity threshold you have set.

**How is complexity calculated?**
The tool counts decision points like `if`, `for`, `while`, and logical operators (`&&`, `||`) within a function, then adds 1 to the total count.

**What does it mean if a function is a refactor candidate?**
A function is flagged via `identify_refactor_candidates` when its complexity score exceeds 10, indicating it has too many execution paths and is difficult to maintain.

**Can I use this to check for regressions?**
Yes, the `compare_complexity_impact` tool allows you to compare two code snippets and see if changes increased the complexity or introduced a regression.