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'], },

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