# Dead-Code & Test-Gap Detection in TypeScript, Python, Rust & Go Using MCP (dead_code & test_gaps)

Updated: 2026-11-30 · Pillar: MCP Code Graph & Token Savings · Target Query: dead code detection typescript · Canonical: https://memoreal.kolivri.com/articles/dead-code-detection-typescript-python-mcp

## Direct Answer (TL;DR)

Legacy dead-code detectors and test coverage tools require heavy compilation setups, language-specific runtimes, and separate configuration files. With Memoreal's dead_code and test_gaps MCP tools, developers and AI agents audit polyglot repositories across TypeScript, Python, Rust, and Go in a single sub-15ms tool call, surfacing orphaned exports, zero-caller functions, and critical test omissions instantly.

## Key Benchmarks & Metrics

- **4 Languages** — Simultaneously audited in a single polyglot workspace namespace (Memoreal AST Engine Specifications)
- **<15 ms** — Query latency for dead_code symbol analysis across 250K LOC (Memoreal Benchmark Report 2026)
- **100% AST Accuracy** — Elimination of false positives from string-based grep sweeps (Comparative Code Quality Audits)

## Dead-Code & Test-Gap Auditing: Traditional Tools vs Memoreal MCP

| Feature / Capability | ts-prune / ts-remove (TypeScript only) | vulture (Python only) | Memoreal MCP (dead_code & test_gaps) |
| --- | --- | --- | --- |
| Polyglot Monorepo Support | TypeScript only | Python only | TypeScript, Python, Rust, Go & 15+ languages in one pass |
| Agent Tool Integration | CLI output requires parsing | CLI output requires parsing | Native MCP JSON-RPC tool for Claude Code & Cursor |
| Test-Gap Correlation | None | None | Directly cross-references test files and computes coverage ratio |
| Entrypoint Awareness | Requires manual config regex | Requires whitelist files | Accepts dynamic entrypoints parameter per audit run |

## The Hidden Toll of Orphaned Code and Untested Modules

As software repositories evolve, deprecated helper functions, obsolete types, and orphaned internal endpoints accumulate across codebase directories. In large polyglot applications, engineering teams rarely dedicate sprints to manual code pruning because tracing every export manually across thousands of files is exhausting.

Compounding this technical debt, new features are frequently deployed without adequate unit or integration test coverage. When AI coding agents refactor these modules, the lack of test coverage prevents automated validation, turning minor updates into high-risk engineering operations.

- Orphaned code bloats repository size, slows build times, and confuses human and AI contributors.
- Language-specific dead-code CLI tools do not scale across polyglot microservice architectures.
- Missing test references prevent AI agents from verifying refactored functionality automatically.

## How dead_code Identifies Zero-Caller Symbols

Memoreal evaluates dead code through comprehensive AST call-graph reachability. When the dead_code tool is called, the engine traverses symbol reference graphs starting from designated entrypoints (such as server bootstrap files or worker entrypoints).

Any symbol that has zero incoming callers outside its own file definition is flagged as an orphan candidate. The tool returns the symbol name, declaration file, line range, and symbol kind (function, class, interface, or constant), giving developers and AI agents clear targets for safe removal.

## Uncovering Testing Blind Spots with test_gaps

Complementing dead-code analysis, the test_gaps tool scans workspace source files and cross-references them against test directory conventions and symbol test links. It identifies source files that lack corresponding test suites, as well as individual public functions that have zero test callers.

By running test_gaps during sprint audits or agent-driven QA workflows, teams can automatically prompt AI assistants to generate targeted unit test suites for untested business logic, systematically driving up codebase test coverage.

## Implementation Example: Auditing Orphaned Symbols and Untested Files via MCP

```json
{
  "jsonrpc": "2.0",
  "id": 5,
  "method": "tools/call",
  "params": {
    "name": "dead_code",
    "arguments": {
      "namespace": "core-backend",
      "entrypoints": ["src/index.ts", "src/workers/queue.ts"]
    }
  }
}
```

## Frequently Asked Questions

### Can I exclude legitimate API entrypoints or public exports from dead_code?

Yes. You can pass an optional entrypoints array specifying routes, handlers, or public library exports that should be excluded from pruning.

### Does test_gaps run my actual unit tests to measure line coverage?

No. test_gaps performs fast AST structural analysis to determine which files and functions lack test references, completing in under 15ms without running test runners.

### Can Claude Code run dead_code and automatically delete orphaned files?

Yes. You can prompt Claude Code to inspect dead_code output, verify zero callers via find_references, and safely remove obsolete functions.

## Related Engineering Guides

- [ast-mcp-server-polyglot-15-languages](https://memoreal.kolivri.com/articles/ast-mcp-server-polyglot-15-languages)
- [ai-code-review-github-actions-blast-radius](https://memoreal.kolivri.com/articles/ai-code-review-github-actions-blast-radius)
- [safe-multi-file-rename-refactoring-mcp](https://memoreal.kolivri.com/articles/safe-multi-file-rename-refactoring-mcp)

### 1-Command Setup
Run `npx -y @kolivri/memoreal-mcp setup` to install the persistent memory MCP server.
