BMI计算与天气查询服务

一个基于Python的MCP服务器示例,提供BMI计算和城市天气查询功能。

  • by zusdn90
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 zusdn90/mcp-server

使用说明

mcp服务器

基于Python的MCP服务器示例

主要功能

  • BMI计算:输入体重(kg)和身高(m)计算BMI(体质量指数)。
  • 查询天气:输入城市名称以查看该城市的当前天气信息。

使用示例

1.BMI计算

@mcp.tool()
def calculate_bmi(weight_kg: float, height_m: float) -> float:
    """ Calculate the BMI given weight in kg and height in meters"""
    return weight_kg / (height_m ** 2)

2.查询天气

@mcp.tool()
async def fetch_weather(city: str) -> str:
    """ Fetch current weather for a city"""
    async with httpx.AsyncClient() as client:
        response = await client.get(f"https://api.weather.com/{city}")
        return response.text

执行方法

  1. 依赖性安装
    pip install httpx fastmcp
    
  2. 运行服务器
    python server.py