对手MCP服务器
](https://badge.fury.io/py/adversary-mcp-server)     ](https://pypi.org/project/adversary-mcp-server/)
🔒 基于AI的漏洞检测和验证的清洁架构安全分析
我们会考虑你的弱点,所以你不必这么做。
安装 • 快速开始 • Claude代码设置 • 光标设置 • CLI使用情况 • MCP工具 • 建筑
______________________________________________________________________
特性
- AI驱动的分析 -OpenAI/Anthropic LLM集成用于智能漏洞检测
- 智能验证 -通过LLM验证减少误报(70%置信阈值)
- 多引擎扫描 -结合Semgrep静态分析和AI分析
- 自动持久化 -自动以JSON、Markdown和CSV格式保存扫描结果
- MCP集成 -原生支持Claude代码和Cursor IDE
- 全面的CLI -具有所有扫描功能的完整命令行界面
- 丰富的遥测技术 -通过仪表板可视化进行全面跟踪
安装
先决条件
- Python 3.10+ (3.11、3.12、3.13测试)
- Semgrep -静态分析引擎(安装)
快速安装
# Install python uv
brew install uv
# Install Semgrep (required)
brew install semgrep # macOS
# or
pip install semgrep # Other platforms
# Install Adversary MCP Server
uv pip install adversary-mcp-server验证安装
adv --version
adv status快速开始
1.配置安全引擎
# Initial setup (interactive)
adv configure setup
# Or configure directly with options
adv configure --llm-provider openai --llm-api-key $OPENAI_API_KEY
adv configure --llm-provider anthropic --llm-api-key $ANTHROPIC_API_KEY
# Check configuration status
adv status2.运行第一次扫描
# Scan a single file (basic)
adv scan-file path/to/file.py
# Scan with AI analysis and validation (recommended)
adv scan-file path/to/file.py --use-llm --use-validation
# Scan entire directory
adv scan-folder ./src --use-llm --use-validation
# Scan code snippet directly
adv scan-code "print('Hello World')" --language python3.查看综合仪表板
# Launch interactive telemetry dashboard
adv dashboardClaude代码设置
配置MCP服务器
创建或更新 ~/.config/claude-code/mcp.json:
{
"mcpServers": {
"adversary": {
"command": "uvx",
"args": ["adversary-mcp-server"]
}
}
}在Claude代码中使用MCP工具
配置后,这些工具在Claude Code中可用:
- 问克劳德:“使用adv_Scan_file扫描此文件以查找安全问题”
- 问克劳德:“使用adv_scan_folder检查当前项目中的漏洞”
- 问克劳德:“使用adv_scan_code分析此代码段的安全问题”
光标IDE设置
配置MCP服务器
创建 .cursor/mcp.json 在您的项目中:
{
"mcpServers": {
"adversary": {
"command": "uvx",
"args": ["adversary-mcp-server"]
}
}
}Alternative Cursor setups (click to expand)
使用pip安装:
{
"mcpServers": {
"adversary": {
"command": "python",
"args": ["-m", "adversary_mcp_server.sync_main"]
}
}
}发展:
{
"mcpServers": {
"adversary": {
"command": "/path/to/.venv/bin/python",
"args": ["-m", "adversary_mcp_server.sync_main"]
}
}
}在游标中使用MCP工具
配置后,这些工具在Cursor的聊天中可用:
- 询问光标:“使用adv_Scan_file扫描此文件以查找安全问题”
- 询问光标:“使用adv_scan_folder检查当前项目中的漏洞”
- 询问光标:“使用adv_scan_code分析此代码段的安全问题”
CLI使用情况
基本命令
# Configure the scanner
adv configure setup
# Check status and configuration
adv status
# Scan individual files
adv scan-file [options]
# Scan directories
adv scan-folder [options]
# Scan code snippets
adv scan-code --language [options]
# Launch comprehensive telemetry dashboard
adv dashboard扫描示例
# Basic file scan
adv scan-file app.py
# Scan with AI analysis and validation (recommended)
adv scan-file app.py --use-llm --use-validation
# Directory scan with full analysis
adv scan-folder ./src --use-llm --use-validation
# Code snippet scan
adv scan-code "SELECT * FROM users WHERE id = ?" --language sql
# Scan with specific severity threshold
adv scan-file app.py --severity high
# Output results in different formats
adv scan-file app.py --output-format json --output-file results.json
adv scan-file app.py --output-format markdown --verbose配置命令
# Interactive setup
adv configure setup
# Direct configuration
adv configure --llm-provider openai --llm-api-key your-key
adv configure --llm-provider anthropic --llm-api-key your-key
# Reset configuration
adv configure reset
# Check current configuration
adv status可用选项
--use-llm / --no-llm # Enable/disable AI analysis
--use-validation / --no-validation # Enable/disable false positive filtering
--use-semgrep / --no-semgrep # Enable/disable Semgrep analysis (default: true)
--severity [low|medium|high|critical] # Minimum severity threshold
--output-format [json|markdown|csv] # Output format for results
--output-file # Save results to specific file
--verbose # Verbose output with detailed informationMCP工具
可用工具
| 工具 | 说明 | 示例用法 |
|---|---|---|
adv_scan_code | 直接扫描代码片段 | “扫描此代码以查找漏洞” |
adv_scan_file | 扫描特定文件并进行全面分析 | “检查auth.py中的安全问题” |
adv_scan_folder | 递归扫描整个目录 | “分析src文件夹中的漏洞” |
adv_get_status | 检查服务器状态和功能 | “是否配置了安全扫描程序?” |
adv_get_version | 获取服务器版本信息 | “正在运行哪个版本?” |
adv_mark_false_positive | 将发现标记为误报 | “将发现XYZ标记为误报” |
adv_unmark_false_positive | 删除假阳性标记 | “将查找ABC标记为假阳性” |
MCP工具示例
// In Claude Code or Cursor, ask the AI assistant:
// Scan current file with full analysis
"Use adv_scan_file to check this file for security issues with LLM validation"
// Scan directory with specific options
"Run adv_scan_folder on the src directory with severity threshold of high"
// Scan code snippet
"Use adv_scan_code to analyze this SQL query for injection vulnerabilities"
// Check scanner status
"Use adv_get_status to see what scan engines are available"自动结果持久化
所有MCP工具都会自动以多种格式保存扫描结果:
- 对象符号:
.adversary.json-具有完整元数据的机器可读结果 - 降价:
.adversary.md-具有补救指导的人类可读报告 - CSV文件:
.adversary.csv-用于分析的电子表格兼容格式
结果会自动放置在扫描的文件/目录旁边,并具有智能冲突解决功能。
仪表板和遥测
全面的HTML仪表板
扫描仪包括一个丰富的基于网络的仪表板,用于全面的遥测分析:
# Launch interactive dashboard
adv dashboard仪表板功能:
- MCP工具分析 -跟踪工具使用情况、成功率和性能
- 扫描引擎指标 -监控Semgrep、LLM和验证性能
- 威胁分析 -按严重程度和置信度对调查结果进行分类
- 系统健康 -性能监控和统计
- 语言分析 -通过编程语言跟踪扫描效率
- 最近的活动 -最近扫描和操作的时间线视图
遥测系统
对抗MCP服务器包括全面的遥测跟踪:
- 自动收集 -所有MCP工具、CLI命令和扫描操作都会自动跟踪
- 本地存储 -所有数据都存储在本地,从不传输到外部服务
- 零配置 -遥测功能开箱即用,无需设置
- 性能洞察 -识别瓶颈并优化扫描工作流程
- 使用情况分析 -了解工具使用模式和有效性
建筑
实施
对抗MCP服务器是使用 清洁建筑 领域驱动设计(DDD)的原则,确保关注点分离、可维护性和可测试性。
graph TB
subgraph "🖥️ **Presentation Layer**"
A[Cursor IDE]
B[CLI Interface]
C[Web Dashboard]
end
subgraph "🔧 **Application Layer**"
D[MCP Server]
E[CLI Commands]
F[Adapters]
subgraph "Adapters"
F1[SemgrepAdapter]
F2[LLMAdapter]
F3[ValidationAdapter]
end
end
subgraph "🏛️ **Domain Layer (Business Logic)**"
subgraph "Entities"
G[ScanRequest]
H[ScanResult]
I[ThreatMatch]
end
subgraph "Value Objects"
J[ScanContext]
K[SeverityLevel]
L[ConfidenceScore]
M[FilePath]
end
subgraph "Domain Services"
N[ScanOrchestrator]
O[ThreatAggregator]
P[ValidationService]
end
subgraph "Interfaces"
Q[IScanStrategy]
R[IValidationStrategy]
end
end
subgraph "⚙️ **Infrastructure Layer**"
S[SemgrepScanner]
T[LLMScanner]
U[LLMValidator]
V[SQLAlchemy Database]
W[File System]
X[Git Operations]
Y[Telemetry System]
end
A -->|MCP Protocol| D
B --> E
C --> Y
D --> F
E --> F
F1 --> N
F2 --> N
F3 --> P
N --> O
N --> P
G --> N
H --> O
I --> P
J --> G
K --> I
L --> I
M --> G
N --> Q
P --> R
F1 -.-> S
F2 -.-> T
F3 -.-> U
S --> W
T --> W
U --> V
Y --> V
X --> W
style N fill:#e1f5fe,stroke:#0277bd,stroke-width:3px
style O fill:#e1f5fe,stroke:#0277bd,stroke-width:3px
style P fill:#e1f5fe,stroke:#0277bd,stroke-width:3px
style G fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
style H fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
style I fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
style F1 fill:#e8f5e8,stroke:#388e3c,stroke-width:2px
style F2 fill:#e8f5e8,stroke:#388e3c,stroke-width:2px
style F3 fill:#e8f5e8,stroke:#388e3c,stroke-width:2px新架构的好处
- 关注点分离:业务逻辑与基础设施隔离
- 依赖倒置:高级模块不依赖于低级细节
- 可测试性:纯域逻辑支持全面的单元测试
- 可维护性:基础设施的更改不会影响业务规则
- 可扩展性:新的扫描策略和验证器易于插入
- 类型安全:具有全面验证的丰富域模型
建筑层
域层 (核心业务逻辑)
- 实体:
ScanRequest,ScanResult,ThreatMatch-丰富的业务对象 - 值对象:
ScanContext,SeverityLevel,ConfidenceScore,FilePath-不可变域概念 - 域服务:
ScanOrchestrator,ThreatAggregator,ValidationService-纯粹的业务编排 - 接口:
IScanStrategy,IValidationStrategy-外部依赖合同
应用层 (用例和协调)
- MCP服务器:通过模型上下文协议处理游标IDE集成
- CLI命令:安全扫描操作的命令行界面
- 适配器:桥接域接口与基础设施实现
- SemgrepAdapter -使Semgrep扫描程序适应域 IScanStrategy - LLMAdapter -使LLM扫描仪适应域 IScanStrategy - ValidationAdapter -使LLM验证器适应域 IValidationStrategy
基础设施层 (外部服务)
- 学期扫描仪:静态分析引擎集成
- LLM扫描仪:AI驱动的漏洞检测
- LLM校准器:使用LLM分析进行误报过滤
- SQLAlchemy数据库:遥测和结果的持久存储
- 文件系统:代码文件访问和Git操作
- 遥测系统:绩效跟踪和仪表板生成
数据流架构
- 输入处理:
ScanRequest创建于ScanContext(文件/目录/代码) - 域编排:
ScanOrchestrator协调扫描策略 - 平行分析:多个
IScanStrategy实现并发执行 - 威胁聚合:
ThreatAggregator消除重复并合并结果 - 验证流程:
ValidationService使用AI过滤误报 - 结果组装:富有
ScanResult具有全面的元数据 - 演示:格式化结果以供CLI、MCP或仪表板使用
关键设计模式
- 策略模式:可插拔的扫描和验证策略
- 适配器模式:无域耦合的基础设施集成
- 工厂模式:Bootstrap和依赖注入
- 值对象:具有验证功能的不可变域概念
- 域服务:复杂的业务逻辑协调
运作原理
- 多引擎分析:并行执行Semgrep静态分析和LLM AI分析
- 智能验证:LLM支持通过置信度评分减少误报
- 威胁聚合:使用指纹和邻近策略进行智能重复数据删除和合并
- 性能优化:异步处理、缓存和批处理操作
- 综合遥测:SQLAlchemy支持的指标,带有交互式Chart.js仪表板
- Git集成:差异感知扫描,实现高效的CI/CD管道集成
- 零配置操作:使用合理的默认值自动发现和配置
配置
环境变量
# Core settings (optional)
ADVERSARY_LOG_LEVEL=INFO # Set logging level
ADVERSARY_WORKSPACE_ROOT=/path # Override workspace detection配置文件
设置通过CLI自动管理并存储在 ~/.adversary/config.json:
# Interactive configuration
adv configure setup
# Direct configuration
adv configure --llm-provider openai --llm-api-key your-key
# Check current settings
adv statusCI/CD集成
GitHub操作
name: Security Scan
on: [pull_request]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
pip install adversary-mcp-server
- name: Run security scan
run: |
adv scan-directory . \
--use-llm \
--use-validation \
--severity medium \
--output-format json \
--output-file scan-results.json
- name: Upload results
uses: actions/upload-artifact@v3
with:
name: security-scan
path: scan-results.json发展
设置开发环境
# Clone repository
git clone https://github.com/brettbergin/adversary-mcp-server.git
cd adversary-mcp-server
# Create virtual environment (using uv or standard venv)
source .venv/bin/activate # Activate existing venv
# Install in development mode
uv pip install -e .[dev]
# Run tests
make test运行测试
# Full test suite with coverage
make test
# Specific test categories
make test-unit # Unit tests only
make test-integration # Integration tests only
make test-security # Security tests only
# Code quality checks
make format # Auto-format code
make mypy # Type checking
make lint # Run all linting
make pre-commit # Run same pre-commit in git commits.支持
许可证
MIT许可证-请参阅 许可证 了解详情。
贡献
欢迎投稿!请查看我们的 贡献指南 了解详情。
______________________________________________________________________
Made with ❤️ for software security.
