quantity-engine
Use it to perform dimensional calculation and unit conversion via MCP with reproducible evidence.
Call the
quantity_executeMCP tool with anoperationsarray.Multiply quantities with units (
op: mul, usingaandb).Convert a quantity to a target unit (
op: convert, usingto).Chain multi-step calculations by referencing previous operands (
a: {ref: ...}).Control precision with
precision.mode(HALF_EVEN/HALF_UP) andprecision.scale.Receive an
exactnessresult, anerror_boundwhen approximate, and afull_evidence_hashfor replay.Failures are reported as structured taxonomy codes (e.g.,
UNKNOWN_UNITorDIMENSION_MISMATCH_UNBRIDGEABLE).
Quantity Engine — MCP Server
An MCP (Model Context Protocol) server that performs dimensional calculation and unit conversion with evidence and reproducibility.
Solves silent unit errors in LLM agent chains. 5 kg × 9.81 m/s^2 returns 49.05 N with evidence, not a plausible-looking wrong number.
MCP usage
The server exposes one MCP tool: quantity_execute. It runs over stdio and follows the MCP protocol via the official Python SDK (mcp).
Register with any MCP client.
Claude Desktop
claude_desktop_config.json:
{
"mcpServers": {
"quantity-engine": {
"command": "python",
"args": ["/absolute/path/to/mcp_server.py"]
}
}
}Cursor / VS Code / Continue
Same shape — command, args, no env required.
Manual run
pip install -r requirements.txt
python mcp_server.pyThe server listens on stdio. Ctrl+C to stop.
Related MCP server: SharkMath MCP
Tool contract
tool.json defines quantity_execute with input and output schemas. The MCP server registers this tool and forwards calls to the engine unchanged — no interpretation, no fallback.
Example call:
{
"operations": [
{"id": "s0", "op": "mul",
"a": {"value": 5, "unit": "kg"},
"b": {"value": 9.81, "unit": "m/s^2"}},
{"id": "s1", "op": "convert",
"a": {"ref": "s0", "as": "N"}, "to": "N"}
]
}Returns 49.05 N with exactness, error_bound if approximated, and full_evidence_hash for replay of the evidence.
Example addition:
{
"operations": [
{"id": "s0", "op": "add",
"a": {"value": 5, "unit": "N"},
"b": {"value": 3, "unit": "N"}}
]
}Returns 8 N (EXACT).
Example division:
{
"operations": [
{"id": "s0", "op": "div",
"a": {"value": 10, "unit": "N"},
"b": {"value": 2, "unit": "s"}}
]
}Returns 5 N/s. Dimension is derived from operand exponents (M·L·T⁻³).
What the engine does
Closed quantity algebra:
mul,add,sub,div,convertExact rational arithmetic (no float drift)
Explicit precision policy (EXACT vs APPROXIMATED with error_bound)
Provenance hash (
full_evidence_hash) for replay of the evidenceStructured failure taxonomy (
MISSING_UNIT_DECLARATION,UNKNOWN_UNIT,INVALID_UNIT_NOTATION,INVALID_UNIT_CAST,UNKNOWN_OP,DIVISION_BY_ZERO,DIMENSION_MISMATCH_UNBRIDGEABLE,NEEDS_CLARIFICATION,NEEDS_REFERENCE_DATA)No automatic reduction of compound units (
N*mis reported asN*m, notJ)Money as separate domain with temporal context (stub)
Evidence is not correctness. The hash proves what inputs, versions, and reference data were used, and allows the same operation to be replayed against the same evidence. Mathematical correctness rests on the dimensional model, the engine rules, and the test suite — not on the hash.
Layout
quantities.py engine (zero external dependencies)
tool.json MCP tool contract
mcp_server.py MCP stdio transport (uses mcp, jsonschema)
requirements.txt mcp, jsonschema — only needed for the MCP transport
Dockerfile container for MCP deploymentStatus
MVP. 14 tests passing (python quantities.py). Not production. FX rates are stub.
Algebra is closed over the current dimensional model. cm, km, h, J, W are not in the registry — they require an explicit registry extension, not a code change.
License
Apache 2.0.
Available Tools
1 toolquantity_executeB
Execute dimensional calculation and unit conversion with audit evidence. Input: sequence of typed operations (mul, add, sub, div, convert). Output: result value with unit, precision metadata, and reproducibility hash, or a structured failure.
| Name | Required | Description | Default |
|---|---|---|---|
| precision | No | ||
| operations | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden, and it does disclose the return shape (value with unit, precision metadata, reproducibility hash, or structured failure) and implies deterministic behavior via the hash. It omits whether the operation is pure/read-only, how failures are triggered, and any validation rules, leaving notable behavioral gaps.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences, front-loaded with the purpose followed by a compact input/output summary; no filler. Slightly terse given the nested schema, but structurally clean.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
No output schema exists, and the description does cover return values, which is a plus. However, for a tool with a nested operations array and an undocumented operand $ref, the description leaves the caller without enough detail on how to assemble operations correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0% at the top level and the tool has a nested operations array plus a precision object, so the description should compensate more. It names the operation types (mul/add/sub/div/convert) and references precision metadata, but does not explain operand structure, the precision.mode/scale fields, or the 'to'/'at' semantics.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb (Execute) and resource (dimensional calculation and unit conversion) with the audit-evidence angle, and enumerates the operation types. No siblings exist to differentiate, but the purpose itself is unambiguous.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
There is no guidance on when to choose this tool, prerequisites, or exclusions; the 'Input/Output' phrasing describes the contract rather than usage conditions. An agent learns what to send, not when this is the right call.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
1 tool update
v0.1.1- Changed
quantity_execute2 fields changed- changed
Input schema / properties / operations / items / properties / b / descriptionPrevious value: -"Required for mul"New value: +"Required for mul, add, sub, div" - changed
Input schema / properties / operations / items / properties / op / enumPrevious value: -[ - "mul", - "convert" -]New value: +[ + "mul", + "add", + "sub", + "div", + "convert" +]
1 tool update
v0.1.0- First observed
quantity_execute
TDQS
Scored across 1 tool
With only one tool in the set, there is no possibility of choosing the wrong tool or confusing overlapping purposes. The single tool's scope (a sequence of typed arithmetic/conversion operations) is clearly bounded and self-contained.
The lone name `quantity_execute` uses a noun_verb pattern that is prefixed consistently with the server name (quantity-engine) and is unambiguous. It is readable and predictable, though a pure verb_noun convention (e.g. execute_quantity) would be more idiomatic.
A single batch-style execute tool is a defensible design for a calculation engine, since operations are passed as a sequence rather than as separate endpoints. However, one tool is thin for the apparent domain and forces everything—including discovery and validation—through the same opaque entry point.
Core arithmetic (mul, add, sub, div) and unit conversion with precision metadata and failure reporting cover the main lifecycle of a dimensional calculation. Gaps remain: no unit/introspection operation to discover valid units, and no support for common operations like exponentiation, roots, rounding, or comparison.
Maintenance
Related MCP Connectors
60+ units, live FX, timezones, and date arithmetic for AI agents.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
MCP server for progressive tool usage at any scale (see https://klavis.ai)
MCP server exposing the Backtest360 engine API as tools for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceVerified unit conversion and dimensional analysis for AI agents. 190+ units, 31 domain formulas (clinical, physics, aerospace, SRE), physical constants with uncertainty propagation. Refuses invalid conversions structurally: the tool that won't convert mg to mL and knows the difference between torque and energy.AGPL 3.0
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server providing 150+ mathematical functions across arithmetic, trigonometry, statistics, unit conversions, and more, consolidated into 15 powerful tools for seamless integration with VS Code Copilot and other MCP-compatible clients.MIT
- AlicenseAqualityDmaintenanceAn MCP server that provides deterministic unit conversions backed by Pint, enabling exact unit conversions, compatibility checks, and parsing of quantities for LLMs.5MIT
- AlicenseAqualityDmaintenanceA stdio MCP server that gives LLMs a safe scientific calculator with infix math, complex numbers, matrices, statistics, unit conversions, and more via tools that return JSON.331MIT