Skip to main content
Glama

detect_ast_clones

Read-onlyIdempotent

Identify Type-2 AST clones across your codebase: functions with identical structure after normalizing identifiers and literals. Groups structurally identical symbols to detect duplicated code for DRY refactoring.

Instructions

Find Type-2 AST clones across the codebase: functions/methods with identical structure after normalizing identifiers and literals. Unlike check_duplication (name/signature similarity — Type-1-ish), this parses each function body with tree-sitter, replaces identifiers and literals with a placeholder, and hashes the AST subtree. Reports groups of structurally identical symbols — prime candidates for DRY refactoring or extracting a shared helper. Supported languages: TypeScript, JavaScript, Python, Ruby, Go, Java, Rust, PHP, C, C++, C#, Swift, Kotlin, Scala, Elixir. Read-only. Returns JSON: { groups: [{ hash, size, loc, symbols: [{ symbol_id, name, file, line_start, line_end }] }], total_groups, total_duplicated_symbols, files_scanned, symbols_scanned }.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
min_locNoMinimum function body line span to consider (default: 10)
min_nodesNoMinimum AST node count to consider (filters trivial clones like one-line getters) (default: 30)
file_patternNoFilter to files whose path contains this substring
limitNoMax clone groups to return (default: 100)
Behavior5/5

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

Annotations already declare readOnlyHint=true, destructiveHint=false, idempotentHint=true. The description adds substantial behavioral context: uses tree-sitter parsing, normalization of identifiers/literals, hashing, grouping of symbols, and output format. It also lists supported languages. No contradictions with annotations.

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 moderately concise for the amount of useful information it conveys. It front-loads the core purpose and type, then adds method details, language list, and output format. Every sentence earns its place, though it could be slightly shorter without loss.

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 complexity of AST clone detection and the absence of an output schema, the description provides a complete picture: what it does, how it works, supported languages, behavioral traits, and exact output structure with example JSON. It covers all necessary context for an agent to select and invoke the tool correctly.

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?

Input schema has 100% description coverage for all 4 parameters. The description adds value by explaining the purpose of 'min_nodes' (filtering trivial clones like one-line getters) and implicitly connecting parameters to the algorithm. However, it does not add significant new detail beyond what the schema already provides.

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 it finds Type-2 AST clones, details the method (normalizing identifiers/literals and hashing AST subtree), and explicitly contrasts with sibling 'check_duplication' (Type-1-ish). This provides a specific verb and resource with clear differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly contrasts with 'check_duplication' and explains when to use this tool for structural clones vs name/signature similarity. It also mentions supported languages and read-only nature, providing clear context. However, it lacks explicit 'when-not' scenarios beyond the sibling distinction.

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/nikolai-vysotskyi/trace-mcp'

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