math-evaluator-service
A lightweight service designed for executing mathematical formulas. It leverages the 'expr-eval' library and provides predefined mathematical constants such as 'E' and 'PI' for immediate utility. Interaction occurs strictly via standard input/output channels, ensuring a minimal overhead computational utility.
Author

pwh-pwh
Quick Info
Actions
Tags
Calculation Engine Module
Module Overview
This component, referred to as the 'Calculation Engine Module' (cal-mcp), is constructed upon the FastMCP architecture and operates within the Bun runtime environment. Its core functionality involves parsing and resolving mathematical expressions supplied by the user, communicating via the standard I/O stream. The objective is to deliver a highly performant and resource-efficient utility for quantitative assessments, inclusive of fundamental arithmetic operations and readily available numeric constants.
Capabilities
- Formula Computation: Accepts mathematical strings as input and returns the computed numerical outcome.
- Predefined Constants: Integrates essential mathematical values:
E: Corresponds toMath.Ewithin the Bun context.PI: Corresponds toMath.PIwithin the Bun context.true: Represents the boolean truth value.false: Represents the boolean falsity value.
- Executable Identifier:
cal. - Input Parameter: Requires a single string argument representing the mathematical expression (aliased as
exp).
Dependencies
fastmcp: Framework for constructing the MCP interface.expr-eval: Engine responsible for expression parsing and evaluation.zod: Utilized for strict input schema validation.
Prerequisites
- Installation of the Bun runtime is mandatory (latest version recommended).
Deployment
Automated Setup via Smithery
To integrate cal-mcp automatically into Claude Desktop using Smithery:
bash npx -y @smithery/cli install @pwh-pwh/cal-mcp --client claude
Client Configuration Snippet
"cal-mcp": { "name": "运算", "description": "", "isActive": true, "command": "bunx", "args": [ "cal-mcp" ] }
Manual Bootstrap
-
Clone the source repository: bash git clone
-
Navigate into the project directory and install required packages: bash bun install
Operational Guide
- Initiate the server process: bash bun run index.ts
The service will commence operation, listening on STDIN/STDOUT.
-
Supply a mathematical expression for processing:
- Example Input:
2 + 3 * PI - Expected Output: The computed result (returned as a text string).
- Example Input:
-
Illustrative Calculation Examples:
- Simple Addition:
2 + 2yields4 - Constant Utilization:
PI * 2results in6.283185307179586 - Advanced Formula:
E ^ 2 + 1evaluates to8.38905609893065
- Simple Addition:
Operational Notes
- Input strings must conform strictly to valid mathematical syntax; non-compliant expressions may trigger runtime errors.
- Communication is exclusively facilitated through the standard I/O interface.
- As this module depends on the Bun runtime, ensure all invoked commands are compatible with the Bun execution environment.
