Elasticsearch MCP Server

Elasticsearch MCP Server

site icon
2025.04.23 1
PythonElasticsearch 接口数据库中间件数据库
Elasticsearch MCP Server 是一个基于 Model Context Protocol (MCP) 的服务器,专门用于与 Elasticsearch 集群进行交互。它提供了一系列工具和资源,帮助用户管理和查询 Elasticsearch 集群中的数据。
View on GitHub

Overview

基本能力

产品定位

Elasticsearch MCP Server 是一个中间件服务,旨在简化与 Elasticsearch 集群的交互,提供标准化的接口和工具集。

核心功能

  1. 索引管理
  2. 列出集群中的所有索引
  3. 获取特定索引的映射信息
  4. 获取特定索引的统计信息

  5. 搜索功能

  6. 使用查询 DSL 进行搜索
  7. 使用简单查询字符串进行搜索

  8. 资源访问

  9. 通过标准化的 URI 访问 Elasticsearch 资源
  10. 提供详细的索引信息和映射信息

适用场景

  1. 需要与 Elasticsearch 集群进行交互的应用程序
  2. 需要标准化 Elasticsearch 访问接口的开发项目
  3. 需要简化 Elasticsearch 查询和管理操作的工具

工具列表

  1. list_indices:列出 Elasticsearch 集群中的所有索引
  2. get_mappings:获取特定索引的映射信息
  3. search:使用查询 DSL 进行搜索
  4. search_with_query_string:使用简单查询字符串进行搜索
  5. get_index_stats:获取特定索引的统计信息

常见问题解答

  1. 如何设置环境变量?
  2. 复制 .env.example 文件为 .env 并编辑
  3. 或者直接在 shell 中设置 ES_CLOUD_IDES_API_KEY

  4. 如何测试 MCP 资源?

  5. 使用提供的测试脚本 test_es_mcp.sh
  6. 或者手动启动服务器并使用 access_mcp_resource 工具

使用教程

使用依赖

  1. Python 3.7+
  2. Elasticsearch Python 客户端
  3. MCP SDK
  4. Elasticsearch 集群凭证(Cloud ID 和 API Key)

安装依赖命令:

pip install -r requirements.txt

安装教程

  1. 克隆仓库:
git clone https://github.com/yourusername/elasticsearch-mcp-server.git
cd elasticsearch-mcp-server
  1. 设置环境变量:
export ES_CLOUD_ID=your_elasticsearch_cloud_id
export ES_API_KEY=your_elasticsearch_api_key
  1. 配置 MCP 服务器:
python configure_mcp_server.py your_cloud_id your_api_key

调试方式

  1. 启动 MCP 服务器:
ES_CLOUD_ID=your_cloud_id ES_API_KEY=your_api_key python es_mcp_server.py
  1. 测试资源访问:
<access_mcp_resource>
<server_name>elasticsearch-mcp-server</server_name>
<uri>elasticsearch://indices</uri>
</access_mcp_resource>
  1. 使用测试脚本:
ES_CLOUD_ID=your_cloud_id ES_API_KEY=your_api_key ./test_es_mcp.sh

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。