Get the FREE Ultimate OpenClaw Setup Guide →

knip

Knip MCP server

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio gtrias-knip-mcp-server npx -y @genar/knip-mcp-server \
  --env KNIP_LOG_LEVEL="<info|debug|warn|error>" \
  --env KNIP_SAFE_MODE="<true|false>" \
  --env KNIP_BACKUP_DIR="<path-to-backups>" \
  --env KNIP_CONFIG_PATH="<path-to-knip.json or config-file>" \
  --env KNIP_PROJECT_ROOT="<path-to-your-project>"

How to use

This MCP server integrates the Knip code cleanup tooling with your AI workflows. It exposes a set of Knip-based operations that allow an agent to scan a project for unused files, imports, exports, and dependencies, and then safely apply fixes. Typical usage is to run a scan to identify cleanup opportunities, inspect the results, and then perform targeted removals or fixes in a safe, backup-enabled manner. The server supports dry-run previews to prevent unintended changes and is designed to work in monorepos or workspace setups.

Available capabilities include: running a comprehensive knip_scan to analyze the project; retrieving lists of unused files via knip_get_unused_files; identifying unused exports with knip_get_unused_exports; detecting unused imports through knip_get_unused_imports; auditing dependencies via knip_get_unused_dependencies; and executing removal or cleanup actions with knip_remove_unused_files, knip_remove_unused_imports, and knip_fix_issues. You can also view or validate the current Knip configuration using knip_get_config and knip_validate_config. These tools can be invoked through MCP interfaces in Cursor AI or via the per-project MCP setup.

How to install

Prerequisites:

  • Node.js and npm installed
  • Access to the project repository where you want to run the server

Install globally (preferred for quick start):

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

Or install in your project locally:

npm install @genar/knip-mcp-server

Running the server:

knip-mcp-server

Alternatively, with npx:

npx @genar/knip-mcp-server

Configuration (example):

  • Set KNIP_PROJECT_ROOT to your project root
  • Provide KNIP_CONFIG_PATH to your knip.json if you use a custom config
  • Enable KNIP_SAFE_MODE for safety
  • Adjust KNIP_LOG_LEVEL as needed

Additional notes

Tips and common setup notes:

  • Use the dry-run option by default to preview changes before applying them.
  • Backups are created automatically before destructive operations.
  • For monorepos, ensure KNIP_PROJECT_ROOT points to the root and configure workspaces as needed.
  • You can adjust safety thresholds (e.g., max files to remove) via Knip configuration or MCP parameters.
  • If Cursor AI integration is used, configure the MCP server with the appropriate command and name, and restart the agent after changes.
  • Review the knip_mcp rules and documentation to tailor the cleanup workflow to your project’s conventions.

Related MCP Servers

Sponsor this space

Reach thousands of developers