Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

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
NameRequiredDescriptionDefault
valueYesPressure value to convert
from_unitYesSource unit
to_unitYesTarget 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]
  • 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", ]
  • 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, )

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zazencodes/unit-converter-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server