gradle-analyzer-mcp
Analyzes Gradle dependencies in Android projects, supporting Version Catalog, duplicate detection, module comparison, and dependency tree generation.
README
Gradle 依赖分析
一个专为 Android 项目设计的 Gradle 依赖分析工具,支持 Version Catalog (TOML) 配置。
功能特性
1. 依赖分析
- 分析指定模块的所有依赖配置
- 支持 implementation, api, kapt, ksp, testImplementation 等配置
- 识别 Version Catalog 引用(libs.xxx)
- 识别模块间依赖(project:xxx)
2. 模块管理
- 列出项目中的所有模块
- 对比不同模块的依赖差异
- 查找重复依赖
3. Version Catalog 解析
- 解析
gradle/libs.versions.toml文件 - 提取版本号、库定义、插件定义
- 支持 bundles 配置
4. 版本检查
- 检查依赖版本更新(基础功能)
- 可扩展集成第三方版本检查 API
5. 依赖树生成
- 调用 Gradle 命令生成完整依赖树
- 支持指定配置(如 debugRuntimeClasspath)
安装
前置要求
- Python 3.10 或更高版本
- pip 包管理器
方法 1: 从 PyPI 安装(推荐,发布后可用)
pip install gradle-analyzer-mcp
在 Kiro 的 MCP 配置文件中添加(.kiro/settings/mcp.json):
{
"mcpServers": {
"gradle-analyzer": {
"command": "uvx",
"args": ["gradle-analyzer-mcp"],
"env": {},
"disabled": false,
"autoApprove": []
}
}
}
方法 2: 从 GitHub 源码安装
# 克隆仓库
git clone https://github.com/hpuhsp/gradle-analyzer-mcp.git
cd gradle-analyzer-mcp
# 安装依赖
pip install -e .
在 Kiro 的 MCP 配置文件中添加:
{
"mcpServers": {
"gradle-analyzer": {
"command": "python",
"args": ["/path/to/gradle-analyzer-mcp/server.py"],
"env": {},
"disabled": false,
"autoApprove": []
}
}
}
方法 3: 使用 uvx 直接运行(无需安装)
{
"mcpServers": {
"gradle-analyzer": {
"command": "uvx",
"args": ["--from", "git+https://github.com/hpuhsp/gradle-analyzer-mcp.git", "python", "server.py"],
"env": {},
"disabled": false,
"autoApprove": []
}
}
}
可用工具
1. analyze_dependencies
分析指定模块的依赖配置
参数:
project_path(必需): 项目根目录路径module(可选): 模块名称,默认 "app"
示例:
{
"project_path": "D:\\WorkPlace\\Android\\Test",
"module": "app"
}
返回示例:
{
"module": "app",
"dependencies": {
"implementation": [
"libs.bundles.coroutines",
"project:msc",
"project:base"
],
"kapt": [
"libs.arouter.compiler",
"libs.hilt.compiler"
],
"ksp": [
"libs.androidx.room.compiler",
"libs.glide.ksp"
]
}
}
2. list_all_modules
列出项目中的所有模块
参数:
project_path(必需): 项目根目录路径
返回示例:
{
"total": 4,
"modules": ["app", "base", "swallow", "msc"]
}
3. parse_version_catalog
解析 libs.versions.toml 文件
参数:
project_path(必需): 项目根目录路径
返回示例:
{
"versions": {
"agp": "8.7.3",
"kotlin": "2.0.21",
"hilt": "2.57.2"
},
"libraries": {
"androidx-core-ktx": "...",
"hilt-android": "..."
},
"plugins": {...},
"bundles": {...}
}
4. check_version_updates
检查依赖版本更新
参数:
project_path(必需): 项目根目录路径
5. find_duplicate_dependencies
查找重复依赖
参数:
project_path(必需): 项目根目录路径
返回示例:
{
"total_duplicates": 5,
"duplicates": {
"libs.hilt.android": [
{"module": "app", "configuration": "implementation"},
{"module": "base", "configuration": "implementation"}
]
}
}
6. generate_dependency_tree
生成依赖树(调用 Gradle)
参数:
project_path(必需): 项目根目录路径module(可选): 模块名称,默认 "app"
7. compare_module_dependencies
对比两个模块的依赖
参数:
project_path(必需): 项目根目录路径module1(必需): 第一个模块名称module2(必需): 第二个模块名称
使用示例
在 Kiro 中使用
配置好 MCP 服务器后,在 Kiro 中直接对话:
分析 app 模块的依赖
列出项目中的所有模块
查找重复的依赖
对比 app 和 base 模块的依赖差异
技术栈
- Python 3.10+
- MCP (Model Context Protocol) 0.9.0+
- tomli (TOML 解析)
目录结构
gradle-analyzer/
├── server.py # MCP 服务器主文件
├── pyproject.toml # Python 项目配置
├── README.md # 说明文档
└── .gitignore # Git 忽略文件
扩展建议
-
集成版本检查 API:
- Maven Central API
- GitHub Releases API
- 自定义版本服务
-
依赖冲突检测:
- 解析 Gradle 依赖树
- 识别版本冲突
- 提供解决方案
-
依赖可视化:
- 生成依赖关系图
- 导出为 DOT/SVG 格式
-
安全扫描:
- 集成 CVE 数据库
- 检查已知漏洞
故障排除
问题:找不到 mcp 模块
解决方案:
pip install mcp
问题:找不到 tomli 模块
解决方案:
pip install tomli
问题:Gradle 命令执行失败
解决方案:
- 确保项目根目录有
gradlew或gradlew.bat - 检查 Gradle 配置是否正确
- 尝试手动运行
./gradlew :app:dependencies
开发与贡献
本地开发
# 克隆仓库
git clone https://github.com/hpuhsp/gradle-analyzer-mcp.git
cd gradle-analyzer-mcp
# 创建虚拟环境(推荐)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 安装开发依赖
pip install -e ".[dev]"
# 运行测试
pytest
# 本地测试 MCP 服务器
python server.py
贡献指南
欢迎提交 Issue 和 Pull Request!
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
许可证
MIT License
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.