Skip to main content
Glama

get_complexity_metrics

Analyze a Java file to measure cyclomatic and cognitive complexity, LOC, and per-method risk. Identify high, medium, or low complexity methods before refactoring.

Instructions

Get cyclomatic complexity, cognitive complexity, LOC.

USAGE: get_complexity_metrics(filePath="path/to/File.java") OUTPUT: The file's line counts, a summary and risk assessment over its methods and, with includeDetails (default true), each method's metrics with the type declaring it

Metrics:

  • Cyclomatic Complexity: Count of decision points (+1 for if/for/while/case/catch)

  • Cognitive Complexity: Penalizes nesting and breaks in linear flow

  • LOC: Physical and logical lines of code

Risk levels:

  • High: CC > 10

  • Medium: CC 6-10

  • Low: CC <= 5

Requires load_project to be called first.

Input Schema

NameRequiredDescriptionDefault
filePathYesPath to source file
includeDetailsNoInclude per-method breakdown (default: true)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.5.3
    • removedInput schema / properties / granularity
      Removed value: -{
      -  "description": "Level of detail: 'file', 'type', or 'method' (default: 'file')",
      -  "type": "string"
      -}
  2. Addedv1.3.4
  3. Removedv1.3.3
  4. First observedv1.2.0

TDQS

A3.7/5.0
Behavior4/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 does well: it describes the output structure, the default behavior of includeDetails, and how risk levels are derived. It does not explicitly state read-only behavior or error conditions, but otherwise gives strong behavioral context.

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?

The description is front-loaded with the core purpose and organized into usage, output, metrics, and risk sections. It is reasonably concise, though some metric and risk-level detail could be considered supplementary rather than essential.

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

Completeness4/5

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

There is no output schema and no annotations, so the description must explain return values and behavior. It does so effectively by describing line counts, summary/risk assessment, per-method details, and risk thresholds. Minor gaps remain around read-only guarantees and error behavior.

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

Parameters3/5

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

Schema description coverage is 100%, so both parameters are already documented. The description repeats the includeDetails default and gives a filePath example, but does not add substantial meaning beyond what the schema already provides.

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 states a specific verb and resource: retrieve cyclomatic complexity, cognitive complexity, and LOC for a file. It is clearly distinguishable from most siblings by resource, though it does not explicitly differentiate itself from related analysis tools like analyze_file or analyze_method.

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?

It provides a usage example and the prerequisite that load_project must be called first, which is useful context. However, it does not explain when to choose this tool over alternatives such as analyze_file, analyze_method, or health_check, so usage guidance is only implied.

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