Skip to main content
Glama
rohitkhamrai

Precision-MCP

by rohitkhamrai
README.md
<div align="center">

# โšก Precision-MCP

**Cursor-style AST Codebase Indexing & Surgical Slicing MCP Server for AI Coding Agents**

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![CI](https://github.com/rohitkhamrai/precision-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/rohitkhamrai/precision-mcp/actions/workflows/ci.yml)
[![Python: >=3.10](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org/)
[![Protocol: MCP](https://img.shields.io/badge/MCP-2024--11--05-green.svg)](https://modelcontextprotocol.io/)
[![Zero External Dependencies](https://img.shields.io/badge/Dependencies-Zero-success.svg)](#features)

*Stop dumping 500-line files into your LLM context window. Give any AI agent Cursor-grade AST symbol navigation in <15ms.*

</div>

---

## ๐Ÿš€ The Problem

Modern coding agents (Claude Code, Gemini CLI, Cursor, Windsurf, OpenCode) suffer from **context rot**:
1. **Whole-File Dumping**: Reading entire files to inspect a single 20-line method floods the context window with boilerplate, increasing API costs by 10x.
2. **Context Window Degradation**: Large codebases cause fast models to lose instruction adherence, skip edge cases, or crash on token limits.
3. **Slow Brute-Force Regex**: Scanning with regex fails to distinguish between declarations, call sites, and comments.
4. **Indentation & Syntax Drift**: Blind search-and-replace mutates line numbers, corrupting codebases.

**Precision-MCP** solves this by providing a lightweight, high-performance AST indexing engine over the **Model Context Protocol (MCP)**. It indexes your workspace in milliseconds, lets agents retrieve exact symbol slices, analyzes cascading blast radius, and guarantees zero syntax errors via AST-safe mutations.

---

## โšก Performance Benchmarks

*Live benchmarks measured across real-world codebases*:

| Metric | Brute-Force File Read | Standard Ripgrep | **Precision-MCP** |
|---|---|---|---|
| **Cold Index Speed** | N/A (no index) | N/A | **~70-120 ms** (Initial scan) |
| **Warm Re-Index Speed** | N/A | N/A | **<8.5 ms** (Incremental `mtime` cache) |
| **Query Latency** | ~45 ms (full read) | ~25 ms (text search) | **<1.0 ms** (Indexed AST) |
| **Token Usage per Query** | 800 - 1,500+ tokens | Snippet only (no body) | **35 - 150 tokens (96.4% saved)** |
| **Cascading Blast Radius** | Manual search | Incomplete regex | **Automated multi-level call graph** |
| **Code Mutation Safety** | Fragile text replace | None | **Cross-Language AST/Syntax Gate with Auto-Rollback** |
| **Memory Footprint** | Process memory bloat | Variable | **<12 MB** (Zero dependencies) |

Run the visual benchmark demo on your own machine:
```bash
python -m precision_mcp.demo
```


---

## ๐Ÿ› ๏ธ Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  AI Coding Agent (Claude Code / Cursor / Gemini CLI)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚ JSON-RPC 2.0 (stdio)
                           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Precision-MCP                       โ”‚
โ”‚                                                        โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚   MCP Server     โ”‚           โ”‚    AST Parser     โ”‚  โ”‚
โ”‚  โ”‚  (stdio driver)  โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ โ”‚  (Python AST +    โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚   Regex TS/Go/Rs) โ”‚  โ”‚
โ”‚           โ”‚                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚           โ–ผ                               โ–ผ            โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚     CodebaseIndexer (.precision_index.json)      โ”‚  โ”‚
โ”‚  โ”‚     - Symbol graph (Classes, Methods, Funcs)     โ”‚  โ”‚
โ”‚  โ”‚     - Exact [start_line, end_line] slices        โ”‚  โ”‚
โ”‚  โ”‚     - Call-site graph & caller tracing           โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

---

## ๐Ÿ“ฆ Installation & Setup

### Option 1: Run instantly with `uvx` (No installation needed)
```bash
uvx precision-mcp
```

### Option 2: Install via `pip`
```bash
pip install -e .
precision-mcp
```

---

## โš™๏ธ Configuration in Agents

### 1. Claude Desktop / Claude Code (`claude_desktop_config.json`)
```json
{
  "mcpServers": {
    "precision-mcp": {
      "command": "python",
      "args": ["-m", "precision_mcp.server", "--root", "/path/to/your/project"]
    }
  }
}
```

### 2. Cursor IDE (`settings.json`)
```json
{
  "mcp": {
    "servers": {
      "precision-mcp": {
        "command": "precision-mcp",
        "args": ["--root", "."]
      }
    }
  }
}
```

### 3. Antigravity IDE / Gemini CLI (`mcp_config.json`)
```json
{
  "mcpServers": {
    "precision-mcp": {
      "command": "python",
      "args": ["-m", "precision_mcp.server", "--root", "."]
    }
  }
}
```

---

## ๐Ÿงฉ Exposed MCP Tools

| Tool | Parameters | Description |
|---|---|---|
| `index_codebase` | `workspace_path?`, `force?` | Scans workspace with incremental `mtime` caching (<8.5ms warm re-index). |
| `find_symbol` | `query` | Locates functions, classes, or methods with exact line boundaries `[start, end]`, signatures, and docstrings. |
| `get_outline` | `file_path` | Generates structural skeleton of any file without reading its entire body. |
| `get_symbol_slice` | `file_path`, `symbol_name` | Extracts the exact source code block of a single function or class. |
| `find_callers` | `symbol_name` | Identifies all direct callers of a given symbol across the codebase. |
| `get_impact_radius` | `symbol_name`, `max_depth?` | **Blast Radius Analyzer**: Traces cascading multi-level callers and affected files before refactoring. |
| `patch_symbol` | `file_path`, `symbol_name`, `new_code` | **Syntax-Safe Surgical Mutator**: Replaces symbol block with cross-language syntax verification (Python, TS/JS, Go, Rust) and automatic rollback. |


---

## ๐Ÿงช Testing

Run 20 unit tests across parser, indexer, and MCP protocol handlers:

```bash
python -m unittest discover -s tests -v
```

---

## ๐Ÿ“„ License

MIT ยฉ [Rohit Kumar Khamrai](https://github.com/rohitkhamrai)

TDQS

A3.7/5.0

Scored across 7 tools

Disambiguation4/5

Most tools target distinct actions: indexing, symbol lookup, file outline, source slicing, caller search, impact analysis, and patching. Find_callers and get_impact_radius overlap since impact_radius includes caller discovery, but the descriptions distinguish direct callers from broader blast-radius analysis.

Naming Consistency5/5

All tool names use consistent snake_case with a verb-first pattern: index_, find_, get_, and patch_. The convention is predictable despite a mix of verbs, and each name clearly signals the operation and target.

Tool Count5/5

Seven tools is well-scoped for a code-intelligence and refactoring server. Each tool covers a distinct step in the workflow, from indexing to patching, without obvious redundancy.

Completeness4/5

The surface covers discovery, navigation, slicing, caller analysis, impact analysis, and safe patching. It lacks explicit create, delete, rename, or move-symbol operations, but agents can work around these via patch_symbol and impact analysis.

Maintenance

ActivityMaintained
ResponsivenessNo issues