Elastic MCP Server

Elastic MCP Server

Provides comprehensive tools for managing Elasticsearch clusters, including security management, search operations, and index administration. It enables users to monitor cluster health, handle InfoSec tasks, and execute complex queries using Elasticsearch Query DSL and ES|QL.

Category
访问服务器

README

Elastic MCP Server

A comprehensive MCP (Model Context Protocol) server for Elasticsearch with InfoSec-focused tools for security management, search operations, index management, and cluster monitoring.

Features

  • Security Management: Users, roles, API keys, privileges
  • Search & Query: Full-text search, ES|QL, aggregations
  • Index Operations: List, create, delete, mappings, settings
  • Cluster Monitoring: Health, stats, nodes, shards
  • Cross-Platform: Works on Windows, macOS, and Linux

Quick Start

1. Install Dependencies

npm install

2. Configure Environment

Copy .env.example to .env and configure your Elasticsearch connection:

# macOS/Linux
cp .env.example .env

# Windows (Command Prompt)
copy .env.example .env

# Windows (PowerShell)
Copy-Item .env.example .env

Edit .env with your credentials:

# Elasticsearch endpoint
ELASTIC_URL=https://your-deployment.es.region.azure.elastic-cloud.com

# API Key authentication (recommended)
ELASTIC_API_KEY_ENCODED=your-base64-encoded-api-key

3. Build

npm run build

4. Run

npm start

Configuration

Environment Variables

Variable Required Description
ELASTIC_URL Yes Elasticsearch cluster URL
ELASTIC_API_KEY_ENCODED Yes* Pre-encoded API key (base64)
ELASTIC_API_KEY_ID Yes* API key ID (alternative to encoded)
ELASTIC_API_KEY_SECRET Yes* API key secret (use with ID)
ELASTIC_USERNAME Yes* Basic auth username
ELASTIC_PASSWORD Yes* Basic auth password
ELASTIC_SKIP_SSL_VERIFY No Skip SSL verification (default: false)
ELASTIC_TIMEOUT No Request timeout in ms (default: 30000)
LOG_LEVEL No Logging level (default: info)

*One authentication method is required: encoded API key, ID+secret, or username+password.

Authentication Methods

API Key (Recommended)

Use the pre-encoded API key from the Elasticsearch API key creation response:

ELASTIC_API_KEY_ENCODED=YWNCT3hKc0JjVEtMYUN5ZWVNa046UGR4OUxwOFRtY2R5WElfTjBvMEhrQQ==

Separate ID and Secret

If you have the raw ID and secret:

ELASTIC_API_KEY_ID=acBOxJsBcTKLaCyeeMkN
ELASTIC_API_KEY_SECRET=Pdx9Lp8TmcdyXI_N0o0HkA

Basic Auth (Not Recommended)

ELASTIC_USERNAME=elastic
ELASTIC_PASSWORD=your-password

Available Tools

Search Tools (5 tools)

Tool Description
search Execute search queries using Elasticsearch Query DSL
esql_query Execute ES|QL queries for data analysis
get_document Retrieve a specific document by ID
count Count documents matching a query
msearch Execute multiple search queries in one request

Security Tools (12 tools)

Tool Description
list_users List all users in the security realm
get_user Get detailed user information
create_user Create a new user with roles
delete_user Delete a user
set_user_enabled Enable or disable a user
list_roles List all defined roles
get_role Get role details
create_role Create or update a role
delete_role Delete a role
list_api_keys List API keys
create_api_key Create a new API key
invalidate_api_key Invalidate API keys
get_privileges Get current user privileges
has_privileges Check specific privileges
authenticate Get current authenticated user info

Index Tools (9 tools)

Tool Description
list_indices List all indices with health and stats
get_index Get index details
get_mappings Get field mappings
get_settings Get index settings
create_index Create a new index
delete_index Delete an index (requires confirmation)
refresh_index Refresh an index
get_index_stats Get index statistics
get_aliases Get index aliases

Cluster Tools (8 tools)

Tool Description
cluster_health Get cluster health status
cluster_stats Get comprehensive cluster statistics
cluster_info Get basic cluster info and version
nodes_info Get node information
nodes_stats Get node statistics
pending_tasks List pending cluster tasks
allocation_explain Explain shard allocation
get_shards Get shard allocation details

Usage Examples

Search for Security Events

{
  "tool": "search",
  "arguments": {
    "index": "logs-*",
    "query": {
      "bool": {
        "must": [
          { "match": { "event.category": "authentication" } },
          { "match": { "event.outcome": "failure" } }
        ]
      }
    },
    "size": 100,
    "sort": [{ "@timestamp": "desc" }]
  }
}

List All Users

{
  "tool": "list_users",
  "arguments": {}
}

Check Cluster Health

{
  "tool": "cluster_health",
  "arguments": {
    "level": "indices"
  }
}

Create an API Key

{
  "tool": "create_api_key",
  "arguments": {
    "name": "my-api-key",
    "expiration": "30d",
    "role_descriptors": {
      "read-only": {
        "cluster": ["monitor"],
        "indices": [{
          "names": ["logs-*"],
          "privileges": ["read"]
        }]
      }
    }
  }
}

Development

Run Tests

npm test

Run Tests with Coverage

npm run test:coverage

Lint

npm run lint

Watch Mode

npm run dev

Claude Desktop Integration

macOS / Linux

Config location: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or ~/.config/claude/claude_desktop_config.json (Linux)

{
  "mcpServers": {
    "elastic": {
      "command": "node",
      "args": ["/path/to/elastic-mcp/dist/index.js"],
      "env": {
        "ELASTIC_URL": "https://your-deployment.es.region.azure.elastic-cloud.com",
        "ELASTIC_API_KEY_ENCODED": "your-encoded-api-key"
      }
    }
  }
}

Windows

Config location: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "elastic": {
      "command": "node",
      "args": ["C:\\Users\\YourName\\elastic-mcp\\dist\\index.js"],
      "env": {
        "ELASTIC_URL": "https://your-deployment.es.region.azure.elastic-cloud.com",
        "ELASTIC_API_KEY_ENCODED": "your-encoded-api-key"
      }
    }
  }
}

Windows Notes:

  • Use double backslashes (\\) in JSON paths, or forward slashes (/) which also work
  • Ensure Node.js is installed and available in your PATH
  • Run npm install and npm run build before first use

Security Considerations

  • API keys are never logged or exposed in responses
  • All credentials must be provided via environment variables
  • SSL certificate verification is enabled by default
  • The delete_index tool requires explicit confirmation
  • Created API keys return the encoded value but not the raw secret

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选