convert_force
Convert force values between units like newtons, pounds force, kilonewtons, and more. Simplify unit conversions for engineering, physics, and everyday applications.
Instructions
Convert force between units.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_unit | Yes | Source unit | |
| to_unit | Yes | Target unit | |
| value | Yes | Force value to convert |
Implementation Reference
- Core function implementing the force unit conversion logic by normalizing to newtons.def convert_force_tool( value: float, from_unit: FORCE_UNIT, to_unit: FORCE_UNIT, ) -> float: """Convert force between units.""" # Convert to newtons first to_newtons = { "dynes": 1e-05, "kilograms force": 9.80665, "kilonewtons": 1_000.0, "kips": 4_448.222, "meganewtons": 1_000_000.0, "newtons": 1.0, "pounds force": 4.44822161526, "tonnes force": 9_806.65, "long tons force": 9_964.01641818352, "short tons force": 8_896.443230521, } newtons = value * to_newtons[from_unit] return newtons / to_newtons[to_unit]
- Literal type defining all supported force units for input validation.FORCE_UNIT = Literal[ "dynes", "kilograms force", "kilonewtons", "kips", "meganewtons", "newtons", "pounds force", "tonnes force", "long tons force", "short tons force", ]
- src/unit_converter_mcp/server.py:130-144 (registration)MCP tool registration using @app.tool() that wraps the core handler and formats the standardized response dictionary.@app.tool() def convert_force( value: Annotated[float, Field(description="Force value to convert")], from_unit: Annotated[FORCE_UNIT, Field(description="Source unit")], to_unit: Annotated[FORCE_UNIT, Field(description="Target unit")], ) -> dict: """Convert force between units.""" converted_value = convert_force_tool(value, from_unit, to_unit) return { "original_value": value, "original_unit": from_unit, "converted_value": converted_value, "converted_unit": to_unit, "conversion_type": "force", }