How to Build Local MCP Servers | MCP Trilogy | CampusX

Share

Summary

This video is part of CampusX's MCP playlist. This video explains how to build custom MCP servers locally. The tutorial covers the steps to create a simple demo server and then incrementally build a more complex expense tracker MCP server. It also clarifies the distinction between MCP SDK and Fast MCP libraries and their evolution.

Highlights

Introduction to MCP Playlist and Today's Goal
00:00:00

The video continues the MCP playlist, recapping previous topics: Why, What (architecture, lifecycle), and How. The current focus is on building custom MCP servers, starting with local servers and then moving to remote ones. The goal for this video is to teach how to build a local MCP server, specifically an Expense Tracker MCP server.

Demonstration of Expense Tracker MCP Server
00:05:07

The presenter demonstrates an Expense Tracker MCP server integrated with Claude Desktop. Users can add expenses naturally (e.g., "add 500 travel expense for cab ride yesterday"), retrieve expenses (e.g., "show all expenses from September in tabular fashion"), and summarize expenses (e.g., "total expense on health in August"). This hands-on demo showcases the utility and natural language interaction capabilities of the server.

Plan of Action: Building the Expense Tracker
00:09:27

The plan involves first creating a basic demo server to understand the process (installation, running, Claude Desktop integration). Then, the expense tracker tool will be built incrementally, adding basic features first and then more advanced ones. This initial setup will be a local server, communicating via stdio transport. The next video will focus on converting it into a remote server.

Clarifying MCP Libraries: SDK vs. Fast MCP
00:11:40

The video explains the evolution of MCP libraries. Initially, Anthropic released the MCP SDK due to the complexity of implementing the protocol from scratch. However, the SDK was verbose. Jeremiah Lowin created Fast MCP, an abstraction on top of the SDK, which was more user-friendly. Fast MCP later became incorporated into the MCP SDK, similar to how Keras was integrated into TensorFlow. Eventually, Fast MCP became an independent library (Fast MCP 2.0). The video clarifies that both approaches use similar code, but Fast MCP is preferred for its developer-friendly abstraction.

Setting Up a Basic Demo MCP Server
00:25:03

The first step is to build a basic MCP server with two tools: roll a dice and add numbers. The setup involves installing `uv`, initializing a new project folder in VS Code, installing `fast-mcp` using `uv add fast-mcp`, and creating the `main.py` file with the server code. The server is designed to be simple, focusing on understanding the overall process.

Testing the Demo Server with MCP Inspector
00:30:59

The demo server is tested using `fast-mcp debug main.py`, which launches the MCP Inspector. This tool allows checking if the server is working correctly, listing available tools (roll dice, add numbers), and executing them. It helps visualize the JSON-RPC messages exchanged between the client and the server, ensuring functionality before integrating with Claude Desktop.

Integrating Demo Server with Claude Desktop
00:34:09

To integrate the server with Claude Desktop, the command `uv run fast-mcp install Claude main.py` is used. A common issue where Claude struggles to connect is addressed by replacing `uv` with its absolute path in Claude's configuration. Once integrated, the server runs in the background, making its tools available for use within Claude Desktop. The presenter demonstrates rolling dice and adding numbers using natural language prompts.

Phase 1: Adding Basic Expense Tracker Features (Add & List Expenses)
00:37:00

The video moves on to building the Expense Tracker MCP server, starting with 'add expense' and 'list expense' features. It involves using `sqlite3` for a local database to store transactions. The `main.py` is updated to create an 'expenses.db' file and an 'expenses' table with columns like `id`, `date`, `amount`, `category`, `subcategory`, and `note`. The 'add_expense' tool inserts new entries, and 'list_expenses' retrieves all records. The presenter demonstrates adding expenses and verifying entries in the database.

Phase 2: Enhancing the 'List Expenses' Feature
00:49:37

The 'list expenses' feature is improved by adding `start_date` and `end_date` parameters, allowing users to query expenses within a specific date range. The SQLite query is modified to include a `WHERE` clause for date filtering. The presenter shows how to query expenses for a specific period (e.g., "show all expenses from September first week") and display them in a tabular format using natural language with Claude.

Phase 3: Adding the 'Summarize Expenses' Feature
00:52:54

A 'summarize expenses' tool is added to allow users to ask for total expenses based on a date range and optionally a category. The tool takes `start_date`, `end_date`, and `category` as arguments. The SQLite query dynamically builds based on whether a category is provided, using `SUM` and `GROUP BY` clauses. This enables queries like "What was my total expense on education last week?".

Phase 4: Improving Data Consistency with Resources
00:56:31

To ensure consistent category and subcategory entries, a resource is added to the MCP server. A `categories.json` file defines a predefined list of categories and subcategories. The MCP server exposes this JSON file as a resource. Claude can then read this resource and use the predefined categories, forcing consistency and preventing arbitrary input. This is demonstrated by adding an expense and having Claude select from the provided categories and subcategories.

Fast MCP and FastAPI Integration
01:02:44

The video concludes by explaining the relationship between Fast MCP and FastAPI. Both libraries share a similar design philosophy. Fast MCP can convert existing FastAPI applications into MCP servers, and vice-versa. This is beneficial for companies with existing FastAPI backends, as they can easily expose their services to MCP clients like Claude Desktop without rewriting the entire codebase. A demo shows how a FastAPI application serving an Expense Tracker can be wrapped with Fast MCP to create an MCP server.

Recently Summarized Articles

Loading...