AI代码清理工具

一款检测并清除AI生成代码中冗余模式的MCP服务器工具,适用于多种编程语言和开发环境。

  • by collin-ho
  • JavaScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 collin-ho/deslop-mcp

使用说明

运行 deslop-mcp

一个MCP(模型上下文协议)服务器,用于检测和删除AI生成的代码溢出模式。

适用于 光标, 克劳德桌面版, 克劳德代码,以及任何兼容MCP的客户端。

什么是“斜坡”?

人工智能生成的代码通常包含损害可维护性的模式:

  • 评论失误:重申代码功能的注释(“此函数获取用户”)
  • 详细日志记录:进入/退出日志、生产中留下的调试语句
  • 不必要的错误处理:尝试捕获只记录并重新抛出的内容
  • 防御性过度杀伤:TypeScript中的冗余空检查
  • 异步误用: async 无功能 await
  • 未使用的进口:重构导致的死代码

安装

选项1:从GitHub克隆

git clone https://github.com/YOUR_USERNAME/deslop-mcp.git
cd deslop-mcp
npm install
npm run build

选项2:npm(如果已发布)

npm install -g deslop-mcp

配置

对于光标

添加到光标MCP设置(~/.cursor/mcp.json 或通过设置>MCP):

{
  "mcpServers": {
    "deslop": {
      "command": "node",
      "args": ["/path/to/deslop-mcp/dist/index.js"]
    }
  }
}

适用于克劳德桌面

添加 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或 %APPDATA%\Claude\claude_desktop_config.json (Windows):

{
  "mcpServers": {
    "deslop": {
      "command": "node",
      "args": ["/path/to/deslop-mcp/dist/index.js"]
    }
  }
}

克劳德代码

添加到您的Claude Code MCP设置中:

{
  "mcpServers": {
    "deslop": {
      "command": "node",
      "args": ["/path/to/deslop-mcp/dist/index.js"]
    }
  }
}

工具

deslop_analyze

分析代码文件中的斜坡图案。

deslop_analyze({ path: "./src" })
deslop_analyze({ path: "./src/utils/api.ts" })

返回包含以下内容的详细报告:

  • 按类别分组的问题
  • 优先级(高/中/低)
  • 每期的行号
  • 自动固定指示器

deslop_fix

自动修复可自动修复的问题。

deslop_fix({ path: "./src" })
deslop_fix({ path: "./src", dryRun: true })  // Preview without changes

deslop_diff

只分析git中更改的文件。

deslop_diff({})                    // Unstaged changes
deslop_diff({ staged: true })      // Staged changes only

示例输出

# Deslop Analysis Report

## Summary
- 🔴 High Priority: 12 issues
- 🟡 Medium Priority: 5 issues
- 🔵 Low Priority: 2 issues
- 🔧 Auto-fixable: 10 issues

## src/services/userService.ts

### 🔴 Comment Slop (3)

- **Line 45**: Comment restates what code does instead of why
  `// This function gets the user from the database`
  *(auto-fixable)*

- **Line 78**: Commented-out code should be removed
  `// const oldUser = await getOldUser(id);`
  *(auto-fixable)*

### 🔴 Verbose Logging (2)

- **Line 23**: Debug/trace logging should be removed in production
  `console.log("Entering getUserById");`
  *(auto-fixable)*

支持的语言

  • TypeScript(.ts、.tsx)
  • JavaScript(.js、.jsx)
  • Python(.py)
  • Java(.Java)
  • 去(.去)
  • 锈蚀(.rs)

安全

该工具将 从不 删除:

  • 捕获实际错误的错误日志记录
  • 解释业务逻辑或“为什么”的评论
  • 许可证标题或版权声明
  • TODO注释和票证参考

许可证

麻省理工学院