Skip to main content
Glama

calculate

Perform basic arithmetic calculations including addition, subtraction, multiplication, and division with two numbers.

Instructions

Perform basic arithmetic calculations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesThe arithmetic operation to perform
aYesFirst number
bYesSecond number

Implementation Reference

  • Handler function for the 'calculate' tool, performing arithmetic operations (add, subtract, multiply, divide) on inputs a and b, handling division by zero, and returning the result as text.
    case 'calculate':
      let result;
      switch (args.operation) {
        case 'add':
          result = args.a + args.b;
          break;
        case 'subtract':
          result = args.a - args.b;
          break;
        case 'multiply':
          result = args.a * args.b;
          break;
        case 'divide':
          if (args.b === 0) {
            throw new Error('Division by zero is not allowed');
          }
          result = args.a / args.b;
          break;
        default:
          throw new Error(`Unknown operation: ${args.operation}`);
      }
      
      return {
        content: [
          {
            type: 'text',
            text: `${args.a} ${args.operation} ${args.b} = ${result}`,
          },
        ],
      };
  • server.js:44-66 (registration)
    Registration of the 'calculate' tool in the ListTools response, defining name, description, and input schema for arithmetic operations.
    {
      name: 'calculate',
      description: 'Perform basic arithmetic calculations',
      inputSchema: {
        type: 'object',
        properties: {
          operation: {
            type: 'string',
            enum: ['add', 'subtract', 'multiply', 'divide'],
            description: 'The arithmetic operation to perform',
          },
          a: {
            type: 'number',
            description: 'First number',
          },
          b: {
            type: 'number',
            description: 'Second number',
          },
        },
        required: ['operation', 'a', 'b'],
      },
    },
  • Input schema definition for the 'calculate' tool, specifying operation (enum), numbers a and b as required properties.
    inputSchema: {
      type: 'object',
      properties: {
        operation: {
          type: 'string',
          enum: ['add', 'subtract', 'multiply', 'divide'],
          description: 'The arithmetic operation to perform',
        },
        a: {
          type: 'number',
          description: 'First number',
        },
        b: {
          type: 'number',
          description: 'Second number',
        },
      },
      required: ['operation', '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 tool performs calculations but doesn't mention any behavioral traits like error handling (e.g., division by zero), performance limits, or output format. This is a significant gap for a tool with potential side effects, scoring a 2 for inadequate transparency.

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 ('Perform basic arithmetic calculations') that is front-loaded and wastes no words. It directly conveys the core purpose without unnecessary elaboration, earning a 5 for optimal conciseness and structure.

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 tool's complexity (basic arithmetic with three parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't explain return values, error cases, or behavioral constraints, leaving gaps that could hinder an agent's correct invocation. This scores a 2 for insufficient contextual detail.

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?

The input schema has 100% description coverage, clearly documenting all three parameters (operation, a, b) with enums and descriptions. The description adds no additional parameter semantics beyond what the schema provides, so it meets the baseline of 3 for adequate but not enhanced parameter information.

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 'Perform basic arithmetic calculations' clearly states the tool's function with a specific verb ('perform') and resource ('calculations'), distinguishing it from siblings like 'echo' and 'get_system_info'. However, it doesn't specify the exact operations (add, subtract, etc.) or differentiate from potential alternative calculation tools, keeping it at a 4 rather than a 5.

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 context, prerequisites, or exclusions, such as when to use it over other calculation methods or tools. This leaves the agent without usage direction, scoring a 2 for minimal guidance.

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/balajidommeti/MCP'

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