temperature_convert
Convert temperatures between Celsius and Fahrenheit by providing a numeric value and the original unit (C or F).
Instructions
摄氏度与华氏度互相转换。
参数:
value: 温度数值
from_unit: 原始单位,C 表示摄氏度,F 表示华氏度Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| value | Yes | ||
| from_unit | Yes |
Implementation Reference
- server.py:92-107 (handler)The temperature_convert tool handler function that converts Celsius to Fahrenheit and vice versa. Registered via @mcp.tool() decorator on line 92. Accepts a float value and a from_unit string ('C' or 'F'), returns a dict with input/output strings or an error.
@mcp.tool() def temperature_convert(value: float, from_unit: str) -> dict: """摄氏度与华氏度互相转换。 参数: value: 温度数值 from_unit: 原始单位,C 表示摄氏度,F 表示华氏度 """ if from_unit.upper() == "C": result = value * 9 / 5 + 32 return {"input": f"{value}°C", "output": f"{result:.1f}°F"} elif from_unit.upper() == "F": result = (value - 32) * 5 / 9 return {"input": f"{value}°F", "output": f"{result:.1f}°C"} else: return {"error": "from_unit 必须是 C 或 F"} - server.py:92-92 (registration)The @mcp.tool() decorator registers temperature_convert as an MCP tool on the FastMCP server instance.
@mcp.tool() - server_remote.py:90-105 (handler)Duplicate of temperature_convert in the remote/HTTP version of the server (server_remote.py). Same logic, registered via @mcp.tool() on line 90.
@mcp.tool() def temperature_convert(value: float, from_unit: str) -> dict: """摄氏度与华氏度互相转换。 参数: value: 温度数值 from_unit: 原始单位,C 表示摄氏度,F 表示华氏度 """ if from_unit.upper() == "C": result = value * 9 / 5 + 32 return {"input": f"{value}°C", "output": f"{result:.1f}°F"} elif from_unit.upper() == "F": result = (value - 32) * 5 / 9 return {"input": f"{value}°F", "output": f"{result:.1f}°C"} else: return {"error": "from_unit 必须是 C 或 F"} - server_remote.py:90-90 (registration)The @mcp.tool() decorator registers temperature_convert in the remote HTTP-based server.
@mcp.tool()