analyze_complexity

[architecture]

Analyzes cyclomatic complexity and size metrics. Select an exact member method or type with symbolKey, or use file and name filters.

Why this tool exists

Project graphs, dependencies, unused references, and complexity are too large to infer reliably from scattered files.

How it helps the agent

The model can reason from architecture-level facts before deleting references, moving code, or prioritizing risky areas.

Try it locally in the Glider playground

Parameters

NameTypeRequiredDescription
symbolKeystringNoExact source member method or type key from symbol discovery. Local functions are unsupported. Do not combine with typeName, filePath, or projectName.
typeNamestringNoOptional type name filter.
filePathstringNoOptional file path filter.
projectNamestringNoOptional project name filter.
minCyclomaticComplexitynumberNoOnly include methods with cyclomatic complexity >= this value. Default is 0.
sortBystringNoOptional sort: 'complexity', 'averageComplexity', 'linesOfCode', 'methodCount', 'name'.
sortOrderstringNoSort order: 'asc' (default) or 'desc'.
skipnumberNoPagination offset over returned types. Default is 0.
takenumberNoPagination size over returned types. Default is 50.

Examples

Analyze overall complexity

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "analyze_complexity",
    "arguments": {}
  }
}
Response
{
  "success": true,
  "data": {
    "summary": {
      "totalTypes": 1,
      "totalMethods": 2,
      "totalLinesOfCode": 80,
      "averageComplexity": 8,
      "maxComplexity": 12,
      "highComplexityMethodCount": 1
    },
    "paging": {
      "skip": 0,
      "take": 50,
      "total": 1,
      "returned": 1,
      "hasMore": false
    },
    "types": [
      {
        "name": "OrderService",
        "fullName": "Acme.Orders.OrderService",
        "kind": "Class",
        "filePath": "/workspace/Orders/OrderService.cs",
        "linesOfCode": 80,
        "methodCount": 2,
        "averageComplexity": 8,
        "methods": [
          {
            "name": "SubmitOrder",
            "cyclomaticComplexity": 4,
            "linesOfCode": 16,
            "parameterCount": 1,
            "lineNumber": 10,
            "filePath": "/workspace/Orders/OrderService.cs"
          },
          {
            "name": "ValidateOrder",
            "cyclomaticComplexity": 12,
            "linesOfCode": 32,
            "parameterCount": 1,
            "lineNumber": 30,
            "filePath": "/workspace/Orders/OrderService.cs"
          }
        ]
      }
    ]
  },
  "error": null
}

Analyze one exact method with a key from symbol discovery

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "analyze_complexity",
    "arguments": {
      "symbolKey": "<method symbolKey returned by search_symbols or resolve_symbol>"
    }
  }
}
Response
{
  "success": true,
  "data": {
    "summary": {
      "totalTypes": 1,
      "totalMethods": 1,
      "totalLinesOfCode": 16,
      "averageComplexity": 4,
      "maxComplexity": 4,
      "highComplexityMethodCount": 0
    },
    "paging": {
      "skip": 0,
      "take": 50,
      "total": 1,
      "returned": 1,
      "hasMore": false
    },
    "types": [
      {
        "name": "OrderService",
        "fullName": "Acme.Orders.OrderService",
        "kind": "Class",
        "filePath": "/workspace/Orders/OrderService.cs",
        "linesOfCode": 16,
        "methodCount": 1,
        "averageComplexity": 4,
        "methods": [
          {
            "name": "SubmitOrder",
            "cyclomaticComplexity": 4,
            "linesOfCode": 16,
            "parameterCount": 1,
            "lineNumber": 10,
            "filePath": "/workspace/Orders/OrderService.cs"
          }
        ]
      }
    ]
  },
  "error": null
}

Analyze a type across all partial declarations with a discovered key

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "analyze_complexity",
    "arguments": {
      "symbolKey": "<type symbolKey returned by search_symbols or resolve_symbol>"
    }
  }
}
Response
{
  "success": true,
  "data": {
    "summary": {
      "totalTypes": 1,
      "totalMethods": 2,
      "totalLinesOfCode": 80,
      "averageComplexity": 8,
      "maxComplexity": 12,
      "highComplexityMethodCount": 1
    },
    "paging": {
      "skip": 0,
      "take": 50,
      "total": 1,
      "returned": 1,
      "hasMore": false
    },
    "types": [
      {
        "name": "OrderService",
        "fullName": "Acme.Orders.OrderService",
        "kind": "Class",
        "filePath": "/workspace/Orders/OrderService.cs",
        "linesOfCode": 80,
        "methodCount": 2,
        "averageComplexity": 8,
        "methods": [
          {
            "name": "SubmitOrder",
            "cyclomaticComplexity": 4,
            "linesOfCode": 16,
            "parameterCount": 1,
            "lineNumber": 10,
            "filePath": "/workspace/Orders/OrderService.cs"
          },
          {
            "name": "ValidateOrder",
            "cyclomaticComplexity": 12,
            "linesOfCode": 32,
            "parameterCount": 1,
            "lineNumber": 30,
            "filePath": "/workspace/Orders/OrderService.cs"
          }
        ]
      }
    ]
  },
  "error": null
}

Show only high-complexity methods (>= 10)

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "analyze_complexity",
    "arguments": {
      "minCyclomaticComplexity": 10,
      "sortBy": "complexity",
      "sortOrder": "desc"
    }
  }
}
Response
{
  "success": true,
  "data": {
    "summary": {
      "totalTypes": 1,
      "totalMethods": 2,
      "totalLinesOfCode": 80,
      "averageComplexity": 8,
      "maxComplexity": 12,
      "highComplexityMethodCount": 1
    },
    "paging": {
      "skip": 0,
      "take": 50,
      "total": 1,
      "returned": 1,
      "hasMore": false
    },
    "types": [
      {
        "name": "OrderService",
        "fullName": "Acme.Orders.OrderService",
        "kind": "Class",
        "filePath": "/workspace/Orders/OrderService.cs",
        "linesOfCode": 80,
        "methodCount": 2,
        "averageComplexity": 8,
        "methods": [
          {
            "name": "ValidateOrder",
            "cyclomaticComplexity": 12,
            "linesOfCode": 32,
            "parameterCount": 1,
            "lineNumber": 30,
            "filePath": "/workspace/Orders/OrderService.cs"
          }
        ]
      }
    ]
  },
  "error": null
}

Response Notes

Returns summary metrics and a page of types. A member method key selects one exact overload; all aggregates describe that method. Explicit accessor keys select one accessor body. Position discovery uses declaration keys for constructed generic and reduced extension methods. A type key combines its partial declarations and excludes nested types. Partial methods use their implementation once.

Primary constructor metrics cover the header, base arguments, and instance initializers. Other member bodies and bodyless accessors do not contribute. Each method includes its own filePath. The type filePath identifies the first declaration. Threshold filters affect method lists and type inclusion; aggregates retain the selected scope before filtering and paging.

Bodyless accessor keys, local functions, fields, properties, namespaces, metadata symbols, implicit symbols, and conflicting selectors return errors. Obtain keys from discovery; replace the example placeholders before calling.

↑/↓ NavigateEnter OpenSpace Expand