返回市场
弹性搜索7-MCP服务器

弹性搜索7-MCP服务器

作者:imlewc6 星标更新:2025-05-30

项目介绍

【技术文档摘要】: MseeP.ai 安全评估徽章

Elasticsearch 7.x MCP 服务器

smithery 徽章

这是一个与Elasticsearch 7.x版本兼容的MCP服务器。

<a href="https://glama.ai/mcp/servers/zxwxozvlme"> <img width="380" height="200" src="https://gips1.baidu.com/it/u=983903062,720203676&fm=3081&app=3081&f=PNG?w=760&h=400" alt="Elasticsearch 7.x 服务器 MCP 服务器" /> </a>

功能

  • 提供与Elasticsearch 7.x交互的MCP协议接口
  • 支持基本的Elasticsearch操作(ping、info等)
  • 支持完整的搜索功能,包括聚合查询、高亮显示、排序和其他高级功能
  • 通过任何MCP客户端轻松访问Elasticsearch的功能

要求

  • Python 3.10+
  • Elasticsearch 7.x(推荐7.17.x)

安装

通过Smithery安装

要通过Smithery自动安装Elasticsearch 7.x MCP服务器到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

  1. 创建一个.env文件并设置ELASTIC_PASSWORD
ELASTIC_PASSWORD=your_secure_password
  1. 启动服务:
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示例

基本搜索

# 基本搜索
search_response = client.call("es-search", {
    "index": "my_index",
    "query": {
        "match": {
            "title": "搜索关键词"
        }
    },
    "size": 1
0,
    "from": 0
})

聚合查询

# 聚合查询
agg_response = client.call("es-search", {
    "index": "my_index",
    "size": 0,  # 只需聚合结果,无需文档
    "aggs": {
        "categories": {
            "terms": {
                "field": "category.keyword",
                "size": 10
            }
        },
        "avg_price": {
            "avg": {
                "field": "price"
            }
        }
    }
})

高级搜索

# 高级搜索,带有高亮显示、排序和过滤
advanced_response = client.call("es-search", {
    "index": "my_index",
    "query": {
        "bool": {
            "must": [
                {"match": {"content": "搜索词"}}
            ],
            "filter": [
                {"range": {"price": {"gte": 100, "lte": 200}}}
            ]
        }
    },
    "sort": [
        {"date": {"order": "desc"}},
        "_score"
    ],
    "highlight": {
        "fields": {
            "content": {}
        }
    },
    "_source": ["title", "date", "price"]
})

开发

  1. 克隆仓库
  2. 安装开发依赖
  3. 运行服务器:elasticsearch7-mcp-server

许可证

[许可证在LICENSE文件中]

中文文档