漏洞扫描程序MCP服务器
一个生产就绪的模型上下文协议(MCP)服务器,用于扫描代码库中的依赖性漏洞。使用FastMCP和FastAPI构建,可作为一个copula应用程序部署。
  
🔒 概述
此MCP服务器为AI代理提供了强大的工具,可以:
- 🔍 扫描存储库 用于跨多种语言(Python、JavaScript、Java、R)的依赖关系
- 🛡️ 检查漏洞 使用OSV.dev API(无需下载!)
- 🔬 分析代码使用情况 通过AST解析来理解包的影响(Python+Java)
- ☕ Java代码分析 使用javalang:解析AST,提取方法调用,查找API用法
- ⚠️ 检测破坏性更改 使用变更日志分析和精心策划的数据库
- 📊 可视化补丁 在应用之前使用颜色编码的差异
- 🔧 应用安全补丁 自动与Git集成
- 📈 监控存储库 不断发现新的漏洞
- 🗄️ 与Unity目录集成 用于生产工作流程和审计跟踪
为什么要使用这个工具?
✅ API-第一种方法:无包下载-使用注册表API进行即时元数据\ ✅ 多语言支持:Python、JavaScript、Java、R生态系统\ ✅ 突变检测:自动分析API版本之间的变化\ ✅ 视觉差异:在应用补丁之前,确切地看看会发生什么变化\ ✅ Rancher本机:与copula Repos和Unity Catalog无缝集成\ ✅ 代理就绪:通过MCP协议为AI代理编排而设计\ ✅ 生产级:包括审计跟踪、UC集成和测试验证
🚀 快速开始
先决条件
- Python 3.11或更高版本
- 紫外线 (推荐)或pip
- Rancher工作区(用于部署)
安装
# Clone or navigate to the project
cd vulnerability-scanner-mcp
# Install dependencies with uv
uv sync
# Or with pip
pip install -r requirements.txt在本地运行
# Start the server (port 8000)
./scripts/dev/start_server.sh
# Or manually
uv run python -m server.main
# Or with custom port
uv run python -m server.main --port 8080服务器将在以下位置可用:
- MCP端点:
http://localhost:8000/mcp/v1/ - 健康检查:
http://localhost:8000/health - 网络界面:
http://localhost:8000/
测试服务器
# Run local test (checks tools without authentication)
python scripts/dev/test_local.py
# Run full integration tests (requires Databricks auth)
uv run pytest tests/🏗️ 建筑
vulnerability-scanner-mcp/
├── server/ # MCP server core
│ ├── app.py # FastAPI + FastMCP setup
│ ├── main.py # Entry point
│ ├── tools.py # 15 MCP tools
│ └── utils.py # Databricks authentication
├── services/ # Business logic
│ ├── code_analyzer.py # Parse dependencies from manifests
│ ├── vulnerability_scanner.py # OSV.dev API client
│ ├── package_registry.py # PyPI/npm/Maven APIs
│ ├── static_analyzer.py # AST parsing for code analysis
│ ├── changelog_fetcher.py # Fetch changelogs from GitHub/PyPI
│ ├── api_changelog_analyzer.py # Breaking change detection
│ ├── llm_analyzer.py # LLM-enhanced changelog analysis
│ ├── diff_generator.py # Patch visualization
│ ├── git_client.py # Databricks Repos API
│ └── uc_integration.py # Unity Catalog integration
├── models/ # Pydantic data models
│ ├── package.py # Package and dependency models
│ ├── vulnerability.py # Vulnerability and report models
│ └── usage.py # Usage analysis and API change models
├── tests/ # Integration tests
├── static/ # Web interface
└── docs/ # Detailed documentation
├── AGENT_CONFIGURATION.md
├── AGENT_MCP_TOOLS.md
├── AGENT_TOOL_ORGANIZATION.md
├── CHANGELOG.md
├── CONTRIBUTING.md
├── DEPLOYMENT.md
├── JAVA_ANALYSIS.md
├── LANGGRAPH_ARCHITECTURE.md
├── MCP_TOOLS_FOR_AGENT.md
├── STREAMLIT_APP_INTEGRATION.md
├── TOOL_EXCLUSION_STRATEGY.md
├── TOOL_FLOWS.md
├── TOOL_REQUIREMENTS.md
├── TROUBLESHOOTING.md
└── UC_INTEGRATION.md🔧 可用工具(共17个)
📦 Git仓库管理(1个工具)
1. clone_github_repo 🆕
将任何GitHub存储库克隆到Connection/Reposit/进行分析
使用此功能将远程存储库引入您的copula工作区。克隆后,使用其他工具扫描、分析或修补代码。
Args:
git_url(str):GitHub存储库URL(例如,“https://github.com/org/repo.git")provider(str):Git提供者-“github”、“gitLab”、“bitbucketCloud”或“azure DevOpsServices”(默认值:“github)branch(str):分支到结账(默认:“main”)user_email(str):回购路径的用户电子邮件(默认值:“adminuser4510846@vocareum.com")destination_folder(str):/Reps/{user_email}/下的文件夹名称(默认值:“Repos”)
退货: 存储库信息,包括路径、提交哈希和分支。
例子:
# Clone a repository
result = clone_github_repo(
git_url="https://github.com/databricks/databricks-sdk-py.git",
destination_folder="hackathon_databricks"
)
# Returns: {"repo_path": "/Repos/user@company.com/hackathon_databricks/databricks-sdk-py", ...}
# Then scan it separately
scan_result = scan_repo_dependencies(repo_path=result["repo_path"])它的作用:
- ✅ 将存储库克隆到
/Repos/{user}/{folder}/{repo_name} - ✅ 支持多个Git提供程序
- ✅ 返回存储库信息以供进一步分析
工作流程:
- 使用
clone_github_repo将代码带入工作区 - 使用
scan_repo_dependencies查找依赖关系 - 使用
check_vulnerabilities识别安全问题 - 使用
generate_patch_preview查看修复程序 - 使用
apply_security_patches应用它们
______________________________________________________________________
🔍 发现和扫描(2个工具)
2. scan_repo_dependencies
扫描copula Repo以从清单文件中提取所有库依赖项。
Args:
repo_path(str):ConnectionRepo或工作区文件夹的路径branch(str):要扫描的Git分支(默认:“main”)
退货:
{
"packages": {
"python": {"requests": "2.28.0", "pandas": "1.5.3"},
"javascript": {"react": "18.2.0"}
},
"manifest_files": ["requirements.txt", "package.json"],
"total_packages": 15
}支持的清单:
- python
requirements.txt,pyproject.toml,setup.py,Pipfile - JavaScript:
package.json,package-lock.json - Java
pom.xml,build.gradle - R
DESCRIPTION
3. list_directory_contents
探索存储库结构并验证文件访问权限(对调试很有用)。
🛡️ 漏洞分析(2个工具)
4. check_vulnerabilities
检查与OSV.dev漏洞数据库的依赖关系(聚合NVD、GitHub Security等)。
Args:
dependencies(dict):输出来自scan_repo_dependenciesseverity_threshold(str):“低”|“中”|“高”|“临界”
退货:
{
"vulnerable_packages_count": 2,
"vulnerable_packages": [
{
"name": "requests",
"current_version": "2.28.0",
"recommended_version": "2.31.0",
"vulnerabilities": [
{
"cve_id": "CVE-2023-32681",
"severity": "high",
"cvss_score": 7.5,
"description": "Proxy-Authorization header leak",
"fixed_versions": ["2.31.0"]
}
]
}
]
}5. monitor_repo_security
全面安全审计-一步扫描依赖关系并检查漏洞。
🔬 代码影响分析(3个工具)
6. analyze_package_usage
使用AST解析分析代码库中如何使用包。
Args:
repo_path(str):存储库路径package_name(str):要分析的包(例如,“pandas”、“requests”)specific_file(str,可选):仅分析一个文件
退货:
{
"package_name": "pandas",
"imported_as": {"pd": "pandas"},
"methods_used": ["DataFrame", "read_csv", "concat"],
"files_with_usage": ["analysis.py", "preprocessing.py"],
"usage_count": 47
}7. check_api_changes
检测程序包版本之间正在中断的API更改。
Args:
package_name(str):包名称current_version(str):当前版本target_version(str):目标升级版本methods_used(列表,可选):检查方法(来自analyze_package_usage)
退货:
{
"package_name": "pandas",
"current_version": "1.5.3",
"target_version": "2.0.0",
"is_breaking": true,
"breaking_changes": [
{
"method": "DataFrame.append",
"change_type": "removed",
"description": "Deprecated and removed. Use concat() instead.",
"severity": "high",
"migration_guide": "Replace df.append(other) with pd.concat([df, other])"
}
],
"confidence": 0.92
}检测策略:
- 整理数据库:检查流行包(pandas、numpy、tensorflow、requests等)的已知破坏性更改
- 变更日志分析:从GitHub版本和PyPI获取并分析变更日志
- 语义化版本:将主要版本的颠簸标记为可能会破裂
8. fetch_and_analyze_changelog
获取并分析包更改日志,以发现突破性更改。
来源:
- GitHub发布API
- PyPI元数据
- 常见的变更日志文件(changelog.md、HISTORY.md、CHANGES.md)
🔧 补丁生成和验证(3个工具)
9. generate_patch_preview
在应用补丁之前生成视觉差异预览。
Args:
repo_path(str):通往Rancher Repo的路径upgrade_plan(dict):随版本升级的软件包
退货:
{
"files_to_modify": ["requirements.txt"],
"file_diffs": [
{
"file_path": "requirements.txt",
"diff_text": "--- a/requirements.txt\n+++ b/requirements.txt\n...",
"lines_added": 3,
"lines_removed": 3
}
],
"visual_diff_html": "...",
"impact_summary": {
"total_changes": 6,
"breaking_changes": 0
}
}10. apply_security_patches
将批准的安全补丁应用于存储库。
Args:
repo_path(str):通往Rancher Repo的路径upgrade_plan(dict):已批准的升级计划create_branch(bool):创建新分支(默认值:true)branch_name(str):分支名称(默认:“安全补丁-{timestamp}”)
退货:
{
"status": "success",
"branch_name": "security-patches-20260203",
"files_modified": ["requirements.txt"],
"packages_upgraded": 3,
"commit_message": "Security: Upgrade vulnerable packages"
}安全特性:
- ✅ 从不直接修改主/主分支
- ✅ 始终创建新分支
- ✅ 包括描述性提交消息
- ✅ 保留原始清单格式
11. validate_patch_with_tests
将补丁应用于测试分支并运行测试套件。
Args:
repo_path(str):存储库路径branch_name(str):使用补丁进行测试的分支
退货:
{
"is_valid": true,
"tests_pass": true,
"test_summary": "47 passed, 0 failed",
"errors": []
}☕ Java代码分析(1个工具)
12. analyze_java_repos_from_uc 🆕
使用临时克隆和javalang AST解析分析Java存储库
从Unity Catalog读取仓库URL,将其克隆到临时目录(自动清理),使用以下命令解析Java代码 javalang 提取方法调用和结构,然后将综合分析写回UC。
它发现了什么:
- 类/接口/枚举结构
- 带有调用方上下文的方法调用(API调用)
- 包装组织
- 逐行使用情况跟踪
Args:
catalog(str):UC目录名称(默认:“main”)schema(str):UC架构名称(默认:“security”)table(str):带有要扫描的repos的UC表(默认值:“java_repos_to_scan”)
需要UC表架构:
CREATE TABLE {catalog}.{schema}.{table} (
repo_url STRING, -- Git URL
ref STRING, -- Branch/tag/commit
repo_name STRING -- Human-readable name
);退货:
{
"status": "success",
"repos_analyzed": 5,
"total_java_files": 2847,
"total_method_calls": 45632,
"results": [...]
}使用案例:
- 🔒 安全审计:找出实际使用了哪些易受攻击的API(例如Log4j)
- 📊 迁移规划:在库升级之前确定方法使用情况
- 🔍 依赖性分析:跨Java代码库映射API使用情况
例子:
# Agent workflow
result = analyze_java_repos_from_uc(
catalog="production",
schema="security_audit",
table="vulnerable_java_apps"
)
# Results written to: production.security_audit.java_analysis_results
# Query: Which repos use javax.servlet?主要特点:
- ✅ 临时克隆:无工作区污染,自动清理
- ✅ 不需要JVM:纯Python
javalang解析器 - ✅ 基于AST:精确的方法调用提取
- ✅ UC集成:从表中读取存储库,将结果写回
另请参见: 文档/JAVA_ANALYSIS.md 获取完整的文档
______________________________________________________________________
🗄️ Unity目录集成(3个工具)
用于具有集中跟踪和审计跟踪的生产部署。
13. get_vulnerable_repos_from_uc
从Unity目录表中获取易受攻击的存储库。
Args:
catalog(str):UC目录名称(默认:来自配置)schema(str):UC模式名称(默认:来自配置)table(str):UC表名(默认:来自配置)priority(int,可选):按优先级筛选(1=严重,2=高,3=中等)
退货: 包含包详细信息的易受攻击存储库列表。
14. write_analysis_to_uc
将分析结果写入Unity目录进行跟踪。
Args:
repo_id(str):存储库标识符analysis_results(dict):代码分析和API检查的结果
退货: 使用分析ID进行确认。
15. record_user_decision_to_uc
记录用户的批准/拒绝决定,以便进行审计跟踪。
Args:
repo_id(str):存储库标识符decision(str):“批准”或“拒绝”target_version(str):版本正在升级到reason(str,可选):决策推理
退货: 使用决策ID进行确认。
📊 附加实用程序(2个工具)
16. get_vulnerability_details
获取特定CVE的详细信息。
17. suggest_upgrades
根据漏洞报告(代理内部使用)推荐安全升级路径。
______________________________________________________________________
📖 示例工作流
⚡ 新增:克隆和扫描远程存储库
User: "Scan this repo for vulnerabilities: https://github.com/databricks-industry-solutions/ray-framework-on-databricks"
Agent:
→ clone_github_repo(git_url, destination_folder="security_scans")
→ scan_repo_dependencies(repo_path)
→ check_vulnerabilities(dependencies)
Response: "✅ Cloned ray-framework-on-databricks to /Repos/user@company.com/security_scans/ray-framework-on-databricks
Scan results: Found 15 packages, 2 with vulnerabilities:
- ray 2.0.0 → CVE-2023-xxxxx (HIGH)
- requests 2.28.0 → CVE-2023-32681 (HIGH)
Would you like me to analyze the code impact?"工作流优势:
- ✅ 独立关注点:克隆一次,分析多次
- ✅ 保留存储库以供手动检查
- ✅ 选择运行哪些分析的灵活性
______________________________________________________________________
快速安全扫描(现有回购)
User: "Check /Workspace/Users/me/my-project for vulnerabilities"
Agent:
→ scan_repo_dependencies(repo_path)
→ check_vulnerabilities(dependencies)
Response: "Found 2 HIGH severity vulnerabilities in requests and urllib3.
Would you like me to analyze the code impact?"基于突变检测的深度分析
User: "Analyze impact of upgrading pandas"
Agent:
→ scan_repo_dependencies(repo_path)
→ check_vulnerabilities(dependencies)
→ analyze_package_usage(repo_path, "pandas")
→ check_api_changes("pandas", "1.5.3", "2.0.0", methods_used)
Response: "Upgrade to pandas 2.0.0 fixes 1 vulnerability but has 2 breaking changes:
- DataFrame.append() removed (use concat())
- Used in 5 files, 23 call sites affected
Would you like to see the patch preview?"通过测试进行全面补救
User: "Fix all vulnerabilities and test"
Agent:
→ scan_repo_dependencies(repo_path)
→ check_vulnerabilities(dependencies)
→ analyze_package_usage(...) for each vulnerable package
→ check_api_changes(...) for each upgrade
→ generate_patch_preview(repo_path, upgrade_plan)
→ [User approves]
→ apply_security_patches(repo_path, upgrade_plan)
→ validate_patch_with_tests(repo_path, branch_name)
Response: "✅ Applied patches to branch 'security-patches-20260203'
✅ All 47 tests passed
Ready to merge to main!"生产UC工作流程
Agent (automated):
→ get_vulnerable_repos_from_uc(priority=1) # Critical only
→ For each repo:
- scan_repo_dependencies(repo_path)
- analyze_package_usage(...) for each vulnerable package
- check_api_changes(...) for each upgrade
- write_analysis_to_uc(repo_id, results)
User reviews in Databricks App UI, approves fix
Agent:
→ record_user_decision_to_uc(repo_id, "approved")
→ apply_security_patches(repo_path, upgrade_plan)
→ validate_patch_with_tests(repo_path, branch_name)______________________________________________________________________
🌐 部署到ViewModel
部署为copula应用程序
# Navigate to project directory
cd /path/to/vulnerability-scanner-mcp
# Authenticate with Databricks (use valid profile)
databricks auth login --profile your-profile
# Create the app (requires 'mcp-' prefix for AI Playground discovery)
databricks apps create mcp-vulnerability-scanner --profile your-profile
# Upload source code to Workspace
databricks workspace import-dir . /Workspace/Users/you@company.com/mcp-vulnerability-scanner --profile your-profile
# Deploy the app
databricks apps deploy mcp-vulnerability-scanner \
--source-code-path /Workspace/Users/you@company.com/mcp-vulnerability-scanner \
--profile your-profile
# Check status
databricks apps get mcp-vulnerability-scanner --profile your-profile
# View logs
databricks apps logs mcp-vulnerability-scanner --profile your-profile看 文档/部署.md 了解详细的部署选项和故障排除。
在AI游乐场中配置
- 导航到 AI游乐场 在Databricks中
- 选择一个型号 工具已启用
- 点击 工具>+添加工具
- 选择已部署的MCP服务器:
mcp-vulnerability-scanner - 开始聊天-代理将自动使用您的工具!
MCP端点
部署后,您的MCP端点将是:
https://.databricks.com/serving-endpoints/mcp-vulnerability-scanner/mcp/v1/______________________________________________________________________
🤖 代理配置
有关配置AI代理以使用此MCP服务器的全面指导,包括:
- ✨ 代理友好工具描述的最佳实践
- 🎤 OpenAI SDK代理的完整系统提示
- 🔄 4种执行流程模式(快速扫描→ 完全UC集成)
- ✅ 测试和验证指南
______________________________________________________________________
🔐 认证
本地开发
- 使用来自
~/.databrickscfg - 设置配置文件
DATABRICKS_CONFIG_PROFILE环境变量 - 如果未指定,则使用默认配置文件
# Configure auth
databricks auth login --profile your-profile
# Use profile
export DATABRICKS_CONFIG_PROFILE=your-profile
./scripts/dev/start_server.sh部署为copula应用程序
- 应用程序身份验证 (
get_workspace_client()):具有应用程序级访问权限的服务主体 - 用户认证 (
get_user_authenticated_workspace_client()):用于用户特定操作的最终用户OAuth令牌 - 从以下位置提取用户令牌
x-forwarded-access-token头球
大多数工具使用应用程序级身份验证来保证可靠性和一致性。
______________________________________________________________________
🗄️ Unity目录集成
对于生产部署,请与Unity Catalog集成:
- 📊 集中式漏洞跟踪
- 🔄 自动扫描工作流程
- ✅ 所有决策的审计跟踪
- 📈 报告和合规
看 docs/UC_INTEGRATION.md 完整的设置指南,包括:
- Unity目录表模式
- 代理模型注册
- 生产工作流程示例
______________________________________________________________________
📦 关键依赖
- fastmcp:MCP服务器框架
- FastAPI:异步web框架
- 优维康:带uvloop的ASGI服务器
- sdk数据库:Databricks API客户端
- pyspark:Unity目录集成
- 意图tp:API调用的异步HTTP(OSV.dev、PyPI、npm、Maven)
- pygments:语法高亮显示差异
- 包装:语义版本比较
- 汤米:pyproject.TOML的TOML解析器
______________________________________________________________________
🧪 发展
运行测试
# All tests
uv run pytest tests/
# Specific test
uv run pytest tests/test_integration.py::test_list_tools -v
# With coverage
uv run pytest tests/ --cov=server --cov=services代码格式化
# Format code
uv run ruff format .
# Check linting
uv run ruff check .
# Auto-fix issues
uv run ruff check --fix .本地测试,无需docker
# Test server health and tool listing (no auth required)
python scripts/dev/test_local.py______________________________________________________________________
🎯 为什么采用API-第一种方法?
传统方法(❌):
- 下载完整软件包文件(MB/GB)
- 在本地存储包
- 比较缓慢
- 存储管理开销
- 陈旧数据
我们的方法(✅):
- 查询包注册表API(PyPI、npm、Maven)
- 仅获取元数据(KB)
- 即时查找
- 无需存储
- 始终保持最新状态
- 源代码变更日志分析
使用的API:
- OSV.dev:漏洞数据库(聚合NVD、GitHub安全咨询等)
- PyPI JSON API:Python包元数据和更改日志
- npm注册表:JavaScript包元数据
- Maven Central:Java包元数据
- GitHub发布API:发行说明和变更日志
- Databricks回购API:Rancher中的Git操作
______________________________________________________________________
📚 资源
______________________________________________________________________
🤝 贡献
我们欢迎捐款!看 docs/CONTRIBUTING.md 用于:
- 开发设置
- 代码风格指南
- 测试要求
- 拉取请求流程
- 贡献领域
贡献想法:
- 支持其他生态系统(Go、Rust、PHP、Ruby)
- 与Snyk、GitHub咨询数据库集成
- 通过Git提供程序API自动创建PR
- SBOM生成
- 合规报告(SOC2、HIPAA)
______________________________________________________________________
🆘 故障排除
常见问题
端口已在使用中:
uv run python -m server.main --port 8080导入错误:
uv sync --reinstall身份验证错误(本地):
databricks auth login --profile your-profile
export DATABRICKS_CONFIG_PROFILE=your-profile部署错误:
# Check app logs
databricks apps logs mcp-vulnerability-scanner --profile your-profile
# Check app status
databricks apps get mcp-vulnerability-scanner --profile your-profile看 docs/TROUBLESHOOTING.md 获取全面的故障排除指南。
______________________________________________________________________
📄 许可证
根据Apache许可证2.0授权。看 许可证 了解详情。
______________________________________________________________________
📝 更新日志
看 docs/CHANGELOG.md 查看版本历史和发行说明。
______________________________________________________________________
内置于❤️ 用于安全的软件供应链
当前版本: 1.0.0 | MCP协议: 1.0 | python: 3.11+
