Skip to main content
Glama

Audit Codebase Quality and Static Code Smells

audit_code_quality
Read-onlyIdempotent

Audit source code with static AST analysis to detect complexity, code smells, duplicate blocks, and invalid imports or signatures before PRs or refactoring.

Instructions

Performs AST static code smell analysis, cyclomatic complexity profiling, copy-paste duplicate detection, and hallucination validation, distinguishing from 'verify_security_guard' and 'analyze_code_dependencies' by scanning code maintainability and complexity rather than checking for credential leaks or analyzing module dependencies.

Parameters:

  • project_root: Root directory of the repository to audit; scans supported source files recursively.

  • check_type: Audit scope selector: 'all' performs full comprehensive audit; 'smells' profiles cyclomatic complexity, method length (>30 lines), and argument counts (>5); 'duplicity' detects copy-pasted blocks (6+ identical lines); 'hallucinations' validates import existence and function call signatures against repository AST.

  • file_path: Optional path to scope audit to a single source file rather than scanning the full workspace.

Behavior:

  • Mutability: Strictly read-only; parses syntax trees without modifying or deleting files.

  • Idempotency: Deterministic; returns identical diagnostic findings for the same codebase state.

  • Privacy & Network: 100% offline local AST parsing; zero external linter dependencies or network requests.

  • Performance & Resources: Audits 1,000 files in <500ms using <50MB RAM; thread-safe with zero rate limits.

  • Auth: Zero authentication or cloud credentials required.

  • Return Structure: Emits diagnostic Markdown report categorized by severity (T-001 to T-004) with exact file line numbers and remediation suggestions.

  • Error Handling: Skips unparseable binary files gracefully and continues auditing remaining source files.

Usage Guidelines:

  • When to use: Run before submitting PRs, merging branches, or refactoring code to detect complex methods, missing docstrings, duplicate code blocks, or invalid hallucinated imports.

  • When NOT to use: Do not use for detecting hardcoded secrets or installing git pre-commit security hooks (use 'verify_security_guard' instead); do not use for mapping whole-repository module dependencies (use 'analyze_code_dependencies' instead).

Returns: Comprehensive diagnostic report with severity ratings (T-001 to T-004), exact file line references, and remediation guidance.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "audit_code_quality"
  }
}

Input Schema

NameRequiredDescriptionDefault
file_pathNoOptional path to a single file to audit.
check_typeNoAudit scope: 'all' for complete check, 'smells' for code complexity/smells, 'duplicity' for copy-paste blocks, 'hallucinations' for invalid imports/signatures.all
project_rootNoRoot directory of the repository to audit (default: current directory)..

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv7.3.2
  2. Removedv7.0.1
  3. Addedv7.0.0

TDQS

A4.8/5.0
Behavior5/5

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

Beyond the annotations, the description discloses read-only AST parsing, determinism, fully offline operation, no auth, performance characteristics, and graceful skipping of unparseable files. These details add substantial behavioral context beyond readOnlyHint, idempotentHint, openWorldHint, and destructiveHint.

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 and organized into clear sections for purpose, parameters, behavior, usage, and returns. It is somewhat verbose and repeats some schema and return information, but the added thresholds and behavioral details generally justify the length.

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?

The tool is fully documented for a read-only audit operation: purpose, parameters, behavior, scope, error handling, performance, authentication, and return structure are all covered. Although an output schema exists, the description remains complete and does not leave critical invocation details missing.

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 schema already documents all three parameters. The description still adds useful semantic detail beyond the schema, including recursive source scanning for project_root and concrete thresholds for check_type values such as method length over 30 lines, argument counts over 5, and duplicate blocks of 6+ identical lines.

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 states a specific verb and resource: AST static code smell analysis, complexity profiling, duplicate detection, and hallucination validation. It explicitly distinguishes the tool from 'verify_security_guard' and 'analyze_code_dependencies' by contrasting maintainability/complexity scanning with credential checks and dependency mapping.

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?

The description provides explicit when-to-use guidance such as before PRs, merges, or refactoring. It also gives explicit when-not-to-use guidance and names the alternative tools for secret detection and dependency mapping.

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