Token导航 LogoToken导航TokenDH.com
Custom Elasticsearch MCP Server logo
AI代理stdio官方级别未说明来源级核验

Custom Elasticsearch MCP Server

MCP Server

一个为Elasticsearch设计的定制MCP服务器,无需API密钥,提供增强的工具和并发请求处理能力。

工具数

4

提示词数

0

GitHub Stars

0

资源数

0
PythonCursorAI代理Cursor

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

M0-AR

提供方

M0-AR

最后核验

2026/5/17 20:21

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

python3 simple_elasticsearch_mcp.py &

详细介绍

自定义Elasticsearch MCP服务器

Elasticsearch的一个简单的MCP(模型上下文协议)服务器,专为您的公钥已经在服务器上授权的云环境而设计。

为什么是这个自定义版本?

不需要API密钥 -与需要两者的官方Elasticsearch MCP服务器不同 ES_URLES_API_KEY,此版本只需要URL,因为您的公钥在云服务器上已受信任。

增强工具 -与官方版本相比,可选参数和改进的默认值具有更好的可用性。

这有什么作用

此MCP服务器使用4个强大的工具将Cursor连接到您的Elasticsearch集群:

  • list_indices -列出所有索引(可选模式过滤器)
  • search -完全支持Elasticsearch查询DSL
  • get_mappings -获取任何索引的字段映射
  • get_shards -查看集群碎片信息

快速开始

从源代码构建

git clone https://github.com/M0-AR/Custom-Elasticsearch-MCP-Server.git
cd Custom-Elasticsearch-MCP-Server
docker build -t elasticsearch-mcp:latest .

2.添加到光标MCP配置

将此添加到您的 .cursor/mcp.json 文件:

配置:

{
    "mcpServers": {
        "elasticsearch-custom": {
            "command": "docker",
            "args": [
                "run",
                "-i",
                "--rm",
                "--add-host=host.docker.internal:host-gateway",
                "-e",
                "ES_URL=http://host.docker.internal:9400",
                "elasticsearch-mcp:latest"
            ]
        }
    }
}

3.重新启动游标

关闭并重新打开游标。您应该看到启用了4个工具的elasticsearch自定义服务器。

配置

环境变量:

  • ES_URL -您的Elasticsearch URL(默认值: http://localhost:9400)
  • MAX_CONNECTIONS -最大并发连接数(默认值: 100)
  • MAX_KEEPALIVE_CONNECTIONS -最大保活连接数(默认值: 20)
  • CONNECTION_TIMEOUT -连接超时(秒)(默认值: 30)
  • REQUEST_TIMEOUT -请求超时(秒)(默认值: 30)

对于不同的Elasticsearch端口:

"ES_URL=http://host.docker.internal:9200"

对于高流量环境:

"MAX_CONNECTIONS=200",
"MAX_KEEPALIVE_CONNECTIONS=50",
"CONNECTION_TIMEOUT=60",
"REQUEST_TIMEOUT=60"

示例用法

在Cursor中连接后,您可以:

  • 列出所有指标: “显示所有弹性搜索索引”
  • 搜索数据: “在总部销售指数中搜索销售数据”
  • 获取映射: “hq.menuitems索引中有哪些字段?”
  • 检查集群: “显示elasticsearch集群状态”

与官方服务器比较

功能官方服务器此自定义服务器
认证需要 ES_URL + ES_API_KEY只需要 ES_URL (公钥授权)
list_indices需要 indexPattern parameter默认为“\*”的可选参数
可用工具4工具(功能相同)4工具(增强可用性)
安全基于API密钥公钥授权
并发同步阻塞与连接池异步
演出一次一个请求100+并发请求

并发请求处理

此MCP服务器旨在使用行业最佳实践同时处理来自多个应用程序的多个并行请求:

主要特点:

异步/等待架构 -用于并行请求处理的非阻塞I/O ✅ 连接池 -重用HTTP连接(最多100个并发连接) ✅ HTTP/2支持 -在单个连接上复用多个请求 ✅ 可配置限制 -调整工作负载的连接限制 ✅ 线程安全 -FastMCP安全地处理并发工具执行

性能特点:

  • 违约: 100个并发连接,20个保活连接
  • 可扩展性: 配置多达1000+个并发连接
  • 高效: 连接重用可将延迟减少约50%
  • 可靠: 适当的超时处理可防止连接耗尽

高流量配置:

{
    "mcpServers": {
        "elasticsearch-custom": {
            "command": "docker",
            "args": [
                "run", "-i", "--rm",
                "--add-host=host.docker.internal:host-gateway",
                "-e", "ES_URL=http://host.docker.internal:9400",
                "-e", "MAX_CONNECTIONS=200",
                "-e", "MAX_KEEPALIVE_CONNECTIONS=50",
                "-e", "CONNECTION_TIMEOUT=60",
                "-e", "REQUEST_TIMEOUT=60",
                "elasticsearch-mcp:latest"
            ]
        }
    }
}

测试并发请求:

# Test 10 parallel requests
for i in {1..10}; do
    echo '{"jsonrpc": "2.0", "id": '$i', "method": "tools/call", "params": {"name": "list_indices", "arguments": {}}}' | \
    python3 simple_elasticsearch_mcp.py &
done
wait

文件

  • simple_elasticsearch_mcp.py -主MCP服务器
  • Dockerfile -容器构建说明
  • requirements.txt -Python依赖关系

手动测试

直接测试服务器:

python3 simple_elasticsearch_mcp.py

使用JSON-RPC命令进行测试:

1.列出所有工具:

echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | python3 simple_elasticsearch_mcp.py

2.列出所有指标:

echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "list_indices", "arguments": {}}}' | python3 simple_elasticsearch_mcp.py

3.搜索数据:

echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "search", "arguments": {"index": "hq.sales", "queryBody": {"query": {"match_all": {}}, "size": 3}}}}' | python3 simple_elasticsearch_mcp.py

4.获取索引映射:

echo '{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "get_mappings", "arguments": {"index": "hq.menuitems"}}}' | python3 simple_elasticsearch_mcp.py

5.检查集群碎片:

echo '{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "get_shards", "arguments": {}}}' | python3 simple_elasticsearch_mcp.py

设置自定义Elasticsearch URL:

ES_URL="http://your-es-host:9200" python3 simple_elasticsearch_mcp.py

故障排除

❌ “连接被拒绝”或“超时”错误

根本原因: 当Elasticsearch可以通过SSH隧道访问时,最常见的问题是Docker容器网络。

解决方案: 确保满足以下要求:

1.SSH隧道必须处于活动状态

如果你的Elasticsearch位于SSH隧道之后(常见于云部署):

# Start SSH tunnel to forward port 9400
ssh -L 9400:localhost:9400 -N -f -l username your-server-ip

# Verify tunnel is working
curl -X GET "localhost:9400/_cluster/health?pretty"

2.正确的Docker配置

你的 mcp.json 应该使用 确切地 此配置:

"elasticsearch-custom": {
    "command": "docker",
    "args": [
        "run",
        "-i",
        "--rm",
        "--add-host=host.docker.internal:host-gateway",
        "-e",
        "ES_URL=http://host.docker.internal:9400",
        "elasticsearch-mcp:latest"
    ]
}

要点:

  • ✅ 使用 --add-host=host.docker.internal:host-gateway (不是IP地址)
  • ✅ 使用 ES_URL=http://host.docker.internal:9400 (不是本地主机)
  • ✅ 启动Cursor之前,SSH隧道必须正在运行

3.测试Docker连接

# Test if Docker can reach your Elasticsearch
docker run --rm --add-host=host.docker.internal:host-gateway alpine/curl \
  curl -s http://host.docker.internal:9400/_cluster/health

4.完成MCP Docker测试

使用此综合命令测试完整的MCP工作流程:

# Full MCP server test with proper initialization
{
    echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}}';
    echo '{"jsonrpc": "2.0", "method": "notifications/initialized", "params": {}}';
    echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "list_indices", "arguments": {}}}';
} | docker run -i --rm --add-host=host.docker.internal:host-gateway -e ES_URL="http://host.docker.internal:9400" elasticsearch-mcp:latest

预期产量:

  • 带有服务器信息的初始化响应
  • JSON格式的所有Elasticsearch索引列表
  • 无错误消息

5.替代方案:网络主机模式

如果 host-gateway 不起作用,请尝试网络主机模式:

"args": [
    "run", "-i", "--rm", "--network=host",
    "-e", "ES_URL=http://localhost:9400",
    "elasticsearch-mcp:latest"
]

❌ “初始化完成前收到请求”

根本原因: MCP协议需要正确的初始化顺序。

解决方案: 在调用工具之前始终进行初始化:

# Correct sequence:
echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0"}}}'
echo '{"jsonrpc": "2.0", "method": "notifications/initialized", "params": {}}'
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "list_indices", "arguments": {}}}'

就是这样!

构建→ 添加到配置→ 重新启动游标→ Done! 🚀

目录标签

目录标签

PythonCursorAI代理Elasticsearch本地部署MCP协议并发处理云环境无API密钥

支持客户端

Cursor

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Python

部署方式(deploymentType,部署类型)

remote-capable

工具数量(toolCount,工具数)

4

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiononeremote-capable

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP