OpenSearch MCP\<>LLM集成指南
本指南提供了使用MCP服务器进行自然语言交互,将Amazon Q&Anthropic Claude桌面与OpenSearch集成的分步说明。
人物克劳德

亚马逊Q

先决条件
- 已安装Docker和Docker Compose
- 已安装Python 3.x
- pipx已安装(
pip install pipx) - 亚马逊Q CLI
- 拟人克劳德桌面
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 -d2.安装OpenSearch MCP服务器
- 使用pipx安装OpenSearch MCP服务器:
pipx install opensearch-mcp-server3.使用MCP服务器配置配置LLM
Amazon Q:创建一个mcp.jsonAmazon Q配置目录中的文件(~/.aws/amazonq/mcp.json)
Anthropic Claude:创建一个claude_desktop_config.jsonClaude Desktop配置目录中的文件(~/Library/ApplicationSupport/Claude/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 使用您的系统用户名或指定opensearchmcp服务器的安装位置。
4.验证设置
- 检查OpenSearch是否正在运行:
curl -XGET -u admin:myStrongPassword123! https://localhost:9200- 验证OpenSearch仪表板:
- 打开https://localhost:5601在浏览器中
- 检查指标:
curl -XGET -u admin:myStrongPassword123! https://localhost:9200/_cat/indices5.在OpenSearch中使用自然语言
以下是您可以在LLM中尝试的一些示例命令:
- 创建索引:
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)
- 如果工具不可用:
- 重新启动LLM - 检查MCP服务器日志 - 验证 mcp_config.json 语法
可用的MCP工具
OpenSearch MCP服务器提供了几个与OpenSearch交互的工具:
list_indices:列出所有索引。get_index:返回有关一个或多个索引的信息(映射、设置、别名)。Args:index:索引的名称create_index:创建新索引。Args:index:索引体的名称:可选索引配置,包括映射和设置delete_index:删除索引。Args:index:索引的名称search_documents:搜索文档。Args:index:索引体名称:搜索查询index_document:在索引中创建或更新文档。Args:index:索引文档的名称:文档数据id:可选文档idget_document:按ID获取文档。Args:index:索引名称ID:文档IDdelete_document:按ID删除文档。Args:index:索引名称ID:文档IDdelete_by_query:删除与提供的查询匹配的文档。Args:index:索引体的名称:查询以匹配要删除的文档get_cluster_health:返回有关群集运行状况的基本信息。get_cluster_stats:返回集群统计信息的高级概述。list_aliases:列出所有别名。get_alias:获取特定索引的别名信息。Args:index:索引的名称put_alias:为特定索引创建或更新别名。Args:index:索引名称:别名主体名称:别名配置delete_alias:删除特定索引的别名。Args:index:索引名称:别名名称general_api_request:执行常规HTTP API请求。对于任何没有专用工具的Elasticsearch/OOpenSearch API,请使用此工具。Args:method:HTTP方法(GET、POST、PUT、DELETE等)路径:API端点路径params:Query parameters body:Request body
安全说明
- 在生产中始终使用强密码
- 在生产环境中启用SSL
- 定期轮换凭证
