该项目实现了一个用于Elasticsearch的MCP(模型上下文协议)服务器,提供了与Elasticsearch集群交互的工具和资源。
list_indices: 列出Elasticsearch集群中的所有索引get_mappings: 获取特定索引的映射信息search: 使用提供的查询DSL执行Elasticsearch搜索search_with_query_string: 使用简单的查询字符串执行搜索get_index_stats: 获取特定索引的统计信息elasticsearch://indices: 列出所有Elasticsearch索引elasticsearch://index/{index_name}: 获取特定索引的详细信息elasticsearch://mapping/{index_name}: 获取特定索引的映射信息克隆仓库:
git clone https://github.com/yourusername/elasticsearch-mcp-server.git
cd elasticsearch-mcp-server
安装所需依赖项:
pip install -r requirements.txt
设置环境变量:
cp .env.example .env.env文件并添加您的Elasticsearch凭证或者在您的shell中直接设置它们:
export ES_CLOUD_ID=your_elasticsearch_cloud_id
export ES_API_KEY=your_elasticsearch_api_key
configure_mcp_server.py脚本帮助您在Claude的MCP设置文件中配置Elasticsearch MCP服务器。这允许Claude通过MCP服务器连接到您的Elasticsearch集群。
python configure_mcp_server.py your_cloud_id your_api_key
该脚本:
运行此脚本后,请重新启动VS Code以应用更改。Claude将能够使用Elasticsearch MCP服务器与您的Elasticsearch集群进行交互。
我们提供了一个测试脚本,它会启动MCP服务器并提供测试说明:
# 如果需要,使脚本可执行
chmod +x test_es_mcp.sh
# 运行测试脚本
ES_CLOUD_ID=your_cloud_id ES_API_KEY=your_api_key ./test_es_mcp.sh
该脚本将:
启动MCP服务器:
ES_CLOUD_ID=your_cloud_id ES_API_KEY=your_api_key python es_mcp_server.py
在Claude中,使用access_mcp_resource工具访问资源:
a. 列出所有索引:
<access_mcp_resource>
<server_name>elasticsearch-mcp-server</server_name>
<uri>elasticsearch://indices</uri>
</access_mcp_resource>
b. 获取特定索引的信息:
<access_mcp_resource>
<server_name>elasticsearch-mcp-server</server_name>
<uri>elasticsearch://index/your_index_name</uri>
</access_mcp_resource>
c. 获取特定索引的映射信息:
<access_mcp_resource>
<server_name>elasticsearch-mcp-server</server_name>
<uri>elasticsearch://mapping/your_index_name</uri>
</access_mcp_resource>
我们也提供了一个Python测试脚本,演示如何访问资源:
ES_CLOUD_ID=your_cloud_id ES_API_KEY=your_api_key python test_es_resources.py
elasticsearch://indices返回Elasticsearch集群中所有索引的JSON数组,包括:
elasticsearch://index/{index_name}返回特定索引的详细信息,包括:
elasticsearch://mapping/{index_name}返回特定索引的映射信息,包括:
所有资源都包含适当的错误处理和验证:
欢迎贡献!以下是贡献的方法:
git checkout -b feature/your-feature-namegit commit -am 'Add some feature'git push origin feature/your-feature-name本项目采用MIT许可证 - 详情见LICENSE文件。