Skip to main content

MCP server with date and web search tools - Part of MCP-Transition tutorial

Project description

Step by Step to MCP Glory

A Comprehensive Tutorial for Building Model Context Protocol (MCP) Enabled AI Agents


๐ŸŒŸ Overview

This repository provides a complete, hands-on journey from building a simple AI agent to creating sophisticated, distributed systems using the Model Context Protocol (MCP). Through 6 carefully crafted iterations, you'll master the fundamental concepts and advanced patterns of MCP architecture.

๐ŸŽฏ What You'll Learn

  • Agent Architecture Evolution: From monolithic to modular, protocol-driven design
  • MCP Protocol Mastery: stdio and SSE transports, tool discovery, session management
  • Production Patterns: Error handling, structured data, multi-transport composition
  • Real-world Integration: External APIs, remote services, distributed tool ecosystems

๐Ÿ—บ๏ธ The Journey

๐Ÿ Stage 1 Naive Agent Simple agent with hardcoded tools
๐Ÿ”ง Stage 2 Improved Agent Async patterns and code cleanup
๐Ÿ”Œ Stage 3 MCP Foundation stdio server and custom MCP client
๐Ÿ“š Stage 4 Official Library Using Anthropic's MCP Python SDK
๐ŸŒ Stage 5 Remote Services SSE transport with ather API integration
๐ŸŒ Stage 6 Multi-Transport Unified agent with local + remote tools
๐Ÿ”„ Stage 7 Streamable HTTP Migration SSE to Streamable HTTP transport upgrade

๐Ÿš€ Quick Start

Prerequisites

1-Minute Setup

# Clone and setup
git clone <repository-url>
cd MCP-Transition
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env with your API keys

# Run any stage
python naive_agent.py           # Stage 1
python improved_agent.py        # Stage 2
python mcp_agent_sse.py         # Stage 5 (requires weather server)
python mcp_agent_streamable.py  # Stage 7 (requires streamable server)

Environment Variables

# .env file
OPENAI_API_KEY=your_openai_key_here
TAVILY_API_KEY=your_tavily_key_here
OPENWEATHERMAP_API_KEY=your_weather_key_here

๐Ÿ“– Detailed Documentation

Document Purpose Audience
๐Ÿ“‹ Setup Guide Complete installation and configuration All users
๐ŸŽ“ Step-by-Step Tutorial Detailed code walkthrough with highlights Developers

๐Ÿ“ Repository Structure

MCP-Transition/
โ”œโ”€โ”€ README.md                              # This file
โ”œโ”€โ”€ requirements.txt                       # Python dependencies
โ”œโ”€โ”€ prompts.py                            # Shared prompt templates
โ”‚
โ”œโ”€โ”€ ๐Ÿ STAGE 1: Naive Implementation
โ”‚   โ””โ”€โ”€ naive_agent.py                    # Basic agent with hardcoded tools
โ”‚
โ”œโ”€โ”€ ๐Ÿ”ง STAGE 2: Improved Architecture  
โ”‚   โ””โ”€โ”€ improved_agent.py                 # Async patterns and cleanup
โ”‚
โ”œโ”€โ”€ ๐Ÿ”Œ STAGE 3: MCP Foundation
โ”‚   โ”œโ”€โ”€ mcp_server_stdio.py              # Local MCP server (stdio transport)
โ”‚   โ””โ”€โ”€ mcp_client_stdio.py              # Custom MCP client implementation
โ”‚
โ”œโ”€โ”€ ๐Ÿ“š STAGE 4: Official Library
โ”‚   โ””โ”€โ”€ mcp_agent_with_standard_client.py # Using official Anthropic MCP SDK
โ”‚
โ”œโ”€โ”€ ๐ŸŒ STAGE 5: Remote Services
โ”‚   โ”œโ”€โ”€ mcp_server_sse.py                # Remote weather server (SSE transport)
โ”‚   โ””โ”€โ”€ mcp_agent_sse.py                 # SSE-based agent
โ”‚
โ”œโ”€โ”€ ๐ŸŒ STAGE 6: Multi-Transport
โ”‚   โ””โ”€โ”€ mcp_agent_multi_transport.py     # Unified local + remote agent
โ”‚
โ”œโ”€โ”€ ๐Ÿ”„ STAGE 7: Streamable HTTP Migration
โ”‚   โ”œโ”€โ”€ mcp_server_streamable.py         # Weather server (Streamable HTTP transport)
โ”‚   โ””โ”€โ”€ mcp_agent_streamable.py          # Streamable HTTP-based agent
โ”‚
โ””โ”€โ”€ docs/                                 # Detailed documentation
    โ”œโ”€โ”€ SETUP.md                         # Installation guide
    โ”œโ”€โ”€ TUTORIAL.md                      # Step-by-step code walkthrough
    โ”œโ”€โ”€ MCP_CONCEPTS.md                  # Protocol deep dive
    โ””โ”€โ”€ DEPLOYMENT.md                    # Production deployment

๐ŸŽฏ Stage Overview

Stage 1: Naive Implementation

File: naive_agent.py

  • Basic PydanticAI agent with hardcoded tools
  • Synchronous execution with async workarounds
  • Direct API calls without abstraction

Why PydanticAI? I chose PydanticAI as the starting framework because it provides the cleanest, non-vendor-specific approach to building AI agents. Unlike framework-specific solutions, PydanticAI offers excellent separation between conversation management and tooling, making it ideal for demonstrating MCP integration patterns.

Alternative Frameworks: This is just one of many possible implementations! For the same agent implemented across 8 different frameworks (LangChain, LangGraph, CrewAI, Llama-Index, OpenAI Assistants, Anthropic, and Atomic Agents), check out my Agent Framework Comparison Repository. You can use any of these as your starting point for MCP integration.

Key Concepts: Basic agent architecture, tool registration, conversation flow


Stage 2: Improved Architecture

File: improved_agent.py

  • Proper async/await patterns
  • Better error handling and type hints
  • Cleaner code structure and formatting

Key Concepts: Async programming, code quality, maintainable architecture

๐ŸŽ“ Tutorial Link


Stage 3: MCP Foundation

Files: mcp_server_stdio.py, mcp_client_stdio.py

  • First MCP implementation using stdio transport
  • Custom client with full protocol implementation
  • Tool discovery and JSON-RPC 2.0 messaging

Key Concepts: MCP protocol, stdio transport, JSON-RPC, tool discovery

๐ŸŽ“ Tutorial Link


Stage 4: Official Library

File: mcp_agent_with_standard_client.py

  • Replacement of custom client with official Anthropic MCP SDK
  • Simplified codebase (~100 lines reduction)
  • Production-ready protocol compliance

Key Concepts: Official libraries vs custom implementation, code simplification

๐ŸŽ“ Tutorial Link


Stage 5: Remote Services

Files: mcp_server_sse.py, mcp_agent_sse.py

  • HTTP-based MCP server with Server-Sent Events
  • Real-world API integration (OpenWeatherMap)
  • Remote deployment capabilities

Key Concepts: SSE transport, remote services, external API integration

๐ŸŽ“ Tutorial Link


Stage 6: Multi-Transport

File: mcp_agent_multi_transport.py

  • Simultaneous connection to multiple MCP servers
  • Mixed local (stdio) and remote (SSE) tools
  • Unified tool interface and session management

Key Concepts: Multi-transport architecture, tool composition, distributed systems

๐ŸŽ“ Tutorial Link


Stage 7: Streamable HTTP Migration

Files: mcp_server_streamable.py, mcp_agent_streamable.py

  • Migration from SSE to Streamable HTTP transport
  • Single endpoint design (/mcp vs /sse + /messages)
  • Improved scalability and infrastructure compatibility
  • Future-proof transport implementation

Key Concepts: Transport migration, protocol evolution, backward compatibility patterns


๐Ÿ› ๏ธ Available Tools by Stage

StageToolsTransportLocation
1-2 ๐Ÿ“… Date, ๐Ÿ” Web Search Direct calls Local
3-4 ๐Ÿ“… Date, ๐Ÿ” Web Search stdio MCP Local subprocess
5 ๐ŸŒค๏ธ Current Weather, ๐Ÿ“Š Forecast, ๐Ÿ—บ๏ธ Coordinates SSE MCP Remote HTTP server
6 ๐Ÿ“… Date, ๐Ÿ” Web Search, ๐ŸŒค๏ธ Weather Tools stdio + SSE MCP Local + Remote
7 ๐ŸŒค๏ธ Current Weather, ๐Ÿ“Š Forecast, ๐Ÿ—บ๏ธ Coordinates Streamable HTTP MCP Remote HTTP server

๐Ÿค Contributing

We welcome contributions! Here are some ways to help:

  • ๐Ÿ› Bug Reports: Found an issue? Open an issue
  • ๐Ÿ’ก Feature Requests: Ideas for new stages or improvements
  • ๐Ÿ“– Documentation: Help improve guides and examples
  • ๐Ÿ”ง Code: Submit PRs for bug fixes or enhancements

Development Setup

# Fork and clone the repository
git clone https://github.com/yourusername/MCP-Transition.git
cd MCP-Transition

# Create a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt  # If available

# Run tests
python -m pytest tests/  # If tests are available

๐Ÿ“š Additional Resources

MCP Ecosystem

Related Technologies


๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Anthropic for creating the Model Context Protocol and providing excellent documentation
  • Pydantic AI team for the elegant agent framework
  • Community contributors who helped improve this tutorial

Ready to start your MCP journey?

๐Ÿ“‹ Setup Guide โ†’ ๐ŸŽ“ Tutorial โ†’ ๐Ÿš€ Build Something Amazing

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_rachedblili_mcp_transition-0.1.0.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_rachedblili_mcp_transition-0.1.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_rachedblili_mcp_transition-0.1.0.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_rachedblili_mcp_transition-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b30f70e026fd1f817f9f1606b7a2c6236cbda4cfa3d49754eb9e377150dd620f
MD5 698685e00953292af0c74864dcfa3f7a
BLAKE2b-256 c94a6448ef7ab0c1909e2160a66c6eeafde1a5351b35d88eeb731871a3dc4105

See more details on using hashes here.

File details

Details for the file iflow_mcp_rachedblili_mcp_transition-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_rachedblili_mcp_transition-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 68.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_rachedblili_mcp_transition-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7d36d22d54ca4125895a0e76d10256cebd4ff3b7754cd399a5d388c1b768806
MD5 e7b558fa25224e002d7fe57c3f1711a3
BLAKE2b-256 5707569226b463dca29212574e7a2e4779f800cff1398037428cbd5b3a39f896

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page