
Elasticsearch MCP Server

2025.04.23
1
PythonElasticsearch 接口数据库中间件数据库
Elasticsearch MCP Server 是一个基于 Model Context Protocol (MCP) 的服务器,专门用于与 Elasticsearch 集群进行交互。它提供了一系列工具和资源,帮助用户管理和查询 Elasticsearch 集群中的数据。
View on GitHub
Overview
基本能力
产品定位
Elasticsearch MCP Server 是一个中间件服务,旨在简化与 Elasticsearch 集群的交互,提供标准化的接口和工具集。
核心功能
- 索引管理:
- 列出集群中的所有索引
- 获取特定索引的映射信息
-
获取特定索引的统计信息
-
搜索功能:
- 使用查询 DSL 进行搜索
-
使用简单查询字符串进行搜索
-
资源访问:
- 通过标准化的 URI 访问 Elasticsearch 资源
- 提供详细的索引信息和映射信息
适用场景
- 需要与 Elasticsearch 集群进行交互的应用程序
- 需要标准化 Elasticsearch 访问接口的开发项目
- 需要简化 Elasticsearch 查询和管理操作的工具
工具列表
list_indices
:列出 Elasticsearch 集群中的所有索引get_mappings
:获取特定索引的映射信息search
:使用查询 DSL 进行搜索search_with_query_string
:使用简单查询字符串进行搜索get_index_stats
:获取特定索引的统计信息
常见问题解答
- 如何设置环境变量?
- 复制
.env.example
文件为.env
并编辑 -
或者直接在 shell 中设置
ES_CLOUD_ID
和ES_API_KEY
-
如何测试 MCP 资源?
- 使用提供的测试脚本
test_es_mcp.sh
- 或者手动启动服务器并使用
access_mcp_resource
工具
使用教程
使用依赖
- Python 3.7+
- Elasticsearch Python 客户端
- MCP SDK
- Elasticsearch 集群凭证(Cloud ID 和 API Key)
安装依赖命令:
pip install -r requirements.txt
安装教程
- 克隆仓库:
git clone https://github.com/yourusername/elasticsearch-mcp-server.git
cd elasticsearch-mcp-server
- 设置环境变量:
export ES_CLOUD_ID=your_elasticsearch_cloud_id
export ES_API_KEY=your_elasticsearch_api_key
- 配置 MCP 服务器:
python configure_mcp_server.py your_cloud_id your_api_key
调试方式
- 启动 MCP 服务器:
ES_CLOUD_ID=your_cloud_id ES_API_KEY=your_api_key python es_mcp_server.py
- 测试资源访问:
<access_mcp_resource>
<server_name>elasticsearch-mcp-server</server_name>
<uri>elasticsearch://indices</uri>
</access_mcp_resource>
- 使用测试脚本:
ES_CLOUD_ID=your_cloud_id ES_API_KEY=your_api_key ./test_es_mcp.sh