Knip Mcp Server

by gtrias

363 downloads Not rated yet
GitHub

About

This MCP server provides AI agents with powerful code cleanup capabilities through knip.dev integration. It's designed to work seamlessly with Cursor AI and other MCP-compatible tools to maintain clean, efficient codebases.

Explore

- Code Analysis: Run comprehensive knip analysis to find unused code
- Unused File Detection: Identify files that are no longer referenced
- Import/Export Cleanup: Find and remove unused imports and exports
- Dependency Management: Detect unused npm dependencies and devDependencies
- Safe Operations: Built-in safety checks and backup mechanisms
- Workspace Support: Full support for monorepo and workspace setups
- Dry Run Mode: Preview changes before applying them

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Knip Mcp Server
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

npm install -g @genar/knip-mcp-server

Or in your project:

npm install @genar/knip-mcp-server

1. In Cursor AI settings, navigate to MCP configuration
2. Add a new MCP server:
- Name: "Knip Code Cleanup"
- Command: npx @genar/knip-mcp-server
3. Save and restart Cursor AI

You can also integrate this MCP server through Cursor's rules system by creating a .cursor/rules directory in your project root and adding the following configuration:

1. Create the rules directory structure:

mkdir -p .cursor/rules

2. Create a knip rule file (.cursor/rules/knip-mcp.md):


1. After implementing features: Always run knip_scan to identify cleanup opportunities
2. Before commits: Use knip_fix_issues with dryRun: true to preview cleanup
3. Regular maintenance: Run knip_get_unused_dependencies to audit packages
4. Safety first: Always use dry-run mode first, create backups for destructive operations

Create a local MCP configuration file in your project root (.mcp-config.json):

json
{
"servers": {
"knip": {
"command": "npx",
"args": ["@genar/knip-mcp-server"],
"env": {
"KNIP_PROJECT_ROOT": ".",
"KNIP_LOG_LEVEL": "info",
"KNIP_SAFE_MODE": "true"
}
}
}
}
``

Then reference this configuration in Cursor's MCP settings.

Get the current knip configuration.

Parameters:
-
projectPath (optional): Project path
-
configPath (optional): Specific config file path

Validate knip configuration for correctness.

Parameters:
-
projectPath (optional): Project path
-
configPath (optional): Specific config file path
-
config` (optional): Configuration object to validate

npm install

knip_scan

Run comprehensive code analysis

knip_get_unused_files

Find unused files

knip_get_unused_exports

Find unused exports

knip_get_unused_imports

Find unused imports

knip_get_unused_dependencies

Find unused dependencies

knip_remove_unused_files

Safely remove unused files

knip_remove_unused_imports

Clean up unused imports

knip_fix_issues

Auto-fix common issues

knip_get_config

View knip configuration

knip_validate_config

Validate knip config

- knip_scan - Run comprehensive code analysis
- knip_get_unused_files - Find unused files
- knip_get_unused_exports - Find unused exports
- knip_get_unused_imports - Find unused imports
- knip_get_unused_dependencies - Find unused dependencies
- knip_remove_unused_files - Safely remove unused files
- knip_remove_unused_imports - Clean up unused imports
- knip_fix_issues - Auto-fix common issues
- knip_get_config - View knip configuration
- knip_validate_config - Validate knip config

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "knip mcp server": {
            "knip": {
                "command": "npx",
                "args": [
                    "@genar/knip-mcp-server"
                ],
                "env": {
                    "KNIP_PROJECT_ROOT": ".",
                    "KNIP_LOG_LEVEL": "info",
                    "KNIP_SAFE_MODE": "true"
                }
            }
        }
    }
}

McpServers

{
    "knip": {
        "command": "npx",
        "args": [
            "@genar/knip-mcp-server"
        ],
        "env": {
            "KNIP_PROJECT_ROOT": ".",
            "KNIP_LOG_LEVEL": "info",
            "KNIP_SAFE_MODE": "true"
        }
    }
}

@genar/knip-mcp-server

A Model Control Protocol (MCP) server that integrates with knip.dev to help AI agents identify and clean up unused files, imports, exports, and dependencies in JavaScript/TypeScript projects.

Overview

This MCP server provides AI agents with powerful code cleanup capabilities through knip.dev integration. It's designed to work seamlessly with Cursor AI and other MCP-compatible tools to maintain clean, efficient codebases.

Features

- Code Analysis: Run comprehensive knip analysis to find unused code
- Unused File Detection: Identify files that are no longer referenced
- Import/Export Cleanup: Find and remove unused imports and exports
- Dependency Management: Detect unused npm dependencies and devDependencies
- Safe Operations: Built-in safety checks and backup mechanisms
- Workspace Support: Full support for monorepo and workspace setups
- Dry Run Mode: Preview changes before applying them

Installation

npm install -g @genar/knip-mcp-server

Or in your project:

npm install @genar/knip-mcp-server

Usage

As an MCP Server

Run the server directly:

knip-mcp-server

Or use npx:

npx @genar/knip-mcp-server

Configuration

Configure via environment variables:

export KNIP_PROJECT_ROOT="/path/to/your/project"
export KNIP_CONFIG_PATH="/path/to/knip.json"
export KNIP_BACKUP_DIR="/path/to/backups"
export KNIP_LOG_LEVEL="info"
export KNIP_SAFE_MODE="true"

Integration with Cursor AI

Option 1: MCP Server Configuration

1. In Cursor AI settings, navigate to MCP configuration
2. Add a new MCP server:
- Name: "Knip Code Cleanup"
- Command: npx @genar/knip-mcp-server
3. Save and restart Cursor AI

Option 2: Cursor Rules Configuration

You can also integrate this MCP server through Cursor's rules system by creating a .cursor/rules directory in your project root and adding the following configuration:

1. Create the rules directory structure:

mkdir -p .cursor/rules

2. Create a knip rule file (.cursor/rules/knip-mcp.md):

```markdown

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.