chiasmus
- title
- chiasmus
- type
- toolbox
- summary
- MCP server answering reachability, dead-code and impact questions via tree-sitter plus Prolog
- tags
- typescript, mcp, code-analysis, prolog, ai-agents
- language
- TypeScript
- license
- Unknown
- created
- 2026-04-09
- updated
- 2026-04-09
An MCP server that gives LLM coding assistants a formal reasoning engine for structural code analysis. Instead of iteratively grepping through files, the LLM makes a single tool call and gets a provably correct answer about reachability, dead code, dependency cycles, or impact analysis.
How it works
The pipeline has four stages:
- Tree-sitter parsing โ source files become typed ASTs with method definitions, call relationships, imports, and exports identified.
- Prolog fact generation โ structural relationships are converted to declarative Prolog facts (e.g.,
calls(moduleA, funcX, moduleB, funcY).). - Rule-based analysis โ built-in Prolog rules handle cycle-safe transitive reachability, dead code detection, and dependency analysis.
- Query execution โ Prolog's backtracking engine answers the query exhaustively and returns the result in a single MCP tool response.
This is a neurosymbolic-ai pattern: the LLM handles natural language understanding and decides what to ask, the symbolic solver handles exhaustive graph traversal and constraint satisfaction.
What it can answer
- Transitive reachability: "Can user input reach this SQL query?" โ follows call chains across files and modules.
- Dead code detection: routines never called from any entry point.
- Cycle detection: circular call dependencies.
- Impact analysis: everything that depends on a modified method.
Token economics
A five-hop transitive analysis via grep might cost ~2,500 tokens across multiple tool calls, with the LLM reasoning about each hop. Chiasmus answers the same question in ~200 tokens with one tool call โ the Prolog solver does the heavy computation locally.
Setup
claude mcp add chiasmus -- npx -y chiasmus
Exposes nine MCP tools for graph analysis, formal verification, template creation, and autonomous solving.
Limitations
Depends on tree-sitter grammar availability for the target language. The Prolog fact generation captures call-graph structure but not runtime behavior (reflection, dynamic dispatch, eval). Answers are sound for the static structure but not complete for languages with heavy metaprogramming.