Skip to main content
Glama

cgis_metrics

Compute whole-graph architectural metrics — coupling bottlenecks, God classes, PageRank — to reveal codebase hotspots; scope or exclude domains for focused reviews.

Instructions

Whole-graph architectural metrics — coupling bottlenecks, God classes, PageRank.

Returns JSON ``{bottlenecks, god_classes, critical, file_coupling, class_cohesion,
resolution}``
computed with vectorized DuckDB aggregations over the whole graph (fan-in/fan-out
coupling, declared-member counts, PageRank, per-file Ca/Ce/instability) — the
global "what are the hotspots?" view that complements the node-local
trace/impact/context tools. Requires the optional ``duckdb`` extra; an
unavailable dependency is reported as a normal ❌ message.

``file_coupling`` counts *files*, not calls: Ca is how many other files
depend on a file (by IMPORTS or CALLS), Ce how many it depends on, and
instability ``I = Ce / (Ca + Ce)`` runs from 0 (stable, expensive to change)
to 1 (volatile); it is null for a file linked to no other.

``class_cohesion`` ranks classes by LCOM4: the number of groups their instance
methods fall into when linked by a shared ``self`` attribute or a call. 1 is
cohesive; 2+ is a class doing unrelated jobs. Dunders (``__init__`` above
all), abstract, static and class methods are not counted.

``resolution`` is the share of edges the resolver could not place, by the
same rule as ``cgis validate``. Read the rankings through it: a node whose
calls are mostly unresolved looks uncoupled because its edges point nowhere.
Under ``scope``/``exclude`` it counts the edges the selected code *emits*.

``exclude`` drops any node whose FQN contains one of the given dot-segments
(e.g. ``["tests"]`` removes both ``tests.*`` and ``domains.*.tests.*``) so
test/vendor scaffolding stays out of the rankings.

``scope`` is its complement: it keeps only nodes under one of the given
dot-prefixes, anchored and cut on a dot boundary, so
``["domains.reservation"]`` is that subtree and not
``domains.reservation_archive``. Use it for a per-domain review. The two
compose, and they differ where it matters for PageRank — ``exclude`` removes
nodes from the propagation graph, ``scope`` filters the rows and lets rank
propagate over the whole graph, so a scoped run reports how central the
subtree is *globally*. Coupling in-degree likewise keeps counting callers
from outside the scope, which is the ripple a domain review is after (#239).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoTop-N rows returned per section.
scopeNoKeep only nodes under any of these dot-prefixes, e.g. ["domains.billing"]; rank still propagates over the whole graph.
db_pathNoSQLite graph built by cgis_ingest. A relative path resolves against the MCP server's working directory, not the agent's — prefer an absolute path.graph.db
excludeNoDrop nodes whose FQN contains any of these dot-segments, e.g. ["tests"]; they are removed from PageRank propagation too.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.21.1
    • addedInput schema / properties / db_path / description
      Added value: +"SQLite graph built by cgis_ingest. A relative path resolves against the MCP server's working directory, not the agent's — prefer an absolute path."
    • addedInput schema / properties / exclude / description
      Added value: +"Drop nodes whose FQN contains any of these dot-segments, e.g. [\"tests\"]; they are removed from PageRank propagation too."
    • addedInput schema / properties / limit / description
      Added value: +"Top-N rows returned per section."
    • addedInput schema / properties / scope / description
      Added value: +"Keep only nodes under any of these dot-prefixes, e.g. [\"domains.billing\"]; rank still propagates over the whole graph."
  2. First observedv0.21.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does so richly: it discloses the optional duckdb dependency and its ❌ error path, explains that scope vs exclude differ because exclude removes nodes from PageRank propagation while scope only filters rows, and clarifies that resolution affects how rankings should be read. These are exactly the non-obvious behaviors an agent needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Purpose is front-loaded and each section explains a real output key or parameter behavior, so most sentences earn their place. It is dense and slightly over-long, with some overlap against the already-descriptive schema for scope/exclude.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Complete for this tool: an output schema exists so return values needn't be re-explained, no annotations need compensating, and the description covers dependency requirements, parameter interactions, and ranking interpretation. Nothing an agent needs to invoke it correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3, but the description adds genuine meaning: anchored dot-boundary matching ('domains.reservation' not 'domains.reservation_archive'), dot-segment containment for exclude, and the semantic divergence between the two flags for PageRank and coupling in-degree.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening line states a specific verb+resource and enumerates the concrete outputs (coupling bottlenecks, God classes, PageRank), then explicitly positions it as 'the global what-are-the-hotspots view that complements the node-local trace/impact/context tools.' An agent can distinguish it from cgis_trace_flow/cgis_analyze_impact/cgis_context without opening any schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear context: use it for whole-graph hotspot analysis, and the scope/exclude paragraph tells the agent to reach for it during a 'per-domain review.' It routes between scope and exclude well, but stops short of explicit when-not conditions or naming a specific sibling to avoid.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.