关于 OpenSearch MCP <> LLM Integration Guide
本指南介绍如何通过 MCP 服务将 OpenSearch 连接到 Amazon Q 和 Anthropic Claude Desktop,涵盖本地部署、客户端配置,以及用自然语言管理索引和文档。
主要功能
- 01使用 Docker 部署本地 OpenSearch
- 02通过 pipx 安装 MCP 服务
- 03配置 Amazon Q 和 Claude Desktop
- 04索引与文档操作
- 05集群健康状况与统计信息
- 06通用 OpenSearch API 请求
适用场景
- 01搭建本地 OpenSearch 实例
- 02将 Amazon Q 连接到 OpenSearch
- 03通过自然语言请求管理索引
- 04使用 Claude Desktop 搜索和修改文档
MCP 相关
指南说明如何为 Amazon Q 和 Claude Desktop 配置 OpenSearch MCP 服务。其工具向 MCP 客户端提供索引、文档、别名、集群及通用 API 操作。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
OpenSearch MCP <> 大模型集成指南
本指南将逐步说明如何使用 MCP 服务,将 Amazon Q 和 Anthropic Claude 桌面应用与 OpenSearch 集成,以便通过自然语言进行交互。
Anthropic Claude

Amazon Q

前置条件
- 已安装 Docker 和 Docker Compose
- 已安装 Python 3.x
- 已安装 pipx(
pip install pipx) - Amazon Q CLI
- Anthropic Claude Desktop
1. 设置本地 OpenSearch 实例
-
为项目创建一个新目录:
mkdir opensearch-mcp && cd opensearch-mcp -
创建包含以下内容的
docker-compose.yml文件:version: '3' services: opensearch: image: opensearchproject/opensearch:latest environment: - discovery.type=single-node - bootstrap.memory_lock=true - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" - "OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!" - "plugins.security.ssl.http.enabled=true" - "plugins.security.ssl.transport.enabled=true" - "plugins.security.ssl.http.pemcert_filepath=certs/node.pem" - "plugins.security.ssl.http.pemkey_filepath=certs/node-key.pem" - "plugins.security.ssl.http.pemtrustedcas_filepath=certs/root-ca.pem" - "plugins.security.ssl.transport.pemcert_filepath=certs/node.pem" - "plugins.security.ssl.transport.pemkey_filepath=certs/node-key.pem" - "plugins.security.ssl.transport.pemtrustedcas_filepath=certs/root-ca.pem" ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 65536 volumes: - opensearch-data:/usr/share/opensearch/data - ./certs:/usr/share/opensearch/config/certs ports: - 9200:9200 - 9600:9600 networks: - opensearch-net opensearch-dashboards: image: opensearchproject/opensearch-dashboards:latest environment: - 'OPENSEARCH_HOSTS=["https://opensearch:9200"]' - "OPENSEARCH_SSL_VERIFICATIONMODE=none" - "OPENSEARCH_SECURITY_ADMIN_PASSWORD=myStrongPassword123!" - "SERVER_SSL_ENABLED=true" - "SERVER_SSL_CERTIFICATE=/usr/share/opensearch-dashboards/config/certs/node.pem" - "SERVER_SSL_KEY=/usr/share/opensearch-dashboards/config/certs/node-key.pem" ports: - 5601:5601 volumes: - ./certs:/usr/share/opensearch-dashboards/config/certs depends_on: - opensearch networks: - opensearch-net volumes: opensearch-data: networks: opensearch-net: -
启动容器:
docker compose up -d
2. 安装 OpenSearch MCP 服务
- 使用 pipx 安装 OpenSearch MCP 服务:
pipx install opensearch-mcp-server
3. 使用 MCP 服务配置大模型
-
Amazon Q:在 Amazon Q 配置目录(~/.aws/amazonq/mcp.json)中创建mcp.json文件 -
Anthropic Claude:在 Claude Desktop 配置目录(~/Library/Application Support/Claude/claude_desktop_config.json)中创建claude_desktop_config.json文件{ "mcpServers": { "opensearch-mcp-server": { "command": "/Users/YOUR_USERNAME/.local/bin/opensearch-mcp-server", "args": [], "env": { "OPENSEARCH_URL": "https://localhost:9200", "OPENSEARCH_SSL_VERIFY": "none", "OPENSEARCH_USERNAME": "admin", "OPENSEARCH_PASSWORD": "myStrongPassword123!" } } } }将
YOUR_USERNAME替换为你的系统用户名,或指定安装 opensearch-mcp-server 的位置。
4. 验证设置
-
检查 OpenSearch 是否正在运行:
curl -XGET -u admin:myStrongPassword123! https://localhost:9200 -
验证 OpenSearch Dashboards:
- 在浏览器中打开 https://localhost:5601
-
检查索引:
curl -XGET -u admin:myStrongPassword123! https://localhost:9200/_cat/indices
5. 使用自然语言与 OpenSearch 交互
以下是一些可以在大模型中尝试的示例命令:
-
创建索引:
Create a new index called "books" with title and author fields -
添加文档:
Add a document to the books index with title "The Great Gatsby" and author "F. Scott Fitzgerald" -
搜索文档:
Search for books by F. Scott Fitzgerald -
获取索引信息:
Show me the mapping of the books index
故障排除
-
如果 MCP 服务无法初始化:
- 检查 OpenSearch 是否正在运行(
docker ps) - 验证
mcp_config.json中的凭据 - 检查 OpenSearch 日志(
docker compose logs opensearch)
- 检查 OpenSearch 是否正在运行(
-
如果工具不可用:
- 重启大模型
- 检查 MCP 服务日志
- 验证
mcp_config.json语法
可用的 MCP 工具
OpenSearch MCP 服务提供多个用于与 OpenSearch 交互的工具:
list_indices:列出所有索引。get_index:返回一个或多个索引的信息(映射、设置、别名)。参数:index:索引名称create_index:创建新索引。参数:index:索引名称 body:可选的索引配置,包括映射和设置delete_index:删除索引。参数:index:索引名称search_documents:搜索文档。参数:index:索引名称 body:搜索查询index_document:在索引中创建或更新文档。参数:index:索引名称 document:文档数据 id:可选的文档 IDget_document:根据 ID 获取文档。参数:index:索引名称 id:文档 IDdelete_document:根据 ID 删除文档。参数:index:索引名称 id:文档 IDdelete_by_query:删除符合所提供查询条件的文档。参数:index:索引名称 body:用于匹配待删除文档的查询get_cluster_health:返回集群运行状况的基本信息。get_cluster_stats:返回集群统计信息的高级概览。list_aliases:列出所有别名。get_alias:获取特定索引的别名信息。参数:index:索引名称put_alias:为特定索引创建或更新别名。参数:index:索引名称 name:别名名称 body:别名配置delete_alias:删除特定索引的别名。参数:index:索引名称 name:别名名称general_api_request:执行通用 HTTP API 请求。对于没有专用工具的任何 Elasticsearch/OpenSearch API,请使用此工具。参数:method:HTTP 方法(GET、POST、PUT、DELETE 等) path:API 端点路径 params:查询参数 body:请求正文
安全说明
- 在生产环境中始终使用强密码
- 在生产环境中启用 SSL
- 定期轮换凭证
其他资源
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。