OpenSearch MCP服务器
用于查询和分析OpenSearch中存储的Wazuh安全日志的模型上下文协议(MCP)服务器。
特性
- 使用高级过滤搜索安全警报
- 获取有关特定警报的详细信息
- 生成安全事件的统计数据
- 可视化随时间变化的警报趋势
- 长期运行操作的进度报告
- 结构化错误处理
先决条件
- Node.js v16或更高版本
- 访问包含Wazuh安全日志的OpenSearch实例
安装
选项1:直接从GitHub与npx一起使用(推荐)
您可以直接使用npx运行此工具,而无需克隆存储库:
# Run the latest version from GitHub
npx github:jetbalsa/mcp-opensearch-js
# Run with debug mode enabled
npx github:jetbalsa/mcp-opensearch-js --debug
# You can also specify a specific branch or commit
npx github:jetbalsa/mcp-opensearch-js#main选项2:本地安装
- 克隆此存储库:
git clone https://github.com/jetbalsa/mcp-opensearch-js.git
cd mcp-opensearch-js- 安装依赖项:
npm install- 配置环境变量:
cp .env.example .env- 编辑
.env包含您的OpenSearch连接详细信息的文件:
OPENSEARCH_URL=https://your-opensearch-endpoint:9200
OPENSEARCH_USERNAME=your-username
OPENSEARCH_PASSWORD=your-password
DEBUG=false运行服务器
启动服务器:
npm start这将以stdio模式启动服务器。
启用调试日志记录:
npm run stdio:debug使用MCP CLI进行测试:
npm run dev这将使用FastMCP CLI工具运行服务器以进行交互式测试。
MCP检验员测试:
npm run inspect这将启动服务器并将其连接到MCP检查器进行可视化调试。
服务器工具
服务器提供以下工具:
1.搜索提醒
在Wazuh数据中搜索安全警报。
参数:
query:搜索查询文本timeRange:时间范围(例如1小时、24小时、7天)maxResults:要返回的最大结果数index:要搜索的索引模式
2.获取警报详细信息
按ID获取特定警报的详细信息。
参数:
id:警报IDindex:索引模式
3.警报统计
获取有关安全警报的统计信息。
参数:
timeRange:时间范围(例如1小时、24小时、7天)field:要聚合的字段(例如rule.level、agent.name)index:索引模式
4.可视化警报趋势
可视化随时间变化的警报趋势。
参数:
timeRange:时间范围(例如1小时、24小时、7天)interval:分组时间间隔(如1h、1d)query:查询以筛选警报index:索引模式
示例用法
使用MCP CLI工具:
> tools
Available tools:
- searchAlerts: Search for security alerts in Wazuh data
- getAlertDetails: Get detailed information about a specific alert by ID
- alertStatistics: Get statistics about security alerts
- visualizeAlertTrend: Visualize alert trends over time
> tools.searchAlerts(query: "rule.level:>10", timeRange: "12h", maxResults: 5)与客户端一起使用
要将此MCP服务器与客户端实现一起使用:
import { Client } from "@modelcontextprotocol/sdk";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
const client = new Client(
{
name: "example-client",
version: "1.0.0",
},
{
capabilities: {},
},
);
const transport = new SSEClientTransport(new URL(`http://localhost:3000/sse`));
await client.connect(transport);
// Use tools
const result = await client.executeTool("searchAlerts", {
query: "rule.level:>10",
timeRange: "24h",
maxResults: 10
});
console.log(result);许可证
麻省理工学院
