Skip to main content
Glama

calculate

Perform arithmetic operations (add, subtract, multiply, divide) using a cloud-based, authless server. Submit numerical inputs to compute results instantly without authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aYes
bYes
operationYes

Implementation Reference

  • Handler function for the 'calculate' tool. Performs add, subtract, multiply, or divide operations on inputs a and b based on the operation parameter, handling division by zero error.
    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) }] }; }
  • Input schema for the 'calculate' tool, defining operation as an enum of arithmetic operations and a, b as numbers.
    { operation: z.enum(["add", "subtract", "multiply", "divide"]), a: z.number(), b: z.number(), },
  • src/index.ts:23-57 (registration)
    Registration of the 'calculate' tool using this.server.tool(), including name, schema, and handler.
    this.server.tool( "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) }] }; } );

Other Tools

Related 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