FastMCP tutorial: Python servers and FastAPI integration

Learn to build and test a Python MCP server with tools, JSON course resources, reusable prompts, and a FastAPI integration.

Player not loading? Watch on YouTube

This beginner tutorial uses FastMCP to build a Python MCP server around a local course catalog. The speaker explains how Model Context Protocol connects supported applications to callable functions and readable data, then develops the example in VS Code. Setup covers a virtual environment, package installation, and a requirements.txt file. The presenter discusses Windows, macOS, and Linux terminals, with different environment activation steps.

The first server exposes a greeting, an addition function, and a learning-hours calculator through decorators. A JSON catalog supplies read-only resources for the full course list and individual courses. The tutorial then adds keyword search and a reusable learning-plan prompt. Testing uses terminal commands, a browser-based inspector, and an asynchronous Python client that checks connectivity, calls tools, reads resources, and retrieves prompts.

A separate FastAPI example exposes API routes through MCP and adds a custom course-count tool. The presenter explains the lifespan configuration needed to start the MCP app within FastAPI. The final course assistant combines search, recommendations, study-plan calculations, and course comparisons. Troubleshooting covers missing packages, incorrect folders, absent JSON files, and resource URL mismatches. The demo uses local data; it does not demonstrate running a language model or connecting a chat application.