Skip to main content
Glama
cds-id

MCP Server Boilerplate

by cds-id

calculate

Perform basic arithmetic operations (add, subtract, multiply, divide) on two numbers to get calculation results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYes
aYes
bYes

Implementation Reference

  • The handler function that executes the 'calculate' tool logic, performing basic arithmetic operations (add, subtract, multiply, divide) on two numbers and returning the result or error for division by zero.
    async ({ operation, a, b }) => { let result: number | undefined; 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: Division by zero is not allowed.' }], isError: true, }; } result = a / b; break; } return { content: [ { type: 'text', text: `Result of ${operation}(${a}, ${b}) = ${result}`, }, ], }; }
  • Input schema for the 'calculate' tool, defining the operation type and two numeric operands using Zod.
    { operation: z.enum(['add', 'subtract', 'multiply', 'divide']), a: z.number(), b: z.number(), },
  • Registration of the 'calculate' tool on the MCP server instance, including schema and handler.
    server.tool( 'calculate', { operation: z.enum(['add', 'subtract', 'multiply', 'divide']), a: z.number(), b: z.number(), }, async ({ operation, a, b }) => { let result: number | undefined; 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: Division by zero is not allowed.' }], isError: true, }; } result = a / b; break; } return { content: [ { type: 'text', text: `Result of ${operation}(${a}, ${b}) = ${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/cds-id/mcp-server-boilerplate'

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