# MCP Server

> Use jscpd-server as a Model Context Protocol (MCP) server for AI assistants.

## Overview

`jscpd-server` implements the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/), allowing AI assistants like Claude Desktop, Cursor, and Copilot to detect code duplication directly from the editor — no CLI invocation needed.

## Starting the Server

```bash [Terminal]
# Install and start
npm install -g jscpd-server
jscpd-server /path/to/project

# With custom port
jscpd-server /path/to/project --port 3000
```

> **Note:** The jscpd-server is still Node.js based. The CLI detection engine (`jscpd` command) is Rust-based in v5, but the server uses the v4 engine.

## Configuration

Add to your MCP client config (e.g. Claude Desktop):

```json
{
  "mcpServers": {
    "jscpd": {
      "type": "streamable-http",
      "url": "http://localhost:3000/mcp"
    }
  }
}
```

## Available MCP Tools

### `check_duplication`

Checks a provided code snippet for duplications against the codebase currently being served by `jscpd-server`.

**Arguments:**

- `code` (string, required): The source code snippet to analyze
- `format` (string, required): The format of the code (e.g. "javascript", "typescript")
- `recheck` (boolean, optional): If `true`, triggers a re-scan of the current directory before checking the snippet

### `get_statistics`

Retrieves the overall project duplication statistics.

**Arguments:** None

Returns total lines, sources, clones, and duplication percentage broken down by format.

### `check_current_directory`

Triggers a re-scan of the current working directory for duplications and returns the updated statistics.

**Arguments:** None

## Resources

The server exposes the following resource:

- `jscpd://statistics`: Returns the current duplication statistics in JSON format

## How It Works

1. Start `jscpd-server` against your project directory — it scans and indexes the codebase
2. Your AI assistant connects to the MCP endpoint
3. When you ask your assistant to check for duplications, it calls `check_duplication` or `get_statistics`
4. Results are returned directly in the assistant's context — no manual CLI needed

## Tips

- Check `/api/health` to verify the server has finished its initial scan
- The server accepts request bodies up to 10MB
