Skip to main content
Glama
jaejin0me

TypeScript MCP Server Boilerplate

by jaejin0me

calculator

Perform basic mathematical calculations including addition, subtraction, multiplication, and division using two numbers. This tool handles arithmetic operations for mathematical problem-solving.

Instructions

Perform basic mathematical calculations

Input Schema

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

Implementation Reference

  • The main handler function for the 'calculator' tool. It takes operation ('add', 'subtract', 'multiply', 'divide'), numbers a and b, performs the calculation, handles divide-by-zero and invalid operation errors, and returns the result as text.
    }, async (args) => {
        const { operation, a, b } = args
        
        let result: number
        let operationSymbol: string
        
        switch (operation) {
            case 'add':
                result = a + b
                operationSymbol = '+'
                break
            case 'subtract':
                result = a - b
                operationSymbol = '-'
                break
            case 'multiply':
                result = a * b
                operationSymbol = '×'
                break
            case 'divide':
                if (b === 0) {
                    return {
                        content: [{ 
                            type: 'text', 
                            text: '오류: 0으로 나눌 수 없습니다. (Error: Cannot divide by zero)' 
                        }]
                    }
                }
                result = a / b
                operationSymbol = '÷'
                break
            default:
                return {
                    content: [{ 
                        type: 'text', 
                        text: '오류: 지원되지 않는 연산입니다. (Error: Unsupported operation)' 
                    }]
                }
        }
        
        const calculation = `${a} ${operationSymbol} ${b} = ${result}`
        
        return {
            content: [{ type: 'text', text: calculation }]
        }
    })
  • Zod input schema for the calculator tool defining the parameters: operation (enum of math operations), a and b (numbers).
    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:37-38 (registration)
    Registration of the 'calculator' tool using server.tool(), including name, description, and linking to schema and handler.
    // Add calculator tool
    server.tool('calculator', 'Perform basic mathematical calculations', {
  • src/index.ts:249-249 (registration)
    The 'calculator' tool is listed in the server capabilities within the server-info resource.
    tools: ['greeting', 'calculator', 'time'],
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool performs calculations but doesn't reveal any behavioral traits such as error handling (e.g., division by zero), precision limits, rate limits, or authentication needs. This leaves significant gaps in understanding how the tool behaves in practice.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It's appropriately sized for a simple tool and front-loads the core purpose without unnecessary elaboration. Every word earns its place in conveying the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (basic calculations) and rich input schema (100% coverage), the description is minimally adequate. However, with no annotations and no output schema, it lacks context about behavioral traits and return values. The description doesn't compensate for these gaps, making it incomplete for fully informed tool selection.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with clear parameter descriptions and an enum for operations. The description adds no additional meaning beyond what the schema provides, such as explaining operation semantics or edge cases. However, with full schema coverage, the baseline score of 3 is appropriate as the schema adequately documents parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Perform basic mathematical calculations' clearly states the tool's function with a specific verb ('perform') and resource ('calculations'), distinguishing it from sibling tools like 'greeting' and 'time'. However, it doesn't specify what 'basic' means or differentiate from potential advanced calculation tools, keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention any prerequisites, limitations, or context for choosing this calculator over other methods. The agent must infer usage solely from the tool name and description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/jaejin0me/mcpServer_test'

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