Skip to main content
Glama
shaleen-wonder-ent

Simple MCP Server

calculator

Perform addition, subtraction, multiplication, and division operations using inputs provided. Utilize this tool for quick and precise mathematical calculations on the MCP server.

Instructions

Perform basic mathematical operations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aYesThe first number
bYesThe second number
operationYesThe mathematical operation to perform

Implementation Reference

  • Handler function for the 'calculator' tool that parses input, performs arithmetic operations (add, subtract, multiply, divide), handles division by zero, and returns the result.
    case 'calculator': { const parsed = CalculatorArgsSchema.parse(args); let result: number; switch (parsed.operation) { case 'add': result = parsed.a + parsed.b; break; case 'subtract': result = parsed.a - parsed.b; break; case 'multiply': result = parsed.a * parsed.b; break; case 'divide': if (parsed.b === 0) { throw new Error('Division by zero is not allowed'); } result = parsed.a / parsed.b; break; default: throw new Error(`Unknown operation: ${parsed.operation}`); } return { content: [ { type: 'text', text: `Result is from my Simple MCP Server:=> ${parsed.a} ${parsed.operation} ${parsed.b} = ${result}`, }, { type: 'text', text: 'Ans is from Simple MCP Server.', }, ], }; }
  • Zod schema for validating calculator tool inputs: operation (enum), a and b (numbers).
    // Schema for the calculator tool input const CalculatorArgsSchema = z.object({ operation: z.enum(['add', 'subtract', 'multiply', 'divide']).describe('The mathematical operation to perform'), a: z.number().describe('The first number'), b: z.number().describe('The second number'), });
  • src/index.ts:57-79 (registration)
    Registration of the 'calculator' tool in the listTools response, including name, description, and JSON input schema.
    { name: 'calculator', description: 'Perform basic mathematical operations', inputSchema: { type: 'object', properties: { operation: { type: 'string', enum: ['add', 'subtract', 'multiply', 'divide'], description: 'The mathematical operation to perform', }, a: { type: 'number', description: 'The first number', }, b: { type: 'number', description: 'The second number', }, }, required: ['operation', 'a', 'b'], }, },

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/shaleen-wonder-ent/simple-mcp-server'

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