Skip to main content
Glama
cds-id

MCP Server Boilerplate

by cds-id

calculate

Perform arithmetic operations like addition, subtraction, multiplication, and division using specified numerical inputs. Part of the MCP Server Boilerplate for standardized context in LLM applications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aYes
bYes
operationYes

Implementation Reference

  • The handler function that executes the arithmetic calculation based on the specified operation ('add', 'subtract', 'multiply', 'divide'), handling inputs a and b, with division by zero error check.
    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}`, }, ], }; }
  • Zod input schema for the 'calculate' tool, validating operation as one of the arithmetic enums and a, b as numbers.
    { operation: z.enum(['add', 'subtract', 'multiply', 'divide']), a: z.number(), b: z.number(), },
  • The server.tool call that registers the 'calculate' tool with its name, input schema, and handler function on the MCP server instance.
    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}`, }, ], }; } );

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/cds-id/mcp-server-boilerplate'

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