UNPKG

knip-mcp-server

Version:

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

54 lines 2.02 kB
import { KnipRemoveUnusedImportsInputSchema } from '../types/index.js'; export function createKnipRemoveUnusedImportsTool(knipClient, config) { return { name: 'knip_remove_unused_imports', description: 'Remove unused imports from a specific file', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file to clean up imports', }, imports: { type: 'array', items: { type: 'string' }, description: 'Specific imports to remove. If empty, removes all unused imports.', }, dryRun: { type: 'boolean', default: true, description: 'Run in dry-run mode (no files are modified)', }, createBackup: { type: 'boolean', default: true, description: 'Create backup of file before modifying it', }, }, required: ['filePath'], }, execute: async (args) => { try { const input = KnipRemoveUnusedImportsInputSchema.parse(args); const result = await knipClient.removeUnusedImports(input.filePath, { imports: input.imports, dryRun: input.dryRun, createBackup: input.createBackup, }); return { ...result, filePath: input.filePath, dryRun: input.dryRun, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error), }; } }, }; } //# sourceMappingURL=knip-remove-unused-imports.js.map