Labsco
Anvisimi logo

MCP Agentic AI Crash Course with Python

โ˜… 1

from Anvisimi

A comprehensive crash course on the Model Context Protocol (MCP), covering everything from basic concepts to building production-ready MCP servers and clients in Python.

๐Ÿ”ฅโœ“ VerifiedFreeNeeds API keys

I'll create a comprehensive README.md file based on the MCP Agentic AI Crash Course content. This will serve as a guide for anyone following along with the tutorial.

# MCP Agentic AI Crash Course with Python

A comprehensive crash course on Model Context Protocol (MCP) covering everything from basic concepts to building production-ready MCP servers and clients.

## ๐Ÿ“‹ Table of Contents

- [Overview](#overview)
- [What is MCP?](#what-is-mcp)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Project Structure](#project-structure)
- [Building MCP Server from Scratch](#building-mcp-server-from-scratch)
- [Running MCP Server](#running-mcp-server)
- [Integration Methods](#integration-methods)
- [Client Implementation](#client-implementation)
- [Docker Setup](#docker-setup)
- [Course Information](#course-information)

## ๐ŸŽฏ Overview

This crash course covers:
- **MCP Fundamentals**: Understanding Model Context Protocol architecture   
- **Server Development**: Building MCP servers from scratch   
- **Multiple Integration Methods**: MCP Inspector, Claude Desktop, Cursor IDE   
- **Client Implementation**: Creating MCP clients with LLM integration   
- **Production Deployment**: Docker setup for deployment

## ๐Ÿ”ง What is MCP?

**Model Context Protocol (MCP)** is a standardized way for AI assistants to connect with external services and data sources   . 

### Key Benefits:
- **Unified Protocol**: Like a USB-C cable for AI services - one protocol for multiple connections   
- **Service Provider Managed**: Updates and maintenance handled by service providers   
- **Reduced Code Complexity**: No need to write wrapper code for each service   

### Architecture:

LLM/AI Assistant โ†” MCP Client โ†” MCP Protocol โ†” MCP Server โ†” External Services


## ๐Ÿ“ Project Structure

MCP-crash-course/ โ”œโ”€โ”€ server/ โ”‚ โ”œโ”€โ”€ weather.py # Main MCP server โ”‚ โ”œโ”€โ”€ server.py # Production server with SSE โ”‚ โ””โ”€โ”€ client-sse.py # SSE client example โ”œโ”€โ”€ client.py # MCP client implementation โ”œโ”€โ”€ weather.json # Server configuration โ”œโ”€โ”€ requirements.txt # Dependencies โ”œโ”€โ”€ Dockerfile # Docker configuration โ””โ”€โ”€ README.md # This file


## ๐Ÿ—๏ธ Building MCP Server from Scratch

### 1. Create Weather Service Server (`server/weather.py`)

```python
from typing import Any
import httpx
from mcp.server.fastmcp import FastMCP

# Initialize MCP server
mcp = FastMCP("weather")

# Weather API configuration
WEATHER_API_BASE = "https://api.weather.gov"
USER_AGENT = "MCP-Weather-Server/1.0"

async def make_weather_request(url: str) -> dict[str, Any]:
    """Make request to weather API with proper error handling"""
    headers = {
        "User-Agent": USER_AGENT,
        "Accept": "application/json"
    }
    
    async with httpx.AsyncClient() as client:
        response = await client.get(url, headers=headers, timeout=30)
        response.raise_for_status()
        return response.json()

def format_alerts(response: dict[str, Any]) -> str:
    """Format weather alerts response"""
    if not response.get("features"):
        return "No weather alerts found for this state."
    
    alerts = []
    for feature in response["features"]:
        properties = feature.get("properties", {})
        alerts.append(f"Alert: {properties.get('headline', 'N/A')}")
    
    return "\n".join(alerts)

@mcp.tool()
async def get_alerts(state: str) -> str:
    """Get weather alerts for a US state (provide 2-character state code)"""
    url = f"{WEATHER_API_BASE}/alerts?area={state.upper()}"
    
    try:
        response = await make_weather_request(url)
        return format_alerts(response)
    except Exception as e:
        return f"Error fetching weather alerts: {str(e)}"

# Resource example
@mcp.resource("config://app")
async def get_app_config() -> str:
    """Get application configuration"""
    return "MCP Weather Server v1.0 - Provides weather alerts for US states"

if __name__ == "__main__":
    mcp.run()

๐Ÿ”— Integration Methods

Configuration File (weather.json)

{
  "mcpServers": {
    "weather": {
      "command": "uv",
      "args": ["run", "server/weather.py"],
      "cwd": "/path/to/your/project"
    }
  }
}

Transport Types :

  • STDIO: For local development and same-machine communication
  • SSE (Server-Sent Events): For production with separate client/server hosting

๐Ÿ’ป Client Implementation

Basic Client (client.py)

import asyncio
from langchain_groq import ChatGroq
from mcpus import MCPAgent, MCPClient

async def main():
    # Load configuration
    client = MCPClient("weather.json")
    
    # Initialize LLM
    llm = ChatGroq(
        model="llama-3.1-70b-versatile",
        api_key="your-groq-api-key"
    )
    
    # Create MCP Agent
    agent = MCPAgent(llm=llm, client=client)
    
    # Interactive loop
    while True:
        query = input("Ask about weather: ")
        if query.lower() in ['quit', 'exit']:
            break
            
        response = await agent.run(query)
        print(f"Response: {response}")

if __name__ == "__main__":
    asyncio.run(main())

Running the Client

# Set your Groq API key
export GROQ_API_KEY="your-api-key-here"

# Run client
uv run client.py

๐ŸŽ“ Course Information

This tutorial is part of the 2.0 Agentic AI and GenAI with MCP course :

  • Start Date: May 10th, 2025
  • Schedule: Every Saturday and Sunday, 3 hours per session
  • Focus: Complete coverage of Agentic AI and Generative AI with MCP

๐Ÿ”ง Development Tips

Environment Variables

Create a .env file:

GROQ_API_KEY=your-groq-api-key
WEATHER_API_KEY=your-weather-api-key  # if needed

Testing Your Server

# Test with MCP Inspector
uv run mcp dev server/weather.py

# Test specific tool
# In MCP Inspector: get_alerts("CA")

Debugging

  • Use MCP Inspector for development and testing
  • Check server logs for connection issues
  • Verify JSON configuration syntax
  • Ensure proper port configuration for SSE transport

๐Ÿ“š Additional Resources

๐Ÿค Contributing

Feel free to submit issues and enhancement requests!

๐Ÿ“„ License

This project is licensed under the MIT License.


This README provides a comprehensive guide covering all the major topics from the video, including setup instructions, code examples, and deployment options. It's structured to help users follow along with the tutorial and implement their own MCP servers and clients   .# mcpcrashcourse