21 lines
570 B
Python
21 lines
570 B
Python
# uv add fastmcp
|
|
import logging
|
|
|
|
from fastmcp import FastMCP
|
|
|
|
mcp = FastMCP("mcp demo")
|
|
|
|
|
|
@mcp.tool()
|
|
async def get_weather(city: str) -> str:
|
|
"""获取传入的城市的天气信息"""
|
|
logging.info(f"调用了查询天气服务,传入的参数为{city}")
|
|
return f"{city}的天气很好,阳光明媚,晴空万里"
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
logging.info("启动一个可以通过MCP调用获取天气的服务")
|
|
mcp.run(transport="streamable-http", host="127.0.0.1", port=9000)
|
|
# mcp.run(transport="stdio", host="127.0.0.1", port=9000)
|