Provides tools for managing personal expenses in a SQLite database, including adding expenses with categories and descriptions, retrieving total expenses, and listing all recorded expenses.
π° 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
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
π 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.
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)
π¦ Install Dependencies
βΆοΈ Running the Client
Update paths inside client.py:
Then run:
π§ How It Works (Step-by-Step)
User enters a natural language query
LLM decides whether a tool is needed
If required:
Tool name + arguments are generated
LangChain invokes MCP tool
Result is returned to LLM
LLM generates final user-friendly respons
Just tell me π