Skip to main content
Glama

get_inheritance_chain

Retrieve a C++ class or struct inheritance hierarchy across translation units, showing base and derived classes with access and virtual flags; optionally walk all ancestors and descendants.

Instructions

Return the C++ inheritance chain for a class or struct — libclang-aware hierarchy. Resolves base/derived class relationships across all translation units, which single-file reading cannot do.

Shows direct base classes (what this inherits from) and direct derived classes (what inherits from this), along with access level and virtual flag for each edge.

When transitive=True, walks the full hierarchy up to all ancestors and down to all descendants (bounded by max_depth). Uses BFS with cycle detection to handle diamond inheritance.

For class members use get_class_members. For virtual method override chains use get_method_overrides.

Read-only. No side effects.

Args: class_name: Class or struct name to get inheritance information for. E.g. 'UART_DRIVER' or 'comm::MODEM'. project_root: Project root. Auto-detected if omitted. project: Project name or project_id — call list_projects to get them. Use it to ask about a project that is not the project of the current directory. It is an alternative to project_root, which takes a root path. Give one of the two, not both. transitive: When True, walk the full inheritance tree both up (ancestors) and down (descendants). Default: False (direct bases and derived only). max_depth: Maximum BFS depth for transitive walk (default 10). The schema holds it between 1 and 50, thus a number outside that range is REFUSED and not cut down to fit. limit: Maximum classes in all_bases and in all_derived on one page (default 100, max 500). Only with transitive=True. offset: Skip this many classes in all_bases and in all_derived. One offset pages the two lists together. variant: Variant of the build (a board, or a PlatformIO environment). On a project of more than one build, give the arguments of one build as the refusal lists them: the variant, the image, or the two. fw-context does not select a build. One query answers for ONE build. image: Image of the build: a separate program, such as the application or the bootloader. Give it when the build has an image name.

Returns: dict: { name, qualified_name, kind, file, line, bases: [{name, usr, access, is_virtual, file}], derived: [{name, usr, access, is_virtual, file}], all_bases: [{name, usr, access, is_virtual, depth, file, kind}] (when transitive=True, ancestors sorted by depth, then name), all_derived: [...] (when transitive=True, descendants, same shape) }

With ``transitive=True`` each of the two lists is one page, and
``all_bases_page`` and ``all_derived_page`` hold its page notice
``{total, offset, shown, more, hint}``.  A hierarchy below a root
class of a framework can hold thousands of classes.

When a file of the answer changed after the last index run, the
dict adds ``stale`` (True) and ``stale_warning`` (str).

On failure the dict holds ``error`` with the reason.

Input Schema

NameRequiredDescriptionDefault
imageNoImage of the build: a separate program, such as the application or the bootloader. On a project of more than one build, give it when that build has an image name, as the refusal lists it.
limitNoMaximum classes in all_bases and in all_derived on one page (default 100, max 500). Only with transitive=True.
offsetNoSkip this many classes in all_bases and in all_derived. Reads the next page of a large hierarchy. Only with transitive=True.
projectNoProject name or project_id — call list_projects to get them. Use it to ask about a project that is not the project of the current directory. It is an alternative to project_root, which takes a root path. Give one of the two, not both.
variantNoVariant of the build (a board, or a PlatformIO environment). On a project of more than one build, give the arguments of one build as the refusal lists them: the variant, the image, or the two. fw-context does not select a build for you. One query answers for ONE build.
max_depthNoMaximum BFS depth for transitive walk (default 10).
class_nameYesClass or struct name to get inheritance information for. E.g. 'UART_DRIVER' or 'comm::MODEM'.
transitiveNoWhen True, walk the full inheritance tree both up (ancestors) and down (descendants). Default: False (direct bases and derived only).
project_rootNoProject root. Auto-detected if omitted. This field also accepts a project name or a project_id, but project is the clear field for those.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.32.1
    • changedInput schema / properties / image / description
      Previous value: -"Sysbuild image within the variant. Required when the variant holds several: each image is a separate program."New value: +"Image of the build: a separate program, such as the application or the bootloader. On a project of more than one build, give it when that build has an image name, as the refusal lists it."
    • addedInput schema / properties / limit
      Added value: +{
      +  "default": 100,
      +  "description": "Maximum classes in all_bases and in all_derived on one page (default 100, max 500). Only with transitive=True.",
      +  "minimum": 1,
      +  "title": "Limit",
      +  "type": "integer"
      +}
    • addedInput schema / properties / offset
      Added value: +{
      +  "default": 0,
      +  "description": "Skip this many classes in all_bases and in all_derived. Reads the next page of a large hierarchy. Only with transitive=True.",
      +  "minimum": 0,
      +  "title": "Offset",
      +  "type": "integer"
      +}
    • changedInput schema / properties / variant / description
      Previous value: -"Build variant (multi-build project). Omit to use default_variant. One query answers for ONE build."New value: +"Variant of the build (a board, or a PlatformIO environment). On a project of more than one build, give the arguments of one build as the refusal lists them: the variant, the image, or the two. fw-context does not select a build for you. One query answers for ONE build."
  2. Changed3 schema fields changedv0.32.0
    • addedInput schema / properties / class_name / minLength
      Added value: +1
    • changedInput schema / properties / image / description
      Previous value: -"Sysbuild image name within the variant (multi-project). Omit for all images of the variant."New value: +"Sysbuild image within the variant. Required when the variant holds several: each image is a separate program."
    • changedInput schema / properties / variant / description
      Previous value: -"Build variant name (multi-project). Omit to use default_variant or fail-closed. Use '*' for all variants."New value: +"Build variant (multi-build project). Omit to use default_variant. One query answers for ONE build."
  3. Changed3 schema fields changedv0.30.0
    • addedInput schema / additionalProperties
      Added value: +false
    • addedInput schema / properties / project
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Project name or project_id — call list_projects to get them. Use it to ask about a project that is not the project of the current directory. It is an alternative to project_root, which takes a root path. Give one of the two, not both.",
      +  "title": "Project"
      +}
    • changedInput schema / properties / project_root / description
      Previous value: -"Project root. Auto-detected if omitted."New value: +"Project root. Auto-detected if omitted. This field also accepts a project name or a project_id, but project is the clear field for those."
  4. Changed2 schema fields changedv0.25.3
    • addedInput schema / properties / image
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Sysbuild image name within the variant (multi-project). Omit for all images of the variant.",
      +  "title": "Image"
      +}
    • addedInput schema / properties / variant
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Build variant name (multi-project). Omit to use default_variant or fail-closed. Use '*' for all variants.",
      +  "title": "Variant"
      +}
  5. Changed1 schema field changedv0.25.2
    • changedInput schema / properties / class_name / description
      Previous value: -"Class or struct name to get inheritance information for. E.g. 'UART_DRIVER' or 'zbox::ZMODEM'."New value: +"Class or struct name to get inheritance information for. E.g. 'UART_DRIVER' or 'comm::MODEM'."
  6. Addedv0.7.0

TDQS

A4.7/5.0
Behavior5/5

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

No annotations are provided, so the description carries the full burden and does so well: it discloses cross-translation-unit resolution, BFS with cycle detection to survive diamond inheritance, that out-of-range max_depth is REFUSED rather than clamped, that paging uses combined offset across two lists, that stale/stale_warning appear when files changed post-index, and that errors surface in an 'error' key. It also declares 'Read-only. No side effects.'

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 purpose and routing sentences are front-loaded and earned, but the Args block largely duplicates parameter descriptions already at 100% schema coverage, and the Returns block enumerates output keys at length. The result is longer than it needs to be given the structured data already present.

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?

With no annotations and no output schema, the description supplies everything an agent needs: return shape including the transitive-only all_bases/all_derived lists, page notice fields, staleness warnings, and the failure shape. For a 9-parameter, paged, cross-file tool this is complete.

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 the baseline is 3 and most Args text restates the schema. It nonetheless adds genuine semantic details beyond the schema, notably that max_depth values outside 1–50 are refused rather than truncated, and that project_root also accepts a project name/id while project is the clearer field for that.

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?

States a specific verb+resource (return the C++ inheritance chain for a class or struct) and immediately qualifies scope with 'libclang-aware hierarchy' resolved across all translation units. It explicitly distinguishes itself from get_class_members and get_method_overrides, so an agent can route 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 Guidelines5/5

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

Gives explicit alternatives ('For class members use get_class_members. For virtual method override chains use get_method_overrides') and a conditional usage rule for transitive=True vs the default direct-only mode. It also advises when each project/variant/image argument is needed, covering when-to-use rather than leaving it to inference.

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