DEV Community

Yonatan Naor
Yonatan Naor

Posted on

How I Fixed Claude's Math Problem with 100 Lines of MCP Code

LLMs are great at explaining math. They're inconsistent at doing math.

Ask Claude to calculate a 30-year mortgage on $400,000 at 6.5% APR twice. You might get $2,528 and $2,533 in the same session. The correct answer is $2,528.27.

This is not a hallucination bug you can prompt your way out of. It's an architecture problem. LLMs are probabilistic text generators — arithmetic is deterministic. The fix is MCP: give the LLM a structured tool that always returns the right number.

Here's how to do it in under 10 minutes.


What You're Building

A connection between Claude Desktop and a calculator server that exposes 7 tools: mortgage, TDEE, compound interest, BMI, loan payoff, percentage, and age.

When you ask "what's my mortgage payment?", Claude calls calculate_mortgage instead of guessing. Always correct. Always the same.


Step 1: Install

npx -y @thicket-team/mcp-calculators
Enter fullscreen mode Exit fullscreen mode

No npm install needed. npx -y handles everything.


Step 2: Configure Claude Desktop

Open your config file:

Mac: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

Add inside "mcpServers":

{
  "mcpServers": {
    "calculators": {
      "command": "npx",
      "args": ["-y", "@thicket-team/mcp-calculators"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Restart Claude Desktop. You'll see a 🔨 in the input area — MCP tools are active.


Step 3: See It Work

Ask: "I want to buy a $450k home, 10% down, 6.75% for 30 years. Monthly payment and total interest?"

Claude calls calculate_mortgage(405000, 6.75, 30, 45000) and returns:

Monthly payment: $2,627.10
Total interest: $540,756.00
Enter fullscreen mode Exit fullscreen mode

Same question, 100 times. Same answer every time.


The 4 Tools Used Most

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

With MCP: message → LLM → tool call → calculator → structured result → LLM → response

The LLM does what it's good at (language, context, explanation). The tool does what it's good at (arithmetic).

The code is ~100 lines of vanilla JavaScript. No dependencies beyond @modelcontextprotocol/sdk. Formulas validated against clinical references (Mifflin-St Jeor) and standard financial math.

The package crossed 100 weekly downloads and is at 106 this week. The people using it got burned by inconsistent finance estimates in Claude and wanted a fix.

npm: @thicket-team/mcp-calculators

Try in browser: thicket.sh


What other tools would you want as MCP servers? Drop a comment — this is open source and PRs are welcome.

Top comments (0)