Skip to content

Fastmcp logging progress example #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions examples/fastmcp/logging_and_progress.py
Original file line number Diff line number Diff line change
@@ -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
Loading