agentic-terminal
README.md
# MCP Masterclass - Complete Guide For Beginners
A comprehensive, hands-on course that teaches you everything about **Model Context Protocol (MCP)** - from creating your first MCP server to deploying production-ready applications using Docker and cloud-native architectures.
## š Table of Contents
- [What is MCP?](#what-is-mcp)
- [Course Overview](#course-overview)
- [Prerequisites](#prerequisites)
- [Getting Started](#getting-started)
- [Course Structure](#course-structure)
- [Project Architecture](#project-architecture)
- [Key Features](#key-features)
- [Technologies](#technologies)
- [Quick Start Guide](#quick-start-guide)
- [Running Examples](#running-examples)
- [FAQ](#faq)
- [Resources](#resources)
## š¤ What is MCP?
**Model Context Protocol (MCP)** is a standardized protocol that enables seamless communication between AI models and external tools/systems. It allows:
- š **Tool Integration**: Connect AI models to custom tools and services
- š **Universal Communication**: Standardized way for LLMs to interact with resources
- š **Multi-Transport Support**: Use stdio, HTTP, or custom transports
- š”ļø **Type-Safe**: Full type support and validation
- š” **Remote Execution**: Execute tools on remote servers
## š Course Overview
This masterclass takes you on a complete journey through MCP development:
```
Beginner āā Intermediate āā Advanced āā Production
ā ā ā ā
CH-1 CH-2,3 CH-4,5 CH-6
```
Whether you're an AI enthusiast, developer, or DevOps engineer, this course has something for you!
## ā
Prerequisites
- **Python 3.12+** (MCP requires modern Python)
- **Git** for version control
- **Docker** (for Chapter 6)
- **Basic Python knowledge** (async/await, decorators)
- **API familiarity** (helpful for understanding HTTP transport)
- **Terminal/Command Line** comfort
## šÆ Getting Started
### 1. Clone the Repository
```bash
git clone https://github.com/yourusername/MCP_Masterclass.git
cd MCP_Masterclass
```
### 2. Set Up Python Environment
Using `uv` (recommended - faster than pip):
```bash
uv venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
Or using traditional venv:
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
### 3. Install Dependencies
```bash
uv pip install -r pyproject.toml
# or
pip install -e .
```
The project includes:
- `fastmcp` - FastMCP framework for building MCP servers
- `langchain` - For integration with language models
- `langchain-mcp-adapters` - Bridge between LangChain and MCP
- `mcp` - Official MCP specification implementation
- `agentic-terminal` - Terminal-based MCP tools
### 4. Verify Installation
```bash
python main.py
# Expected output: "Hello from mcp-masterclass!"
```
## š Course Structure
### **Chapter 1: Creating Your First MCP Server** š±
**File**: `CH-1_CreateMCP/`
Learn the fundamentals of MCP by building a basic server:
- **1_first_mcpserver_stdio.py**: Build a simple MCP server using stdio transport
- Basic tool definition with `@mcp.tool()` decorator
- Fetch and process data patterns
- Running server locally
- **2_python_client.py**: Create a Python client to connect to the MCP server
- Understand client-server communication
- Making tool calls programmatically
- **3_langchain_client.py**: Integrate MCP with LangChain
- Use MCP tools with language models
- Automatic tool discovery and binding
**Key Learnings**:
- FastMCP framework basics
- Stdio transport protocol
- Async function handling
- Tool documentation with docstrings
---
### **Chapter 2: HTTP Transport & Scalability** š
**File**: `CH-2_HTTP_MCP/`
Scale your MCP servers for real-world applications:
- **1_http_mcp.py**: Build an HTTP-based MCP server
- Streamable HTTP transport
- Network accessibility
- Multi-client support
- Running on port 8050
- **2_langchain_client.py**: Connect LangChain to HTTP MCP server
- Remote server communication
- HTTP client setup
- Tool availability over network
**Key Learnings**:
- HTTP transport vs Stdio
- Scalability considerations
- Network security basics
- Multi-client architectures
---
### **Chapter 3: Integrating 3rd Party MCPs** š
**File**: `CH-3_3rdParty_MCPs/`
Leverage community MCP servers in your applications:
- **community_mcp.py**: Use open-source community MCP servers
- Discovering available MCPs
- Integration patterns
- Popular community tools
- **tavily_mcp.py**: Integrate Tavily search MCP
- Real-world API integration
- Web search capabilities
- Data enrichment workflows
**Key Learnings**:
- MCP ecosystem exploration
- Third-party tool integration
- Composition and orchestration
- API key management
---
### **Chapter 4: Publishing to PyPI** š¦
**File**: `CH-4_PyPI_MCP/` & `MCP_PYPI/`
Package and distribute your MCP as a Python package:
- **1_test_package.py**: Test your packaged MCP
- **2_client.py**: Use the published package as a client
- **MCP_PYPI/**: Complete package structure
- `pyproject.toml`: Package configuration
- `src/agentic_terminal/`: Agentic terminal implementation
- `tools.py`: Custom tool definitions
- `main.py`: Entry point
**Key Learnings**:
- Python package structure
- PyPI publishing workflow
- Package versioning and dependency management
- Entry points and CLI tools
---
### **Chapter 5: MCP Gateway & Orchestration** šÆ
**File**: `CH-5_MCP_Gateway/`
Build a unified gateway to manage multiple MCP servers:
- **gateway.py**: Central gateway for orchestrating multiple MCPs
- Mounting multiple MCP servers
- Request routing
- Tool discovery and aggregation
- Unified interface to many tools
- Example: integrating duckduckgo-mcp-server
**Key Learnings**:
- Gateway pattern architecture
- MCP composition and mounting
- Load balancing concepts
- Tool proxy implementations
---
### **Chapter 6: Containerization & Docker** š³
**File**: `CH-6_MCP_Docker/`
Deploy MCP servers in production using Docker:
- **Dockerfile**: Multi-stage Docker configuration
- Base image: Python 3.11-slim
- Pre-installed tools (duckduckgo-mcp-server, agentic_terminal)
- FastMCP runtime
- **requirements.txt**: Python dependencies for container
- **app/gateway.py**: Gateway application for containerized deployment
**Key Learnings**:
- Dockerfile best practices
- Multi-stage builds
- Container environment setup
- Production deployment patterns
- Tool availability in containers
---
## šļø Project Architecture
```
MCP_Masterclass/
ā
āāā CH-1_CreateMCP/ # Basics: Stdio-based MCP
ā āāā 1_first_mcpserver_stdio.py
ā āāā 2_python_client.py
ā āāā 3_langchain_client.py
ā
āāā CH-2_HTTP_MCP/ # HTTP Transport & Scalability
ā āāā 1_http_mcp.py
ā āāā 2_langchain_client.py
ā
āāā CH-3_3rdParty_MCPs/ # Integration Patterns
ā āāā community_mcp.py
ā āāā tavily_mcp.py
ā
āāā CH-4_PyPI_MCP/ # Packaging
ā āāā 1_test_package.py
ā āāā 2_client.py
ā
āāā CH-5_MCP_Gateway/ # Orchestration
ā āāā gateway.py
ā
āāā CH-6_MCP_Docker/ # Production Deployment
ā āāā Dockerfile
ā āāā requirements.txt
ā āāā app/
ā āāā gateway.py
ā
āāā MCP_PYPI/ # PyPI Package Structure
ā āāā pyproject.toml
ā āāā README.md
ā āāā src/
ā āāā agentic_terminal/
ā āāā __init__.py
ā āāā main.py
ā āāā tools.py
ā
āāā Notes/ # Course Notes
ā āāā MCP-Masterclass.png
ā
āāā pyproject.toml # Main project config
āāā package.json # NPM metadata
āāā main.py # Entry point
āāā README.md # This file
```
## š” Key Features
### Progressive Learning Path
- Start with basics (stdio servers)
- Progress to HTTP scalability
- Learn composition and orchestration
- Deploy with Docker
### Hands-On Examples
- Every concept includes working code
- Multiple integration patterns
- Real-world scenarios (search, processing)
### Production-Ready
- Docker containerization
- Gateway architecture
- Multi-server orchestration
- PyPI packaging
### Community Integration
- Third-party MCP servers
- Popular tools (Tavily, DuckDuckGo)
- Integration patterns
- Extensibility examples
## š ļø Technologies
| Technology | Purpose | Version |
|-----------|---------|---------|
| **FastMCP** | MCP framework | 3.2.4+ |
| **Python** | Programming language | 3.12+ |
| **Docker** | Containerization | Latest |
| **LangChain** | LLM framework integration | 1.2.17+ |
| **Async/Await** | Concurrent operations | Built-in Python |
| **HTTP** | Network transport | Standard |
| **Stdio** | Local process communication | Standard |
| **UV** | Package management | Latest |
## š Quick Start Guide
### Example 1: Run the First MCP Server
```bash
# Navigate to Chapter 1
cd CH-1_CreateMCP
# Activate your virtual environment
source .venv/bin/activate # or .venv\Scripts\activate on Windows
# Run the MCP server
python 1_first_mcpserver_stdio.py
```
### Example 2: Connect a Python Client
```bash
# In another terminal, with venv activated
cd CH-1_CreateMCP
python 2_python_client.py
```
### Example 3: Use with LangChain
```bash
cd CH-1_CreateMCP
python 3_langchain_client.py
```
### Example 4: HTTP Server
```bash
cd CH-2_HTTP_MCP
python 1_http_mcp.py
# Server runs on http://localhost:8050
```
### Example 5: Gateway Architecture
```bash
cd CH-5_MCP_Gateway
python gateway.py
```
### Example 6: Docker Deployment
```bash
cd CH-6_MCP_Docker
docker build -t mcp-masterclass .
docker run -p 8050:8050 mcp-masterclass
```
## š Running Examples
### Setup for Examples
1. Install all dependencies: `uv pip install -r pyproject.toml`
2. Ensure Python 3.12+ is active: `python --version`
3. Set any required API keys in environment variables
### Running Individual Examples
Each chapter can be run independently:
```bash
# Chapter 1 - Basic Server
cd CH-1_CreateMCP && python 1_first_mcpserver_stdio.py
# Chapter 2 - HTTP Server
cd CH-2_HTTP_MCP && python 1_http_mcp.py
# Chapter 5 - Gateway
cd CH-5_MCP_Gateway && python gateway.py
# Chapter 6 - Docker
cd CH-6_MCP_Docker && docker build -t mcp . && docker run mcp
```
### Debugging
Enable verbose output for MCP debugging:
```bash
# Set debug environment variable
export MCP_DEBUG=1
python your_mcp_file.py
```
## ā FAQ
### Q: Do I need GPU support?
**A**: No, MCP servers run on CPU. GPU is only needed if running large language models locally.
### Q: Can I use MCP with other frameworks besides LangChain?
**A**: Yes! MCP is framework-agnostic. It works with any LLM framework that supports the MCP protocol.
### Q: What's the difference between Stdio and HTTP transport?
**A**:
- **Stdio**: Local communication, lower latency, single machine
- **HTTP**: Network communication, scalable, accessible remotely
### Q: How do I add my own tools to an MCP server?
**A**: Use the `@mcp.tool()` decorator:
```python
@mcp.tool()
async def my_tool(param: str):
"""Tool description."""
return {"result": "your result"}
```
### Q: Is MCP production-ready?
**A**: Yes! The project includes Docker containerization and gateway patterns for production deployment.
### Q: How do I integrate external APIs?
**A**: Tools can make HTTP calls internally. See Chapter 3 for Tavily integration example.
### Q: Can I run multiple MCP servers together?
**A**: Yes! Use the gateway pattern (Chapter 5) to orchestrate multiple servers.
### Q: What's the purpose of PyPI publishing?
**A**: It allows others to install and use your MCP server as a package: `pip install your-mcp-server`
## š Resources
### Official Documentation
- [MCP Specification](https://modelcontextprotocol.io/)
- [FastMCP Documentation](https://fastmcp.ai/)
- [LangChain Integration](https://python.langchain.com/docs/integrations/tools/)
### Community
- MCP GitHub Repository
- FastMCP GitHub Issues
- LangChain Discord Community
### Related Tutorials
- MCP Tool Creation Best Practices
- LLM Integration Patterns
- Docker & Kubernetes for AI
### Learning Path
1. **Beginner**: Read Chapter 1-2 documentation
2. **Intermediate**: Work through Chapter 3-4 examples
3. **Advanced**: Study Chapter 5-6 architecture
4. **Expert**: Extend with your own MCPs
## š§ Troubleshooting
### Issue: Python version not compatible
**Solution**: Ensure Python 3.12+ is installed
```bash
python --version # Should show 3.12.x or higher
```
### Issue: FastMCP import error
**Solution**: Reinstall dependencies
```bash
uv pip install --force-reinstall fastmcp
```
### Issue: Port already in use
**Solution**: Use a different port or kill the process
```bash
# On Windows
netstat -ano | findstr :8050
# On Linux/Mac
lsof -i :8050
```
### Issue: Docker build fails
**Solution**: Clear Docker cache and rebuild
```bash
docker system prune -a
docker build --no-cache -t mcp-masterclass .
```
## š¬ Contributing
We welcome contributions! Areas for enhancement:
- Additional example MCPs
- Documentation improvements
- Additional transport protocols
- Testing suite expansion
- Deployment examples (Kubernetes, Cloud Run, etc.)
## š Learning Outcomes
After completing this masterclass, you will be able to:
ā
Create and deploy MCP servers using FastMCP
ā
Understand and implement different transport protocols
ā
Integrate with LangChain and other frameworks
ā
Compose multiple MCPs into orchestrated systems
ā
Package and publish MCP tools to PyPI
ā
Deploy MCPs using Docker and containerization
ā
Design scalable, production-ready MCP architectures
ā
Troubleshoot and debug MCP applications
---
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues