Skip to main content
Glama
codewithmsunke

MCP Math Server

GCM tool

gcm

Calculate the greatest common divisor (GCD) of two numbers to find the largest integer that divides both without a remainder.

Instructions

Calculate the greatest common measure (GCD) of two numbers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aYes
bYes

Implementation Reference

  • Handler function that executes the GCD (Greatest Common Divisor) logic using the Euclidean algorithm, takes inputs a and b, 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 result = gcd(a, b);
      return {
        content: [
          { type: "text", text: `The greatest common measure of ${a} and ${b} is ${result}` }
        ]
      };
    }
  • Input schema and metadata (title, description) for the gcm tool, validating two numeric inputs a and b using Zod.
    {
      title: "GCM tool",
      description: "Calculate the greatest common measure (GCD) of two numbers",
      inputSchema: { a: z.number(), b: z.number() },
    },
  • src/index.ts:113-138 (registration)
    Registers the 'gcm' tool with the MCP server, specifying name, schema, and inline handler function.
    server.registerTool(
      "gcm",
      {
        title: "GCM tool",
        description: "Calculate the greatest common measure (GCD) 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 result = gcd(a, b);
        return {
          content: [
            { type: "text", text: `The greatest common measure of ${a} and ${b} is ${result}` }
          ]
        };
      }
    );
  • Inner helper function implementing the Euclidean algorithm for GCD computation.
    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;
    };
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. While 'calculate' implies a read-only operation, the description doesn't specify error handling (e.g., for non-integer inputs), performance characteristics, or output format. It lacks details on what happens with negative numbers, zeros, or large values.

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 wasted words. It's front-loaded with the core purpose and uses precise terminology ('greatest common measure (GCD)'). Every word earns its place by defining the operation and its inputs.

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?

For a simple mathematical tool with 2 parameters, no annotations, and no output schema, the description is minimally adequate. It covers the basic purpose and parameters but lacks behavioral details (e.g., output format, error cases) and usage guidelines relative to siblings. The absence of annotations increases the need for more completeness.

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 explicitly states that the tool calculates GCD for 'two numbers,' which directly maps to parameters a and b. With 0% schema description coverage (schema only specifies types as 'number'), this adds crucial semantic meaning beyond the bare schema. However, it doesn't clarify if these are integers, natural numbers, or any numerical type.

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 resource ('greatest common measure (GCD) of two numbers'), distinguishing it from sibling tools like add, subtract, multiply, divide, lcm, sqrt, and square. It precisely defines the mathematical operation being performed.

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. It doesn't mention sibling tools like lcm (least common multiple) or other mathematical operations, nor does it specify use cases or prerequisites for calculating GCD.

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