Skip to main content
Glama

detect_ast_clones

Read-onlyIdempotent

Find structurally identical functions in your codebase by normalizing identifiers and literals with AST hashing. Helps identify candidates for DRY refactoring or extracting shared helpers.

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?

Beyond annotations (readOnlyHint, etc.), describes the algorithmic process (tree-sitter parsing, normalization, hashing) and output structure, adding significant behavioral detail with no contradictions.

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 informative but relatively concise, front-loaded with purpose. Could be slightly more structured, but effectively communicates key points without excess.

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 no output schema, the description fully covers the return format, including JSON fields. Supported languages, read-only guarantee, and algorithmic details make it complete for a complex analysis tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with good descriptions for all 4 parameters. The description adds minimal extra meaning beyond schema context, so baseline 3 is appropriate.

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 explicitly states 'Find Type-2 AST clones across the codebase' and contrasts with sibling check_duplication (Type-1-ish), clearly differentiating the tool's purpose.

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?

Provides clear context: for detecting structurally identical symbols suitable for DRY refactoring, contrasts with check_duplication, and lists supported languages, guiding appropriate use.

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