代码结构分析引擎

Manifold Engine MCP Server 是一个高性能代码结构分析引擎,提供代码库的结构化索引、混乱检测、依赖风险分析和实时同步功能,适用于代码质量评估和重构决策。

  • by SepDynamics
  • HTML
  • 本地部署
  • 更新于
在 GitHub 查看 SepDynamics/SEP-mcp

使用说明

歧管发动机MCP服务器

一个模型上下文协议服务器,为AI编码助手提供高速、结构化的代码库分析和动态上下文管理。它不是逐个读取代码令牌,而是映射存储库 结构上 --将源文件视为连续的字节流,计算结构签名,并在O(1)时间内检测架构混乱。

当前状态:所有阶段0的关键错误都已解决,包括FAISS语义搜索反序列化, ingest_repo 相对路径解析、组合风险公式透明度和不同的集群命名启发式。所有21个分析工具功能齐全。


核心能力

能力 描述
结构索引 将每个文件扫描到Valkey支持的网格中,其中包含压缩签名和混沌配置文件。亚毫秒级检索。
混沌检测 计算a chaos_score 每个文件。预测哪些文件将无法维护。
依赖性和风险分析 通过AST解析跟踪导入图,测量爆炸半径,将混沌×爆炸组合成一个风险评分。
工作记忆 将持久性事实(项目约定、体系结构规则)注入到动态语义代码簿中,用于零样本学习。
实时同步 文件系统监视器在毫秒内自动接收文件保存,使索引保持最新状态,而无需手动重新扫描。

安装

先决条件

  • Python 3.10+
  • Valkey(或Redis)正在运行 localhost:6379
  • C++20编译器(用于构建本机结构引擎)
  • faiss-cpu (运行 cluster_codebase_structure 工具)

设置

# 1. Start the Valkey backend
valkey-server

# 2. Install the manifold engine
pip install -e .

# 3. Configure your MCP client (Kilo Code, Claude Desktop, Cursor, etc.)

添加到MCP客户端配置中:

{
  "mcpServers": {
    "manifold": {
      "command": "path/to/virtualenv/bin/python",
      "args": ["path/to/SEP-mcp/mcp_server.py"],
      "cwd": "path/to/SEP-mcp"
    }
  }
}

常见工作流和用例

1.新存储库分析

在输入新代码库时,执行初始映射以立即了解技术债务分布。

# 1. Index the repository
ingest_repo  (root_dir=".", clear_first=true, compute_chaos=true)

# 2. Verify ingestion was successful
get_index_stats

# 3. Quickly identify the most complex, chaotic files
batch_chaos_scan  (pattern="*.py", max_files=30)

2.重构决策和Sprint计划

使用结构风险度量来客观地决定重写什么代码。

# 1. Scan for files with BOTH high complexity and high import dependencies
scan_critical_files       (pattern="*.py", max_files=10)

# 2. For candidates, predict how soon the file will become unmaintainable
predict_structural_ejection (path="target.py", horizon_days=30)

# 3. For visual confirmation, generate a 4-panel chaos dashboard
visualize_manifold_trajectory (path="target.py")

3.寻找实施模式

与其按文本搜索,不如按结构签名搜索,以找到类似的逻辑块或克隆。

# 1. Get the mathematical signature of an existing file
get_file_signature  (path="found_file.py")

# 2. Search for any other files that match this structure globally
search_by_structure (signature="c0.213_s0.000_e0.928", tolerance=0.05)

4.连续流动

# Run the watcher inside the repo
start_watcher  (watch_dir=".")

# The engine now automatically syncs and re-evaluates risk natively whenever files are saved.

工具参考(20个工具)

所有工具都记录了参数、示例和工作流程 MCP_TOOL_GUIDE.md.

索引和监控

工具 目的 快速命令
ingest_repo 使用签名和混乱配置文件对Valkey进行完整存储库扫描 ingest_repo root_dir="." clear_first=true compute_chaos=true
get_index_stats 实时索引运行状况:文档计数、内存、混乱平均值 get_index_stats
start_watcher 后台文件系统观察器——在文件保存/删除时自动识别 start_watcher watch_dir="."

文件发现和搜索

工具 目的 快速命令
list_indexed_files 按glob模式浏览索引文件 list_indexed_files pattern="*.py" max_results=200
get_file 从Valkey索引读取完整文件内容 get_file path="src/manifold/sidecar.py"
search_code 使用上下文在所有索引文件中搜索关键字或正则表达式 search_code query="chaos_score" file_pattern="*.py"
get_file_signature 文件的结构指纹(c/s/e) get_file_signature path="mcp_server.py"
search_by_structure 查找具有相似结构签名的文件 search_by_structure signature="c0.213_s0.000_e0.928" tolerance=0.05
search_by_signature_sequence 查找包含连续签名序列的文件 search_by_signature_sequence text="..." min_signatures=3

混沌分析

工具 目的 快速命令
analyze_code_chaos 每个文件的混乱评分、熵、一致性、崩溃风险 analyze_code_chaos path="mcp_server.py"
batch_chaos_scan 按混乱评分对所有文件进行排名(风险最高者优先) batch_chaos_scan pattern="*.py" max_files=50
predict_structural_ejection 预测文件何时变得无法维护 predict_structural_ejection path="mcp_server.py" horizon_days=30
visualize_manifold_trajectory 生成一个包含4个面板的混沌动力学仪表板 visualize_manifold_trajectory path="mcp_server.py"
cluster_codebase_structure K-Means通过结构签名对文件进行聚类 cluster_codebase_structure pattern="*.py" n_clusters=5

依赖性和组合风险

工具 目的 快速命令
analyze_blast_radius 导入依赖关系树和影响文件计数 analyze_blast_radius path="src/manifold/sidecar.py"
compute_combined_risk 综合风险=0.6×混乱+0.4×爆炸 compute_combined_risk path="src/manifold/sidecar.py"
scan_critical_files 全存储库扫描,以获得最高的综合风险 scan_critical_files pattern="*.py" max_files=20

验证和记忆

工具 目的 快速命令
compute_signature 将任意文本压缩为流形签名 compute_signature text="def hello(): ..."
verify_snippet 检查代码在结构上是否与现有代码库模式匹配 verify_snippet snippet="..." coverage_threshold=0.5 scope="*.py"
inject_fact 为动态语义代码簿添加持久性知识 inject_fact fact_id="api_rules" fact_text="All endpoints use snake_case."
remove_fact 删除之前注入的事实 remove_fact fact_id="api_rules"

实证验证

React 15.0案例研究

结构引擎标记了确切的文件(ReactReconcileTransaction.js, ReactInstanceHandles.js)React核心团队随后删除并重写为React Fiber——对JavaScript没有任何语义理解。 → 阅读研究

Langchain ROC分析

盲前向预测研究 langchain v0.0.300 证明了混沌分数阈值 0.396 最佳地预测架构弹出,在O(1)速度下达到昂贵AST解析工具预测能力的91%左右。 → 阅读研究

内存优化

Zstandard压缩将cpython索引从 3.4 GB到28 MB (减少>99%),检索精度零损失。


文档

文件 目的
MCP_TOOL_GUIDE.md 全面的工具参考、工作流程、最佳实践
报告/ 验证研究和生成的报告

许可证

麻省理工学院——见 许可证