Skip to main content
Glama

Why Topos

Coding agents produce working code quickly. The harder question is whether the result is still easy to understand, safe to change, and well-fitted to the rest of the repository. Quality is the new currency.

Topos computes that signal from program structure—not from an LLM review or a style opinion—and returns concrete failure locations and next actions. It is fast enough to sit inside the agent loop: measure, edit, verify, repeat.

Tests check behavior. Topos checks whether the implementation is built to keep changing.

Grounded in category theory, written in Rust.

Related MCP server: sourcebook

Install and Quick Start

One binary. Every supported agent harness. A clean way back out.

1. Install the CLI

Use the verified release installer:

curl -fsSL https://docs.krv.ai/topos/install.sh | bash

Or install with Homebrew:

brew install krv-labs/tap/topos

On Homebrew 6+, that fully qualified one-liner auto-taps and trusts only this formula. If you brew tap krv-labs/tap first, run brew trust --formula krv-labs/tap/topos before brew install topos.

TIP

Prefer an editor-managed install? In VS Code or Cursor, search @mcp topos in the Extensions view or choose Install MCP server. This is an alternative to topos install: your editor installs and manages the Topos MCP server for you.

2. Connect your coding agents

topos install detects every supported MCP harness and lets you configure any—or all—of them from one interactive checklist:

topos install
┌  Which agent integrations do you want to configure?
│
│  ↑↓ move · space toggle · a all · enter confirm · esc cancel
│
│ ❯ ○ Claude Code          (detected)
│   ○ Claude Desktop       (detected)
│   ● Codex CLI            (✓ active)
│   ● Gemini CLI           (✓ active)
│   ○ GitHub Copilot CLI   (detected)
│   ○ Cursor               (detected)
│   ○ VS Code              (detected)
│   ○ Google Antigravity   (detected)
│   ○ pi                   (detected)
│   ○ OpenCode             (detected)
└

Restart the agents you configured, then ask:

"Use Topos to find this repository's worst structural problem, make one focused improvement, and verify the result."

IMPORTANT

Too many tools spray MCP servers across agent JSON files, scatter symlinks around your machine, then leave you to burn half a Claude session untangling the mess—or pull your own hair out doing it. Topos does not play that game. We follow a leave-no-trace policy for harness installation state:topos status shows every registration, while topos uninstall opens the same selector, previews exactly what will change, and removes everything it added to your harness configs. Shared cache bookkeeping and repository-scoped cache leases are not installation state, so uninstall leaves them alone and reports any shared bookkeeping it keeps; generated PR caches are removed only by an explicit topos cache clean or topos cache prune. If Topos makes it easy to do, it should be just as easy to undo.

topos status
topos uninstall

See the agent setup guide for permissions, manual configuration, and troubleshooting.

3. Evaluate from the terminal

topos evaluate . -r

Topos discovers Python, Rust, JavaScript, TypeScript, C++, and Go automatically. Pass --language only when you want to narrow the run.

Reviewing a pull request instead? topos pr-recap 5 gives a structural before/after card and debt ledger for the PR's changed files — no LLM, fully reproducible, with presets calibrated across 1,609 open-source pull requests (PR Recap calibration · lab notes).

See Installation for platform support and alternative install paths.

What Topos checks

Every file gets four independent verdicts:

  • SIMPLE — avoids unnecessary complexity using AST entropy and control-flow complexity.

  • COMPOSABLE — limits a file's outward dependency burden; broader coupling and stability metrics remain available for diagnosis.

  • SECURE — avoids dangerous API reachability and taint paths in the code property graph.

  • NAVIGABLE — stays shallow enough for an agent to read and change in one pass, using depth-weighted nesting divergence over the AST scope tree.

Those verdicts roll up into one memorable quality medal without hiding which pillar failed:

Medal

Criteria

🏆 PLATINUM

Passes all 4

🥇 GOLD

Passes 3 of 4

🥈 SILVER

Passes 2 of 4

🥉 BRONZE

Passes 1 of 4

❌ SLOP

Passes 0, or fails to parse

See the full metrics reference. Refactor guidance also surfaces control-flow cycles, load-bearing dependency edges, and process bottlenecks.

The four pillars are pairwise incomparable and form a sixteen-element evaluation lattice (a 4-cube); PLATINUM is their intersection. Labels below abbreviate the pillars as Simple, Composable, Sc = Secure, Navigable.

Measures · Category-theory foundations

Under the hood

Topos is a self-contained Rust CLI and MCP server. Analysis runs locally; your source code is not sent to an external model or hosted analysis service.

Component

Role

tree-sitter

Parses six languages and powers the native AST, CFG, CPG, PDG, and UAST representations.

GitNexus

Supplies the repository dependency graph scored by COMPOSABLE (topos depgraph generate). Requires npm install -g gitnexus@1.6.8.

Sighthound

Embedded in the MCP server for supplementary security findings; native CPG probes remain the SECURE scoring source.

The result is one agent-facing contract over several structural lenses: one score to optimize, explicit evidence for each failure, and a verification loop that can tell a real improvement from cosmetic churn.

More ways to use Topos

Distribution

Topos ships four ways:

  • GitHub Releases — the topos CLI binary (macOS/Linux), via install.sh or a direct release download.

  • PyPI — topos-mcp, a thin bin-wheel bundling the MCP server binary (pip install topos-mcp / uvx topos-mcp), zero Python runtime.

  • VS Code Marketplace — the Topos extension, bundling platform binaries.

  • Docker — a container image for Glama and other MCP-registry hosting.

Crate layout and adapter details: docs.krv.ai/topos/architecture.

Contributing

Topos is used internally at Krv Labs to manage AI-agent code output. We welcome bugs, ideas, and contributions.


Full documentation · Measures and metrics · Engineering notes

Available Tools

18 tools
topos_assess_changesetA
Read-onlyIdempotent

Assess a multi-file changeset against a git baseline and roll the per-file verdicts into a project before/after (read-only). Use for a module split or any edit spanning several files. Each file is compared to baseline_ref (new files have no baseline). Flags complexity_relocated_within_file and project_regression. Returns a ChangesetResult.

Inputs: files (required), allow, preferences, baseline_ref, +2 more.

topos_assess_improvementA
Read-onlyIdempotent

Compare a baseline to a side-by-side proposed variant (read-only). For normal edit-in-place loops, use topos_assess_worktree_change or snapshot first with topos_begin_refactor then topos_assess_snapshot. This tool is for variants supplied as proposed_code or proposed_filepath. Returns an AssessmentResult with status and score/metric deltas.

Inputs: allow, filepath, language, preferences, +5 more.

topos_assess_snapshotA
Read-onlyIdempotent

Assess the current file against a baseline captured by topos_begin_refactor. Loads the stored baseline by snapshot_id and compares it to the current on-disk file, with the same status semantics as topos_assess_improvement. A missing or expired snapshot is reported via blocked_by.

Inputs: filepath (required), snapshot_id (required), allow, include_security_findings.

topos_assess_worktree_changeA
Read-onlyIdempotent

Assess an in-place edit against a git revision — the common refactor loop. Stateless: the baseline is read from git (git show <baseline_ref>:<path>, default HEAD) and compared to the current working-tree file. No prior call required. For untracked/new files or an uncommitted pre-edit baseline, use topos_begin_refactor + topos_assess_snapshot. Do not call if you have not edited the file. A no-change result on a passing file has no next_tool.

Inputs: filepath (required), allow, preferences, baseline_ref, +2 more.

topos_begin_refactorA
Idempotent

Persist the file's current source as a baseline snapshot before you edit it (writes a snapshot record — its only side effect). Returns a snapshot_id; edit the file in place, then call topos_assess_snapshot(snapshot_id, filepath). Use this when the baseline is not a committed git revision.

Inputs: filepath (required), preferences, gitnexus_dir.

topos_calculate_coverageA
Read-onlyIdempotent

Measure how well a test suite exercises its program-under-test, via structural (UAST) coverage (read-only). A standalone signal, separate from the four-pillar quality lattice; for a quality verdict use topos_evaluate_* instead. Computes UAST bipartite declaration matching and k-gram path recall. Returns a CoverageResult.

Inputs: put_files (required), k, language, test_files, +2 more.

topos_compare_codeA
Read-onlyIdempotent

Compute the AST (tree-edit) distance between two source-code strings. Read-only and idempotent; parses both snippets in memory, never writes or scores. Use for clone detection or to measure refactor impact; the topos_assess_* tools already fold this in as an anti-gaming check, so call it directly only for the raw number. Returns a ComparisonResult: normalized_distance in [0, 1], similarity (= 1 - it), raw_distance, an operations edit-count map, and source_valid/target_valid (error set if either fails to parse).

Inputs: source_code (required), target_code (required), language.

topos_compare_filesA
Read-onlyIdempotent

Compute the AST (tree-edit) distance between two source files on disk. Read-only; parses both files, never writes or scores. Both files are parsed in the language their suffix names, the same way topos compare does; an unsupported suffix or two different languages is an error. Use for clone detection or refactor impact; use topos_assess_* for a quality verdict. Returns a ComparisonResult (see topos_compare_code).

Inputs: source (required), target (required).

topos_depgraph_statusA
Read-onlyIdempotent

Report .gitnexus availability and freshness (read-only). Distinguishes a missing graph from a stale one and from a load/schema failure, so an agent knows whether COMPOSABLE can be trusted and what to do next. Never shells out and never mutates state.

Inputs: directory, gitnexus_dir.

topos_evaluate_codeA
Read-onlyIdempotent

Score a raw code string on the SIMPLE / SECURE / NAVIGABLE quality lattice (read-only; never writes or runs the code). Use for a snippet not yet on disk. SIMPLE, SECURE, and NAVIGABLE are reachable here (CFG/CPG/UAST); COMPOSABLE needs a module dependency graph, so for it use topos_evaluate_file with gitnexus_dir, or topos_evaluate_project for a whole tree. Returns an EvaluationResult: the lattice verdict (SLOP…IDEAL), per-generator scores, and a next-step agent contract.

Inputs: code (required), allow, verbose, language, +1 more.

topos_evaluate_fileA

Score a file on disk on the SIMPLE / COMPOSABLE / SECURE / NAVIGABLE lattice — the only evaluate tool that can reach COMPOSABLE (side-effecting). Unless no_composable is set, this generates/refreshes .gitnexus (given by gitnexus_dir or auto-detected at <root>/.gitnexus) when it's missing or stale, then attaches the resulting ModuleDependencyGraph — the same default behavior as the CLI's topos evaluate. SIMPLE/SECURE/NAVIGABLE always run. When GitNexus isn't installed or generation fails, coupling_available is false and warnings explains why; the rest of the evaluation still succeeds. Do not call again when agent_contract.next_tool is absent: the file already passes, or this call already returned the edit span.

Inputs: filepath (required), allow, verbose, preferences, +5 more.

topos_evaluate_projectA

Recursively score every supported source file in a directory on the SIMPLE / COMPOSABLE / SECURE / NAVIGABLE lattice, with a project rollup (side-effecting). Autodetects all supported languages in one walk. Returns a summary by default: the rollup (aggregate_floor_verdict is the pillars every scored file holds), the five worst files with absolute paths and the metric behind each, counts, and warnings. detail: "full" returns per-file rows (limit / offset) and the named lists. Unless no_composable is set, generates/refreshes .gitnexus when missing or stale before scoring, same as topos_evaluate_file and the CLI's topos evaluate — coupling_available/warnings explain it when that isn't possible, without failing the evaluation. Do not call this for one file, or after a file already passed. It walks the tree. A person asks for the project rollup; an agent editing one file does not.

Inputs: path (required), allow, limit, detail, +6 more.

topos_generate_depgraphA

Generate the .gitnexus dependency graph via GitNexus (side-effecting). Ensures the graph by default: no-ops when current, otherwise runs gitnexus analyze. force=true always regenerates.

Inputs: force, directory, gitnexus_dir.

topos_get_docA
Read-onlyIdempotent

Return a Topos documentation page as Markdown. Use when your MCP client does not expose resource fetching to the agent. Clients that do surface resources should prefer the equivalent resource URI for efficiency: topos://docs/{topic}. Topics: agent-contract (compact loop contract, read first for refactors), lattice (the 16-element H(G_qual) over four generators), metrics (every metric key, thresholds, interpretation), preferences (strict generator rankings and preference walks), priority (priority profiles), workflows (the expanded refactor loop guide).

Inputs: topic (required).

topos_inspect_codeA

Full metric breakdown for a single code unit (inline string or file). Provide exactly one of code or filepath. Use when you need the per-function detail behind a verdict; use topos_evaluate_* when the medal alone is enough. Returns an InspectionResult: the lattice evaluation, a top-N function complexity table (top_n_functions, default 10), total_functions, and entropy details. With filepath, the verdict is scored on all four generators and agrees with topos_evaluate_file: unless no_composable is set, this generates/refreshes .gitnexus (given by gitnexus_dir or auto-detected at <root>/.gitnexus) when missing or stale, then attaches the ModuleDependencyGraph — so this tool is side-effecting. With inline code there is no module to place in the graph, so only SIMPLE/SECURE/NAVIGABLE are reachable, as in topos_evaluate_code. Do not call after topos_evaluate_file already returned a passing verdict or a refactor_targets span. This is the detail view, not the next step.

Inputs: code, allow, verbose, filepath, +5 more.

topos_preference_walkA
Read-onlyIdempotent

Turn a generator ranking into a preference-ordered relaxation walk. Pure and read-only (lattice math only; no files, no scoring). Call after an evaluation to pick the next verdict to aim for, or to relax the goal gracefully under a token/time budget. Returns a PreferenceWalkResult: walk (steps from target down to just above current), next_step, progress in [0, 1], aspirational_target/fallback_target, and induced_order (all 16 verdicts ranked).

Inputs: ranking (required), target, current, gate_scores.

topos_pr_recapB
Read-onlyIdempotent

Structural PR or commit-range recap: gate readiness, blocking findings, files needing attention. Summary by default; detail: "full" for topos.pr_recap.v3.

Inputs: pr, base, head, paths, +7 more.

topos_refactorA
Read-onlyIdempotent

Rank structural refactor hotspots for one file (read-only, advisory). Does not score the four pillars — use topos_evaluate_* for medals and topos_assess_* to verify edits afterward. target selects the engine: cycles (CFG loop/branch bodies), dependencies (MDG Forman curvature on imports; needs .gitnexus), or process (execution choke points; needs .gitnexus). Returns a RefactorResult with ranked hotspots (kind, label, score, suggestion, optional lines).

Inputs: target (required), filepath (required), limit, gitnexus_dir.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 18 tools

    Disambiguation4/5

    The set contains several near-sibling families — four assess_* variants, three evaluate_* variants, and a compare_code/compare_files pair — which is inherently risky, but each description explicitly states when to use it and, unusually, when NOT to (e.g. 'do not call this for one file', 'use topos_assess_worktree_change for in-place edits'). The remaining tools (coverage, depgraph, docs, preference_walk, pr_recap, inspect_code) are clearly separate concerns. A careless agent could still pick the wrong assess_* variant, but the guidance resolves most ambiguity.

    Naming Consistency4/5

    All names use a uniform topos_ prefix plus snake_case, and nearly all follow a verb_noun shape (evaluate_file, assess_changeset, begin_refactor, calculate_coverage, generate_depgraph). A few are bare verbs or noun phrases (topos_refactor, topos_pr_recap, topos_preference_walk, topos_depgraph_status), which breaks the pattern slightly but remains readable and predictable.

    Tool Count3/5

    At 18 tools this sits in the heavy/borderline band for a single analysis domain, and a chunk of the count comes from input-shape variants of the same operation (evaluate_code/file/project, compare_code/compare_files, four assess_* tools). The surface is coherent and each tool has a defensible role, but consolidation could cut the count meaningfully without losing capability.

    Completeness4/5

    The refactor lifecycle is well covered end to end: snapshot creation (begin_refactor), evaluation at snippet/file/project granularity, four diff/assessment modes, hotspot ranking, AST comparison, dependency-graph status/generation, coverage, and doc lookup. Gaps are minor — no way to list or delete stored snapshots, and no explicit configuration/preference-setting tool (preferences are only documented, not applied).

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides comprehensive code analysis through three MCP servers: static analysis for code quality and security, dependency analysis for package management and vulnerabilities, and complexity analysis for maintainability assessment across multiple programming languages.
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Live codebase intelligence for AI agents. Import graph PageRank for file importance, git forensics for co-change coupling and fragile code, convention detection across 16 domains, and blast radius analysis.
      16 npm
      3
      Business Source 1.1
    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides deterministic Python code quality analysis using flake8, mypy, McCabe, and vulture, enabling LLMs to access real linting and type checking results.
      1
      -