Skip to content

Repo for demonstrating simple Model Context Protocol (MCP) server with several Agent Frameworks

Notifications You must be signed in to change notification settings

andrewginns/agents-mcp-usage

Repository files navigation

Model Context Protocol (MCP) Agent Frameworks Demo

This repository demonstrates the usage of a simple Model Context Protocol (MCP) server with several frameworks:

  • Google Agent Development Toolkit (ADK)
  • LangGraph Agents
  • OpenAI Agents
  • Pydantic-AI Agents

Included MCP Server is based on MCP Python SDK Quickstart

  • Modified to include a datetime tool and run as a server invoked by Agents

Tracing is done through Pydantic Logfire.

MCP Concept

Quickstart

cp .env.example .env

  • Add GEMINI_API_KEY and/or OPENAI_API_KEY
  • [Optional] Add LOGFIRE_TOKEN to visualise evaluations in Logfire web ui

Run an Agent framework script e.g.:

  • uv run basic_mcp_use/pydantic_mcp.py - Requires GEMINI_API_KEY by default

  • uv run basic_mcp_use/oai-agent_mcp.py - Requires OPENAI_API_KEY by default

Check console or Logfire for output

Project Overview

This project aims to teach:

  1. How to use MCP with multiple LLM Agent frameworks
    • Example MCP tools for adding numbers, getting current time
  2. How to see traces LLM Agents with Logfire

Logfire UI

MCP Architecture

graph LR
    User((User)) --> |"Run script<br>(e.g., pydantic_mcp.py)"| Agent

    subgraph "Agent Frameworks"
        Agent[Agent]
        ADK["Google ADK<br>(adk_mcp.py)"]
        LG["LangGraph<br>(langgraph_mcp.py)"]
        OAI["OpenAI Agents<br>(oai-agent_mcp.py)"]
        PYD["Pydantic-AI<br>(pydantic_mcp.py)"]
        
        Agent --> ADK
        Agent --> LG
        Agent --> OAI
        Agent --> PYD
    end

    subgraph "MCP Server"
        MCP["Model Context Protocol Server<br>(run_server.py)"]
        Tools["Tools<br>- add(a, b)<br>- get_current_time()"]
        Resources["Resources<br>- greeting://{name}"]
        MCP --- Tools
        MCP --- Resources
    end

    subgraph "LLM Providers"
        OAI_LLM["OpenAI Models"]
        GEM["Google Gemini Models"]
        OTHER["Other LLM Providers..."]
    end
    
    Logfire[("Logfire<br>Tracing")]
    
    ADK --> MCP
    LG --> MCP
    OAI --> MCP
    PYD --> MCP
    
    MCP --> OAI_LLM
    MCP --> GEM
    MCP --> OTHER
    
    ADK --> Logfire
    LG --> Logfire
    OAI --> Logfire
    PYD --> Logfire
    
    LLM_Response[("Response")] --> User
    OAI_LLM --> LLM_Response
    GEM --> LLM_Response
    OTHER --> LLM_Response

    style MCP fill:#f9f,stroke:#333,stroke-width:2px
    style User fill:#bbf,stroke:#338,stroke-width:2px
    style Logfire fill:#bfb,stroke:#383,stroke-width:2px
    style LLM_Response fill:#fbb,stroke:#833,stroke-width:2px
Loading

The diagram illustrates how MCP serves as a standardised interface between different agent frameworks and LLM providers.The flow shows how users interact with the system by running a specific agent script, which then leverages MCP to communicate with LLM providers, while Logfire provides tracing and observability.

Repository Structure

  • basic_mcp_use/ - Contains basic examples of MCP usage:

    • adk_mcp.py - Example of using MCP with Google's Agent Development Kit (ADK)
    • langgraph_mcp.py - Example of using MCP with LangGraph
    • oai-agent_mcp.py - Examoke of using MCP with OpenAI Agents
    • pydantic_mcp.py - Example of using MCP with Pydantic-AI
  • run_server.py - Simple MCP server that runs locally implemented in Python

What is MCP?

The Model Context Protocol allows applications to provide context for LLMs in a standardised way, separating the concerns of providing context from the actual LLM interaction.

Learn more: https://modelcontextprotocol.io/introduction

Why MCP

By defining clear specifications for components like resources (data exposure), prompts (reusable templates), tools (actions), and sampling (completions), MCP simplifies the development process and fosters consistency.

A key advantage highlighted is flexibility; MCP allows developers to more easily switch between different LLM providers without needing to completely overhaul their tool and data integrations. It provides a structured approach, potentially reducing the complexity often associated with custom tool implementations for different models. While frameworks like Google Agent Development Kit, LangGraph, OpenAI Agents, or libraries like PydanticAI facilitate agent building, MCP focuses specifically on standardising the interface between the agent's reasoning (the LLM) and its capabilities (tools and data), aiming to create a more interoperable ecosystem.

Setup Instructions

  1. Clone this repository
  2. Install required packages:
    uv sync
  3. Set up your environment variables in a .env file:
    LOGFIRE_TOKEN=your_logfire_token
    GEMINI_API_KEY=your_gemini_api_key
    OPENAI_API_KEY=your_openai_api_key
    
  4. Run any of the sample scripts to see a simple MCP server being used via an Agent framework

About Logfire

Logfire is an observability platform from the team behind Pydantic that makes monitoring AI applications straightforward. Features include:

  • Simple yet powerful dashboard
  • Python-centric insights, including rich display of Python objects
  • SQL-based querying of your application data
  • OpenTelemetry support for leveraging existing tooling
  • Pydantic integration for analytics on validations

Logfire gives you visibility into how your code is running, which is especially valuable for LLM applications where understanding model behavior is critical.

About

Repo for demonstrating simple Model Context Protocol (MCP) server with several Agent Frameworks

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages