DependencyMCP Server
用于分析代码依赖关系的模型上下文协议(MCP)服务器。
概述
依赖MCP是一个模型上下文协议服务器,用于分析代码库、生成依赖图并提供架构洞察。支持多种编程语言,包括TypeScript、JavaScript、C#和Python。
安装步骤
# 1. 克隆仓库
git clone <repository-url>
# 2. 安装依赖
npm install
# 3. 构建项目
npm run build
配置
在~/.config/cline/mcp_settings.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"
}
}
}
}
主要功能
分析依赖关系
const result = await client.callTool("DependencyMCP", "analyze_dependencies", {
path: "/path/to/project",
excludePatterns: ["node_modules", "dist"],
maxDepth: 10,
fileTypes: [".ts", ".js", ".cs"]
});
获取依赖图
const result = await client.callTool("DependencyMCP", "get_dependency_graph", {
path: "/path/to/project",
format: "dot" // 或 "json"
});
获取文件元数据
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": []
}
}
环境变量
MAX_LINES_TO_READ
: 每个文件读取的最大行数(默认:1000)CACHE_DIR
: 缓存目录(默认:.dependency-cache)CACHE_TTL
: 缓存有效期,毫秒(默认:3600000)
更多信息请参阅完整文档。