Skip to main content
Glama

calculate

Perform arithmetic operations including addition, subtraction, multiplication, and division on two numbers using this calculation tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYes
aYes
bYes

Implementation Reference

  • The handler function for the 'calculate' tool that performs add, subtract, multiply, or divide operations on inputs a and b, handling division by zero.
    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": if (b === 0) return { content: [ { type: "text", text: "Error: Cannot divide by zero", }, ], }; result = a / b; break; } return { content: [{ type: "text", text: String(result) }] }; }
  • Zod schema defining the input parameters for the 'calculate' tool: operation (enum), a (number), b (number).
    operation: z.enum(["add", "subtract", "multiply", "divide"]), a: z.number(), b: z.number(), }, async ({ operation, a, b }) => {
  • src/index.ts:24-57 (registration)
    Registration of the 'calculate' tool using this.server.tool, including name, input schema, and handler function.
    "calculate", { operation: z.enum(["add", "subtract", "multiply", "divide"]), a: z.number(), b: z.number(), }, async ({ operation, a, b }) => { 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": if (b === 0) return { content: [ { type: "text", text: "Error: Cannot divide by zero", }, ], }; result = a / b; break; } return { content: [{ type: "text", text: String(result) }] }; } );
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/feraranas/remote-mcp-server-authless'

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