Skip to main content
Glama

cgis_find_orphans

Identify orphan classes that survive only via re-exports, using construction, inheritance, and references to flag dead-code candidates for deletion.

Instructions

Classes nothing in production builds, extends or names — dead-code candidates.

Finds classes that no test, type checker or linter flags, because each is
still imported somewhere: a package re-export keeps a class importable long
after its last real caller is gone. On one mid-sized backend this reported
43 of 1 789 classes, and the hand-written equivalent's findings were all
real and all deleted.

Two filters decide the answer. **Tests are not users** — a class built only
by its own test is exactly the shape being hunted. **A re-export is not a
use** — ``IMPORTS_SYMBOL`` does not count, or nothing is ever reported. What
counts is construction (``CALLS``), inheritance (``EXTENDS``) and being named
(``REFERENCES`` — an annotation, or a class handed to a framework); the last
keeps abstract ports and Protocols off the list.

``prefix`` narrows to one package on a dot boundary. ``include_tests`` counts
test code as a user, turning the report into "unreachable from anywhere".

Machine-generated classes are **hidden by default**, and ``include_generated``
puts them back. The query is right about them — nothing constructs a
betterproto stub — but nobody hand-deletes one either, so they are noise
rather than a finding. Measured on owner-api at b7d02fe6, five of six
reported orphans were generated entities and the sixth a nested pydantic
``Config``: the unfiltered report had no actionable row in it (#432).

Returns JSON ``{orphans, considered, test_sources, generated_excluded}``;
each orphan carries ``fqn``/``file``/``line``. **A listing is a candidate for
deletion, not a proof** — a class named only inside a decorator (#429) or
arriving through a star import is invisible here, so the sweep errs towards
reporting a live class rather than hiding a dead one. ``test_sources: 0`` in a
repository that has tests means the graph predates the ``is_test`` column:
re-ingest. ``generated_excluded`` counts every generated class left out of
the population under the same ``prefix``, referenced or not — so ``0`` on a
repository with generated code means the same for ``is_generated``, which has
no backfill: the marker is in the file header, not in the database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
prefixNoOnly consider classes under this FQN prefix, cut on a dot boundary.
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
include_testsNoCount test code as a user, so the report means "unreachable from anywhere".
include_generatedNoInclude machine-generated classes, which are hidden by default.

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 / include_generated / description
      Added value: +"Include machine-generated classes, which are hidden by default."
    • addedInput schema / properties / include_tests / description
      Added value: +"Count test code as a user, so the report means \"unreachable from anywhere\"."
    • addedInput schema / properties / prefix / description
      Added value: +"Only consider classes under this FQN prefix, cut on a dot boundary."
  2. First observedv0.21.0

TDQS

A4/5.0
Behavior5/5

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

With no annotations provided, the description carries the full burden — and it excels. It discloses the return shape {orphans, considered, test_sources, generated_excluded}, the error bias (errs toward reporting a live class rather than hiding a dead one), the invisible cases (decorator-only names, star imports), the test_sources: 0 meaning re-ingest, the generated_excluded counting semantics, and the machine-generated hidden-by-default behavior with a measured example. This is exceptionally rich behavioral disclosure.

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

Conciseness3/5

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

The description is long and dense. Most content earns its place — the caveats about decorators, star imports, and re-ingest are genuinely important. But it carries some bloat: the commit hash b7d02fe6, issue numbers (#432, #429), and the '43 of 1 789 classes' anecdote add authenticity but length without changing agent behavior. The first sentence is awkward. It is structured in digestible paragraphs and reasonably front-loaded, but not lean.

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?

For a complex dead-code analysis tool, this is complete. Even though an output schema exists, the description goes beyond it by explaining the failure modes (test_sources: 0 meaning stale graph, generated_excluded: 0 with generated code meaning missing backfill), the false-positive bias, and the filtering semantics. An agent has everything needed to invoke it correctly and interpret results — nothing critical 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% and the schema's own parameter descriptions are already strong. The tool description adds meaningful nuance on top: prefix's dot-boundary cutting, include_tests converting the report to 'unreachable from anywhere', and include_generated framing generated classes as noise rather than findings. This goes beyond the schema baseline of 3, though the schema already did heavy lifting, so the increment is moderate.

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

Purpose4/5

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

The description clearly identifies the tool's job: finding dead-code candidates (orphan classes). The second paragraph clarifies the purpose precisely — classes kept importable by re-exports but with no real callers. However, the opening sentence 'Classes nothing in production builds, extends or names' is awkwardly phrased and reads like a fragment; the intent is recoverable but the first line hurts clarity. The description does distinguish this from siblings by framing it as a dead-code sweep rather than a reachability/impact query.

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

Usage Guidelines3/5

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

The description explains the tool's philosophy deeply — tests are not users, re-exports are not uses, what counts is CALLS/EXTENDS/REFERENCES — which implicitly tells an agent when this tool applies. It also explains how flags change the semantics (include_tests becomes 'unreachable from anywhere'). However, it never explicitly names sibling alternatives or states when NOT to use this tool in favor of, say, cgis_audit_reachability or cgis_analyze_impact. The usage context is strong but the exclusion/alternative routing is absent.

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