](https://mseep.ai/app/imlewc-elasticsearch7-mcp-server)
Elasticsearch 7.x MCP服务器
](https://smithery.ai/server/@imlewc/elasticsearch7-mcp-server)
Elasticsearch7.x的MCP服务器,提供与Elasticsearch 7.x版本的兼容性。
特性
- 提供MCP协议接口,用于与Elasticsearch 7.x交互
- 支持基本的Elasticsearch操作(ping、info等)
- 支持完整的搜索功能,包括聚合查询、突出显示、排序和其他高级功能
- 通过任何MCP客户端轻松访问Elasticsearch功能
需求
- Python 3.10+
- Elasticsearch 7.x(推荐7.17.x)
安装
通过Smithery安装
通过以下方式自动安装Elasticsearch 7.x MCP Server for Claude Desktop 史密瑟里:
npx -y @smithery/cli install @imlewc/elasticsearch7-mcp-server --client claude手动安装
pip install -e .环境变量
服务器需要以下环境变量:
ELASTIC_HOST:Elasticsearch主机地址(例如。,http://localhost:9200)ELASTIC_USERNAME:Elasticsearch用户名ELASTIC_PASSWORD:Elasticsearch密码MCP_PORT:(可选)MCP服务器侦听端口,默认9999
使用Docker Compose
- 创建一个
.env文件和设置ELASTIC_PASSWORD:
ELASTIC_PASSWORD=your_secure_password- 启动服务:
docker-compose up -d这将启动一个三节点Elasticsearch 7.17.10集群、Kibana和MCP服务器。
使用MCP客户端
您可以使用任何MCP客户端连接到MCP服务器:
from mcp import MCPClient
client = MCPClient("localhost:9999")
response = client.call("es-ping")
print(response) # {"success": true}API文档
当前支持的MCP方法:
es-ping:检查Elasticsearch连接es-info:获取Elasticsearch集群信息es-search:在Elasticsearch索引中搜索文档
搜索API示例
基本搜索
# Basic search
search_response = client.call("es-search", {
"index": "my_index",
"query": {
"match": {
"title": "search keywords"
}
},
"size": 10,
"from": 0
})聚合查询
# Aggregation query
agg_response = client.call("es-search", {
"index": "my_index",
"size": 0, # Only need aggregation results, no documents
"aggs": {
"categories": {
"terms": {
"field": "category.keyword",
"size": 10
}
},
"avg_price": {
"avg": {
"field": "price"
}
}
}
})高级搜索
# Advanced search with highlighting, sorting, and filtering
advanced_response = client.call("es-search", {
"index": "my_index",
"query": {
"bool": {
"must": [
{"match": {"content": "search term"}}
],
"filter": [
{"range": {"price": {"gte": 100, "lte": 200}}}
]
}
},
"sort": [
{"date": {"order": "desc"}},
"_score"
],
"highlight": {
"fields": {
"content": {}
}
},
"_source": ["title", "date", "price"]
})发展
- 克隆存储库
- 安装开发依赖项
- 运行服务器:
elasticsearch7-mcp-server
许可证
\[许可证文件中的许可证\]
*中文文档*
