这是一个使用 AWS Athena 查询 Amazon Security Lake 数据的 MCP(模型上下文协议)服务器。该服务器提供了对存储在 Security Lake 中的 OCSF 标准化安全数据的结构化访问,使 AI 助手和应用程序能够搜索 IP 地址、GuardDuty 发现,并探索可用的数据源。
pip install amazon-security-lake-mcp
git clone <repository-url>
cd amazon-security-lake-mcp
pip install -e .
docker build -t amazon-security-lake-mcp .
docker run -it amazon-security-lake-mcp
MCP 服务器可以自动发现您的 Security Lake 资源!只需配置您的 AWS 凭据,服务器将找到:
最小配置:
# 只需提供 AWS 区域以启用自动发现
export ASL_MCP_AWS_REGION="us-east-1"
export ASL_MCP_AWS_PROFILE="your-aws-profile" # 如果使用默认凭据则可选
测试发现:
# 安装后测试资源发现
python -c "
from asl_mcp_server.aws.discovery import AWSResourceDiscovery
discovery = AWSResourceDiscovery('us-east-1')
print(discovery.get_discovery_summary())
"
如果您偏好手动配置或自动发现失败:
# 必需
export ASL_MCP_ATHENA_OUTPUT_LOCATION="s3://your-athena-results-bucket/path/"
# 可选(有默认值)
export ASL_MCP_AWS_REGION="us-east-1"
export ASL_MCP_AWS_PROFILE="your-aws-profile"
export ASL_MCP_SECURITY_LAKE_DATABASE="amazon_security_lake_glue_db"
export ASL_MCP_ATHENA_WORKGROUP="primary"
export ASL_MCP_AUTO_DISCOVER_RESOURCES="false" # 禁用自动发现
export ASL_MCP_LOG_LEVEL="INFO"
export ASL_MCP_MAX_QUERY_RESULTS="1000"
export ASL_MCP_QUERY_TIMEOUT_SECONDS="300"
在项目目录中创建一个 .env 文件:
# 最小配置(启用自动发现)
ASL_MCP_AWS_REGION=us-east-1
ASL_MCP_AWS_PROFILE=security-lake-user
# 或完整的手动配置
ASL_MCP_ATHENA_OUTPUT_LOCATION=s3://my-athena-results/
ASL_MCP_AWS_REGION=us-east-1
ASL_MCP_SECURITY_LAKE_DATABASE=amazon_security_lake_glue_db
ASL_MCP_AUTO_DISCOVER_RESOURCES=false
ASL_MCP_LOG_LEVEL=INFO
MCP 服务器需要以下 AWS 权限:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"athena:StartQueryExecution",
"athena:GetQueryExecution",
"athena:GetQueryResults",
"athena:ListDataCatalogs",
"athena:ListDatabases",
"athena:ListTableMetadata"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::aws-security-data-lake-*",
"arn:aws:s3:::aws-security-data-lake-*/*",
"arn:aws:s3:::your-athena-results-bucket",
"arn:aws:s3:::your-athena-results-bucket/*"
]
},
{
"Effect": "Allow",
"Action": [
"glue:GetDatabase",
"glue:GetTable",
"glue:GetPartitions"
],
"Resource": "*"
}
]
}
要将此 MCP 服务器与 Claude Desktop 结合使用,您需要在 Claude Desktop 的设置中进行配置。
选项 A:使用 pipx(推荐用于 Claude Desktop)
# 如果没有 pipx,请安装它
brew install pipx # macOS
# 或:pip install --user pipx # 其他系统
# 全局安装 MCP 服务器
pipx install amazon-security-lcp
# 或从源代码安装
git clone <repository-url>
cd amazon-security-lake-mcp
pipx install -e .
选项 B:使用 pip 和虚拟环境
# 创建虚拟环境
python3 -m venv asl-mcp-env
source asl-mcp-env/bin/activate # Linux/macOS
# 或:asl-mcp-env\Scripts\activate # Windows
# 安装包
pip install amazon-security-lake-mcp
查找已安装命令路径:
# 对于 pipx 安装
which asl-mcp-server
# 典型输出:/Users/username/.local/bin/asl-mcp-server
# 对于 pip 安装在 venv 中
which asl-mcp-server # (激活 venv 后)
将 MCP 服务器添加到您的 Claude Desktop 配置中。配置文件的位置取决于您的操作系统:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json选项 A:使用命令的完整路径(推荐)
{
"mcpServers": {
"amazon-security-lake": {
"command": "/Users/username/.local/bin/asl-mcp-server",
"env": {
"ASL_MCP_AWS_REGION": "us-east-1",
"ASL_MCP_AWS_PROFILE": "your-aws-profile",
"ASL_MCP_LOG_LEVEL": "INFO"
}
}
}
}
替换 /Users/username/.local/bin/asl-mcp-server 为实际路径 which asl-mcp-server 输出
选项 B:使用 Python 模块(最可靠)
{
"mcpServers": {
"amazon-security-lake": {
"command": "/opt/homebrew/bin/python3",
"args": ["-m", "asl_mcp_server.server"],
"cwd": "/path/to/amazon-security-lake-mcp",
"env": {
"ASL_MCP_AWS_REGION": "us-east-1",
"ASL_MCP_AWS_PROFILE": "your-aws-profile",
"PYTHONPATH": "/path/to/amazon-security-lake-mcp/src",
"ASL_MCP_LOG_LEVEL": "INFO"
}
}
}
}
选项 C:使用 Python 路径(如果未全局安装)
{
"mcpServers": {
"amazon-security-lake": {
"command": "python",
"args": ["-m", "asl_mcp_server.server"],
"cwd": "/path/to/amazon-security-lake-mcp",
"env": {
"ASL_MCP_AWS_REGION": "us-east-1",
"ASL_MCP_AWS_PROFILE": "your-aws-profile"
}
}
}
}
保存配置文件后,完全重启 Claude Desktop(退出并重新启动应用程序)。
在 Claude Desktop 中,您可以现在询问如下问题:
用户:你能帮我调查我在 AWS 环境中的安全事件吗?
Claude:我可以使用您的 Amazon Security Lake 数据来帮助您调查安全事件!让我先发现您的 Security Lake 资源,然后我们可以搜索特定的指标。
[Claude 使用 discover_aws_resources 工具]
我发现您的 Security Lake 设置如下:
- 数据库:amazon_security_lake_glue_db_us_east_1
- 区域:us-east-1
- Athena 结果:s3://aws-athena-query-results-123456789012-us-east-1/
您想调查什么?我可以:
1. 搜索特定的 IP 地址
2. 查找 GuardDuty 发现
3. 显示可用的数据源
4. 按时间段或严重级别搜索
用户:搜索与 IP 地址 203.0.113.45 相关的任何活动
Claude:[使用 search_ip_addresses 工具查询 Security Lake 数据]
我找到了涉及 IP 203.0.113.45 的 3 个安全事件:
...
考虑这些额外配置:
环境特定配置:
{
"mcpServers": {
"security-lake-prod": {
"command": "asl-mcp-server",
"env": {
"ASL_MCP_AWS_REGION": "us-east-1",
"ASL_MCP_AWS_PROFILE": "prod-security-readonly",
"ASL_MCP_MAX_QUERY_RESULTS": "500",
"ASL_MCP_QUERY_TIMEOUT_SECONDS": "180"
}
},
"security-lake-dev": {
"command": "asl-mcp-server",
"env": {
"ASL_MCP_AWS_REGION": "us-west-2",
"ASL_MCP_AWS_PROFILE": "dev-security",
"ASL_MCP_LOG_LEVEL": "DEBUG"
}
}
}
}
您也可以单独运行服务器进行测试:
# 使用已安装的命令
asl-mcp-server
# 或使用 Python 模块
python -m asl_mcp_server.server
在 Security Lake 数据中搜索 IP 地址:
{
"tool": "search_ip_addresses",
"arguments": {
"ip_address": "192.168.1.100",
"start_time": "2024-01-15T00:00:00Z",
"end_time": "2024-01-15T23:59:59Z",
"sources": ["guardduty", "cloudtrail"],
"limit": 100
}
}
参数:
ip_address(必需):要搜索的 IP 地址(IPv4 或 IPv6)start_time(可选):ISO 格式的开始时间(默认:7 天前)end_time(可选):ISO 格式的结束时间(默认:现在)sources(可选):要搜索的数据源(guardduty、cloudtrail、vpcflow 等)limit(可选):返回的最大结果数(默认:100,最大:1000)查询 GuardDuty 安全发现:
{
"tool": "search_guardduty_findings",
"arguments": {
"finding_id": "12345abc-def0-1234-5678-90abcdef1234",
"severity": "High",
"finding_type": "Trojan:EC2/MaliciousIP",
"start_time": "2024-01-15T00:00:00Z",
"end_time": "2024-01-15T23:59:59Z",
"limit": 50
}
}
参数:
finding_id(可选):特定的 GuardDuty 发现 IDseverity(可选):严重性级别(Critical、High、Medium、Low、Informational)finding_type(可选):要搜索的发现类型start_time(可选):ISO 格式的开始时间(默认:7 天前)end_time(可选):ISO 格式的结束时间(默认:现在)limit(可选):返回的最大结果数(默认:100,最大:1000)发现可用的 Security Lake 数据源:
{
"tool": "list_data_sources",
"arguments": {
"include_schema": true
}
}
参数:
include_schema(可选):是否包含详细的表模式信息(默认:false)自动发现您 AWS 账户中的 Security Lake 资源:
{
"tool": "discover_aws_resources",
"arguments": {}
}
此工具扫描您的 AWS 账户以找到:
智能搜索所有可用的 Security Lake 数据源:
{
"tool": "universal_security_search",
"arguments": {
"query_type": "findings",
"filters": {
"severity": "High",
"start_time": "2024-01-15T00:00:00Z",
"end_time": "2024-01-15T23:59:59Z"
},
"limit": 50
}
}
查询类型:
findings:搜索安全发现(GuardDuty、Security Hub)network:搜索网络活动(VPC 流、DNS、Route53)api_calls:搜索 API 活动(CloudTrail)ip_search:跨所有来源搜索 IP 地址关键特性:
验证与 AWS 服务的连接:
{
"tool": "test_connection",
"arguments": {}
}
所有工具均返回一致的响应格式:
{
"success": true,
"error": null,
"results": [...],
"metadata": {
"query_info": {...},
"summary": {...}
},
"count": 10
}
{
"success": true,
"results": [
{
"timestamp": "2024-01-15T10:30:00Z",
"event_type": "网络活动",
"severity": "中等",
"ip_context": {
"角色": "源",
"方向": "出站"
},
"network_info": {
"源 IP": "192.168.1.100",
"目标 IP": "203.0.113.45",
"源端口": 3456,
"目标端口": 443
},
"aws_context": {
"账户 ID": "123456789012",
"区域": "us-east-1"
},
"product_info": {
"名称": "VPC 流日志",
"供应商": "AWS"
}
}
],
"metadata": {
"summary": {
"总事件数": 1,
"最常见的事件类型": "网络活动",
"最高严重性": "中等"
}
},
"count": 1
}
# 克隆仓库
git clone <repository-url>
cd amazon-security-lake-mcp
# 安装开发依赖
pip install -e ".[dev]"
# 安装 pre-commit 钩子
pre-commit install
# 运行所有测试
pytest
# 运行带有覆盖率的测试
pytest --cov=asl_mcp_server --cov-report=html
# 运行特定测试类别
pytest -m unit # 仅单元测试