Xiaozhi MCP sample program
A powerful interface for extending AI capabilities through remote control, calculations, email operations, knowledge search, and more.
一个强大的接口,用于通过远程控制、计算、邮件操作、知识搜索等方式扩展AI能力。
MCP (Model Context Protocol) is a protocol that allows servers to expose tools that can be invoked by language models. Tools enable models to interact with external systems, such as querying databases, calling APIs, or performing computations. Each tool is uniquely identified by a name and includes metadata describing its schema.
MCP(模型上下文协议)是一个允许服务器向语言模型暴露可调用工具的协议。这些工具使模型能够与外部系统交互,例如查询数据库、调用API或执行计算。每个工具都由一个唯一的名称标识,并包含描述其模式的元数据。
pip install -r requirements.txt
export MCP_ENDPOINT=<your_mcp_endpoint>
python mcp_pipe.py calculator.py
mcp_pipe.py
: Main communication pipe that handles WebSocket connections and process management | 处理WebSocket连接和进程管理的主通信管道calculator.py
: Example MCP tool implementation for mathematical calculations | 用于数学计算的MCP工具示例实现requirements.txt
: Project dependencies | 项目依赖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")
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文件。
{ "mcpServers": { "mcp-calculator": { "command": "python", "args": [ "mcp_pipe.py", "calculator.py" ] } } }
Related projects feature coming soon
Will recommend related projects based on sub-categories