For Agents¶
The Agent Loop
Give any MCP-compatible coding agent a live feed of Topos verdicts so it can evaluate and iterate on its own output.
Topos lets you set the quality target while the agent handles the loop: measure, change, verify, stop when the target or budget is reached.
MCP Setup¶
Start with the path your agent will actually use. The install path should be short; troubleshooting belongs after the client is registered.
Choose an agent path¶
If you use VS Code or an MCP-capable Cursor build, install the Marketplace extension instead of hand-editing MCP JSON:
Topos: Code Quality Targets for Agents
The extension registers a topos-mcp server provider, resolves a
bundled, cached, local, or downloaded Topos runtime, and starts
topos mcp for agent mode. Topos still runs locally; the editor owns
server registration and trust prompts.
Run setup from the repository root you want Topos to evaluate. Prefer the CLI-native registration path for your agent so the host owns trust, lifecycle, and status checks.
Claude Code
Claude Code uses claude mcp add. The double dash is required:
everything after it is passed to topos unchanged.
claude mcp add --transport stdio topos -- topos mcp
claude mcp list
For a team-shared project config, add --scope project; Claude will
write .mcp.json and ask each user to approve it.
Codex CLI
Codex stores MCP servers in config.toml and shares that setup
between the CLI and IDE extension.
codex mcp add topos -- topos mcp
In the Codex TUI, run /mcp to confirm the server is active. For a
project-scoped setup, put the equivalent table in .codex/config.toml
after trusting the project:
[mcp_servers.topos]
command = "topos"
args = ["mcp"]
Gemini CLI
Gemini CLI can add the stdio server directly and defaults to project scope.
gemini mcp add topos topos mcp
gemini mcp list
If Gemini reports the server as disconnected in an untrusted folder, trust the repository first:
gemini trust
Antigravity CLI / agy
The current agy CLI does not expose a documented mcp setup
command. Use one of these verified paths instead:
In VS Code or Cursor, install the Topos extension above.
If your Antigravity build exposes manual MCP JSON, use the
Manual JSONtab below.If you already manage MCP through Claude or Gemini plugins, import that host’s plugin configuration with Antigravity’s plugin commands, then verify in Antigravity before relying on Topos tools.
Use this for Cursor JSON, Windsurf, or another MCP client that accepts a stdio server configuration.
Add this server configuration in your client’s MCP settings:
{ "mcpServers": { "topos": { "command": "topos", "args": ["mcp"] } } }
Troubleshooting and optional checks
Use these only when the server does not connect, Topos cannot see your files,
or COMPOSABLE / IDEAL is unavailable.
- Dependency graph
COMPOSABLE and
IDEALrequire a.gitnexus/store. SIMPLE, SECURE, AST comparison, MCP docs, and UAST coverage work without it.Prefer the MCP tools (no shell required):
topos_depgraph_status({"params": {}}) topos_generate_depgraph({"params": {}})topos_depgraph_statusis read-only and reportsmissing,present,stale,load_error,schema_mismatch, orinvalid_dir.topos_generate_depgraphshells out to GitNexus and rewrites.gitnexus/— approval-gated in most clients. Re-run when imports change, modules are renamed, or directories are restructured.CLI equivalent (requires
npm install -g gitnexus):cd /path/to/your/repo topos depgraph generate
- Root override
If the MCP host starts Topos outside the repository, set the trusted root explicitly:
{ "command": "topos", "args": ["mcp"], "env": { "TOPOS_MCP_FILE_ROOT": "/absolute/path/to/repo" } }
- Server smoke check
Verify the binary before wiring it into editors:
topos mcptopos mcpprints the FastMCP banner and waits on standard input. PressCtrl-Cafter the smoke check.- Workflow docs
Topos exposes the workflow docs through MCP resources:
topos://docs/agent-contract topos://docs/workflows
Some hosts surface MCP resources directly as attachable context. Others do not expose resource fetching to the model, so use the equivalent tool call:
topos_get_doc(topic="agent-contract") topos_get_doc(topic="workflows")
Clients that expose MCP prompts can also invoke the refactor-loop prompt:
topos_refactor_until_ideal(filepath="path/to/file.py")
For a full smoke test, ask:
Use topos_evaluate_project to find the worst file in src/. Edit it in place, then verify with topos_assess_worktree_change. If COMPOSABLE is blocked, call topos_depgraph_status first.
If COMPOSABLE stays unavailable, call
topos_depgraph_statusor passgitnexus_direxplicitly. Evaluation results includeagent_contractwithblocked_bycodes such asmissing_gitnexus_dirorstale_gitnexus_dirandnext_toolpointing attopos_generate_depgraph.topos_evaluate_codecan only score SIMPLE and SECURE because raw strings do not carry dependency-graph context.
Setting Preferences¶
A preference ranking is a strict total order over the three quality pillars:
simple, composable, and secure. Topos uses the ranking to compute a
relaxation walk: the sequence of lattice targets an agent should try when
IDEAL is not reachable within the available time or token budget.
Use it when you care about the order of tradeoffs. For example,
["simple", "composable", "secure"] tells the agent to preserve simplicity
first, then composability, then security if all three cannot be improved at once.
Rank |
Primary Focus |
Optimizes toward |
|---|---|---|
1 (Top) |
Mandatory |
The property that must be achieved first. |
2 (Middle) |
Aspirational |
The secondary goal; forms the “ideal intersection” with Rank 1. |
3 (Bottom) |
Pragmatic |
The final property needed to reach |
Example Ranking: (SIMPLE, COMPOSABLE, SECURE)
Aspirational target: The agent first tries to reach
IDEAL(all three pillars pass).Pragmatic fallback: If progress stalls, the agent diverts to
SIMPLE_COMPOSABLE(the intersection of the top two).
MCP Tools¶
Topos registers sixteen MCP tools. Evaluation, inspection, assessment, coverage,
and depgraph tools take a single params object. topos_get_doc takes a
direct topic argument.
Most evaluation and assessment tools accept optional preferences with a
strict ranking (for example
{"ranking": ["simple", "composable", "secure"]}).
Structured responses may include:
agent_contractOutcome-first guidance:
next_tool,next_actions,blocked_by,verification_gates, andrisk_flags. Prefer these fields over parsing markdown prose. Commonblocked_byvalues includemissing_gitnexus_dir,stale_gitnexus_dir,invalid_gitnexus_dir, andparse_failures.metric_locationsOn
topos_evaluate_fileandtopos_inspect_code, maps failing complexity gates (cfg.cyclomatic,ast.max_function_complexity) to concrete source spans withqualified_name,kind, line range, and nesting info.suggestionsActionable fix hints for failing pillars; markdown includes a checklist when present.
Core Evaluation¶
topos_evaluate_file({"params": {"filepath": ..., "preferences": ..., "gitnexus_dir": ..., "include_security_findings": ..., "allow": ..., "verbose": ...}})Classifies a file on disk. Pass
gitnexus_dirto enable the COMPOSABLE pillar and reach higher badges likeIDEAL. Missing or rejected GitNexus configuration is reported inwarnings,agent_contract.blocked_by, and the COMPOSABLE pillar interpretation. Returnsmetric_locationsfor failing complexity gates.topos_evaluate_code({"params": {"code": ..., "language": ..., "preferences": ..., "allow": ..., "verbose": ...}})Classifies a raw code string (SIMPLE and SECURE only).
topos_evaluate_project({"params": {"path": ..., "preferences": ..., "gitnexus_dir": ..., "limit": ..., "offset": ..., "include_security_findings": ..., "allow": ..., "verbose": ...}})Python project rollup with progress reporting and pagination. Returns worst-scoring files first. Use
aggregate_floor_verdictfor the codebase floor andworst_files/guidancefor the next action.topos_inspect_code({"params": {"code": ..., "filepath": ..., "language": ..., "preferences": ..., "top_n_functions": ..., "allow": ..., "verbose": ...}})Detailed metric breakdown: top-N functions by complexity (with line numbers and
qualified_name), entropy details, and full metric table. Provide exactly one ofcodeorfilepath.
Refactor & Iterate¶
topos_assess_worktree_change({"params": {"filepath": ..., "baseline_ref": "HEAD", "preferences": ..., "gitnexus_dir": ..., "include_security_findings": ..., "allow": ...}})Default edit-in-place loop. Compares the working-tree file to a git baseline (
git show <baseline_ref>:<path>). Edit the file, then call this — no snapshot or pasted source required.topos_begin_refactor({"params": {"filepath": ..., "preferences": ..., "gitnexus_dir": ...}})Captures the current file as a baseline snapshot before editing. Returns a
snapshot_id. Use for untracked files or uncommitted baselines that git cannot serve.topos_assess_snapshot({"params": {"snapshot_id": ..., "filepath": ..., "include_security_findings": ..., "allow": ...}})Compares the current on-disk file to a snapshot from
topos_begin_refactor.topos_assess_improvement({"params": {"filepath": ..., "current_code": ..., "proposed_code": ..., "proposed_filepath": ..., "language": ..., "preferences": ..., "gitnexus_dir": ..., "include_security_findings": ..., "allow": ...}})Side-by-side variant assessment. Provide exactly one of
filepathorcurrent_codeand exactly one ofproposed_codeorproposed_filepath.Anti-gaming check: if scores improved but AST edit distance is near zero, it returns
SUSPICIOUS_NO_STRUCTURAL_CHANGE.When SECURE fails, file-level assessment includes
security_findingswith the dangerous callee, line, and source snippet.topos_assess_changeset({"params": {"files": [...], "baseline_ref": "HEAD", "preferences": ..., "gitnexus_dir": ..., "include_security_findings": ..., "allow": ...}})Multi-file / module-split assessment (read-only). Each file is compared to the git baseline; new files have no baseline. Returns per-file verdicts, a project rollup (
aggregate_before/aggregate_after), and flagscomplexity_relocated_within_fileandproject_regression. When COMPOSABLE is blocked, calltopos_generate_depgraphfirst, then re-assess.topos_preference_walk({"params": {"ranking": ..., "target": ..., "current": ...}})Returns the concrete relaxation walk (sequence of Quality Badges) the agent should follow to reach the target from its current state.
Dependency Graph¶
topos_depgraph_status({"params": {"gitnexus_dir": ...}})Read-only
.gitnexusstate:missing,present,stale,load_error,schema_mismatch, orinvalid_dir(a badgitnexus_diroverride). Staleness is anchored to the commit the graph was built from (falling back to file mtimes for graphs built before that marker existed), so a regenerate reliably clearsstale. Never shells out.topos_generate_depgraph({"params": {"directory": ...}})Runs
gitnexus analyzeand writes.gitnexus/. Side-effecting and approval-gated. Requires thegitnexusCLI (npm install -g gitnexus).
Structure & Coverage¶
topos_compare_files({"params": {"source": ..., "target": ...}})AST edit distance (topological drift) between two files on disk.
topos_compare_code({"params": {"source_code": ..., "target_code": ..., "language": ...}})AST edit distance (topological drift) between two code strings.
topos_calculate_coverage({"params": {"put_files": ..., "test_files": ..., "language": ..., "k": ..., "include_unknown": ..., "coverage_threshold": ...}})Calculates structural test coverage (UAST declaration matching and k-gram recall). Coverage is a separate signal; it does not change the SIMPLE / COMPOSABLE / SECURE lattice verdict.
Agent Knowledge¶
topos_get_doc(topic)Retrieves Topos documentation (
agent-contract,workflows,lattice,metrics,preferences, orpriority) as Markdown. Use it when the client does not expose MCP resource fetching to the model.
MCP Prompt¶
topos_refactor_until_ideal(filepath, priority, max_iterations, preferences)Returns a compact refactor-loop prompt with the baseline measure call, inspection call, improvement-assessment call, and acceptance gates. Use it when a client exposes MCP prompts directly.
MCP Resources¶
Topos exposes these Markdown resources. Clients may surface them as browsable resources, attachable context, or direct agent context depending on host support:
topos://docs/agent-contract— compact outcome-first loop contract and done gatestopos://docs/workflows— expanded review → plan → refactor → re-measure guidetopos://docs/lattice— the 8-element Quality Badge latticetopos://docs/metrics— every metric key, pillar, and thresholdtopos://docs/priority— priority profiles (simple / composable / secure)topos://docs/preferences— strict generator rankings and preference walks