API

MCP Server

Use jscpd as a Model Context Protocol (MCP) server for AI assistants with the built-in stdio transport.

Overview

jscpd implements the Model Context Protocol (MCP), allowing AI assistants like Claude Desktop, Claude Code, Cursor, and Copilot to detect code duplication directly from the editor — no CLI invocation needed.

The server is built into the binary (v5.0.16+) and speaks MCP over stdio: MCP clients spawn and manage the process themselves — no port, no network policy, no separate package to install.

stdio Transport

The cpd/jscpd binary serves MCP over stdio directly. The project is scanned once at startup and kept in memory as detection-ready token hashes, so snippet checks answer in milliseconds even on large codebases.

Terminal
cpd --mcp /path/to/project

# All detection options apply to the scan and to snippet checks:
cpd --mcp --min-tokens 30 --format javascript,typescript /path/to/project

Add to your MCP client config (Claude Desktop, Claude Code, Cursor, ...):

{
  "mcpServers": {
    "jscpd": {
      "command": "cpd",
      "args": ["--mcp", "/path/to/project"]
    }
  }
}

The server implements MCP protocol revision 2025-06-18 (also accepting 2025-03-26 and 2024-11-05 clients).

Available MCP Tools

check_duplication

Checks a provided code snippet for duplications against the scanned project.

Arguments:

  • code (string, required): The source code snippet to analyze
  • format (string, required): Format name (javascript) or file extension (js)
  • limit (number, optional): Maximum matches to return (default 100)

get_file_clones

Returns clones involving one file — useful for file-scoped refactoring.

Arguments:

  • path (string, required): Scan-root-relative (as shown in results) or absolute path
  • limit (number, optional): Maximum clones to return (default 100)

get_statistics

Returns totals and per-format statistics from the last scan.

Arguments: None

check_current_directory

Re-scans the configured paths and returns updated counts plus the clone list.

Arguments:

  • limit (number, optional): Maximum clones to return (default 100)

Tool results are compact JSON. Every clone/match list is sorted biggest-first (by tokens) and capped by limit — the accompanying count field always reports the untruncated total, and truncation is flagged with a note.

How It Works

  1. Start the server (cpd --mcp <path>) — it scans and indexes the codebase
  2. Your AI assistant connects over stdio
  3. When you ask your assistant to check for duplications, it calls check_duplication, get_file_clones, or get_statistics
  4. Results are returned directly in the assistant's context — no manual CLI needed

Tips

  • The startup scan is logged to stderr; stdout carries protocol messages only
  • Pass the same detection flags you use on the CLI (--min-tokens, --format, --ignore, ...) so MCP results match your CI runs

Looking for the Node.js HTTP server (jscpd-server, REST API + MCP over HTTP)? It belongs to v4 and is documented on the master-v4 branch and the v4 page.