Skip to main content
Glama
Calculator MCP Server

Calculator MCP Server

Calculator MCP Server

A small, working Model Context Protocol (MCP) server written in TypeScript.

It exposes five MCP tools:

  • add(a, b)

  • subtract(a, b)

  • multiply(a, b)

  • divide(a, b)

  • square(a)

Prerequisites

  • Node.js 20+

  • npm

Related MCP server: Calculator MCP Server

Install

npm install

Build

npm run build

Run

npm start

The server uses stdio, so it waits for an MCP client. Seeing no normal output is expected.

Server diagnostics are written to stderr because stdout is reserved for MCP protocol traffic.

Development mode

npm run dev

Test with MCP Inspector

Run:

npm run inspect

This starts the MCP Inspector and launches this server through stdio.

In the Inspector:

  1. Connect to the server.

  2. Open the Tools section.

  3. You should see:

    • add

    • subtract

    • multiply

    • divide

    • square

  4. Try add with a=10, b=20.

  5. Expected result: 10 + 20 = 30.

  6. Try square with a=5.

  7. Expected result: 5² = 25.

  8. Try divide with a=10, b=0.

  9. Expected result: an MCP tool error saying division by zero is not allowed.

MCP client configuration

After publishing this package to npm, another user can configure a compatible MCP client using:

{
  "mcpServers": {
    "calculator": {
      "command": "npx",
      "args": ["-y", "sample-calculator-mcp"]
    }
  }
}

For local development, point the client to the local project instead:

{
  "mcpServers": {
    "calculator": {
      "command": "npx",
      "args": ["tsx", "C:\\path\\to\\calculator-mcp\\src\\index.ts"]
    }
  }
}

Use the correct path for your machine.

Publishing to npm

First create an npm account and log in:

npm login

Build:

npm run build

Check what will be published:

npm pack --dry-run

Publish:

npm publish

After publishing, users can run:

npx -y sample-calculator-mcp

Project structure

calculator-mcp/
├── src/
│   └── index.ts
├── package.json
├── tsconfig.json
├── .gitignore
├── README.md
└── LICENSE

How MCP works here

LLM / MCP Host
       |
       v
   MCP Client
       |
      stdio
       |
       v
Calculator MCP Server
       |
   +---+---+---+---+
   |   |   |   |   |
  add sub mul div square

The MCP server exposes tools. The MCP client discovers those tools and sends tool calls. The server executes the calculation and returns the result.

Important

Do not use console.log() for application/debug output in a stdio MCP server. stdout is used by the MCP protocol. Use console.error() for diagnostics.

Available Tools

4 tools
addC

Add two numbers

Inputs: a (required), b (required).

divideB

Divide the first number by the second number

Inputs: a (required), b (required).

multiplyA

Multiply two numbers

Inputs: a (required), b (required).

subtractA

Subtract the second number from the first number

Inputs: a (required), b (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool performs a single, clearly distinct arithmetic operation with no overlap. An agent can easily tell multiply, divide, add, and subtract apart based on the operation name and description.

    Naming Consistency5/5

    All tool names are simple, lowercase verbs that directly describe the operation. The naming follows a consistent verb pattern without any deviations.

    Tool Count5/5

    Four tools is a well-scoped set for a basic calculator server, covering the fundamental arithmetic operations without extraneous tools. Each tool earns its place.

    Completeness4/5

    The four basic operations cover core arithmetic needs, but a calculator domain typically includes additional operations like exponentiation, square root, or modulo. These are minor gaps that limit some use cases.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides basic calculator operations (add, subtract, multiply, divide) as MCP tools for use with Claude Desktop and other MCP clients.
      -
    • F
      license
      A
      quality
      D
      maintenance
      Provides basic arithmetic operations (add, subtract, multiply, divide) through MCP, enabling AI clients to perform calculations via natural language.
      4
      -
    • F
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to perform arithmetic operations such as addition, subtraction, multiplication, and division through standardized MCP tools.
      1
      -
    • F
      license
      A
      quality
      C
      maintenance
      Enables AI agents to perform arithmetic operations — addition, subtraction, multiplication, and division with divide-by-zero validation — through MCP tool calls. It can be run locally over stdio or as an HTTP microservice via streamable-http transport.
      4
      -