Skip to main content
Glama

calculate

Perform addition, subtraction, multiplication, or division with this arithmetic tool. Input two numbers and choose the operation to receive precise results instantly via the MCP server.

Instructions

Perform basic arithmetic calculations

Input Schema

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

Implementation Reference

  • Handler function for the 'calculate' tool that performs arithmetic operations (add, subtract, multiply, divide) based on the input operation, a, and b parameters, and returns 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}`, }, ], };
  • Input schema for the 'calculate' tool, defining the operation (enum: add, subtract, multiply, divide), and required numbers a and b.
    { 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'], },
  • server.js:27-77 (registration)
    Registration of the 'calculate' tool via the ListToolsRequestHandler, including it in the list of available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'echo', description: 'Echo back the input message', inputSchema: { type: 'object', properties: { message: { type: 'string', description: 'Message to echo back', }, }, required: ['message'], }, }, { 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'], }, }, { name: 'get_system_info', description: 'Get basic system information', inputSchema: { type: 'object', properties: {}, }, }, ], }; });

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

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