Skip to main content
Glama
wxt2rr

Math Calculator MCP Server

by wxt2rr
server.ts983 B
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod"; export function createMcpServer() { const server = new McpServer({ name: "math-server", version: "1.0.0", }); server.tool( "calculate", { operation: z.enum(["add", "subtract", "multiply", "divide"]), a: z.number(), b: z.number(), }, async ({ operation, a, b }) => { switch (operation) { case "add": return { content: [{ type: "text", text: String(a + b) }] }; case "subtract": return { content: [{ type: "text", text: String(a - b) }] }; case "multiply": return { content: [{ type: "text", text: String(a * b) }] }; case "divide": if (b === 0) { return { isError: true, content: [{ type: "text", text: "Division by zero" }] }; } return { content: [{ type: "text", text: String(a / b) }] }; } } ); return server; }

Implementation Reference

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/wxt2rr/mcp-server-test'

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