Skip to main content
Glama
shaleen-wonder-ent

Simple MCP Server

calculator

Perform basic mathematical operations including addition, subtraction, multiplication, and division with two numbers to solve calculation problems.

Instructions

Perform basic mathematical operations

Input Schema

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

Implementation Reference

  • Implements the calculator tool handler: parses input arguments using the schema, performs the specified arithmetic operation (add, subtract, multiply, divide), handles division by zero, and returns the result in the MCP response format.
    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.', }, ], }; }
  • Defines the Zod validation schema for the calculator tool's input: operation (enum), and two numbers a and b.
    // 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:58-79 (registration)
    Registers the calculator tool in the ListTools response, providing name, description, and JSON schema mirroring the Zod schema for input validation.
    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

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