Skip to content

Commit 03e19f1

Browse files
Fastmcp logging progress example (#1270)
Co-authored-by: Felix Weinberger <[email protected]>
1 parent 20596e5 commit 03e19f1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
FastMCP Echo Server that sends log messages and progress updates to the client
3+
"""
4+
5+
import asyncio
6+
7+
from mcp.server.fastmcp import Context, FastMCP
8+
9+
# Create server
10+
mcp = FastMCP("Echo Server with logging and progress updates")
11+
12+
13+
@mcp.tool()
14+
async def echo(text: str, ctx: Context) -> str:
15+
"""Echo the input text sending log messages and progress updates during processing."""
16+
await ctx.report_progress(progress=0, total=100)
17+
await ctx.info("Starting to process echo for input: " + text)
18+
19+
await asyncio.sleep(2)
20+
21+
await ctx.info("Halfway through processing echo for input: " + text)
22+
await ctx.report_progress(progress=50, total=100)
23+
24+
await asyncio.sleep(2)
25+
26+
await ctx.info("Finished processing echo for input: " + text)
27+
await ctx.report_progress(progress=100, total=100)
28+
29+
# Progress notifications are process asynchronously by the client.
30+
# A small delay here helps ensure the last notification is processed by the client.
31+
await asyncio.sleep(0.1)
32+
33+
return text

0 commit comments

Comments
 (0)