
Elasticsearch MCP Server

2025.04.14
7
TypeScriptElasticsearch 连接器自然语言查询数据库管理数据库
Elasticsearch MCP Server 是一个通过 Model Context Protocol (MCP) 连接 Elasticsearch 集群的服务,允许用户通过自然语言对话与 Elasticsearch 索引进行交互。它支持多种 Elasticsearch 操作,如列出索引、获取映射、执行搜索等,适用于需要高效管理和查询 Elasticsearch 数据的场景。
View on GitHub
Overview
基本能力
产品定位
Elasticsearch MCP Server 是一个中间件服务,旨在通过 MCP 协议将 Elasticsearch 集群的功能暴露给各种 MCP 客户端(如 Claude Desktop、Cursor),使用户能够通过自然语言与 Elasticsearch 数据进行交互。
核心功能
list_indices
: 列出可用的 Elasticsearch 索引,支持正则表达式get_mappings
: 获取特定 Elasticsearch 索引的字段映射search
: 使用提供的查询 DSL 执行 Elasticsearch 搜索elasticsearch_health
: 获取 Elasticsearch 集群健康状态,可选包括索引级详细信息create_index
: 创建 Elasticsearch 索引,可选设置和映射create_mapping
: 为 Elasticsearch 索引创建或更新映射结构bulk
: 批量导入数据到 Elasticsearch 索引reindex
: 将数据从源索引重新索引到目标索引,可选查询和脚本create_index_template
: 创建或更新索引模板get_index_template
: 获取索引模板信息delete_index_template
: 删除索引模板
适用场景
- 需要快速查询和管理 Elasticsearch 数据的开发者和数据分析师
- 希望通过自然语言与 Elasticsearch 交互的非技术用户
- 需要批量操作 Elasticsearch 索引的场景
- 需要监控 Elasticsearch 集群健康状况的场景
工具列表
- MCP Inspector: 用于调试和分析请求的工具,可以启动代理服务器并监听端口
常见问题解答
- 必须提供 API key 或用户名和密码进行认证
- 需要配置 Elasticsearch 实例的 URL
- 支持自定义 CA 证书用于 SSL/TLS 连接
使用教程
使用依赖
- Elasticsearch 实例
- Elasticsearch 认证凭证(API key 或用户名/密码)
- MCP 客户端(如 Claude Desktop、Cursor)
安装教程
使用 NPM 包
- 配置 MCP 客户端
- 打开 MCP 客户端
- 转到 Settings > Developer > MCP Servers
-
点击
Edit Config
并添加以下配置:json { "mcpServers": { "elasticsearch-mcp": { "command": "npx", "args": [ "-y", "@awesome-ai/elasticsearch-mcp" ], "env": { "HOST": "your-elasticsearch-host", "API_KEY": "your-api-key" } } } }
-
开始对话
- 在 MCP 客户端中打开新对话
- MCP 服务器应自动连接
- 现在可以询问关于 Elasticsearch 数据的问题
本地开发
-
使用正确的 Node.js 版本
bash nvm use
-
安装依赖
bash npm install
-
构建项目
bash npm run build
-
在 Claude Desktop App 中本地运行
- 配置 MCP 服务器如下:
json { "mcpServers": { "elasticsearch-mcp": { "command": "node", "args": [ "/path/to/your/project/dist/index.js" ], "env": { "HOST": "your-elasticsearch-host", "API_KEY": "your-api-key" } } } }
调试方式
HOST=your-elasticsearch-url API_KEY=your-api-key npm run inspector
这将启动 MCP Inspector,允许调试和分析请求。您应该看到:
Starting MCP inspector...
Proxy server listening on port 3000
🔍 MCP Inspector is up and running at http://localhost:5173 🚀