UNPKG

knip-mcp-server

Version:

MCP server for knip.dev integration to help AI agents identify and clean up unused code

72 lines 3.09 kB
import { KnipScanInputSchema } from '../types/index.js'; export function createKnipScanTool(knipClient, config) { return { name: 'knip_scan', description: 'Run knip analysis on project or specific directories to identify unused files, imports, exports, and dependencies', inputSchema: { type: 'object', properties: { projectPath: { type: 'string', description: 'Path to the project to analyze (defaults to current directory)', }, configPath: { type: 'string', description: 'Path to knip configuration file', }, includePaths: { type: 'array', items: { type: 'string' }, description: 'Array of paths to include in the analysis', }, excludePaths: { type: 'array', items: { type: 'string' }, description: 'Array of paths to exclude from the analysis', }, dryRun: { type: 'boolean', default: true, description: 'Run in dry-run mode (no files are modified)', }, workspace: { type: 'string', description: 'Specific workspace to analyze (for monorepo setups)', }, }, }, execute: async (args) => { try { const input = KnipScanInputSchema.parse(args); // Note: dryRun doesn't apply to analysis operations as they are inherently read-only // Only file modification operations (remove, fix) need dryRun handling const analyzeOptions = {}; if (input.workspace) analyzeOptions.workspace = input.workspace; if (input.includePaths) analyzeOptions.includePaths = input.includePaths; if (input.excludePaths) analyzeOptions.excludePaths = input.excludePaths; const result = await knipClient.scan(analyzeOptions); return { success: true, result: { unusedFiles: result.files || [], unusedExports: result.exports || {}, unusedImports: result.imports || {}, unusedDependencies: result.dependencies || [], unusedDevDependencies: result.devDependencies || [], issues: [], // We'll need to convert from the new result format }, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error), }; } }, }; } //# sourceMappingURL=knip-scan.js.map