Skip to main content
Glama
gclluch
by gclluch

code_complexity

Analyze Python code complexity by cyclomatic metric, revealing decision points and per-function ranks. Pinpoints complex functions needing refactoring to improve maintainability.

Instructions

Cyclomatic complexity per function, with rank and decision-point breakdown.

Counts if/elif, for, while, except, comprehension fors and ifs, boolean operators, ternaries, and match cases other than the irrefutable one. Scores match radon cc --no-assert.

with and assert are deliberately not counted: neither branches. with still adds nesting depth.

Args: path: Path to a .py file. function: Optional single function to analyse in detail.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
functionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior5/5

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

With no annotations, the description carries the full burden and excels: it details exactly which constructs are counted (if/elif, for, while, except, comprehensions, booleans, ternaries, match cases) and which are not (with, assert), and even references radon compatibility. This is thorough and transparent.

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

Conciseness5/5

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

The description is front-loaded with the main purpose, then provides concise, well-organized technical details and an Args section. Every sentence contributes value, and unnecessary fluff is absent.

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?

Given the existence of an output schema, the description only needs to explain behavioral nuances, which it does comprehensively (counting rules, exclusions, and radon match). It is complete for a complexity-analysis tool.

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?

The schema provides only titles, but the description clarifies that path is a .py file and function is an optional single function for detailed analysis. This adds meaning beyond the schema, though it could specify function name format.

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?

The description clearly states the tool's purpose: 'Cyclomatic complexity per function, with rank and decision-point breakdown.' This is a specific verb+resource that distinguishes it from sibling tools like list_functions or code_smells, which focus on different aspects.

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 provides implied usage context (for analyzing cyclomatic complexity), but it lacks explicit when-to-use or alternatives. There is no mention of preferring this over analyze_file or code_smells, or any exclusions, so 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.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gclluch/py-ast-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server