Simple MCP Client - 连接到 Elasticsearch MCP 并进行自然语言搜索

在我之前的文章 "将 agents 连接到 Elasticsearch 使用模型上下文协议 - docker",我展示了如何使用 Claude Desktop 来连接到 Elasticsearch MCP 并进行自然语言查询。由于一些原因,Claude Desktop 对中国的很多的开发者并不可用。我在另外的一篇文章 "如何在 vscode 里配置 MCP 并连接到 Elasticsearch" 里详述了如上在 vscode 里配置并连接到 Elasticsearch MCP 服务器。在今天的文章中,我讲使用一个自建的客户端来连接到 Elasticsearch MCP 服务器。Simple MCP client 是我们将要使用的客户端。

安装

我们首先参考文章 "将 agents 连接到 Elasticsearch 使用模型上下文协议 - docker" 来安装好自己的 Elasticsearch 及 Elasticsearch MCP 服务器。

部署 Simple MCP Client

我们首先使用如下的命令来下载代码:

复制代码
git clone https://github.com/jeffvestal/simple-mcp-client

我们进入到项目的根目录,然后运行如下的脚本来创建虚拟环境:

复制代码
 ./setup.sh 

$ ./setup.sh 
🤖 Simple MCP Client Setup
==========================
Detected OS: macos

📋 Checking prerequisites...
✅ Python 3.11.8 found
✅ Node.js v22.14.0 found
✅ npm 10.9.2 found

🐍 Setting up Backend...
------------------------
Creating Python virtual environment...
✅ Virtual environment created
Activating project virtual environment...
✅ Virtual environment activated
Upgrading pip...
Requirement already satisfied: pip in ./venv/lib/python3.11/site-packages (24.0)
Collecting pip
  Using cached pip-25.2-py3-none-any.whl.metadata (4.7 kB)
Using cached pip-25.2-py3-none-any.whl (1.8 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 24.0
    Uninstalling pip-24.0:
      Successfully uninstalled pip-24.0
Successfully installed pip-25.2
✅ pip upgraded
...

然后安装一个 js 包:

复制代码
sudo npm install vite
sudo npm install @vitejs/plugin-react
sudo npm install react@latest react-dom@latest
sudo npm install lucide-react
sudo npm install react-markdown
sudo npm install zustand
sudo npm install @radix-ui/react-toast @radix-ui/react-dialog @radix-ui/react-dropdown-menu @radix-ui/react-label @radix-ui/react-popover @radix-ui/react-scroll-area @radix-ui/react-select @radix-ui/react-slot @radix-ui/react-tabs @radix-ui/react-tooltip
sudo npm install react react-dom typescript vite @vitejs/plugin-react \
tailwindcss postcss autoprefixer class-variance-authority clsx \
lucide-react zustand \
@radix-ui/react-toast @radix-ui/react-dialog @radix-ui/react-dropdown-menu \
@radix-ui/react-label @radix-ui/react-popover @radix-ui/react-scroll-area \
@radix-ui/react-select @radix-ui/react-slot @radix-ui/react-tabs @radix-ui/react-tooltip \
@radix-ui/react-separator
sudo npm install -D @tailwindcss/postcss

然后运行如下的脚步:

复制代码
./start-dev.sh

$ ./start-dev.sh local
Simple MCP Chat Client - Development Environment
=============================================
Mode: local

Managing Python virtual environment...
Activating project virtual environment...
✅ Project virtual environment activated

Starting backend server...
Backend server started (PID: 86058)
  URL: http://localhost:8002
  Logs: logs/backend.log
Starting frontend server...
Frontend server started (PID: 86096)
  URL: http://localhost:5173 (or next available port)
  API: http://localhost:8002/api
  Logs: logs/frontend.log

Both servers are running in local mode!
Press Ctrl+C to stop both servers

Logs are being written to:
  Backend:  logs/backend.log
  Frontend: logs/frontend.log

You can monitor logs in real-time with:
  tail -f logs/backend.log
  tail -f logs/frontend.log

我们成功地启动后,在浏览器地址栏输入 http://localhost:5173/,可以看到如下的界面:

点击上面的 Add Configuration,我们可以看到添加的 LLM。我们可以尝试 DeepSeek。

我们可以看到 my config 已经被成功地连接上了。在上面,我使用 OpenAI 来进行的尝试。

接下来,我们来配置 Elasticsearch MCP server。我们可以参考之前的文章 "将 agents 连接到 Elasticsearch 使用模型上下文协议 - docker"。做如下的配置:

注意:在上面的 Arguments (one per line) 里,我们填入如下的信息。在每一行的输入中,我们的每行结尾不能含有空格。你需要根据自己的配置进行相应的修改。

复制代码
run
-i
--rm
-e
ES_URL=https://host.docker.internal:9200
-e
ES_API_KEY=cE81UzFwa0JsMDB0UUE5N3lNTzY6ZUt4ZmFrSVY5ZC1YUDg5WXc3RV9hUQ==
-e
ES_SSL_SKIP_VERIFY=true
docker.elastic.co/mcp/elasticsearch
stdio

点击上面的 Add Local Server,我们可以看到如下的界面:

我们可以点击 Start 按钮来启动 Elasticsearch MCP server:

在配置的过程中,如果我们遇到错误信息,我们可以查看如下的 log 文件:

在上述文件中,它会指出在 backend 里发生错误的文件:

一旦配置完整后,我们需要重新启动:

复制代码
./start-dev.sh

我们做如下的查询:

复制代码
list all of the indices

注意:由于一些原因,有时会遇到错误信息。

复制代码
How many documents are there in index people?

在上面,我们使用如下的索引 people:

复制代码
PUT /people
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text"
      },
      "description": {
        "type": "text"
      },
      "sex": {
        "type": "keyword"
      },
      "age": {
        "type": "integer"
      },
      "address": {
        "type": "text"
      }
    }
  }
}

POST /_bulk
{ "index" : { "_index" : "people", "_id" : "1" } }
{ "name" : "John Doe", "description" : "A software developer", "sex" : "Male", "age" : 30, "address" : "123 Elm Street, Springfield" }
{ "index" : { "_index" : "people", "_id" : "2" } }
{ "name" : "Jane Smith", "description" : "A project manager", "sex" : "Female", "age" : 28, "address" : "456 Maple Avenue, Anytown" }
{ "index" : { "_index" : "people", "_id" : "3" } }
{ "name" : "Alice Johnson", "description" : "A graphic designer", "sex" : "Female", "age" : 26, "address" : "789 Oak Lane, Metropolis" }
{ "index" : { "_index" : "people", "_id" : "4" } }
{ "name" : "Bob Brown", "description" : "A marketing specialist", "sex" : "Male", "age" : 32, "address" : "321 Pine Street, Gotham" }
{ "index" : { "_index" : "people", "_id" : "5" } }
{ "name" : "Charlie Davis", "description" : "An IT analyst", "sex" : "Male", "age" : 29, "address" : "654 Cedar Blvd, Star City" }
{ "index" : { "_index" : "people", "_id" : "6" } }
{ "name" : "Diana Prince", "description" : "A diplomat", "sex" : "Female", "age" : 35, "address" : "987 Birch Road, Themyscira" }
{ "index" : { "_index" : "people", "_id" : "7" } }
{ "name" : "Evan Wright", "description" : "A journalist", "sex" : "Male", "age" : 27, "address" : "213 Willow Lane, Central City" }
{ "index" : { "_index" : "people", "_id" : "8" } }
{ "name" : "Fiona Gallagher", "description" : "A nurse", "sex" : "Female", "age" : 31, "address" : "546 Spruce Street, South Side" }
{ "index" : { "_index" : "people", "_id" : "9" } }
{ "name" : "George King", "description" : "A teacher", "sex" : "Male", "age" : 34, "address" : "879 Elm St, Smallville" }
{ "index" : { "_index" : "people", "_id" : "10" } }
{ "name" : "Helen Parr", "description" : "A full-time superhero", "sex" : "Female", "age" : 37, "address" : "123 Metro Avenue, Metroville" }

我们仿照之前的文章 "将 agents 连接到 Elasticsearch 使用模型上下文协议 - docker" 导入 kibana_sample_data_flights,我们做如下查询:

我们也可以配置 Elastic Serverless。我们可以仿照之前的文章 "Elastic AI agent builder 介绍" 创建 Elastic serverless。这个 Agents 将会在未来的 9.2.0 里提供。我们拷贝它的 MCP server。

我们把上面的 MCP Server URL 拷贝下来。也把如下的 API key 拷贝下来:

点击上面的 Connect Server,我们可以为 Serverless 来配置 MCP Server。请注意:在 Elastic Stack 里,Kibana 创建了一个 MCP server。我们无需再创建一个单独的 Elasticsearch MCP server。

我们再次聊天:

你们也可以配置一下自己的 DeepSeek 试试。我这里就不一一赘述!

相关推荐
聆风吟º31 分钟前
CANN runtime 全链路拆解:AI 异构计算运行时的任务管理与功能适配技术路径
人工智能·深度学习·神经网络·cann
uesowys38 分钟前
Apache Spark算法开发指导-One-vs-Rest classifier
人工智能·算法·spark
AI_567838 分钟前
AWS EC2新手入门:6步带你从零启动实例
大数据·数据库·人工智能·机器学习·aws
User_芊芊君子41 分钟前
CANN大模型推理加速引擎ascend-transformer-boost深度解析:毫秒级响应的Transformer优化方案
人工智能·深度学习·transformer
CRzkHbaXTmHw1 小时前
探索Flyback反激式开关电源的Matlab Simulink仿真之旅
大数据
智驱力人工智能1 小时前
小区高空抛物AI实时预警方案 筑牢社区头顶安全的实践 高空抛物检测 高空抛物监控安装教程 高空抛物误报率优化方案 高空抛物监控案例分享
人工智能·深度学习·opencv·算法·安全·yolo·边缘计算
七夜zippoe1 小时前
CANN Runtime任务描述序列化与持久化源码深度解码
大数据·运维·服务器·cann
qq_160144871 小时前
亲测!2026年零基础学AI的入门干货,新手照做就能上手
人工智能
Howie Zphile1 小时前
全面预算管理难以落地的核心真相:“完美模型幻觉”的认知误区
人工智能·全面预算
人工不智能5771 小时前
拆解 BERT:Output 中的 Hidden States 到底藏了什么秘密?
人工智能·深度学习·bert