Lesson 13 Building Your Own MCP Server
Theme:

Lab Guide — Building Your Own MCP Server

Three exercises building an MCP server from scratch with tools and resources.

Setup: Install the MCP SDK: pip install "mcp[cli]". Open lab.pdf in Jupyter. The notebook simulates the MCP server locally so you can iterate without restarting processes. See demo/notes_server.py for the complete standalone server.

📥 Lab Notebooks

⬇ lab.pdf ⬇ lab_answer.pdf

📥 Demo Files

⬇ notes_server.py

Exercise 1 — Minimal Server with Echo Tool

EX 1

Build a minimal MCP server with one tool

Create the simplest possible MCP server: a single echo tool that returns its input.

  1. Create a FastMCP server instance
  2. Register an echo tool that takes a message: str and returns it
  3. Test the tool function directly (without running the server)
# Your echo tool should work like:
result = echo(message="Hello MCP!")
# Returns: "Echo: Hello MCP!"

Checkpoint: The echo tool is registered and works when called directly.

Exercise 2 — Add Notes Tools

EX 2

Add add_note and list_notes tools

Extend the server with note management tools:

  1. add_note(title: str, content: str) -> str — saves a note and returns confirmation
  2. list_notes() -> str — returns all note titles

Test by adding 3 notes and listing them.

add_note(title="Python", content="A versatile programming language")
add_note(title="MCP", content="Model Context Protocol for LLM tools")
print(list_notes())
# - MCP
# - Python

Checkpoint: Notes persist across calls. list_notes shows all added notes.

Exercise 3 — Add Notes Resource

EX 3

Add a notes:// resource

Add resources that expose notes data:

  1. notes://all — returns all notes as formatted text
  2. notes://{title} — returns a specific note by title

Test both resource functions.

Checkpoint: Both resources return the expected content. Missing titles return a clear error.

Tip: After completing the exercises, try running the complete server from demo/notes_server.py with mcp dev demo/notes_server.py to see the Inspector UI.