Elasticsearch/OpenSearch MCP服务器

一个实现模型上下文协议(MCP)的服务器,提供Elasticsearch和OpenSearch的交互功能,包括文档搜索、索引分析和集群管理。

  • by Rbedoyag
  • Python
  • 混合部署
  • 更新于
在 GitHub 查看 rbedoyag/elasticsearch-mcp-server

使用说明

Elasticsearch/OpenSearch MCP服务器

概述

提供Elasticsearch和OpenSearch交互的模型上下文协议(MCP)服务器实现。此服务器允许通过一组工具搜索文档、分析索引和管理集群。

特性

一般操作

  • general_api_request:执行常规HTTP API请求。对于任何没有专用工具的Elasticsearch/OOpenSearch API,请使用此工具。

索引操作

  • list_indices:列出所有索引。
  • get_index:返回有关一个或多个索引的信息(映射、设置、别名)。
  • create_index:创建新索引。
  • delete_index:删除索引。

文档操作

  • search_documents:搜索文档。
  • index_document:在索引中创建或更新文档。
  • get_document:通过ID获取文档。
  • delete_document:按ID删除文档。
  • delete_by_query:删除与提供的查询匹配的文档。

集群操作

  • get_cluster_health:返回有关群集运行状况的基本信息。
  • get_cluster_stats:返回集群统计信息的高级概述。

别名操作

  • list_aliases:列出所有别名。
  • get_alias:获取特定索引的别名信息。
  • put_alias:为特定索引创建或更新别名。
  • delete_alias:删除特定索引的别名。

配置环境变量

复制 .env.example 文件到 .env 并相应地更新这些值。

启动Elasticsearch/OpenSearch集群

使用Docker Compose启动Elasticsearch/OpenSearch集群:

# For Elasticsearch
docker-compose -f docker-compose-elasticsearch.yml up -d

# For OpenSearch
docker-compose -f docker-compose-opensearch.yml up -d

默认的Elasticsearch用户名是 elastic 密码为 test123默认的OpenSearch用户名为 admin 密码为 admin.

您可以从以下网址访问Kibana/OpenSearch仪表板http://localhost:5601.

标准输入输出

选项1:使用uvx

使用 uvx 将自动从PyPI安装软件包,无需在本地克隆存储库。将以下配置添加到的配置文件中 claude_desktop_config.json.

// For Elasticsearch
{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "command": "uvx",
      "args": [
        "elasticsearch-mcp-server"
      ],
      "env": {
        "ELASTICSEARCH_HOSTS": "https://localhost:9200",
        "ELASTICSEARCH_USERNAME": "elastic",
        "ELASTICSEARCH_PASSWORD": "test123"
      }
    }
  }
}

// For OpenSearch
{
  "mcpServers": {
    "opensearch-mcp-server": {
      "command": "uvx",
      "args": [
        "opensearch-mcp-server"
      ],
      "env": {
        "OPENSEARCH_HOSTS": "https://localhost:9200",
        "OPENSEARCH_USERNAME": "admin",
        "OPENSEARCH_PASSWORD": "admin"
      }
    }
  }
}

方案2:在当地发展中使用紫外线

使用 uv 需要在本地克隆存储库并指定源代码的路径。将以下配置添加到Claude Desktop的配置文件中 claude_desktop_config.json.

// For Elasticsearch
{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "command": "uv",
      "args": [
        "--directory",
        "path\\to_folder_proyect\\elasticsearch_mcp_server",
        "run",
        "elasticsearch-mcp-server"
      ],
      "env": {
        "ELASTICSEARCH_HOSTS": "https://localhost:9200",
        "ELASTICSEARCH_USERNAME": "elastic",
        "ELASTICSEARCH_PASSWORD": "test123"
      }
    }
  }
}

// For OpenSearch
{
  "mcpServers": {
    "opensearch-mcp-server": {
      "command": "uv",
      "args": [
        "--directory",
        "path\\to_folder_proyect\\elasticsearch-mcp-server",
        "run",
        "opensearch-mcp-server"
      ],
      "env": {
        "OPENSEARCH_HOSTS": "https://localhost:9200",
        "OPENSEARCH_USERNAME": "admin",
        "OPENSEARCH_PASSWORD": "admin",
        "OPENSEARCH_VERIFY_CERTS": "false"
      }
    }
  }
}

SSE

选项1:使用uvx

# export environment variables
export ELASTICSEARCH_HOSTS="https://localhost:9200"
export ELASTICSEARCH_USERNAME="elastic"
export ELASTICSEARCH_PASSWORD="test123"

# By default, the SSE MCP server will serve on http://127.0.0.1:8000/sse
uvx elasticsearch-mcp-server --transport sse

# The host, port, and path can be specified using the --host, --port, and --path options
uvx elasticsearch-mcp-server --transport sse --host 0.0.0.0 --port 8000 --path /sse

选项2:使用紫外线


py -m pip install u #LOCAL MACHINE
pip install uv     #VIRTUAL ENV

# By default, the SSE MCP server will serve on http://127.0.0.1:8000/sse
uv run src/server.py elasticsearch-mcp-server --transport sse
uv run src/server.py opensearch-mcp-server --transport sse

# The host, port, and path can be specified using the --host, --port, and --path options
uv run src/server.py elasticsearch-mcp-server --transport sse --host 0.0.0.0 --port 8000 --path /sse
uv run src/server.py opensearch-mcp-server --transport sse --host 0.0.0.0 --port 8000 --path /sse
opensearch-mcp-server

流式HTTP

选项1:使用uvx

# export environment variables
export ELASTICSEARCH_HOSTS="https://localhost:9200"
export ELASTICSEARCH_USERNAME="elastic"
export ELASTICSEARCH_PASSWORD="test123"

# By default, the Streamable HTTP MCP server will serve on http://127.0.0.1:8000/mcp
uvx elasticsearch-mcp-server --transport streamable-http

# The host, port, and path can be specified using the --host, --port, and --path options
uvx elasticsearch-mcp-server --transport streamable-http --host 0.0.0.0 --port 8000 --path /mcp

选项2:使用紫外线


py -m pip install u #LOCAL MACHINE
pip install uv     #VIRTUAL ENV
# By default, the Streamable HTTP MCP server will serve on http://127.0.0.1:8000/mcp
uv run src/server.py elasticsearch-mcp-server --transport streamable-http

# The host, port, and path can be specified using the --host, --port, and --path options
uv run src/server.py elasticsearch-mcp-server --transport streamable-http --host 0.0.0.0 --port 8000 --path /mcp
uv run src/server.py opensearch-mcp-server --transport streamable-http --host 0.0.0.0 --port 8000 --path /mcp

许可证

此项目根据Apache许可证版本2.0获得许可-请参阅 许可证 文件以获取详细信息。