Skip to main content
Glama
jyotibasm
by jyotibasm

AI Agent with MCP and Ollama: MCP Server for Calculator Application

Introduction

This project demonstrates how to build a simple AI Agent using Model Context Protocol (MCP) and Ollama. The application uses Ollama to run an LLM locally and MCP to connect the AI agent with calculator tools exposed by an MCP server.

An AI Agent is an application that can understand a user's request, determine what action is required, select an appropriate tool, execute that tool, and use the tool's result to generate a response.

Model Context Protocol (MCP) provides a standardized way for AI applications to discover and interact with external tools and services. In this project, the MCP server exposes calculator operations such as addition, subtraction, multiplication, and division.

Ollama runs the LLM locally and acts as the intelligence behind the agent. Based on the user's request, the LLM can select the appropriate calculator tool and provide the required arguments. The MCP client then invokes that tool on the MCP server and sends the result back to the LLM.

Project Flow

User
  |
  v
AI Agent / MCP Client
  |
  v
Ollama (Local LLM)
  |
  | Selects appropriate tool
  v
MCP Client
  |
  | Tool call
  v
MCP Server
  |
  +-- add
  +-- subtract
  +-- multiply
  +-- divide
  |
  v
Tool Result
  |
  v
Ollama
  |
  v
Final Answer

This project provides a basic understanding of how LLMs, AI Agents, MCP Clients, and MCP Servers work together to create tool-using AI applications.


Related MCP server: Math Operations MCP Server

1. Setup

Prerequisites

Install:

  • Python 3.10+

  • Ollama

  • Git (optional)

Create a virtual environment:

python -m venv venv

Activate it:

.\venv\Scripts\Activate.ps1

Install dependencies:

python -m pip install -r requirements.txt

2. Ollama — Run LLM Locally

Ollama allows you to run open-source LLMs locally without requiring an external API.

Pull the model:

ollama pull qwen3:8b

Verify the model:

ollama list

You can also run the model directly:

ollama run qwen3:8b

The Python application communicates with the locally running Ollama service.


3. Project Folder Structure

MCP_Calculator/
│
├── server.py
├── client.py
├── requirements.txt
├── README.md
└── venv/

4. MCP Server

server.py creates the MCP server and exposes calculator operations as tools.

mcp = MCPServer("Calculator")

Tools are registered using:

@mcp.tool()

The server provides four tools:

add
subtract
multiply
divide

For example:

@mcp.tool()
def add(a: float, b: float) -> float:
    return a + b

The MCP server is responsible for hosting and executing the tools.


5. MCP Client

client.py acts as the bridge between the Ollama LLM and the MCP server.

The client:

  1. Starts the MCP server.

  2. Establishes an MCP session.

  3. Discovers available tools using list_tools().

  4. Converts MCP tools into tools understood by Ollama.

  5. Sends the user's question and available tools to Ollama.

  6. Receives the selected tool and arguments from the LLM.

  7. Calls the selected MCP tool.

  8. Sends the tool result back to Ollama.

  9. Displays the final answer.

The LLM does not directly execute the Python functions.

Instead:

Ollama / LLM
     |
     v
MCP Client
     |
     v
MCP Server
     |
     v
Calculator Tool

6. Run the Application

Make sure Ollama is installed and the model is available:

ollama list

Then run:

python client.py

Enter a question:

You: What is 10 + 30?

The LLM can select:

add

with arguments:

a = 10
b = 30

The MCP client calls:

add(10, 30)

The MCP server returns:

40

The result is sent back to Ollama, which generates the final response:

Assistant: 10 + 30 = 40

7. How It Works

                 User
                   |
                   v
              MCP Client
                   |
                   v
                Ollama
                   |
            Tool Selection
                   |
                   v
              MCP Client
                   |
                 stdio
                   |
                   v
              MCP Server
                   |
        +----------+----------+
        |          |          |
       add      subtract   multiply
                              |
                            divide
                   |
                   v
               Result
                   |
                   v
                Ollama
                   |
                   v
              Final Answer

Key Concept

The main components have different responsibilities:

Ollama / LLM
    ↓
Understands the user's request
and selects an appropriate tool.

MCP Client
    ↓
Connects the LLM with MCP tools
and invokes the selected tool.

MCP Server
    ↓
Exposes and executes the actual tools.

Calculator Tools
    ↓
Perform the required calculation.

Together, these components form a simple tool-using AI Agent architecture.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

No tool schema history has been recorded yet.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Provides basic mathematical calculation functionality through MCP tools including arithmetic operations, exponentiation, and square root calculations. Features proper error handling for edge cases like division by zero and negative square roots.
    6
    53
    2
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI applications to perform basic mathematical operations like addition and subtraction through MCP tools. Also provides REST API endpoints for the same operations.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides a comprehensive set of mathematical functions as MCP tools, enabling language models to perform calculations including arithmetic, trigonometry, logarithms, and more.
    23
    1
    MIT
  • F
    license
    Not graded
    quality
    C
    maintenance
    Provides basic calculator operations (add, subtract, multiply, divide) as MCP tools for use with Claude Desktop and other MCP clients.
    -

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jyotibasm/AI-Agent-with-MCP-and-Ollama-MCP-Server-for-Calculator-Application-'

If you have feedback or need assistance with the MCP directory API, please join our Discord server