Stop AI agents from writing duplicate code. MCP server using AST graph isomorphism.
6.8K
█ █ █
█ █ █ █ █
█ █
█ █ █ █ █
█ █ █
█ █ █ █
█ █
Stop writing code that already exists in your codebase.
ASTrograph is an MCP server that detects when you're about to create duplicate code - and blocks it before it happens.
Your codebase already has this:
# src/math.py
def calculate_sum(a, b):
return a + b
Your AI agent tries to write this:
# src/utils.py
def add_numbers(x, y):
return x + y
ASTrograph intercepts and blocks:
BLOCKED: Cannot write - identical code exists at src/math.py:calculate_sum (lines 1-2).
Reuse the existing implementation instead.
Different variable names, same structure. ASTrograph compares code graphs, not text.
Add .mcp.json to your project root:
{
"mcpServers": {
"astrograph": {
"command": "docker",
"args": [
"run", "--rm", "-i", "--pull", "always",
"-v", ".:/workspace",
"thaylo/astrograph"
]
}
}
}
The codebase is auto-indexed when the Docker container starts. Then:
astrograph_analyze() - Find existing duplicatesastrograph_write / astrograph_edit - They'll block duplicates automaticallyLarge codebases accumulate duplicate code because:
| Tool | What It Does |
|---|---|
astrograph_analyze | Find duplicate Python code (verified via graph isomorphism) |
astrograph_write | Write Python file. Blocks if duplicate exists, warns on similarity |
astrograph_edit | Edit Python file. Blocks if new code duplicates existing, warns on similarity |
.mcp.jsonNote: Python only for now.
Find duplicate Python code (verified via graph isomorphism).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
auto_reindex | boolean | No | true | Auto re-index if stale (default: true) |
Write Python file. Blocks if duplicate exists, warns on similarity.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
file_path | string | Yes | - | Absolute file path |
content | string | Yes | - | Python code to write |
Edit Python file. Blocks if new code duplicates existing, warns on similarity.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
file_path | string | Yes | - | Absolute file path |
old_string | string | Yes | - | Exact text to replace (must be unique) |
new_string | string | Yes | - | Replacement code |
Suppress a duplicate by WL hash (from analyze output).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
wl_hash | string | Yes | - | WL hash from analyze output |
Suppress multiple duplicates by WL hash list.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
wl_hashes | string[] | Yes | - | WL hashes from analyze output |
Unsuppress a hash.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
wl_hash | string | Yes | - | The WL hash to unsuppress |
Unsuppress multiple hashes.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
wl_hashes | string[] | Yes | - | WL hashes to unsuppress |
List suppressed hashes.
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"astrograph": {
"command": "docker",
"args": [
"run", "--rm", "-i", "--pull", "always",
"-v", "/path/to/your/project:/workspace",
"-v", "/path/to/your/project/.metadata_astrograph:/workspace/.metadata_astrograph",
"thaylo/astrograph"
]
}
}
}
{
"mcpServers": {
"astrograph": {
"command": "docker",
"args": [
"run", "--rm", "-i", "--pull", "always",
"-v", "${workspaceFolder}:/workspace",
"-v", "${workspaceFolder}/.metadata_astrograph:/workspace/.metadata_astrograph",
"thaylo/astrograph"
]
}
}
}
{
"mcpServers": {
"astrograph": {
"command": "docker",
"args": [
"run", "--rm", "-i", "--pull", "always",
"-v", ".:/workspace",
"-v", "./.metadata_astrograph:/workspace/.metadata_astrograph",
"thaylo/astrograph"
]
}
}
}
pip install -e .
{
"mcpServers": {
"astrograph": {
"command": "python",
"args": ["-m", "astrograph.server"],
"cwd": "/path/to/astrograph"
}
}
}
Python Source → AST Parser → Graph → WL Hash → Index Lookup → Match
The Docker image runs in event-driven mode by default:
pip install -e ".[dev]"
pytest tests/ -q
docker build -t astrograph .
MIT
Content type
Image
Digest
sha256:28e58c6dd…
Size
145.5 MB
Last updated
4 months ago
docker pull thaylo/astrograph