convert_pressure
Convert pressure values between units like psi, bar, pascal, and atmosphere for engineering, scientific, or industrial applications.
Instructions
Convert pressure between units.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| value | Yes | Pressure value to convert | |
| from_unit | Yes | Source unit | |
| to_unit | Yes | Target unit |
Implementation Reference
- Core handler function that implements the pressure unit conversion logic by converting to Pascals as intermediate unit.def convert_pressure_tool( value: float, from_unit: PRESSURE_UNIT, to_unit: PRESSURE_UNIT, ) -> float: """Convert pressure between units.""" # Convert to pascals first to_pascals = { # SI units and simple multiples "pascal": 1.0, "hectopascal": 100.0, "kilopascal": 1_000.0, "megapascal": 1_000_000.0, # Reference pressures "bar": 100_000.0, # common in industry & diving "atmosphere": 101_325.0, # Water‑column units "centimeters of water": 98.0665, "inches of water": 249.08891, "feet of water": 2_989.06692, "meters of water": 9_806.65, # Mercury‑column units "millimeters of mercury": 133.322, "inches of mercury": 3_386.388, # Force per area "kilogram force per square centimeter": 98_066.5, "newtons per square centimeter": 10_000.0, "newtons per square millimeter": 1_000_000.0, # Widely‑recognised US customary symbols "psi": 6_894.757293168362, "psf": 47.880258980336, } pascals = value * to_pascals[from_unit] return pascals / to_pascals[to_unit]
- src/unit_converter_mcp/server.py:147-161 (handler)MCP tool handler for 'convert_pressure', registers the tool and wraps the core logic with standardized response format.@app.tool() def convert_pressure( value: Annotated[float, Field(description="Pressure value to convert")], from_unit: Annotated[PRESSURE_UNIT, Field(description="Source unit")], to_unit: Annotated[PRESSURE_UNIT, Field(description="Target unit")], ) -> dict: """Convert pressure between units.""" converted_value = convert_pressure_tool(value, from_unit, to_unit) return { "original_value": value, "original_unit": from_unit, "converted_value": converted_value, "converted_unit": to_unit, "conversion_type": "pressure", }
- Type schema defining the supported pressure units as a Literal union for input validation.from typing import Literal PRESSURE_UNIT = Literal[ "pascal", "hectopascal", "kilopascal", "megapascal", "bar", "atmosphere", "centimeters of water", "inches of water", "feet of water", "meters of water", "millimeters of mercury", "inches of mercury", "kilogram force per square centimeter", "newtons per square centimeter", "newtons per square millimeter", "psi", "psf", ]
- src/unit_converter_mcp/server.py:8-38 (registration)Imports the convert_pressure_tool and PRESSURE_UNIT into the server for use in tool definitions.from .tools import ( ANGLE_UNIT, AREA_UNIT, COMPUTER_DATA_UNIT, DENSITY_UNIT, ENERGY_UNIT, FORCE_UNIT, LENGTH_UNIT, MASS_UNIT, POWER_UNIT, PRESSURE_UNIT, SPEED_UNIT, TEMPERATURE_UNIT, TIME_UNIT, VOLUME_UNIT, convert_angle_tool, convert_area_tool, convert_batch_tool, convert_computer_data_tool, convert_density_tool, convert_energy_tool, convert_force_tool, convert_length_tool, convert_mass_tool, convert_power_tool, convert_pressure_tool, convert_speed_tool, convert_temperature_tool, convert_time_tool, convert_volume_tool, )