Skip to main content
Glama
Omkar4141

Expense Tracker MCP Server

by Omkar4141
README.md


# šŸ’° Expense Tracker using MCP (FastMCP + LangChain + Ollama)- Sample Project for understanding MCP 

This project demonstrates a **simple end-to-end MCP (Model Context Protocol)** example where:

* A **FastMCP server** exposes tools to manage expenses stored in **SQLite**
* A **LangChain client** connects to the MCP server
* An **LLM (Llama 3.2 via Ollama)** decides when to call tools
* Natural language queries like

  > *"Add my expense 500 to groceries"*
  > automatically trigger backend database operations


## šŸ“Œ Architecture Overview

```
User (CLI)
   │
   ā–¼
LangChain Client (client.py)
   │
   │  MCP (stdio)
   ā–¼
FastMCP Server (main.py)
   │
   ā–¼
SQLite Database (expenses.db)
```

### Key Components

| Component                 | Description                            |
| ------------------------- | -------------------------------------- |
| **FastMCP**               | Exposes database operations as tools   |
| **LangChain MCP Adapter** | Connects LLM to MCP tools              |
| **Ollama (Llama 3.2:3b)** | Interprets user intent and calls tools |
| **SQLite**                | Persistent expense storage             |

---

## šŸ“‚ Project Structure

```
.
ā”œā”€ā”€ main.py        # FastMCP expense database server
ā”œā”€ā”€ client.py      # LangChain MCP client with LLM
ā”œā”€ā”€ expenses.db    # SQLite database (auto-created)
└── README.md
```

## šŸš€ Features

* āœ… Add expenses using natural language
* āœ… View total expenses
* āœ… List all expenses
* āœ… Automatic tool selection by LLM
* āœ… Persistent storage using SQLite
* āœ… MCP-compliant architecture


## šŸ› ļø Tools Exposed by MCP Server

The FastMCP server exposes the following tools:

### `add_expense`

Adds a new expense entry.

```json
{
  "amount": 500,
  "category": "groceries",
  "description": "weekly shopping"
}
```

### `get_total`

Returns the total sum of all expenses.


### `get_all_expenses`

Returns a list of all recorded expenses.


## āš™ļø Prerequisites

Make sure you have the following installed:

* **Python 3.10+**
* **Ollama**
* **Llama 3.2 model**
* **uv** (Python package runner)

```bash
ollama pull llama3.2:3b
```

## šŸ“¦ Install Dependencies

```bash
uv add fastmcp langchain langchain-mcp-adapters langchain-ollama
```

## ā–¶ļø Running the Client

Update paths inside `client.py`:

```python
"command": "/home/omkar/.local/bin/uv",
"args": [
    "run",
    "fastmcp",
    "run",
    "/full/path/to/main.py"
]
```

Then run:

```bash
uv run client.py
```

## 🧠 How It Works (Step-by-Step)

1. User enters a natural language query
2. LLM decides whether a tool is needed
3. If required:

   * Tool name + arguments are generated
4. LangChain invokes MCP tool
5. Result is returned to LLM
6. LLM generates final user-friendly respons




Just tell me šŸ‘

TDQS

B3/5.0

Scored across 3 tools

Disambiguation5/5

Each tool has a distinct purpose: add_expense creates new records, get_all_expenses retrieves all records, and get_total calculates a sum. There is no overlap or ambiguity between these operations.

Naming Consistency5/5

All tools follow a consistent verb_noun pattern (add_expense, get_all_expenses, get_total) with clear, descriptive names. The naming style is uniform throughout the set.

Tool Count2/5

With only 3 tools, the set feels thin for an expense tracker domain. It lacks essential operations like updating or deleting expenses, viewing expenses by category or date, or filtering, which limits functionality.

Completeness2/5

The tool set is severely incomplete for expense tracking. It supports adding and viewing all expenses but misses critical operations such as update_expense, delete_expense, get_expense_by_id, and filtering by category or date, leaving significant gaps in the CRUD lifecycle.

Maintenance

ActivityInactive
ResponsivenessNo issues