Skip to main content
Glama
ref-tools

Widget MCP

by ref-tools

Unit Conversion

conversion

Perform real-time unit conversions with a widget that supports multiple units and their respective formulas. Input units and initial values to instantly calculate and display conversions in an interactive format.

Instructions

Display a unit conversion widget that allows real-time conversion between multiple units. Each unit should contain a formula for each other unit in terms of the current unit. Example input: { units: [{id: 'ft', name: 'Feet', formulas: {in:'{ft} * 12'}, {id: 'in', name: 'Inches', formulas: {ft:'{in} * 12'}}], initialValue: { id: 'ft', value: 1 }}. You don't need to say anything else after answering with this tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
initialValueYesInitial value to display in the converter
unitsYesArray of units with conversion formulas

Implementation Reference

  • Handler function that executes the tool logic: creates a templated UI resource for the unit conversion widget using the input units and initialValue, and returns it as content.
    async ({ units, initialValue }) => {
      const conversionResource = createTemplatedUIResource(
        createUIResource,
        "ui://widget/conversion",
        conversionHtml,
        { units, initialValue }
      );
    
      return {
        content: [conversionResource],
      };
    }
  • Zod-based input schema defining the expected parameters: an array of units (each with id, name, and formulas record) and an initialValue object with id and value.
    inputSchema: {
      units: z
        .array(
          z.object({
            id: z.string().describe("Unique identifier for the unit"),
            name: z.string().describe("Display name for the unit"),
            formulas: z
              .record(z.string())
              .describe("Conversion formulas to other units, using {id} as placeholder."),
          })
        )
        .describe("Array of units with conversion formulas"),
      initialValue: z
        .object({
          id: z.string().describe("ID of the unit to set initial value for"),
          value: z.number().describe("Initial value for the unit"),
        })
        .describe("Initial value to display in the converter"),
    },
  • index.ts:86-124 (registration)
    Registration of the 'conversion' tool on the MCP server, including the tool name, title, description, input schema, and handler function.
    server.registerTool(
      "conversion",
      {
        title: "Unit Conversion",
        description:
          "Display a unit conversion widget that allows real-time conversion between multiple units. Each unit should contain a formula for each other unit in terms of the current unit. Example input: { units: [{id: 'ft', name: 'Feet', formulas: {in:'{ft} * 12'}, {id: 'in', name: 'Inches', formulas: {ft:'{in} * 12'}}], initialValue: { id: 'ft', value: 1 }}. You don't need to say anything else after answering with this tool.",
        inputSchema: {
          units: z
            .array(
              z.object({
                id: z.string().describe("Unique identifier for the unit"),
                name: z.string().describe("Display name for the unit"),
                formulas: z
                  .record(z.string())
                  .describe("Conversion formulas to other units, using {id} as placeholder."),
              })
            )
            .describe("Array of units with conversion formulas"),
          initialValue: z
            .object({
              id: z.string().describe("ID of the unit to set initial value for"),
              value: z.number().describe("Initial value for the unit"),
            })
            .describe("Initial value to display in the converter"),
        },
      },
      async ({ units, initialValue }) => {
        const conversionResource = createTemplatedUIResource(
          createUIResource,
          "ui://widget/conversion",
          conversionHtml,
          { units, initialValue }
        );
    
        return {
          content: [conversionResource],
        };
      }
    );
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'display a widget' and 'real-time conversion,' but does not specify whether this is a read-only or interactive operation, what happens on invocation (e.g., UI display, data processing), or any constraints like rate limits or permissions. The description adds minimal behavioral context beyond the basic action.

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

Conciseness4/5

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

The description is appropriately sized with two sentences: one stating the purpose and one providing an example. It is front-loaded with the core functionality, though the example is detailed and could be slightly verbose. Overall, it avoids unnecessary information and earns its place efficiently.

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

Completeness3/5

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

Given the tool's complexity (2 parameters with nested objects, no output schema, and no annotations), the description is moderately complete. It covers the purpose and provides an example for parameters, but lacks details on behavioral traits, return values, or error handling. This leaves gaps for an agent to fully understand tool behavior without annotations or output schema.

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

Parameters4/5

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

Schema description coverage is 100%, so the schema already documents the parameters 'units' and 'initialValue' thoroughly. The description adds value by providing an example input that illustrates how to structure the parameters, including nested objects and formula placeholders, which clarifies semantics beyond the schema's technical definitions.

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

Purpose5/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: 'Display a unit conversion widget that allows real-time conversion between multiple units.' It specifies the verb ('display'), resource ('widget'), and functionality ('real-time conversion'), distinguishing it from sibling tools like display-fact, stopwatch, and timer which serve different purposes.

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

Usage Guidelines3/5

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

The description implies usage for unit conversion scenarios but does not explicitly state when to use this tool versus alternatives. It provides an example input, which hints at context, but lacks guidance on prerequisites, exclusions, or comparisons to sibling tools. This leaves the agent to infer usage from the purpose 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

Related 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/ref-tools/widget-mcp'

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