A minimal Model Context Protocol (MCP) server for basic math operations (add, subtract, multiply, divide) using FastMCP and zod.
- Exposes four math tools as MCP endpoints:
add,subtract,multiply,divide - Input validation with zod
- HTTP streaming transport on port 8083
- Built with TypeScript
Prerequisites:
- Node.js (v18+ recommended)
- npm
Clone the repository:
git clone https://github.com/umin-ai/math-mcp.git
cd math-mcpInstall dependencies:
npm installDevelopment mode:
npm run devProduction mode:
npm run build
npm startThe server will listen on http://localhost:8083/mcp.
The server exposes the following tools via the MCP protocol at the /mcp endpoint:
| Tool | Description | Parameters | Output |
|---|---|---|---|
add |
Add two numbers | { a: number, b: number } |
Result as string |
subtract |
Subtract two numbers | { a: number, b: number } |
Result as string |
multiply |
Multiply two numbers | { a: number, b: number } |
Result as string |
divide |
Divide two numbers | { a: number, b: number } |
Result as string (error if b is 0) |
To call the add tool using HTTP POST (replace with your MCP client as needed):
curl -X POST http://localhost:8083/mcp \
-H "Content-Type: application/json" \
-d '{
"tool": "add",
"parameters": { "a": 5, "b": 3 }
}'Example Response:
{
"result": "8"
}- Division by zero in the
dividetool will return an error.
math-mcp/
├── src/
│ └── math.ts # Main server code
├── package.json # Project metadata and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
ISC
Contributions are welcome! Please open an issue or submit a pull request.