Skip to content

DarkInno/LintPulse-MCP

Repository files navigation

LintPulseMCP

基于 MCP 协议的 AI 代码生成防护工具 — 语法校验、重复检测、多 Agent 协调。

npm License Node

功能特性

  • 语法校验 — 单次遍历状态机,检测括号/引号匹配、多行字符串、未闭合符号,支持 7 种语言
  • 重复检测 — 项目级符号提取(名称+类型去重)、Levenshtein 相似度(长名截断优化)、10K 文件扫描上限
  • 多 Agent 协调 — 符号所有权声明、冲突检测、complete_agent 完成标记、互斥锁 + 状态持久化
  • 模式检测 — 检测 as anyconsole.logTODOunwrap() 等反模式
  • 行尾管理 — LF/CRLF 检测、转换、项目级规范化(自动跳过二进制文件)
  • MCP Resources — 暴露项目状态、符号表、Agent 列表为可订阅资源
  • 并发安全 — Promise-chain 互斥锁、全局写队列(失败自动恢复)、跨实例状态同步

快速开始

环境要求

  • Node.js >= 18.0.0
  • npm >= 9.0.0

安装

npm install -g lintpulse-mcp

配置 MCP

推荐先运行初始化命令,自动注册到本机常见 MCP 客户端:

npx lintpulse-mcp init

默认会尝试注册到 Claude Code、Claude Desktop、Codex。可用参数:

npx lintpulse-mcp init --target claude-code
npx lintpulse-mcp init --target claude-desktop,codex
npx lintpulse-mcp init --dry-run
npx lintpulse-mcp init --force

默认 MCP server 启动命令保持为 lintpulse-mcp,不带参数时仍通过 stdio 启动服务。也可以手动在编辑器 MCP 配置中添加(以 JSON 配置为例):

{
  "mcpServers": {
    "code-guard": {
      "command": "npx",
      "args": ["lintpulse-mcp"]
    }
  }
}

MCP 工具列表

工具名 功能 优先级
validate_syntax 检查括号/引号匹配 P0
check_duplicates 检查符号是否重复 P0
scan_project_symbols 扫描项目所有符号 P0
analyze_code 语法 + 模式 + 重复综合分析 P0
detect_line_endings 检测行尾类型(LF/CRLF/mixed) P0
convert_line_endings 转换单文件行尾格式 P0
normalize_line_endings 批量规范化项目行尾 P0
register_agent 注册 Agent 实例 P1
claim_symbol 声明符号所有权 P1
release_symbol 释放符号所有权 P1
check_before_write 写入前冲突检查 P1
get_project_state 获取项目状态 P1
cleanup_agent 清理 Agent 资源 P1
complete_agent 标记 Agent 完成,符号转为已实现 P1
batch_validate 批量验证多个文件语法 P1
smart_check 智能选择检查项 P2
quick_analyze 快速分析返回简化结果 P2

MCP Resources

URI 名称 描述
lintpulse://project/{path}/state 项目状态 Agent 数量、符号数量、活跃 Agent 概览
lintpulse://project/{path}/symbols 符号表 项目完整符号列表及位置
lintpulse://project/{path}/agents Agent 列表 所有 Agent 的任务、状态、声明符号

支持语言: TypeScript, JavaScript, Python, Rust, Go, Java, C++, C#, Ruby, PHP, Swift, Kotlin

关键词过滤: 每种语言内置 40~60 个关键字黑名单,避免 Java/C++ 函数模式将 ifforreturn 等误识别为函数名。扫描时自动跳过 dist/build/target/__pycache__/.git 等构建目录。

项目结构

src/
├── index.ts                    # 入口文件
├── server.ts                   # MCP Server wiring(stdio、工具/资源注册、公开方法委托)
├── types.ts                    # 类型定义 + 符号提取正则
├── cli/
│   └── init.ts                 # init 子命令:注册 Claude/Codex MCP 配置
├── core/
│   └── symbol-cache.ts         # LRU 符号缓存 + 扫描缓存 helper
├── tools/
│   ├── schemas.ts              # Zod schema 单一来源
│   ├── registry.ts             # 工具表 + Zod → JSON Schema 派生
│   └── handlers.ts             # 17 个工具 handler
├── resources/
│   └── registry.ts             # MCP Resource templates + read 分发
├── validators/
│   ├── syntax.ts               # 语法校验器(栈 + 状态机 + O(log n) 行列定位)
│   ├── duplicate.ts            # 重复检测器(符号提取 + Levenshtein + 项目扫描)
│   ├── patterns.ts             # 模式检测器(as any / console.log / TODO 等)
│   └── line-endings.ts         # 行尾检测、转换、项目级规范化
├── coordination/
│   ├── agent-manager.ts        # Agent 管理(互斥锁 + 状态缓存刷新)
│   └── state-store.ts          # JSON 状态持久化(原子写入 + 备份轮转 + 全局写队列)
└── utils/
    ├── errors.ts               # CodeGuardError 错误类
    ├── logger.ts               # 分级日志(debug/info/warn/error)
    ├── code-position.ts        # 行列计算工具(预计算 + 二分查找)
    └── path-safety.ts          # projectPath + filePath 越界校验
tests/
├── unit/                       # 单元测试(8 个文件)
├── integration/                # MCP 集成测试
└── stress/                     # 高并发压力测试

开发

git clone https://github.com/DarkInno/LintPulse-MCP.git
cd LintPulse-MCP

npm install       # 安装依赖
npm run build     # 编译 TypeScript
npm test          # 运行 105 个测试
npm run typecheck # TypeScript 类型检查
npm run lint      # ESLint 检查
npm run format    # Prettier 格式化

可用命令

命令 说明
npm run build 编译 src/dist/
npm run typecheck tsc --noEmit 类型检查
npm test Vitest 运行所有单元测试
npm run test:watch Vitest 监视模式
npm run test:coverage 运行测试并生成覆盖率报告
npm run lint ESLint 检查 src/tests/
npm run lint:fix ESLint 自动修复
npm run format Prettier 格式化
npm start 启动 MCP Server(node dist/index.js
npx lintpulse-mcp init 自动注册到 Claude Code / Claude Desktop / Codex

性能指标

指标 目标
语法校验响应 < 100ms(1000 行)
项目扫描时间 < 5s(1000 文件)
内存占用 < 200MB
并发 Agent 10+

许可证

MIT License

About

Code Linting for Agents 面向 Agent 的代码检查工具

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors