一个强大的MCP (Model Context Protocol) 服务器,提供用户、产品、订单数据的查询功能,支持WebSocket连接到小智AI平台。
A powerful MCP (Model Context Protocol) server that provides user, product, and order data querying capabilities with WebSocket support for XiaoZhi AI platform.
本项目实现了一个数据查询MCP服务器,包含以下功能:
- 用户数据查询和过滤
- 产品数据查询和过滤
- 订单数据查询和分析
- 用户订单关联查询
- 数据统计分析
This project implements a data query MCP server with the following features:
- User data querying and filtering
- Product data querying and filtering
- Order data querying and analysis
- User-order association queries
- Data statistics analysis
- 🔌 支持WebSocket连接到小智AI平台 | WebSocket connection to XiaoZhi AI platform
- 🔄 自动重连机制 | Automatic reconnection with exponential backoff
- 📊 实时数据查询 | Real-time data querying
- 🛠️ 简单易用的工具接口 | Easy-to-use tool interface
- 🔒 安全的WebSocket通信 | Secure WebSocket communication
- ⚙️ 多种传输类型支持 | Multiple transport types support (stdio/websocket/sse/http)
Windows PowerShell:
.\start.ps1
Linux/Mac 标准脚本 | Linux/Mac Standard Script:
chmod +x start.sh
./start.sh
Linux/Mac 简化脚本 | Linux/Mac Simple Script:
chmod +x start_simple.sh
./start_simple.sh
自动部署(推荐用于服务器)| Auto Deployment (Recommended for Servers):
chmod +x deploy.sh
./deploy.sh
手动部署 | Manual Deployment:
参考 MANUAL_START.md
文件获取详细步骤。
Linux系统服务 | Linux System Service:
# 1. 编辑服务文件
sudo cp mcp-server.service /etc/systemd/system/
sudo nano /etc/systemd/system/mcp-server.service
# 2. 启动服务
sudo systemctl daemon-reload
sudo systemctl enable mcp-server
sudo systemctl start mcp-server
# 3. 查看状态
sudo systemctl status mcp-server
- 安装依赖 | Install dependencies:
pip install -r requirements.txt
- 设置环境变量 | Set environment variables:
Windows PowerShell:
$env:MCP_ENDPOINT = "wss://api.xiaozhi.me/mcp/?token=your_token_here"
$env:MCP_CONFIG = "./mcp_config.json"
Linux/Mac Bash:
export MCP_ENDPOINT="wss://api.xiaozhi.me/mcp/?token=your_token_here"
export MCP_CONFIG="./mcp_config.json"
- 启动服务器 | Start the server:
# 运行所有配置的服务器 | Run all configured servers
python mcp_pipe.py
# 或单独运行数据查询服务器 | Or run data query server individually
python mcp_pipe.py data_query_server.py
data_query_server.py
: 数据查询MCP服务器,提供用户、产品、订单查询功能 | Data query MCP server with user, product, and order queryingmcp_pipe.py
: WebSocket连接和进程管理的主通信管道 | Main communication pipe handling WebSocket connections and process managementmcp_config.json
: 服务器配置文件 | Server configuration filerequirements.txt
: Python依赖包列表 | Python dependencies list.env
: 环境变量配置文件 | Environment variables configurationstart.ps1
: Windows PowerShell启动脚本 | Windows PowerShell startup scriptstart.sh
: Linux/Mac Bash启动脚本 | Linux/Mac Bash startup scriptcalculator.py
: Example MCP tool implementation for mathematical calculations | 用于数学计算的MCP工具示例实现requirements.txt
: Project dependencies | 项目依赖
编辑 mcp_config.json
文件来配置服务器列表(也可设置 MCP_CONFIG
环境变量指向其他配置文件)。
配置说明:
- 无参数时启动所有配置的服务(自动跳过
disabled: true
的条目) - 有参数时运行单个本地脚本文件
type=stdio
直接启动;type=sse/http
通过python -m mcp_proxy
代理
Here's a simple example of creating an MCP tool | 以下是一个创建MCP工具的简单示例:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("YourToolName")
@mcp.tool()
def your_tool(parameter: str) -> dict:
"""Tool description here"""
# Your implementation
return {"success": True, "result": result}
if __name__ == "__main__":
mcp.run(transport="stdio")
- Mathematical calculations | 数学计算
- Email operations | 邮件操作
- Knowledge base search | 知识库搜索
- Remote device control | 远程设备控制
- Data processing | 数据处理
- Custom tool integration | 自定义工具集成
- Python 3.7+
- websockets>=11.0.3
- python-dotenv>=1.0.0
- mcp>=1.8.1
- pydantic>=2.11.4
- mcp-proxy>=0.8.2
Contributions are welcome! Please feel free to submit a Pull Request.
欢迎贡献代码!请随时提交Pull Request。
This project is licensed under the MIT License - see the LICENSE file for details.
本项目采用MIT许可证 - 详情请查看LICENSE文件。
- Thanks to all contributors who have helped shape this project | 感谢所有帮助塑造这个项目的贡献者
- Inspired by the need for extensible AI capabilities | 灵感来源于对可扩展AI能力的需求