Skip to main content
Glama
codewithmsunke

MCP Math Server

LCM tool

lcm

Calculate the least common multiple of two numbers to find the smallest positive integer divisible by both values.

Instructions

Calculate the least common multiple of two numbers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aYes
bYes

Implementation Reference

  • Handler function for the 'lcm' tool that computes the least common multiple using an inline GCD function and returns a formatted text response.
    async ({ a, b }) => {
      const gcd = (x: number, y: number): number => {
        x = Math.abs(x);
        y = Math.abs(y);
        while (y !== 0) {
          const temp = y;
          y = x % y;
          x = temp;
        }
        return x;
      };
      const lcm = (a: number, b: number): number => (a * b) / gcd(a, b);
      return {
        content: [
          { type: "text", text: `The least common multiple of ${a} and ${b} is ${lcm(a, b)}` }
        ]
      };
    }
  • Input schema for the 'lcm' tool defining parameters a and b as numbers using Zod validation.
    {
      title: "LCM tool",
      description: "Calculate the least common multiple of two numbers",
      inputSchema: { a: z.number(), b: z.number() },
    },
  • src/index.ts:140-166 (registration)
    Registration of the 'lcm' MCP tool via server.registerTool, including schema, title, description, and inline handler implementation.
    // LCM (Least Common Multiple)
    server.registerTool(
      "lcm",
      {
        title: "LCM tool",
        description: "Calculate the least common multiple of two numbers",
        inputSchema: { a: z.number(), b: z.number() },
      },
      async ({ a, b }) => {
        const gcd = (x: number, y: number): number => {
          x = Math.abs(x);
          y = Math.abs(y);
          while (y !== 0) {
            const temp = y;
            y = x % y;
            x = temp;
          }
          return x;
        };
        const lcm = (a: number, b: number): number => (a * b) / gcd(a, b);
        return {
          content: [
            { type: "text", text: `The least common multiple of ${a} and ${b} is ${lcm(a, b)}` }
          ]
        };
      }
    );
  • Inline helper function 'gcd' implementing the Euclidean algorithm for greatest common divisor, used in LCM calculation.
    const gcd = (x: number, y: number): number => {
      x = Math.abs(x);
      y = Math.abs(y);
      while (y !== 0) {
        const temp = y;
        y = x % y;
        x = temp;
      }
      return x;
    };
  • Inline helper function 'lcm' that computes least common multiple using the formula LCM(a,b) = |a*b| / GCD(a,b).
    const lcm = (a: number, b: number): number => (a * b) / gcd(a, b);
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the calculation action but does not describe traits like error handling (e.g., for non-integer inputs), performance characteristics, or output format. This is a significant gap for a tool with zero annotation coverage.

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 a single, efficient sentence with zero waste—it directly states the tool's function without unnecessary words. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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 low complexity (basic arithmetic operation) and lack of annotations or output schema, the description is minimally adequate. It covers the core purpose but lacks details on behavior, usage guidelines, and output, which could hinder an agent's ability to use it effectively in varied contexts.

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?

The description adds meaningful context beyond the input schema by specifying that the parameters are 'two numbers' for calculating the LCM, which clarifies the purpose of 'a' and 'b'. With 0% schema description coverage and 2 parameters, this compensates well, though it doesn't detail constraints like integer-only inputs.

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 specific verb 'calculate' and the resource 'least common multiple of two numbers', which precisely distinguishes it from sibling tools like 'add', 'divide', 'gcm', etc. It directly communicates the mathematical operation without ambiguity.

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 like 'gcm' (likely greatest common divisor) or other arithmetic operations. It lacks context about use cases, prerequisites, or comparisons with sibling tools, leaving the agent to infer usage scenarios.

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/codewithmsunke/MCPMathTools'

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