MCP-CampusX
A learning project that demonstrates building MCP servers with FastMCP, featuring a demo server with basic tools (dice rolling, addition) and a full-featured expense tracker with SQLite persistence, hierarchical categories, CRUD operations, and expense summarization.
README
Learn FastMCP - MCP Server Examples
A learning project demonstrating how to build Model Context Protocol (MCP) servers using FastMCP, a Python framework for creating MCP-compatible tools and resources.
About This Project
This repository contains two complete MCP server implementations:
- Demo Server - Simple examples to learn FastMCP basics
- Expense Tracker - A full-featured real-world application
Perfect for understanding how to build MCP servers that can be used with Claude, other AI models, or custom applications.
π Server 1: Demo Server (main.py)
A simple starter MCP server with basic tools.
Tools
roll_dice(n_dice: int) -> list[int]
Rolls n six-sided dice and returns the results.
roll_dice(3) β [4, 2, 6]
add_numbers(a: float, b: float) -> float
Adds two numbers and returns the sum.
add_numbers(5, 3) β 8
Running the Demo Server
python main.py
π° Server 2: Expense Tracker (test.py)
A comprehensive expense management MCP server with database persistence, categorization, and advanced filtering.
Features
- SQLite database for persistent storage
- Hierarchical category system (main category + subcategory)
- Date range filtering
- Expense summarization by category
- CRUD operations (Create, Read, Update, Delete)
- Category merging/renaming
Data Structure
Each expense entry contains:
id- Unique identifier (auto-increment)date- Expense date (string format)amount- Expense amount in numeric valuecategory- Main category (from categories.json)subcategory- Optional subcategory for detailed trackingnote- Optional description/notes
Available Categories
The expense tracker supports 12 main categories with multiple subcategories each:
- Food - groceries, dining out, coffee, etc.
- Transport - fuel, public transport, cab/ride-hailing, parking, tolls
- Housing - rent, maintenance, property tax, repairs, furnishing
- Utilities - electricity, water, gas, internet, mobile, TV
- Health - medicines, doctor consultation, diagnostics, fitness
- Education - books, courses, online subscriptions, exam fees
- Family & Kids - school fees, daycare, toys, events
- Entertainment - movies, streaming subscriptions, gaming, outings
- Shopping - clothing, footwear, electronics, appliances, home dΓ©cor
- Subscriptions - SaaS tools, cloud/AI, music, storage, newsletters
- Personal Care - salon, grooming, cosmetics, hygiene
- Gifts & Donations - personal gifts, charity, festival gifts
- Finance & Fees - bank fees, investment fees, etc.
Tools
add_expense(date: str, amount: int, category: str, subcategory: str = "", note: str = "")
Add a new expense entry to the database.
{
"date": "2026-08-20",
"amount": 45,
"category": "food",
"subcategory": "dining_out",
"note": "Lunch with friends"
}
Returns: {"status": "ok", "id": 1}
list_expenses(start_date: str, end_date: str)
List all expenses within an inclusive date range (YYYY-MM-DD format).
list_expenses("2026-08-01", "2026-08-31")
Returns array of expense records with all fields.
summarize(start_date: str, end_date: str, category: str = None)
Get total amount spent by category within a date range. Optionally filter by a specific category.
summarize("2026-08-01", "2026-08-31")
summarize("2026-08-01", "2026-08-31", "food")
Returns:
[
{"category": "food", "total_amount": 150},
{"category": "transport", "total_amount": 50}
]
update_expense(id: int, date: str = None, amount: float = None, category: str = None, subcategory: str = None, note: str = None)
Update specific fields of an existing expense. Only provided fields are modified.
update_expense(1, amount=50, note="Updated note")
Returns: {"status": "ok", "id": 1, "updated_fields": {...}}
delete_expense(id: int)
Delete an expense entry by id.
delete_expense(1)
Returns: {"status": "ok", "deleted_id": 1}
merge_categories(old_categories: list[str], new_category: str)
Rename or merge one or more category labels into a single new category. Useful for consolidating expense categories.
merge_categories(["food", "dining"], "meals")
Returns: {"status": "ok", "rows_updated": 15, "new_category": "meals"}
Resources
expense://categories
Returns the categories structure as JSON. This resource is read fresh each time, so you can edit categories.json without restarting the server.
Running the Expense Tracker
python test.py
Database: Creates expenses.db in the same directory for persistent storage.
Installation & Setup
Prerequisites
- Python 3.14+
- FastMCP 3.4.7+
Install Dependencies
pip install fastmcp>=3.4.7
Or using the project's pyproject.toml:
pip install -e .
Project Structure
learn-fastmcp/
βββ main.py # Demo server (roll_dice, add_numbers)
βββ test.py # Expense Tracker server (full MCP implementation)
βββ categories.json # Category definitions for expense tracker
βββ expenses.db # SQLite database (auto-created by test.py)
βββ pyproject.toml # Project configuration
βββ README.md # This file
Learning Path
-
Start with
main.pyto understand the basics:- How to create a FastMCP instance
- How to define simple tools with
@mcp.tooldecorator - How to run the server with
mcp.run()
-
Progress to
test.pyto learn advanced patterns:- SQLite database integration
- File I/O and resource management
- Complex tool logic (CRUD operations)
- Resources with
@mcp.resourcedecorator - Optional and conditional parameters
- Error handling and validation
Key FastMCP Concepts
Tools
Functions decorated with @mcp.tool() that can be called by MCP clients. Each tool has:
- Input parameters with type hints
- A docstring describing functionality
- A return value
Resources
Static or dynamic content accessible via URI. Defined with @mcp.resource():
- Identified by a unique URI (e.g.,
expense://categories) - Optionally specify MIME type
- Can read from files or compute dynamically
Server Lifecycle
mcp = FastMCP("ServerName") # Create instance
@mcp.tool() # Define tools
def my_tool(): ...
if __name__ == "__main__":
mcp.run() # Start the server
Next Steps
- Modify the demo server to add new tools
- Extend the expense tracker with new features (e.g., budgets, recurring expenses)
- Create your own MCP server for a domain you're interested in
- Connect your MCP server to Claude using the MCP protocol
Resources
Happy learning! π
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.