Skip to main content
Glama

Check a snippet for duplication

check_duplication
Read-onlyIdempotent

Detect duplicate code in your project before writing or committing new functions, blocks, or classes. It scans existing code to find exact or similar matches, helping you reuse existing implementations.

Instructions

Check whether a code snippet duplicates code that already exists in the scanned project. Use it before writing or committing a function, class or block, to find the existing copy you should reuse instead. Detection is token-based with the server's --min-tokens / --min-lines thresholds: a snippet shorter than the threshold returns count 0 with a 'note' explaining why. Returns {format, count, returned, duplications[]} where each duplication has 'file', 'fileStartLine', 'fileEndLine', 'snippetStartLine', 'snippetEndLine', 'tokens' and 'kind' (exact, renamed or similar), biggest match first. With 'similarity' below 1, the response also carries 'similar[]' and 'similarCount': project functions whose syntax-tree structure resembles each function in the snippet (JavaScript/TypeScript only), each with 'file', 'name', line ranges and a 'similarity' ratio. Does not modify the project or the scan; the snippet is compared against the last scan, so call check_current_directory first if files changed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe source code to check, verbatim (whole functions or blocks work best; it must reach the server's --min-tokens threshold, 50 tokens by default)
limitNoMaximum number of duplications to include in the response. 'count' always carries the untruncated total, so a small limit still tells you how much was found.
formatYesLanguage of the snippet: a jscpd format name such as 'javascript', 'typescript', 'python', 'java', or a file extension such as 'js', 'py' (run `jscpd --list` for all 224). Unknown values return an error naming the problem.
similarityNoAlso return project functions whose syntax-tree structure is similar to the snippet's functions, when the similarity ratio reaches this value. 1 means exact matches only (no 'similar' section); 0.85 catches renames, literal changes and one-line edits; 0.7 tolerates a couple of added or removed statements. Defaults to the server's --similarity setting (1 unless configured). JavaScript/TypeScript only; other formats ignore it.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed6 schema fields changedv5.2.0
    • changedInput schema / properties / code / description
      Previous value: -"Source code snippet to check"New value: +"The source code to check, verbatim (whole functions or blocks work best; it must reach the server's --min-tokens threshold, 50 tokens by default)"
    • changedInput schema / properties / format / description
      Previous value: -"Language format (javascript, python, ...) or file extension (js, py, ...); see `cpd --list`"New value: +"Language of the snippet: a jscpd format name such as 'javascript', 'typescript', 'python', 'java', or a file extension such as 'js', 'py' (run `jscpd --list` for all 224). Unknown values return an error naming the problem."
    • addedInput schema / properties / format / examples
      Added value: +[
      +  "javascript",
      +  "python",
      +  "ts"
      +]
    • addedInput schema / properties / limit / default
      Added value: +100
    • changedInput schema / properties / limit / description
      Previous value: -"Maximum matches to include in the response (default 100); 'count' always carries the untruncated total"New value: +"Maximum number of duplications to include in the response. 'count' always carries the untruncated total, so a small limit still tells you how much was found."
    • addedInput schema / properties / similarity
      Added value: +{
      +  "description": "Also return project functions whose syntax-tree structure is similar to the snippet's functions, when the similarity ratio reaches this value. 1 means exact matches only (no 'similar' section); 0.85 catches renames, literal changes and one-line edits; 0.7 tolerates a couple of added or removed statements. Defaults to the server's --similarity setting (1 unless configured). JavaScript/TypeScript only; other formats ignore it.",
      +  "examples": [
      +    0.85
      +  ],
      +  "exclusiveMinimum": 0,
      +  "maximum": 1,
      +  "type": "number"
      +}
  2. First observedv0.1.0

TDQS

A4.6/5.0
Behavior4/5

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

Annotations already declare read-only, idempotent, and non-destructive behavior; the description reinforces this with 'Does not modify the project or the scan' and adds the nuance of comparing against the last scan. It also discloses token-based detection, the threshold effect on results, and the JavaScript/TypeScript limitation for similarity, which are not captured in annotations. No contradiction exists.

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 dense but efficiently organized: purpose, usage, detection logic, return structure, similarity behavior, and side-effects in logical order. Every sentence carries actionable information; there is no fluff or repetition. The length is justified by the tool's complexity.

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 description covers everything an agent needs: purpose, usage timing, prerequisites, parameter semantics, return format with field names, and behavioral caveats (token threshold, language restriction). Even without an output schema, the agent can predict the response structure and understand edge cases. It is fully self-contained.

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

Parameters5/5

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

Although schema coverage is 100%, the description adds substantial meaning beyond the schema. For 'code' it explains the verbatim requirement and the token threshold; for 'limit' it clarifies that 'count' always gives the untruncated total; for 'format' it explains jscpd naming and error behavior; and for 'similarity' it details what different values imply (0.85 catches renames, 0.7 tolerates added statements). This goes far beyond the raw schema.

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 opens with a precise verb and resource: 'Check whether a code snippet duplicates code that already exists in the scanned project.' It then gives a concrete use case ('Use it before writing or committing a function, class or block'), making the purpose unmistakable. The tool is clearly distinct from siblings like get_file_clones and get_statistics, which focus on per-file clones and aggregate stats respectively.

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 states when to use it ('before writing or committing') and provides a critical prerequisite ('call check_current_directory first if files changed'), which is essential for correct operation. It also explains the threshold behavior that yields count 0. It does not name alternative tools, but the context is sufficient for an agent to know when this tool applies versus others.

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