使用说明
OpenSearch FastMCP服务器
一个用于OpenSearch的简单MCP服务器,使用FastMCP检索集群索引。默认情况下在HTTP上运行。
它做什么
此服务器公开了一个工具: get_indexes -它返回OpenSearch集群中的所有索引。
快速开始
1.安装依赖项
cd test-zed
uv sync
2.配置OpenSearch连接
创建一个 .env 项目根目录中的文件(如果不存在):
PORT=9200
URL=http://localhost:9200
SECURE=false
USERNAME=
PASSWORD=
配置选项:
URL-您的OpenSearch集群URLPORT-OpenSearch端口(默认值:9200)SECURE-设置为true对于HTTPS,false对于HTTPUSERNAME-可选:身份验证用户名PASSWORD-可选:身份验证密码
3.运行服务器
默认值:HTTP传输(推荐)
uv run python src/test_zed/server.py
服务器启动于 端口8000处的HTTP 默认情况下: http://localhost:8000/mcp
替代命令:
# Using main.py
uv run python src/test_zed/main.py
# Using FastMCP CLI with custom port
fastmcp run src/test_zed/server.py:mcp --transport http --port 3000
# For stdio transport (local only)
fastmcp run src/test_zed/server.py:mcp --transport stdio
测试
cURL快速测试
curl http://localhost:8000/health
使用Python客户端进行测试
服务器运行后,使用简单的客户端进行测试:
import asyncio
from fastmcp import Client
async def test():
client = Client("http://localhost:8000/mcp")
async with client:
result = await client.call_tool("get_indexes", {})
print(result.content[0].text)
asyncio.run(test())
工具输出示例
{
"success": true,
"indexes": ["movies", "logs", "users"],
"count": 3,
"details": {
"movies": {"aliases": {}},
"logs": {"aliases": {}},
"users": {"aliases": {}}
}
}
项目结构
test-zed/
├── src/test_zed/
│ ├── __init__.py # Package initialization
│ ├── server.py # FastMCP server (main file)
│ ├── opensearch_client.py # OpenSearch connection
│ └── main.py # Entry point
├── .env # Configuration (create this)
├── .env.example # Configuration template
├── pyproject.toml # Dependencies
└── README.md # This file
故障排除
OpenSearch连接错误:
- 确保OpenSearch正在运行:
curl http://localhost:9200 - 检查你的
.env文件具有正确的URL和PORT - 如果使用身份验证,请确保设置了用户名和密码
未找到模块:
- 跑
uv sync安装依赖项 - 确保你在
test-zed目录
端口8000已在使用中:
- 更改端口
server.py:修改port=8000到port=3000 - 或者使用端口8000终止进程
无法连接到本地主机:8000:
- 确保服务器首先运行
- 检查您是否使用了正确的URL:
http://localhost:8000/mcp
工具不工作:
- 检查服务器日志中的“✅ OpenSearch客户端已初始化”
- 验证您的OpenSearch集群是否有索引(创建一个:
curl -X PUT "http://localhost:9200/test-index")
部署到FastMCP云
- 将此仓库推送到GitHub
- 首选 fastmcp.cloud
- 使用GitHub登录
- 使用入口点创建新项目:
src/test_zed/server.py:mcp
免费供个人使用!
许可证
麻省理工学院