Skip to main content
Glama

sum

Add multiple numbers together with precision using Math-MCP's sum function. Ideal for quick and accurate numerical calculations in any workflow.

Instructions

Adds any number of numbers together

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
numbersYesArray of numbers to sum

Implementation Reference

  • Handler function for the "sum" tool. It takes an array of numbers, calls Arithmetic.sum to compute the sum, and returns the result as MCP text content.
    }, async ({ numbers }) => { const value = Arithmetic.sum(numbers) return { content: [{ type: "text", text: `${value}` }] } })
  • Input schema for the "sum" tool using Zod: requires an array of at least one number.
    numbers: z.array(z.number()).min(1).describe("Array of numbers to sum")
  • src/index.ts:98-108 (registration)
    Registration of the "sum" tool on the MCP server, including description, schema, and handler.
    mathServer.tool("sum", "Adds any number of numbers together", { numbers: z.array(z.number()).min(1).describe("Array of numbers to sum") }, async ({ numbers }) => { const value = Arithmetic.sum(numbers) return { content: [{ type: "text", text: `${value}` }] } })
  • Arithmetic.sum static method: computes the sum of an array of numbers using Array.reduce.
    static sum(numbers: number[]) { // Use reduce to accumulate the sum, starting with 0 const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0); return sum }

Other Tools

Related Tools

  • @wrtnlabs/calculator-mcp
  • @zhangzhefang-github/mcp-add-server
  • @KrishnaPapana/mcpserverexample
  • @githubpradeep/calc-mcp72
  • @EthanHenrickson/math-mcp
  • @YuheiNakasaka/arithmetic-mcp-server

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/EthanHenrickson/math-mcp'

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