Skip to content

Conversation

@nullren
Copy link

@nullren nullren commented Dec 15, 2025

Summary

Adds support for querying Elasticsearch datasources through the MCP server, implementing the feature requested in #283.

Features

  • New query_elasticsearch tool that supports:
    • Lucene query syntax for simple queries (e.g., status:200 AND host:server1)
    • Elasticsearch Query DSL JSON for complex queries with aggregations
    • Time range filtering using RFC3339 format
    • Configurable result limits (default: 10, max: 100)
    • Returns documents with index, ID, source fields, and optional relevance score

Changes

  • Add tools/elasticsearch.go with ElasticsearchClient and query implementation
  • Add tools/elasticsearch_test.go with integration tests
  • Update cmd/mcp-grafana/main.go to register Elasticsearch tools
  • Add --disable-elasticsearch flag for selective tool disabling
  • Update README.md with comprehensive Elasticsearch documentation

Implementation

  • Follows the same patterns as existing Prometheus and Loki datasource integrations for consistency
  • Uses Grafana's datasource proxy endpoint (/api/datasources/proxy/uid/{uid})
  • Properly handles TLS configuration and authentication
  • Includes proper error handling and validation

Testing

  • Added integration tests following the existing test patterns
  • Tests cover basic queries, time range filtering, Lucene syntax, empty results, and error cases

Documentation

Updated README.md with:

  • Elasticsearch in the Features section
  • Elasticsearch in the Datasources supported types
  • New Elasticsearch Querying section
  • query_elasticsearch tool in the Tools table with RBAC permissions
  • --disable-elasticsearch flag in CLI flags reference

Fixes #283

Add support for querying Elasticsearch datasources through the MCP server.

Features:
- New query_elasticsearch tool that supports:
  - Lucene query syntax for simple queries
  - Elasticsearch Query DSL JSON for complex queries
  - Time range filtering using RFC3339 format
  - Configurable result limits (default: 10, max: 100)
  - Returns documents with index, ID, source fields, and optional score

Changes:
- Add tools/elasticsearch.go with ElasticsearchClient and query implementation
- Add tools/elasticsearch_test.go with integration tests
- Update cmd/mcp-grafana/main.go to register Elasticsearch tools
- Add --disable-elasticsearch flag for selective tool disabling
- Update README.md with Elasticsearch documentation in:
  - Features section
  - Datasources section
  - Tools table with RBAC permissions
  - CLI flags reference

Implementation follows the same patterns as existing Prometheus and Loki
datasource integrations for consistency.

Fixes grafana#283
@nullren nullren requested a review from a team as a code owner December 15, 2025 20:08
@CLAassistant
Copy link

CLAassistant commented Dec 15, 2025

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Elasticsearch support

2 participants