DependencyMCP Server

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Analyzes JavaScript codebases to generate dependency graphs, extract file metadata, and evaluate architectural patterns and dependencies.

  • Analyzes Python codebases to generate dependency graphs, extract file metadata, and evaluate architectural patterns and dependencies.

  • Analyzes TypeScript codebases to generate dependency graphs, extract imports/exports, and evaluate code against architectural rules and patterns.

DependencyMCP 服务器

模型上下文协议 (MCP) 服务器,用于分析代码库以生成依赖关系图和架构洞察。该服务器有助于理解跨多种编程语言的代码结构、依赖关系和架构模式。

特征

  • 多语言支持:分析 TypeScript、JavaScript、C#、Python 等语言的依赖关系
  • 依赖图生成:以 JSON 或 DOT 格式创建详细的依赖图
  • 架构分析:推断架构层并根据规则进行验证
  • 文件元数据:从源文件中提取导入、导出和其他元数据
  • 评分系统:根据架构规则和模式评估代码库

安装

  1. 克隆存储库
  2. 安装依赖项:
npm install
  1. 构建项目:
npm run build

配置

添加到您的 MCP 设置文件(通常位于 ~/.config/cline/mcp_settings.json 或同等位置):

json { mcpServers: { \DependencyMCP: { \command: \node, \args: [\path/to/dependency-mcp/dist/index.js], \env: { \MAX_LINES_TO_READ: \1000, \CACHE_DIR: \path/to/dependency-mcp/.dependency-cache, \CACHE_TTL: \3600000 } } }

环境变量:

  • MAX_LINES_TO_READ:从每个文件读取的最大行数(默认值:1000)
  • CACHE_DIR:存储依赖项缓存文件的目录(默认值:.dependency-cache)
  • CACHE_TTL:缓存生存时间(毫秒)(默认值:1 小时 = 3600000)

可用工具

分析依赖关系

分析代码库中的依赖关系并生成依赖关系图。

const result = await client.callTool("DependencyMCP", "analyze_dependencies", { path: "/path/to/project", excludePatterns: ["node_modules", "dist"], // optional maxDepth: 10, // optional fileTypes: [".ts", ".js", ".cs"] // optional });

获取依赖关系图

获取 JSON 或 DOT 格式的代码库依赖关系图。

const result = await client.callTool("DependencyMCP", "get_dependency_graph", { path: "/path/to/project", format: "dot" // or "json" (default) });

获取文件元数据

获取有关特定文件的详细元数据。

const result = await client.callTool("DependencyMCP", "get_file_metadata", { path: "/path/to/file.ts" });

获取建筑分数

根据架构规则和模式对代码库进行评分。

const result = await client.callTool("DependencyMCP", "get_architectural_score", { path: "/path/to/project", rules: [ { pattern: "src/domain/**/*", allowed: ["src/domain/**/*"], forbidden: ["src/infrastructure/**/*"] } ] });

示例输出

依赖图(JSON)

{ "src/index.ts": { "path": "src/index.ts", "imports": ["./utils", "./services/parser"], "exports": ["analyze", "generateGraph"], "namespaces": [], "architecturalLayer": "Infrastructure", "dependencies": ["src/utils.ts", "src/services/parser.ts"], "dependents": [] } }

建筑乐谱

{ "score": 85, "violations": [ "src/domain/user.ts -> src/infrastructure/database.ts violates architectural rules" ], "details": "Score starts at 100 and deducts 5 points per violation" }

发展

该服务器使用 TypeScript 构建并使用:

  • Zod 用于模式验证
  • diff 用于文件比较
  • minimatch 用于全局模式匹配

项目结构

dependency-mcp/ ├── src/ │ └── index.mts # Main server implementation ├── package.json ├── tsconfig.json └── README.md

添加对新语言的支持

要添加对新编程语言的支持:

  1. 将文件扩展名添加到默认的fileTypes数组
  2. parseFileImportsparseFileExports中实现特定于语言的正则表达式模式
  3. 将任何特定于语言的架构模式添加到inferArchitecturalLayer

执照

麻省理工学院

-
security - not tested
F
license - not found
-
quality - not tested

分析代码库以生成跨多种编程语言的依赖关系图和架构洞察,帮助开发人员理解代码结构并根据架构规则进行验证。

  1. Features
    1. Installation
      1. Configuration
        1. Available Tools
          1. analyze_dependencies
          2. get_dependency_graph
          3. get_file_metadata
          4. get_architectural_score
        2. Example Output
          1. Dependency Graph (JSON)
          2. Architectural Score
        3. Development
          1. Project Structure
          2. Adding Support for New Languages
        4. License
          ID: 4ndnq31gxp