Skip to main content
Glama
mazah81-gif

TypeScript MCP Server Boilerplate

by mazah81-gif

calculator

Perform basic arithmetic operations including addition, subtraction, multiplication, and division with two numbers.

Instructions

Perform basic arithmetic operations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesThe operation to perform
aYesFirst number
bYesSecond number

Implementation Reference

  • Handler function that executes the calculator tool logic: performs add, subtract, multiply, or divide on inputs a and b, handles division by zero, returns result in MCP text content format.
    async ({ operation, a, b }: { operation: 'add' | 'subtract' | 'multiply' | 'divide'; a: number; b: number }) => {
        let result: number;
        
        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: '오류: 0으로 나눌 수 없습니다.'
                            }
                        ]
                    }
                }
                result = a / b
                break
        }
    
        return {
            content: [
                {
                    type: 'text',
                    text: `결과: ${result}`
                }
            ]
        }
    }
  • Zod schema defining the input parameters for the calculator tool: operation (enum), a (number), b (number).
    {
        operation: z.enum(['add', 'subtract', 'multiply', 'divide']).describe('The operation to perform'),
        a: z.number().describe('First number'),
        b: z.number().describe('Second number')
    },
  • src/index.ts:50-96 (registration)
    Registration of the calculator tool on the MCP server using server.tool(), including name, description, schema, and handler.
    // Define calculator tool
    server.tool(
        'calculator',
        'Perform basic arithmetic operations',
        {
            operation: z.enum(['add', 'subtract', 'multiply', 'divide']).describe('The operation to perform'),
            a: z.number().describe('First number'),
            b: z.number().describe('Second number')
        },
        async ({ operation, a, b }: { operation: 'add' | 'subtract' | 'multiply' | 'divide'; a: number; b: number }) => {
            let result: number;
            
            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: '오류: 0으로 나눌 수 없습니다.'
                                }
                            ]
                        }
                    }
                    result = a / b
                    break
            }
    
            return {
                content: [
                    {
                        type: 'text',
                        text: `결과: ${result}`
                    }
                ]
            }
        }
    )
  • Helper documentation of the calculator tool's capabilities in the server-info resource.
    {
        name: 'calculator',
        description: '기본 산술 연산을 수행합니다',
        supportedOperations: ['add', 'subtract', 'multiply', 'divide']
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. The description only states what the tool does ('perform basic arithmetic operations') without mentioning any behavioral traits like error handling (e.g., division by zero), precision limitations, or output format. This leaves significant gaps for a tool that performs calculations.

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 extremely concise with a single, clear sentence that directly states the tool's purpose. There is no wasted language or unnecessary elaboration, making it front-loaded and efficient.

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

Completeness2/5

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

Given the tool's complexity (performing calculations with potential edge cases) and the absence of both annotations and an output schema, the description is incomplete. It doesn't address behavioral aspects like error handling or result formatting, leaving the agent with insufficient context for reliable use.

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 schema description coverage is 100%, with all parameters well-documented in the input schema. The description adds no additional meaning beyond what the schema provides, as it doesn't elaborate on parameter usage or constraints. This meets the baseline score when schema coverage is high.

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 clearly states the tool's purpose with a specific verb ('perform') and resource ('basic arithmetic operations'). It distinguishes from siblings like 'greeting' and 'image_generation' by focusing on mathematical calculations. However, it could be more specific about what constitutes 'basic' operations.

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. There are no explicit instructions about when to use it, when not to use it, or what alternatives might exist. The agent must infer usage solely from the purpose statement.

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/mazah81-gif/my-mcp-server-2025'

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