Skip to main content
Glama
cyberbalsa

OpenSearch MCP Server

by cyberbalsa
README.md
# OpenSearch MCP Server

A Model Context Protocol (MCP) server for querying and analyzing Wazuh security logs stored in OpenSearch.

## Features

- Search for security alerts with advanced filtering
- Get detailed information about specific alerts
- Generate statistics on security events
- Visualize alert trends over time
- Progress reporting for long-running operations
- Structured error handling

## Prerequisites

- Node.js v16 or higher
- Access to an OpenSearch instance containing Wazuh security logs

## Installation

### Option 1: Use with npx directly from GitHub (recommended)

You can run this tool directly using npx without cloning the repository:

```bash
# 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
```

### Option 2: Local Installation

1. Clone this repository:
```bash
git clone https://github.com/jetbalsa/mcp-opensearch-js.git
cd mcp-opensearch-js
```

2. Install dependencies:
```bash
npm install
```

3. Configure your environment variables:
```bash
cp .env.example .env
```

4. Edit the `.env` file with your OpenSearch connection details:
```
OPENSEARCH_URL=https://your-opensearch-endpoint:9200
OPENSEARCH_USERNAME=your-username
OPENSEARCH_PASSWORD=your-password
DEBUG=false
```

## Running the Server

### Start the server:

```bash
npm start
```

This will start the server in stdio mode.

### Enable debug logging:

```bash
npm run stdio:debug
```

### Test with MCP CLI:

```bash
npm run dev
```

This runs the server with the FastMCP CLI tool for interactive testing.

### Test with MCP Inspector:

```bash
npm run inspect
```

This starts the server and connects it to the MCP Inspector for visual debugging.

## Server Tools

The server provides the following tools:

### 1. Search Alerts

Search for security alerts in Wazuh data.

**Parameters:**
- `query`: The search query text
- `timeRange`: Time range (e.g., 1h, 24h, 7d)
- `maxResults`: Maximum number of results to return
- `index`: Index pattern to search

### 2. Get Alert Details

Get detailed information about a specific alert by ID.

**Parameters:**
- `id`: The alert ID
- `index`: Index pattern

### 3. Alert Statistics

Get statistics about security alerts.

**Parameters:**
- `timeRange`: Time range (e.g., 1h, 24h, 7d)
- `field`: Field to aggregate by (e.g., rule.level, agent.name)
- `index`: Index pattern

### 4. Visualize Alert Trend

Visualize alert trends over time.

**Parameters:**
- `timeRange`: Time range (e.g., 1h, 24h, 7d)
- `interval`: Time interval for grouping (e.g., 1h, 1d)
- `query`: Query to filter alerts
- `index`: Index pattern

## Example Usage

Using the MCP CLI tool:

```
> 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)
```

## Using with a Client

To use this MCP server with a client implementation:

```javascript
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);
```

## License

MIT

TDQS

B3.2/5.0

Scored across 9 tools

Disambiguation4/5

Most tools have distinct purposes, but 'searchAlerts' and 'searchLogs' could be confused as both involve searching, though they target different data types (alerts vs. logs). The descriptions clarify this distinction, but the overlap in naming might cause initial ambiguity for an agent.

Naming Consistency3/5

The naming is mixed with some tools using verb_noun patterns (e.g., 'listIndexes', 'searchAlerts') and others using noun_verb or descriptive phrases (e.g., 'alertStatistics', 'exploreFieldValues'). This inconsistency makes the set less predictable, though the names remain readable overall.

Tool Count5/5

With 9 tools, the count is well-scoped for an OpenSearch server, covering key operations like listing, searching, monitoring, and visualizing data. Each tool appears to serve a specific function without redundancy, fitting the domain appropriately.

Completeness4/5

The tool set covers core OpenSearch and Wazuh security alert functionalities, including listing, searching, monitoring, and visualization. Minor gaps might exist, such as lack of CRUD operations for indexes or alerts (e.g., create/update/delete), but agents can likely work around this for common use cases.

Maintenance

ActivityInactive
ResponsivenessNo issues