mcp初探
一、mcp服务部署
1.1、编写mcp服务代码
建立一个名为 mcp_test.py的文件,内容如下
import json
import os
import asyncio
from fastmcp import FastMCP
from datetime import datetimemcp = FastMCP(name="查询服务器信息MCP")# 使用@mcp.tool装饰器定义MCP工具
@mcp.tool(name="get_system_time",description="获取当前系统的时间和日期"
)
async def get_system_time():"""获取当前系统时间的工具函数"""current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")return {"status": "success","data": {"system_time": current_time},"message": "当前系统时间获取成功"}if __name__ == "__main__":# 使用SSE传输(取消注释下面这行)mcp.run(transport="sse", host="0.0.0.0", port=8888)
上述代码主要是获取系统时间