Skip to main content

Elasticsearch MCP 服务器

基于 Model Context Protocol (MCP) 的 Elasticsearch 工具服务器,提供索引查询、映射获取、搜索等功能。

其他语言版本: 🇺🇸 English | 🇫🇷 Français | 🇩🇪 Deutsch | 🇯🇵 日本語

项目目录结构

.
├── es_mcp_server/         # 服务器代码
│   ├── __init__.py        # 包初始化
│   ├── server.py          # 服务器主程序
│   ├── config.py          # 配置管理
│   ├── client.py          # ES客户端工厂
│   └── tools.py           # ES MCP工具实现
├── es_mcp_client/         # 客户端代码
│   ├── __init__.py        # 包初始化
│   └── client.py          # 客户端测试程序
├── test/                  # 单元测试
│   ├── __init__.py        # 测试包初始化
│   └── test_server.py     # 服务器单元测试
├── claude_config_examples/ # Claude配置示例
│   ├── elasticsearch_stdio_config.json # stdio模式配置
│   └── elasticsearch_sse_config.json   # sse模式配置
├── .vscode/               # VSCode配置
│   └── launch.json        # 调试配置
├── docs/                  # 文档
│   └── requires.md        # 需求文档
├── pyproject.toml         # 项目配置文件
├── README.md              # 中文说明文档
├── README.en.md           # 英文说明文档
├── README.fr.md           # 法语说明文档
├── README.de.md           # 德语说明文档
├── README.jp.md           # 日语说明文档
├── .gitignore             # Git忽略文件
└── LICENSE                # MIT许可证

服务器功能和使用说明

Elasticsearch MCP 服务器提供以下工具:

  1. list_indices - 显示 ES 集群的所有索引
  2. get_mappings - 返回指定索引的字段映射信息
  3. search - 在指定索引中执行搜索查询,支持高亮显示
  4. get_cluster_health - 获取 ES 集群的健康状态信息
  5. get_cluster_stats - 获取 ES 集群的运行状态统计信息

安装

# 从PyPI安装
pip install es-mcp-server

# 或从源码安装
pip install .

# 安装开发依赖
pip install ".[dev]"

配置

服务器通过环境变量或命令行参数进行配置:

环境变量 说明 默认值
ES_HOST ES 主机地址 localhost
ES_PORT ES 端口 9200
ES_USERNAME ES 用户名 无
ES_PASSWORD ES 密码 无
ES_API_KEY ES API 密钥 无
ES_USE_SSL 是否使用 SSL false
ES_VERIFY_CERTS 是否验证证书 true
ES_VERSION ES 版本 (7 或 8) 8

启动服务器

stdio 模式 (与 Claude Desktop 等客户端集成)

# 使用默认配置
uvx es-mcp-server

# 自定义 ES 连接
uvx es-mcp-server --host 192.168.0.13 --port 9200 --es-version 8

SSE 模式 (Web 服务器模式)

# 启动 SSE 服务器
uvx es-mcp-server --transport sse --host 192.168.0.13 --port 9200

客户端使用说明

项目包含一个用于验证服务器功能的客户端程序。

启动客户端

# 连接到默认 SSE 服务器 (http://localhost:8000/sse)
uvx es-mcp-client

# 自定义 SSE 服务器地址
uvx es-mcp-client --url http://example.com:8000/sse

对接其他工具

与 Claude Desktop 集成

Claude Desktop 可以通过 MCP 协议使用本服务,以便访问 Elasticsearch 数据。

stdio 模式配置

在 Claude Desktop 中添加以下配置:

{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "command": "uvx",
      "args": ["es-mcp-server"],
      "env": {
        "ES_HOST": "your-es-host",
        "ES_PORT": "9200",
        "ES_VERSION": "8"
      }
    }
  }
}

SSE 模式配置

如果您已经启动了 SSE 模式的服务器,可以使用以下配置:

{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "url": "http://localhost:8000/sse"
    }
  }
}

单元测试

运行单元测试以验证功能:

pytest

开发调试

本项目包含 VSCode 调试配置,打开 VSCode 后可直接使用调试功能启动服务器或客户端。

注意事项

  • 本项目同时支持 Elasticsearch 7 和 8 版本的 API
  • 服务器默认使用 stdio 传输模式,适合与 Claude Desktop 等客户端集成
  • SSE 模式适合作为独立服务启动

许可证

MIT License


本项目的大部分代码、文档、配置示例都是用cursor的claude-3.7-sonnet根据需求文档 生成出来的(提示词:基于本文件生成项目所有程序)。

Metadata

Release files for es-mcp-server 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for es-mcp-server 0.1.4
File Size Uploaded Provenance
es_mcp_server-0.1.4.tar.gz 22.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for es-mcp-server 0.1.4
File Interpreter ABI Platform
es_mcp_server-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 38.7 kB

Release files / es_mcp_server-0.1.4.tar.gz

Download URL es_mcp_server-0.1.4.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bd4ff3d83f684e0ec4bd7ee758e083cde61dada78ca92f0ea50a827b04ed980a
BLAKE2b-256 checksum
How to use checksums
9083891956d7b8399ece88465b136dfb30795f3ed9ab8bbaeb9319da1fb2850c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / es_mcp_server-0.1.4-py3-none-any.whl

Download URL es_mcp_server-0.1.4-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d7526ce74d1df8c48021c3f6b0cb16e7ecdb2fc5ee21056aea4c41159bde5c8
BLAKE2b-256 checksum
How to use checksums
5b821212c7416c62ff6bdbf4113aa2d7f8634e74fad3d3d02e8f606b61e7ff10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Security for es-mcp-server 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page