mcp-calculator
Enables users to perform mathematical calculations through natural language by integrating an AI model with calculator tools via the Model Context Protocol.
README
MCP Calculator Agent
A simple calculator powered by the Model Context Protocol (MCP) and Ollama. Ask math questions in plain English and get answers.
What is this?
This project connects an AI model (Ollama) to a set of calculator tools via MCP. The AI understands your question, picks the right tool, and returns the result — all through a simple chat interface.
How it works
You ──> Agent ──> Ollama (AI) ──> MCP Server (tools)
│ │ │
│ send msg │ pick tool call │ execute math
│<────────────│<───────────────────│
│ get answer │ return result │
│<────────────│<───────────────────│
- MCP Server — exposes 6 calculator tools (add, subtract, multiply, divide, power, sqrt)
- Agent — middleman that connects Ollama to the MCP server and runs the chat loop
- Ollama — the AI brain that reads your question and decides which tool to use
Prerequisites
# Pull a model
ollama pull qwen3:4b
Setup
# Install dependencies
npm install
Run
# Interactive chat
npm run dev
Then ask things like:
What is 12 * 15?
What's the square root of 144?
Calculate (3 + 7) * 2
What is 2 to the power of 10?
Type quit or exit to stop.
Available Tools
| Tool | Description | Example |
|---|---|---|
add |
Add two numbers | 3 + 5 |
subtract |
Subtract second from first | 10 - 4 |
multiply |
Multiply two numbers | 6 * 7 |
divide |
Divide first by second | 20 / 4 |
power |
Raise number to a power | 2^8 |
sqrt |
Square root of a number | sqrt(144) |
Use a different model
Set the OLLAMA_MODEL environment variable:
OLLAMA_MODEL=qwen2.5-coder:3b npm run dev
Integrate with OpenCode
Add this to opencode.jsonc in your project root:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"calculator": {
"type": "local",
"command": ["npx", "tsx", "src/server-runner.ts"],
"cwd": "."
}
}
}
Project structure
mcp-calculator/
├── src/
│ ├── server.ts # MCP server with calculator tools
│ ├── server-runner.ts # Entry point for the MCP server
│ ├── agent.ts # Agent connecting Ollama to MCP
│ ├── index.ts # Interactive REPL
│ └── test.ts # Quick end-to-end test
├── package.json
└── tsconfig.json
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.