Skip to main content
Glama
dh1789

My First MCP

by dh1789

calculate

Perform basic arithmetic operations (addition, subtraction, multiplication, division) on two numbers to get calculation results.

Instructions

두 숫자의 사칙연산(덧셈, 뺄셈, 곱셈, 나눗셈)을 수행합니다.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aYes첫 번째 숫자
bYes두 번째 숫자
operationYes연산 종류: add(덧셈), subtract(뺄셈), multiply(곱셈), divide(나눗셈)

Implementation Reference

  • Core pure function implementing the arithmetic calculation logic with operation handling and division-by-zero error check.
    export function calculate(
      a: number,
      b: number,
      operation: Operation
    ): CalculateResult {
      const symbols: Record<Operation, string> = {
        add: "+",
        subtract: "-",
        multiply: "×",
        divide: "÷",
      };
    
      if (operation === "divide" && b === 0) {
        return {
          result: NaN,
          expression: `${a} ${symbols[operation]} ${b}`,
          isError: true,
          errorMessage: "오류: 0으로 나눌 수 없습니다.",
        };
      }
    
      let result: number;
      switch (operation) {
        case "add":
          result = a + b;
          break;
        case "subtract":
          result = a - b;
          break;
        case "multiply":
          result = a * b;
          break;
        case "divide":
          result = a / b;
          break;
      }
    
      return {
        result,
        expression: `${a} ${symbols[operation]} ${b} = ${result}`,
        isError: false,
      };
    }
  • TypeScript type definitions for the operation enum and result interface used by the calculate tool.
    export type Operation = "add" | "subtract" | "multiply" | "divide";
    
    export interface CalculateResult {
      result: number;
      expression: string;
      isError: boolean;
      errorMessage?: string;
    }
  • src/index.ts:121-155 (registration)
    MCP server.tool registration for the 'calculate' tool, defining description, Zod input schema, and async handler that wraps the core calculate function and formats MCP response.
    server.tool(
      "calculate",
      "두 숫자의 사칙연산(덧셈, 뺄셈, 곱셈, 나눗셈)을 수행합니다.",
      {
        a: z.number().describe("첫 번째 숫자"),
        b: z.number().describe("두 번째 숫자"),
        operation: z
          .enum(["add", "subtract", "multiply", "divide"])
          .describe("연산 종류: add(덧셈), subtract(뺄셈), multiply(곱셈), divide(나눗셈)"),
      },
      async ({ a, b, operation }) => {
        const result = calculate(a, b, operation as Operation);
    
        if (result.isError) {
          return {
            content: [
              {
                type: "text",
                text: result.errorMessage!,
              },
            ],
            isError: true,
          };
        }
    
        return {
          content: [
            {
              type: "text",
              text: result.expression,
            },
          ],
        };
      }
    );
  • Zod schema for input parameters (a, b, operation) used in the tool registration.
    {
      a: z.number().describe("첫 번째 숫자"),
      b: z.number().describe("두 번째 숫자"),
      operation: z
        .enum(["add", "subtract", "multiply", "divide"])
        .describe("연산 종류: add(덧셈), subtract(뺄셈), multiply(곱셈), divide(나눗셈)"),
    },
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 it states what the tool does, it doesn't mention error handling (e.g., division by zero), output format, precision limits, or any side effects. For a tool with mathematical operations, this lack of behavioral context is a significant gap.

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 in Korean that directly states the tool's function without any fluff or redundant information. It's 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.

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete for a tool performing mathematical operations. It doesn't address potential errors (like division by zero), return value format, or numerical precision, which are critical for an AI agent to use the tool correctly and handle edge cases.

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 clear descriptions for all three parameters in the input schema. The description adds no additional parameter semantics beyond what's already documented in the schema (e.g., it doesn't explain parameter constraints or usage examples). This meets the baseline for high schema coverage.

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 performs basic arithmetic operations (addition, subtraction, multiplication, division) on two numbers. It specifies both the action ('performs') and the resource ('two numbers'), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'get_random_number' or 'count_lines', which prevents a perfect score.

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 any prerequisites, limitations, or specific contexts where this tool is preferred over other calculation methods or sibling tools. The agent must infer usage purely from the tool's name and description.

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/dh1789/my-first-mcp'

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