From 03e19f1c90fd8a4e31c7f66c978a76ade6af5ae0 Mon Sep 17 00:00:00 2001 From: Steve Billings Date: Tue, 23 Sep 2025 09:48:38 -0400 Subject: [PATCH] Fastmcp logging progress example (#1270) Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com> --- examples/fastmcp/logging_and_progress.py | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/fastmcp/logging_and_progress.py diff --git a/examples/fastmcp/logging_and_progress.py b/examples/fastmcp/logging_and_progress.py new file mode 100644 index 00000000..91c2b806 --- /dev/null +++ b/examples/fastmcp/logging_and_progress.py @@ -0,0 +1,33 @@ +""" +FastMCP Echo Server that sends log messages and progress updates to the client +""" + +import asyncio + +from mcp.server.fastmcp import Context, FastMCP + +# Create server +mcp = FastMCP("Echo Server with logging and progress updates") + + +@mcp.tool() +async def echo(text: str, ctx: Context) -> str: + """Echo the input text sending log messages and progress updates during processing.""" + await ctx.report_progress(progress=0, total=100) + await ctx.info("Starting to process echo for input: " + text) + + await asyncio.sleep(2) + + await ctx.info("Halfway through processing echo for input: " + text) + await ctx.report_progress(progress=50, total=100) + + await asyncio.sleep(2) + + await ctx.info("Finished processing echo for input: " + text) + await ctx.report_progress(progress=100, total=100) + + # Progress notifications are process asynchronously by the client. + # A small delay here helps ensure the last notification is processed by the client. + await asyncio.sleep(0.1) + + return text