# Code Clone Detector MCP for AI Agents MCP

> Code Clone Detector MCP identifies duplicate or structurally similar code blocks within your project files to prevent logic duplication and reduce technical debt. It uses AST normalization and deterministic hashing to find both exact matches and near-misses in your codebase, making it easy to manage refactoring tasks through any compatible AI client.

## Overview
- **Category:** developer-tools
- **Price:** Free
- **Endpoint:** https://edge.vinkius.com/vk_preview_YGD1xol8dAmTvfbU4o2Vu6RF8ZIY2hJRu58wik9I/mcp
- **Tags:** code-duplication, refactoring, static-analysis, cloning-detection, clean-code

## Description

Finding and fixing duplicate code is a tedious manual process that usually happens too late during a code review or after a bug has already been introduced. This MCP allows you to scan your entire project for patterns of redundancy. Instead of manually hunting through files, you can ask your agent to find where logic has been copied and pasted across different modules. It strips away the noise like comments and whitespace to see if the underlying structure is actually the same. You'll be able to see exactly which parts of your codebase are bloating with unnecessary repetition. By connecting this to your preferred AI client via Vinkius, you can turn a simple scan into an actionable refactoring plan without ever leaving your editor. It helps you spot those subtle variations that look different on the surface but behave identically under the hood.

## Tools

### generate_normalized_signature
Provides a normalized, anonymized version of a code block

### identify_exact_duplicates
Finds blocks of code that are structurally identical after normalization

### identify_near_matches
Finds code blocks that are highly similar but not exact duplicates

## Prompt Examples

**Prompt:** 
```
Are there any exact duplicates in these files: ['src/auth.ts', 'src/user.ts']?
```

**Response:** 
```
I found one cluster of identical code in your project:

| Cluster ID | Files Involved |
| :--- | :--- |
| cluster-123 | `src/auth.ts` (lines 10-25) and `src/user.ts` (lines 5-20) |

**Summary:** This logic is functionally identical across both files.
```

**Prompt:** 
```
undefined
```

**Response:** 
```
undefined
```

## Capabilities

### Spot identical code clusters
Finds groups of code that are functionally and structurally the same.

### Detect near-miss similarity
It identifies blocks of code that have slight variations but follow the same logic.

### undefined
undefined

### Anonymize identifiers for better matching
It renames variables and functions during analysis to find matches that are hidden by different naming conventions.

### Analyze structural similarity
It uses AST normalization to look at the logic rather than just the text.

## Use Cases

### Cleaning up a legacy codebase
A developer is overwhelmed by a massive, unorganized project. They ask their agent to find all exact clones in the src/ folder to start identifying candidates for abstraction.

### undefined
undefined

### Pre-refactor audit
Manual checking is impossible in large projects. A tech lead uses the tool to get a duplication percentage across the entire components folder to understand the scale of' the task.

## Benefits

- Reduces technical debt by using find_exact_clones to spot identical blocks of code.
- Improves refactoring efficiency with near-miss detection via find_near_clones.
- Provides clear, measurable data on duplication percentage through calculate_duplication_metrics.
- Speeds up maintenance by identifying logic that should be consolidated into a single utility function.
- Improates codebase health by stripping away noise like comments and whitespace during analysis.

## How It Works

The bottom line is you get an automated, structural analysis of your codebase's redundancy.

1. Connect your AI client to the Code Clone Detector MCP via Vinkius.
2. Point your agent to the specific files or directories you want to analyze.
3. You receive a detailed report of all detected clones and duplication metrics.

## Frequently Asked Questions

**How does the tool identify exact duplicates?**
The `find_exact_clones` tool uses AST Normalization to strip non-functional elements and then applies Deterministic Hashing to identify identical subtrees.

**Can I detect code that is similar but not identical?**
Yes, the `find_near_clones` tool calculates the Levenshtein Distance between normalized code strings to find pairs with high structural similarity.

**What metrics does the system provide?**
Using `calculate_duplication_metrics`, you can obtain the duplication percentage, total lines analyzed, and the number of redundant lines detected.

**How does the tool detect duplicates?**
It uses `identify_exact_duplicates` to find identical structures via hashing and `identify_near_matches` for similar blocks using Levenshtein distance.

**Can I see the normalized version of my code?**
Yes, you can use the `generate_normalized_signature` tool to see how your code looks after stripping comments and renaming variables.

**What is the similarity threshold?**
The default threshold for `identify_near_matches` is 0.8, but you can adjust it between 0 and 1.