Welcome to MCPFromScratch - a comprehensive educational project that demonstrates how to build a complete client-server application using the Model Context Protocol (MCP) from the ground up.
This repository is designed to help you understand:
- Client-Server Architecture: How intelligent agents communicate with service providers
- Model Context Protocol (MCP): A custom protocol for AI agents to discover and use server capabilities
- Modern Python Web Development: Using FastAPI, WebSockets, and async/await patterns
- AI Integration: How to build agents that leverage Large Language Models (LLMs)
- Real-time Communication: WebSocket-based persistent connections for dynamic interactions
The project consists of two main components:
- Server (
MCPFromScratch/server/): A FastAPI-based server that provides tools, prompts, and resources - Client (
MCPFromScratch/client/): An intelligent agent that connects to the server and processes user queries
👉 For the complete learning experience, open notebook.ipynb
The notebook provides:
- Step-by-step explanations of all concepts
- Detailed code walkthroughs
- Beginner-friendly explanations of complex topics
- Setup and installation instructions
- Real-world examples and use cases
Prefer learning through video? Watch the accompanying tutorial:
Build an MCP Server from Scratch - YouTube
- FastAPI: Modern, fast web framework for building APIs
- WebSockets: Real-time bidirectional communication
- Pydantic: Data validation and serialization
- OpenAI API: LLM integration for intelligent responses
- SQLite: Database for server-side data storage
- asyncio: Asynchronous programming for high performance
By following this project, you'll create:
-
A Capable Server that offers:
- Tools (like calculators, database queries, text-to-SQL conversion)
- Prompts (templates for LLM interactions)
- Resources (configuration and user data access)
-
An Intelligent Client that:
- Connects to the server via WebSocket
- Understands natural language queries
- Selects appropriate tools automatically
- Provides conversational responses
- Start Here: Open
notebook.ipynbfor the complete guide - Explore the Code: Examine the server and client implementations
- Run the Application: Follow the setup instructions in the notebook
- Experiment: Try adding your own tools, prompts, or resources
- Model Context Protocol (MCP): Custom communication protocol design
- WebSocket Session Management: Handling persistent connections
- API Authentication: Secure access with API keys and quotas
- Schema Validation: Using Pydantic for robust data handling
- LLM Integration: Building AI-powered applications
- Async Programming: Modern Python concurrency patterns