Skip to main content
Glama

Check a snippet for duplication

check_duplication
Read-onlyIdempotent

Detect whether a code snippet duplicates existing project code before writing or committing it. Find exact, renamed, similar, or semantic matches so you can reuse existing functions instead.

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 code you should reuse instead; pass kinds ["exact", "renamed", "similar"] to find copies with other names or edited lines as well. Returns {format, kinds, count, returned, duplications[]}, each duplication with 'kind', 'format' (the language of the code that matched), 'file', 'fileStartLine', 'fileEndLine', 'lines' (how many of those lines count as duplicated, as in jscpd's reports: fewer when the match runs over other blocks of the file), 'snippetStartLine', 'snippetEndLine' and 'tokens'; similar and semantic ones add 'similarity' (and 'method': gap or ast), and ast and semantic ones add 'name' (the name of the project's function) and 'snippetName'. Exact matches come first, then renamed, similar and semantic ones. A request without 'kinds' gets its ast matches under 'similar' with 'similarCount', as earlier versions answered. A Markdown, Vue, Svelte or Astro snippet is split into blocks the way a scan splits such a file, so the code of a fence or a script matches code in its language; by meaning, only the functions in a component's scripts are compared. A snippet or a block of code in it shorter than the server's --min-tokens (50 by default) cannot match, and a 'note' says so. Kinds that could not be searched are listed under 'unavailable' with the reason. The snippet is compared with the last scan: call check_current_directory first if files changed.

Input Schema

NameRequiredDescriptionDefault
codeYesThe source code to check, verbatim. Whole functions or blocks work best.
kindsNoThe kinds of clone to look for: exact (type1), renamed (type2), similar (type3; 'gap' or 'ast' for one of its two mechanisms) and semantic (type4). Without it: exact, what jscpd reports with this server's options. Renamed and similar clones may need one scan more, and semantic ones run an embedding model, which takes a while the first time.
limitNoMaximum number of duplications in the response. 'count' always carries the full count, 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' (`jscpd --list` lists all 224).
similarityNoThe share of subtrees two functions' normalized syntax trees must have in common to be an ast match: 1 finds copies with other names, each standing for one name, and other literals only, 0.8 also one-line edits, 0.7 a couple of added or removed statements. Giving it asks for ast matches. Defaults to the server's --similarity, or 0.8. Functions of JavaScript, TypeScript, Python, Java, Kotlin, Scala, C#, Go, Rust, C, C++, PHP, Ruby, Swift and Clojure. In ast matches each function's syntax tree is normalized: the names of the functions and methods it calls and its operators count, local names, field names and literals do not, as long as each name stands for one name on the other side, and two functions score the share of subtrees their trees have in common. Test files are left out.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed7 schema fields changedv5.4.2
    • addedInput schema / additionalProperties
      Added value: +false
    • changedInput schema / properties / code / description
      Previous 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)"New value: +"The source code to check, verbatim. Whole functions or blocks work best."
    • changedInput schema / properties / format / description
      Previous 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."New value: +"Language of the snippet: a jscpd format name such as 'javascript', 'typescript', 'python', 'java', or a file extension such as 'js', 'py' (`jscpd --list` lists all 224)."
    • addedInput schema / properties / kinds
      Added value: +{
      +  "description": "The kinds of clone to look for: exact (type1), renamed (type2), similar (type3; 'gap' or 'ast' for one of its two mechanisms) and semantic (type4). Without it: exact, what jscpd reports with this server's options. Renamed and similar clones may need one scan more, and semantic ones run an embedding model, which takes a while the first time.",
      +  "examples": [
      +    [
      +      "exact",
      +      "renamed",
      +      "similar"
      +    ],
      +    [
      +      "semantic"
      +    ]
      +  ],
      +  "items": {
      +    "enum": [
      +      "exact",
      +      "renamed",
      +      "similar",
      +      "gap",
      +      "ast",
      +      "semantic",
      +      "type1",
      +      "type2",
      +      "type3",
      +      "type4"
      +    ],
      +    "type": "string"
      +  },
      +  "type": "array",
      +  "uniqueItems": true
      +}
    • changedInput schema / properties / limit / description
      Previous 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."New value: +"Maximum number of duplications in the response. 'count' always carries the full count, so a small limit still tells you how much was found."
    • changedInput schema / properties / similarity / description
      Previous value: -"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."New value: +"The share of subtrees two functions' normalized syntax trees must have in common to be an ast match: 1 finds copies with other names, each standing for one name, and other literals only, 0.8 also one-line edits, 0.7 a couple of added or removed statements. Giving it asks for ast matches. Defaults to the server's --similarity, or 0.8. Functions of JavaScript, TypeScript, Python, Java, Kotlin, Scala, C#, Go, Rust, C, C++, PHP, Ruby, Swift and Clojure. In ast matches each function's syntax tree is normalized: the names of the functions and methods it calls and its operators count, local names, field names and literals do not, as long as each name stands for one name on the other side, and two functions score the share of subtrees their trees have in common. Test files are left out."
    • changedInput schema / properties / similarity / examples
      Previous value: -[
      -  0.85
      -]New value: +[
      +  0.8
      +]
  2. 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"
      +}
  3. First observedv0.1.0

TDQS

A4.8/5.0
Behavior5/5

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

Annotations only cover the safe-read profile; the description adds substantial behavior: results are ordered exact → renamed → similar → semantic, a --min-tokens threshold (50 default) prevents short snippets from matching, unfindable kinds appear under 'unavailable', semantic search runs an embedding model that is slow the first time, and renamed/similar may need an extra scan. It also documents the legacy no-'kinds' response shape, which is real behavioral variance.

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?

Purpose and usage are front-loaded in the first sentence, and the dense return-format detail is justified because no output schema exists. It does read as one long wall of text bundling edge cases (Markdown/Vue/Svelte/Astro splitting, threshold notes) that could be sectioned, but little is truly wasted.

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?

With no output schema, the description takes on the full burden and delivers: it enumerates every returned field, explains the 'lines' vs match-span distinction, and covers degraded responses ('note', 'unavailable'). An agent has everything needed to call this and interpret the result.

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 carries most parameter meaning. The description still adds cross-parameter semantics the schema does not: supplying 'similarity' implicitly requests ast matches, and omitting 'kinds' changes how ast results are reported ('similar' with 'similarCount'), plus the note that ast matching only covers a listed set of languages.

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?

States a specific verb and resource ('Check whether a code snippet duplicates code that already exists in the scanned project') and scopes it to the last scan. It is clearly distinguishable from siblings like get_file_clones (project-wide listing) and compare_folders (folder-to-folder).

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?

Gives an explicit trigger ('Use it before writing or committing a function, class or block, to find the existing code you should reuse instead') and an explicit prerequisite/alternative: 'call check_current_directory first if files changed'. Both when-to-use and when-to-refresh are covered.

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