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
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | First number | |
| b | Yes | Second number | |
| operation | Yes | The arithmetic operation to perform |
Implementation Reference
- server.js:94-123 (handler)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}`, }, ], };
- server.js:44-65 (schema)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: {}, }, }, ], }; });