Back to MCP directory
publicPublicdnsLocal runtime

jedrazb_elastic-semantic-search-mcp-server

该项目是一个基于Elasticsearch的语义搜索工具,用于对Search Labs博客文章进行语义检索,包含爬虫配置、索引映射更新和MCP服务器集成功能。

article

README

🚀 MCP 服务器:Elasticsearch 语义搜索工具

本项目提供了一个基于 Python 实现的 MCP 服务器,可借助 Search Labs 博客文章在 Elasticsearch 上开展语义搜索,助力高效信息检索。

🚀 快速开始

运行 MCP 服务器

ES_URLES_AP_KEY 添加到 .env 文件中(可查看 这里 以生成具有最小权限的 API 键)。

MCP 检查器 中启动服务器:

make dev

启动后,可访问 MCP 检查器:http://localhost:5173

与 Claude Desktop 集成

要将 MCP 服务器添加到 Claude Desktop 中,可执行以下命令:

make install-claude-config

此命令会更新您家目录中的 claude_desktop_config.json。下次重启时,Claude 应用程序会检测到该服务器并加载声明的工具。

📦 安装指南

爬取 Search Labs 博客文章

1. 验证爬虫配置

要检查 Elastic Open Crawler 是否正常工作,请运行以下命令:

docker run --rm \
  --entrypoint /bin/bash \
  -v "$(pwd)/crawler-config:/app/config" \
  --network host \
  docker.elastic.co/integrations/crawler:latest \
  -c "bin/crawler crawl config/test-crawler.yml"

该命令应输出从单个页面爬取的内容。

2. 配置 Elasticsearch

设置 Elasticsearch URL 和 API 键。生成具有 最小爬虫权限 的 API 键:

POST /_security/api_key
{
  "name": "crawler-search-labs",
  "role_descriptors": {
    "crawler-search-labs-role": {
      "cluster": ["monitor"],
      "indices": [
        {
          "names": ["*"],
          "privileges": ["read", "write"]
        }
      ]
    }
  },
  "managed": true
}

运行以下命令以获取 API 键:

curl -X GET http://localhost:9200/_security/api_key \
  -H 'Content-Type: application/json' \
  -d '{"name":"crawler-search-labs"}'

将返回的 api_keyid 添加到您的 .env 文件中:

ES_URL=http://localhost:9200
ES_AP_KEY=your_api_key_here
ES_AP_ID=your_api_id_here

3. 更新语义搜索索引映射

要启用 动态字段数据自动映射,请更新 Elasticsearch 索引映射:

curl -X PUT http://localhost:9200/search-labs/_mapping \
  -H 'Content-Type: application/json' \
  -d '{"dynamic": true}'

4. 开始爬取

使用以下命令开始爬取 Search Labs 博客文章:

python3 crawler.py --config config/crawler_config.yml

crawler_config.yml 示例内容如下:

start_url: "https://search-labs.com/blog"
output_file: "blog_posts.json"
concurrency: 5
max_depth: 2

5. 验证已索引文档

要验证博客文章是否正确索引,请运行以下命令:

curl -X GET http://localhost:9200/search-labs/_search \
  -H 'Content-Type: application/json' \
  -d '{"query":{"match_all":{}}}'

该命令将返回所有已索引的博客文章。

💻 使用示例

完整示例

创建 .env 文件

ES_URL=http://localhost:9200
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client