EliotShift/lore-mcp

GitHub: EliotShift/lore-mcp

LORE 通过 MCP 协议与 13 个分析器,为代码库提供架构理解与 AI 推荐,解决 AI 编码缺乏架构记忆的问题。

Stars: 2 | Forks: 1

**由 [EliotShift](https://github.com/EliotShift) 构建 · 在 16 个真实项目中经过实战检验 · 100% 通过率。** ## 为什么选择 LORE? AI 编码助手写得很快,但缺乏 **架构记忆**。它们无法记住: - 哪些文件紧密耦合 - 循环依赖存在的位置 - 哪些类型在边界间扩散 - 哪些文件变更过于频繁(热点) - 架构层级是什么 LORE 通过提供对你的代码库架构的 **深度理解** 来解决这个问题——通过 CLI 分析和 MCP 服务器集成。 ## 功能特性 ### 13 个分析器 | # | 分析器 | 功能说明 | |---|--------|----------| | 1 | **AST 解析器** | 使用 ts-morph + 正则混合的完整 TypeScript/TSX 解析 | | 2 | **依赖关系图** | 映射项目中所有的导入、导出、重新导出 | | 3 | **循环依赖检测器** | 查找循环并按严重程度排序 | | 4 | **依赖方向检查器** | 强制执行层级规则(例如:控制器不得导入数据库) | | 5 | **香农熵** | 按文件计算复杂度评分(简单 → 非常复杂) | | 6 | **热点分析** | Git 变更检测——频繁变更的文件 | | 7 | **导入影响分析器** | 显示每个导入的波及范围 | | 8 | **类型安全评分器** | 评估 `any` 使用、显式类型和严格性 | | 9 | **隐式耦合检测器** | 查找通过共享类型产生的隐式依赖 | | 10 | **AI 推荐** | 优先级修复建议(P0–P3) | | 11 | **工具配置检查器** | 验证 ESLint、Prettier、tsconfig 设置 | | 12 | **破坏性变更检测器** | 标记高风险的弃用模式 | | 13 | **架构缺口查找器** | 识别缺失的抽象和模式 | ### MCP 集成(8 个工具 + 3 个资源) 将 LORE 暴露给 **Claude Desktop、VS Code、Cursor 或任何 MCP 客户端**: | 工具 | 描述 | |------|------| | `analyze` | 完整项目分析——评分、违规、复杂度、热点 | | `get-scores` | 健康评分:总体、类型安全、工具、架构 | | `get-violations` | 循环依赖、层级违规、架构缺口 | | `get-recommendations` | AI 改进建议(P0–P3) | | `get-hotspots` | 高 Git 变更文件(红/黄/绿) | | `get-entropy` | 香农熵复杂度报告 | | `query-file` | 文件导入、导出、消费者、复杂度 | | `analyze_architecture` | 深度 TS 分析:框架、层级、异步链、类型流 | | 资源 | 描述 | |------|------| | `lore://analysis` | 最新分析结果(JSON) | | `lore://architecture` | 深度架构图(JSON) | | `lore://config` | 环境和缓存状态(JSON) | ### CLI 命令 ``` lore [path] Analyze project (default: cwd) lore analyze [path] Explicit analysis lore init Extract architectural decisions lore status View decisions by category lore diff Diff against saved baseline lore doctor Environment + tooling check lore doctor --fix Auto-fix project setup lore ignore List/manage ignore patterns lore watch Watch + re-analyze on change lore mcp inspect Inspect MCP server setup lore mcp config Claude Desktop config snippet lore version Show version ``` ## 文档 | 页面 | 描述 | |------|------| | [入门页面](https://eliotshift.github.io/lore-mcp/) | 完整功能概览、徽章和快速开始 | | [安装指南](https://eliotshift.github.io/lore-mcp/installation.html) | npm、npx 和 Docker 安装 | | [命令参考](https://eliotshift.github.io/lore-mcp/commands.html) | 全部 CLI 命令:init、status、doctor、watch、diff 等 | | [MCP 集成](https://eliotshift.github.io/lore-mcp/mcp.html) | Claude Desktop、Cursor 和 Windsurf 设置 | | [示例](https://eliotshift.github.io/lore-mcp/examples.html) | Express、NestJS、Next.js 等真实项目分析 | | [常见问题](https://eliotshift.github.io/lore-mcp/faq.html) | 常见问题解答 | ## 快速开始 ### 安装 ``` npm install -g lore-mcp ``` ### CLI 用法 ``` # 分析当前项目 lore # 分析特定项目 lore ./my-typescript-project # 检查环境并自动修复 lore doctor --fix # 观察变更 lore watch --filter src/ # 与上次基线的差异 lore diff ``` ### MCP 集成(Claude Desktop) 将以下内容添加到你的 Claude Desktop 配置: **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json` **Linux:** `~/.config/Claude/claude_desktop_config.json` **Windows:** `%APPDATA%\Claude\claude_desktop_config.json` ``` { "mcpServers": { "lore": { "command": "npx", "args": ["-y", "lore-mcp"] } } } ``` 或者如果全局安装: ``` { "mcpServers": { "lore": { "command": "lore", "args": ["mcp"] } } } ``` 重启 Claude Desktop,然后询问: ## 架构 ``` lore-mcp/ ├── src/ │ ├── algorithm/ # LoreGraph, AST parser, async chain builder, type tracker │ ├── algorithms/ # AI recommendations, hotspot analysis, entropy, scoring │ ├── analyzer/ # Dependency parsers, circular deps, direction, imports │ ├── commands/ # CLI: doctor, diff, ignore, init, status, watch │ ├── core/ # Plugin system, pipeline runner, graph engine │ ├── lib/ # Hidden coupling, gaps, middleware chain, ontology │ ├── mcp/ # MCP server + architecture bridge │ ├── output/ # Formatter, markdown, SARIF, logger │ ├── plugins/built-in/ # 13 built-in analysis plugins │ ├── storage/ # Cache and decision store │ ├── types/ # TypeScript type definitions │ ├── cli.ts # CLI entry point │ └── index.ts # MCP server entry point ├── package.json └── tsconfig.json ``` ### 插件系统 LORE 使用 **基于插件的架构**——每个分析器都是一个插件: ``` interface LorePlugin { name: string; version: string; analyze(context: AnalysisContext): Promise; } ``` 内置插件包括:`circular-deps`、`coupling-matrix`、`dep-direction`、`entropy`、`gaps`、`hidden-coupling`、`hotspot`、`import-impact`、`middleware-chain`、`breaking-changes`、`type-safety`、`tooling-config`、`ai-recommendations`。 ## 工作原理 1. **解析** — LORE 使用混合 ts-morph + 正则解析器解析所有 `.ts`/`.tsx` 文件 2. **构建图** — 构建依赖关系图,包含类型化边(导入、类型引用、装饰器、异步链、实现、扩展) 3. **运行插件** — 13 个分析器通过插件管道并行运行 4. **评分** — 计算健康评分(类型安全、工具、架构、总体 0–100) 5. **推荐** — AI 引擎生成优先级建议(P0 关键 → P3 锦上添花) 6. **服务** — 结果可通过 CLI 输出、MCP 工具或 SARIF 格式获取 ## 验证 | 项目 | 文件数 | 结果 | |------|--------|------| | Express | 42 | 100% 通过 | | Next.js | 68 | 100% 通过 | | Fastify | 55 | 100% 通过 | | NestJS | 38 | 100% 通过 | | Prisma | 45 | 100% 通过 | | Zod | 35 | 100% 通过 | | TypeORM | 60 | 100% 通过 | + 9 个其他项目 | **全部 16 个测试项目:100% 通过率,零崩溃。** ## 支持平台 LORE 基于 **Node.js** 构建——无原生依赖。只要你的系统能运行 Node.js,LORE 就能运行。 | 平台 | 状态 | 说明 | |------|--------|------| | **macOS** | 完全支持 | Intel 与 Apple Silicon(M1/M2/M3/M4) | | **Ubuntu** | 完全支持 | 20.04、22.04、24.04 | | **Debian** | 完全支持 | 11、12 | | **Fedora** | 完全支持 | 39、40、41 | | **Arch Linux** | 完全支持 | 滚动发布 | | **Kali Linux** | 完全支持 | 2024.x、2025.x | | **Linux Mint** | 完全支持 | 21、22 | | **CentOS / RHEL** | 完全支持 | 8、9 | | **Alpine Linux** | 完全支持 | 3.19+ | | **Windows** | 完全支持 | Windows 10/11(PowerShell + CMD) | | **CI/CD** | 完全支持 | GitHub Actions、GitLab CI、Jenkins | ### 各平台快速安装 ``` # macOS (Homebrew) brew install node npm install -g lore-mcp # Ubuntu / Debian curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash - sudo apt install -y nodejs lore-mcp # Kali Linux sudo apt install nodejs npm npm install -g lore-mcp # Fedora sudo dnf install nodejs npm npm install -g lore-mcp # Arch Linux sudo pacman -S nodejs npm npm install -g lore-mcp # Windows (PowerShell) npm install -g lore-mcp # 或任何地方 — 无需安装 npx lore-mcp init ``` ## 要求 - **Node.js** >= 18.0.0 - **TypeScript** 项目(分析 `.ts` 和 `.tsx` 文件) - **Git**(可选,用于热点分析) - **ripgrep**(可选,用于更快的文件发现) ## 技术栈 | 组件 | 技术 | |------|------| | 语言 | TypeScript 5.5+ | | AST 解析 | ts-morph 21 || 协议 | 模型上下文协议(MCP)SDK 1.0 | | 传输 | Stdio(兼容 Claude Desktop / IDE) | | 验证 | Zod 模式 | | 输出 | ANSI 终端、Markdown、SARIF | ## 许可证 MIT © 2025 [EliotShift](https://github.com/EliotShift)

LORE — 因为你的 AI 应该理解你的架构,而不仅仅是你的代码。

标签:AI原生开发, AI推荐, MCP协议, MITM代理, SEO关键词, TypeScript解析, 代码考古, 企业级代码分析, 依赖图谱, 依赖方向检查, 全栈分析, 导入影响分析, 工具配置检查, 工程治理, 循环依赖检测, 性能优化, 智能分析, 架构洞察, 架构缺口发现, 检测绕过, 热点分析, 破坏性变更检测, 类型安全评分, 自动化攻击, 隐藏耦合检测, 项目重构, 香农熵复杂度