Stellarion
Tools

stellarion_analyze_complexity

Measure cyclomatic and cognitive complexity with per-function grading

Measures code complexity for refactoring decisions. Supports cyclomatic complexity (number of independent test paths) and cognitive complexity (how hard code is to understand). Returns per-function scores with grades from A to F.

When to Use

  • Identifying functions that need simplification
  • Reviewing code quality during pull requests
  • Prioritizing technical debt reduction
  • Tracking complexity trends over time
  • Setting quality gates in CI pipelines

Parameters

ParameterTypeRequiredDefaultDescription
uristringYes--File URI to analyze (e.g., file:///path/to/file.ts)
linenumberNo--Line number to analyze a specific function (0-indexed). Omit to analyze all functions in the file.
typeenumNocyclomaticType of analysis: cyclomatic (test paths), cognitive (readability), or all (both)
thresholdnumberNo10Complexity threshold for flagging. Functions below this are not flagged.
summarybooleanNofalseReturn a condensed summary

Examples

Analyze an Entire File

Natural Language: "Check the complexity of all functions in the router file"

MCP Tool Call:

{
  "name": "stellarion_analyze_complexity",
  "arguments": {
    "uri": "file:///home/dev/project/src/api/router.ts",
    "type": "all"
  }
}

Returns: Per-function cyclomatic and cognitive scores for every function in the file, each with a letter grade and detailed breakdown.

Check a Specific Function

Natural Language: "How complex is the parseConfig function?"

MCP Tool Call:

{
  "name": "stellarion_analyze_complexity",
  "arguments": {
    "uri": "file:///home/dev/project/src/config/parser.rs",
    "line": 25,
    "type": "cognitive"
  }
}

Returns: Cognitive complexity score for parseConfig with a breakdown showing which nesting levels and control flow structures contribute most to the score.

Find High-Complexity Functions Only

Natural Language: "Show me functions with complexity above 15"

MCP Tool Call:

{
  "name": "stellarion_analyze_complexity",
  "arguments": {
    "uri": "file:///home/dev/project/src/engine/processor.py",
    "threshold": 15,
    "type": "cyclomatic"
  }
}

Returns: Only functions exceeding the threshold of 15, sorted by complexity score.

Output Format

Each function in the response includes:

  • name -- Function name
  • lineStart / lineEnd -- Line range in the file
  • cyclomaticComplexity -- Number of independent paths (when type is cyclomatic or all)
  • cognitiveComplexity -- Readability difficulty score (when type is cognitive or all)
  • grade -- Letter grade from A (simple) to F (extremely complex)
    • A: 1-5
    • B: 6-10
    • C: 11-15
    • D: 16-25
    • E: 26-50
    • F: 51+

Tips

  • Cyclomatic complexity tells you how many test cases you need for full branch coverage. High cyclomatic = hard to test.
  • Cognitive complexity tells you how hard the code is to read. It penalizes deep nesting and breaks in linear flow (e.g., continue, break, nested conditions).
  • Use type: "all" for a comprehensive view. A function can have low cyclomatic but high cognitive complexity (deeply nested but few branches) or vice versa.
  • A threshold of 10 is a good default. Functions above 15 are strong candidates for refactoring. Functions above 25 should be split.
  • Pair with stellarion_tech_debt_report (Pro) to see complexity hotspots in the context of overall codebase health.