Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_density

Convert density measurements between units like grams per cubic centimeter, kilograms per cubic meter, pounds per gallon, and more for scientific, engineering, or industrial calculations.

Instructions

Convert density between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesDensity value to convert
from_unitYesSource unit
to_unitYesTarget unit

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP server tool handler named 'convert_density' that performs the density unit conversion by calling the core convert_density_tool and formatting the response.
    @app.tool()
    def convert_density(
        value: Annotated[float, Field(description="Density value to convert")],
        from_unit: Annotated[DENSITY_UNIT, Field(description="Source unit")],
        to_unit: Annotated[DENSITY_UNIT, Field(description="Target unit")],
    ) -> dict:
        """Convert density between units."""
        converted_value = convert_density_tool(value, from_unit, to_unit)
        return {
            "original_value": value,
            "original_unit": from_unit,
            "converted_value": converted_value,
            "converted_unit": to_unit,
            "conversion_type": "density",
        }
  • Core implementation of density unit conversion, normalizing all units to kilograms per liter using predefined conversion factors.
    def convert_density_tool(
        value: float,
        from_unit: DENSITY_UNIT,
        to_unit: DENSITY_UNIT,
    ) -> float:
        """Convert density between units."""
    
        # Convert to kilograms per liter first
        to_kilograms_per_liter = {
            # grain‑based hardness units
            "grains per gallon (UK)": 1.4253948e-05,
            "grains per gallon (US)": 1.7118012e-05,
            "grains per gallon": 1.7118012e-05,  # Default to US grains per gallon
            # metric staples
            "grams per cubic centimeter": 1.0,
            "grams per liter": 0.001,
            "kilograms per liter": 1.0,
            "kilograms per cubic meter": 0.001,
            "milligrams per liter": 1e-06,
            # fluid‑ounce units
            "ounces per gallon (UK)": 0.006236023,
            "ounces per gallon (US)": 0.007489152,
            "ounces per gallon": 0.007489152,  # Default to US ounces per gallon
            # pound‑based units
            "pounds per cubic foot": 0.016018463,
            "pounds per gallon (UK)": 0.099776373,
            "pounds per gallon (US)": 0.119826427,
            "pounds per gallon": 0.119826427,  # Default to US pounds per gallon
            # tonne/ton bulk‑density units
            "tonnes per cubic meter": 1.0,
            "tons per cubic yard (UK)": 1.328939184,
            "tons per cubic yard (US)": 1.186552843,
            "tons per cubic yard": 1.186552843,  # Default to US tons per cubic yard
        }
    
        kilograms_per_liter = value * to_kilograms_per_liter[from_unit]
        return kilograms_per_liter / to_kilograms_per_liter[to_unit]
  • Pydantic/Literal type definition for all supported density units used in tool parameters.
    DENSITY_UNIT = Literal[
        "grains per gallon (UK)",
        "grains per gallon (US)",
        "grains per gallon",
        "grams per cubic centimeter",
        "grams per liter",
        "kilograms per liter",
        "kilograms per cubic meter",
        "milligrams per liter",
        "ounces per gallon (UK)",
        "ounces per gallon (US)",
        "ounces per gallon",
        "pounds per cubic foot",
        "pounds per gallon (UK)",
        "pounds per gallon (US)",
        "pounds per gallon",
        "tonnes per cubic meter",
        "tons per cubic yard (UK)",
        "tons per cubic yard (US)",
        "tons per cubic yard",
    ]
  • Imports the convert_density_tool and DENSITY_UNIT from tools package for use in MCP server 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,
    )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. 'Convert density between units' implies a pure calculation/transformation, but doesn't specify whether this is a read-only operation, whether it has side effects, error conditions, or performance characteristics. The description is minimal and lacks behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise - a single sentence that directly states the tool's function. There's zero waste or redundancy. It's appropriately sized for a straightforward conversion tool with comprehensive schema documentation.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a simple conversion tool with 100% schema coverage and an output schema (implied by context signals), the description is reasonably complete. The combination of clear purpose, comprehensive parameter documentation in schema, and expected output schema reduces the burden on the description. However, it could benefit from minimal context about unit relationships.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with all parameters clearly documented in the schema. The description doesn't add any parameter semantics beyond what's already in the structured fields - it doesn't explain unit relationships, conversion precision, or special cases. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: converting density between units. It specifies both the resource (density) and the action (convert between units). However, it doesn't differentiate from sibling tools beyond the 'density' specification - all other convert_* tools have similar descriptions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of when density conversion is appropriate versus other conversion types, nor any prerequisites or constraints. The agent must infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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