Skip to main content
Glama
OpenSearch Logs MCP Server

OpenSearch Logs MCP Server

OpenSearch Logs MCP Server

MCP (Model Context Protocol) server para consultar logs de OpenTelemetry en OpenSearch. Soporta ambientes de desarrollo (dev) y producción (prod).

Arquitectura

El servidor sigue los principios SOLID y Clean Architecture:

src/
├── index.ts                     # Entry point
├── server.ts                    # MCP Server setup
├── config/
│   └── environments.ts          # Environment configuration
├── types/
│   └── index.ts                 # Type definitions
├── services/
│   ├── opensearch-client.ts     # HTTP client for OpenSearch
│   └── log-search.service.ts    # Business logic
├── tools/
│   ├── tool-definitions.ts      # Tool schemas
│   └── tool-handlers.ts         # Tool execution
└── utils/
    ├── query-builder.ts         # Query construction (Builder pattern)
    └── time-range.ts            # Time utilities

Principios Aplicados

  • Single Responsibility (SRP): Cada módulo tiene una única responsabilidad

  • Open/Closed (OCP): Fácil agregar nuevas herramientas sin modificar código existente

  • Dependency Inversion (DIP): Los servicios dependen de abstracciones (interfaces)

  • Builder Pattern: QueryBuilder para construcción fluida de queries

Related MCP server: datadog-logs-mcp

Instalación

cd Tools/mcp-opensearch-logs
npm install
npm run build

Configuración en Cursor

Agrega esto a tu configuración de Cursor (~/.cursor/mcp.json):

{
  "mcpServers": {
    "opensearch-logs": {
      "command": "node",
      "args": ["/ruta/al/proyecto/Tools/mcp-opensearch-logs/dist/index.js"],
      "env": {
        "OPENSEARCH_DEV_USERNAME": "tu-usuario-dev",
        "OPENSEARCH_DEV_PASSWORD": "tu-password-dev",
        "OPENSEARCH_PROD_USERNAME": "tu-usuario-prod",
        "OPENSEARCH_PROD_PASSWORD": "tu-password-prod"
      }
    }
  }
}

Herramientas Disponibles

search_logs

Búsqueda libre con sintaxis Lucene.

Parámetro

Tipo

Requerido

Descripción

environment

dev | prod

✅

Ambiente a consultar

query

string

✅

Query en sintaxis Lucene

timeRange

15m | 1h | 6h | 24h | 7d

❌

Rango de tiempo (default: 1h)

size

number

❌

Máximo de resultados (default: 50, max: 200)

Ejemplos:

  • "Busca logs que contengan 'error' en dev de la última hora"

  • "Busca logs con status 500 en prod de las últimas 6 horas"

search_by_trace

Busca todos los logs de un trace de OpenTelemetry.

Parámetro

Tipo

Requerido

Descripción

environment

dev | prod

✅

Ambiente a consultar

traceId

string

✅

ID del trace

size

number

❌

Máximo de resultados (default: 100)

Ejemplo:

  • "Dame todos los logs del trace abc123 en dev"

search_by_service

Filtra logs por nombre de servicio.

Parámetro

Tipo

Requerido

Descripción

environment

dev | prod

✅

Ambiente a consultar

serviceName

string

✅

Nombre del servicio

level

DEBUG | INFO | WARN | ERROR | FATAL

❌

Nivel de log

query

string

❌

Query adicional

timeRange

string

❌

Rango de tiempo

size

number

❌

Máximo de resultados

Ejemplos:

  • "Busca logs del servicio stori-ios en prod"

  • "Dame los errores del servicio stori-ios en dev"

search_errors

Busca logs de nivel ERROR o superior (severityNumber >= 17).

Parámetro

Tipo

Requerido

Descripción

environment

dev | prod

✅

Ambiente a consultar

serviceName

string

❌

Filtrar por servicio

query

string

❌

Query adicional

timeRange

string

❌

Rango de tiempo

size

number

❌

Máximo de resultados

Ejemplos:

  • "Dame los errores de la última hora en prod"

  • "Busca errores relacionados con KYC en dev"

get_field_values

Obtiene los valores más comunes de un campo (agregación).

Parámetro

Tipo

Requerido

Descripción

environment

dev | prod

✅

Ambiente a consultar

field

string

✅

Campo a agregar

size

number

❌

Máximo de valores únicos (default: 20)

Ejemplos:

  • "Qué valores tiene el campo 'event' en prod?"

  • "Dame los tipos de error más comunes en dev"

search_by_field

Busca por un campo y valor específico.

Parámetro

Tipo

Requerido

Descripción

environment

dev | prod

✅

Ambiente a consultar

field

string

✅

Nombre del campo

value

string

✅

Valor a buscar

timeRange

string

❌

Rango de tiempo

size

number

❌

Máximo de resultados

Ejemplo:

  • "Busca logs con transactionId=abc123 en prod"

get_mapping

Obtiene el mapeo de campos del índice.

Parámetro

Tipo

Requerido

Descripción

environment

dev | prod

✅

Ambiente a consultar

Ejemplo:

  • "Qué campos están disponibles en los logs de prod?"

get_sample_log

Obtiene un log de ejemplo para ver la estructura.

Parámetro

Tipo

Requerido

Descripción

environment

dev | prod

✅

Ambiente a consultar

Ejemplo:

  • "Dame un ejemplo de log de prod para ver la estructura"

Sintaxis de Búsqueda Lucene

El campo query soporta sintaxis Lucene completa:

Sintaxis

Descripción

Ejemplo

término

Busca en cualquier campo

error

campo:valor

Busca en campo específico

event:kyc_error

campo:*valor*

Wildcard

errorMessage:*timeout*

AND

Ambos términos

error AND authentication

OR

Cualquier término

error OR warning

NOT

Excluye término

NOT debug

[a TO b]

Rango

statusCode:[400 TO 499]

"frase exacta"

Match exacto

"connection refused"

Rangos de Tiempo

Valor

Descripción

15m

Últimos 15 minutos

1h

Última hora (default)

6h

Últimas 6 horas

24h

Últimas 24 horas

7d

Últimos 7 días

Desarrollo

# Desarrollo con watch mode
npm run dev

# Build
npm run build

# Lint
npm run lint

Estructura de Logs OpenTelemetry

Los logs siguen el esquema OpenTelemetry:

{
  "time": "2024-01-15T10:30:00.000Z",
  "severityText": "ERROR",
  "severityNumber": 17,
  "body": "Error message",
  "attributes": {
    "event": "kyc_error",
    "kycFlow": "creditL1",
    "transactionId": "abc123"
  },
  "resource": {
    "service.name": "stori-ios",
    "service.version": "1.0.0"
  }
}

Available Tools

8 tools
get_field_valuesB

Get the most common values for a specific field. Useful for discovering available services, log levels, or other field values.

NameRequiredDescriptionDefault
environmentYesEnvironment to search: 'dev'/'prod' (iOS) or 'android-dev'/'android-prod' (Android)
fieldYesThe field to get values for. Examples: 'service.name', 'level', 'host.name'
sizeNoMaximum number of unique values to return (default: 20)
get_mappingA

Get the field mapping for the index. Useful for discovering available fields and their types.

NameRequiredDescriptionDefault
environmentYesEnvironment to search: 'dev'/'prod' (iOS) or 'android-dev'/'android-prod' (Android)
get_sample_logB

Get a single sample log entry to see the structure and available fields.

NameRequiredDescriptionDefault
environmentYesEnvironment to search: 'dev'/'prod' (iOS) or 'android-dev'/'android-prod' (Android)
search_by_fieldC

Search logs by a specific field and value.

NameRequiredDescriptionDefault
environmentYesEnvironment to search: 'dev'/'prod' (iOS) or 'android-dev'/'android-prod' (Android)
fieldYesThe field name to search. Examples: 'user_id', 'request_id', 'endpoint'
valueYesThe value to search for
timeRangeNoTime range to search within
sizeNoMaximum number of results to return (default: 50)
search_by_serviceC

Search logs filtered by service name, optionally with additional filters.

NameRequiredDescriptionDefault
environmentYesEnvironment to search: 'dev'/'prod' (iOS) or 'android-dev'/'android-prod' (Android)
serviceNameYesThe service name to filter by
levelNoLog level to filter by
queryNoAdditional free-text query to apply
timeRangeNoTime range to search within
sizeNoMaximum number of results to return (default: 50)
search_by_traceA

Search logs by OpenTelemetry trace ID to see all logs related to a specific request/transaction.

NameRequiredDescriptionDefault
environmentYesEnvironment to search: 'dev'/'prod' (iOS) or 'android-dev'/'android-prod' (Android)
traceIdYesThe OpenTelemetry trace ID to search for
sizeNoMaximum number of results to return (default: 100)
search_errorsC

Search for error logs, optionally filtered by service or additional query.

NameRequiredDescriptionDefault
environmentYesEnvironment to search: 'dev'/'prod' (iOS) or 'android-dev'/'android-prod' (Android)
serviceNameNoOptional service name to filter by
queryNoAdditional free-text query to apply
timeRangeNoTime range to search within (default: 1h)
sizeNoMaximum number of results to return (default: 50)
search_logsA

Search OpenSearch logs with a free-text query. Supports Lucene query syntax. Examples: 'error AND authentication', 'status:500', 'message:timeout'

NameRequiredDescriptionDefault
environmentYesEnvironment to search: 'dev'/'prod' (iOS) or 'android-dev'/'android-prod' (Android)
queryYesFree-text search query using Lucene syntax. Examples: 'error', 'status:500 AND service.name:auth'
timeRangeNoTime range to search within. Defaults to 1h if not specified.
sizeNoMaximum number of results to return (default: 50, max: 200)

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 8 tool updatesv1.0.0
    • First observedget_field_values
    • First observedget_mapping
    • First observedget_sample_log
    • First observedsearch_by_field
    • First observedsearch_by_service
    • First observedsearch_by_trace
    • First observedsearch_errors
    • First observedsearch_logs

TDQS

A3.5/5.0

Scored across 8 tools

Disambiguation4/5

Most tools have distinct purposes, but there is some overlap between search_by_field, search_by_service, search_errors, and search_logs, which could cause confusion about which to use for specific filtering needs. However, the descriptions clarify their specialized roles, such as search_by_service for service filtering and search_errors for error-specific queries, reducing ambiguity.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern with snake_case, such as get_field_values, search_by_trace, and search_logs. This uniformity makes the tool set predictable and easy to understand, enhancing usability for agents.

Tool Count5/5

With 8 tools, the server is well-scoped for log analysis in OpenSearch, covering essential operations like discovery (get_field_values, get_mapping, get_sample_log) and various search methods. Each tool serves a clear purpose without feeling excessive or insufficient for the domain.

Completeness4/5

The tool set provides strong coverage for log querying and discovery, including field analysis, sample inspection, and multiple search types. A minor gap is the lack of tools for log management operations like deleting or exporting logs, but core workflows for analysis are well-supported.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables querying and searching logs from Kibana (ELK stack) via MCP, with support for project-based data views, trace ID correlation, and log expansion.
    -
  • A
    license
    A
    quality
    A
    maintenance
    Enables AI agents to search and analyze SAP Commerce Cloud (CCv2) runtime logs via OpenSearch Dashboards using a session cookie, providing read-only tools for full-text search and error aggregation.
    3
    MIT