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! 🚀
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。