How I Fixed Claude's Math Problem with 100 Lines of MCP Code
Source: Dev.to
LLMs are great at explaining math, but they’re inconsistent at doing math.
Ask Claude to calculate a 30‑year mortgage on $400,000 at 6.5 % APR twice, and you might get $2,528 and $2,533 in the same session. The correct answer is $2,528.27.
This isn’t a hallucination bug you can prompt away—it’s an architecture problem. LLMs are probabilistic text generators, while arithmetic is deterministic. The fix is MCP: give the LLM a structured tool that always returns the right number.
Below is a quick guide to set up a connection between Claude Desktop and a calculator server that exposes seven tools: mortgage, TDEE, compound interest, BMI, loan payoff, percentage, and age. Once configured, Claude will call calculate_mortgage (or the appropriate tool) instead of guessing, guaranteeing consistent and correct results.
What You’re Building
A bridge between Claude Desktop and a calculator server that provides the following tools:
- mortgage
- TDEE
- compound interest
- BMI
- loan payoff
- percentage
- age
When you ask “what’s my mortgage payment?”, Claude calls calculate_mortgage and returns the exact figure every time.
Step 1: Install
npx -y @thicket-team/mcp-calculatorsnpx -y handles everything; no separate npm install is required.
Step 2: Configure Claude Desktop
Open the Claude Desktop configuration file:
- Mac:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Add the following entry inside the top‑level object:
{
"mcpServers": {
"calculators": {
"command": "npx",
"args": ["-y", "@thicket-team/mcp-calculators"]
}
}
}Restart Claude Desktop. You’ll see a 🔨 icon in the input area, indicating that MCP tools are active.
Step 3: See It Work
Ask Claude:
“I want to buy a $450k home, 10 % down, 6.75 % for 30 years. Monthly payment and total interest?”
Claude will invoke:
calculate_mortgage(405000, 6.75, 30, 45000)and return:
Monthly payment: $2,627.10
Total interest: $540,756.00Run the same question 100 times—you’ll get the identical answer each time.
The 4 Tools Used Most
| Tool | Example Call | Result |
|---|---|---|
| Mortgage | calculate_mortgage(480000, 7.0, 30, 120000) | Monthly: $3,194.02 |
| TDEE | calculate_tdee(175, 70, 34, "male", "moderate") | 2,847 kcal/day |
| Compound Interest | calculate_compound_interest(10000, 7, 20, 500) | $296,477.83 after 20 years |
| Loan Payoff | calculate_loan_payoff(8500, 22, 300) | Paid off in 38 months |
Why It Works
- Without MCP:
message → LLM → text(LLM must perform arithmetic itself). - With MCP:
message → LLM → tool call → calculator → structured result → LLM → response.
The LLM handles language, context, and explanation, while the dedicated tool handles deterministic arithmetic. The implementation is ~100 lines of vanilla JavaScript, with no dependencies beyond @modelcontextprotocol/sdk. Formulas are validated against clinical references (Mifflin‑St Jeor) and standard financial mathematics.
The package has surpassed 100 weekly downloads, reflecting strong community interest in reliable finance calculations within Claude.
What other tools would you like as MCP servers? Feel free to contribute—this project is open source and PRs are welcome.