Gen-AI Developer Classroom notes 18/Dec/2025

Redoing fastapi + fastmcp

  • Watch classroom recording for steps
  • To run mcp inspector directly
npx @modelcontextprotocol/inspector

Topics on server

  • Context (Notification)
  • Client (Langchain with mcp tools)
  • Sampling
  • Elicitations
  • Auth (basic, jwt and oauth2)

Context

  • When mcp tools are executing we need notifications
    • logs
    • progress
  • Best practices, tools which use context are generally recommended to be async.

  • Run this code and execute using mcp inspector

from fastmcp import FastMCP, Context
import asyncio

mcp = FastMCP("Streamable Demo")

@mcp.tool()
def add(a: int, b: int):
    """Adds two numbers"""
    return a + b

@mcp.tool()
def echo(message: str):
    """Echoes a string"""
    return f"you said {message}"


@mcp.tool()
async def some_long_running(a: int, b: int, ctx: Context) -> int:
    ctx.info("Starting long running task")
    asyncio.sleep(0.1)
    ctx.info("Finished long running task")
    # ctx progress
    ctx.report_progress(0.25, 1.0)
    ctx.report_progress(0.5, 1.0)
    ctx.report_progress(0.75,1.0)
    ctx.report_progress(1.0,1.0)
    return a * b

if __name__ == "__main__":
    mcp.run(transport="http", host="0.0.0.0", port=8000)

  • See if you are recieving notifications

By continuous learner

enthusiastic technology learner

Leave a comment