Elasticsearch MCP服务

通过模型上下文协议(MCP)将Elasticsearch集群连接到兼容客户端,实现自然语言交互的数据查询与管理。

  • by Akhilvis
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 akhilvis/elastic-mcp

使用说明

演示

https://github.com/user-attachments/assets/907c3f6f-807c-4805-879a-649c74804c29

弹性MCP

使用模型上下文协议(MCP)从任何兼容MCP的客户端(如Claude Desktop)连接到Elasticsearch集群。 此服务器通过MCP接口公开您的Elasticsearch数据和操作,使代理和应用程序能够通过自然语言交互查询、管理和分析您的数据。


1.设置

先决条件

安装依赖项

使用 uv 包管理器:

uv pip install -r requirements.txt

2.运行MCP服务器

使用MCP检查器进行测试

ELASTIC_URL="http://localhost:9200" ELASTIC_USERNAME="your_username" ELASTIC_PASSWORD="your_password" fastmcp dev tools/elastic_tool.py

或

通过以下方式运行mcp服务器

ELASTIC_URL="http://localhost:9200" ELASTIC_USERNAME="elastic" ELASTIC_PASSWORD="hKsXqDsd" python3 tools/elastic_tool.py

并在另一个终端中运行mcp客户端

python3 mcp_client.py

或

通过编辑Claude_Desktop_config.json添加到Claude桌面,并添加以下代码片段


{
  "mcpServers": {
    "Elastic MCP Server": {
      "command": "uv",
      "args": [
        "run",
        "--with-requirements",
        "<absolute path to requirements.txt>",
        "fastmcp",
        "run",
        "<absolute path to elastic_tool.py>"
      ],
      "env": {
        "ELASTIC_URL": "http://localhost:9200",
        "ELASTIC_USERNAME": "your_username",
        "ELASTIC_PASSWORD": "your_password"
      }
    }
  }
}


3.提供的工具

  • search_index:使用查询字符串搜索索引。
  • list_indices:列出所有指标(不包括系统指标)。
  • get_index_mappings:获取特定索引的映射。

4.许可证

MIT许可证


5.注意事项

  • 为了生产,做 不 硬编码凭证。
  • 有关MCP的更多信息,请参阅 FastMCP文档.