@@ -419,21 +419,27 @@ def create_thumbnail(image_path: str) -> Image:
419419
420420The Context object gives your tools and resources access to MCP capabilities:
421421
422+ <!-- snippet-source examples/servers/everything/src/everything/server.py#L43-L58 -->
422423``` python
423- from mcp.server.fastmcp import FastMCP, Context
424-
425- mcp = FastMCP(" My App" )
426-
424+ # Tool with context for logging and progress
425+ @mcp.tool (description = " A tool that demonstrates logging and progress" , title = " Progress Tool" )
426+ async def tool_with_progress (message : str , ctx : Context, steps : int = 3 ) -> str :
427+ await ctx.info(f " Starting processing of ' { message} ' with { steps} steps " )
428+
429+ # Send progress notifications
430+ for i in range (steps):
431+ progress_value = (i + 1 ) / steps
432+ await ctx.report_progress(
433+ progress = progress_value,
434+ total = 1.0 ,
435+ message = f " Processing step { i + 1 } of { steps} " ,
436+ )
437+ await ctx.debug(f " Completed step { i + 1 } " )
427438
428- @mcp.tool ()
429- async def long_task (files : list[str ], ctx : Context) -> str :
430- """ Process multiple files with progress tracking"""
431- for i, file in enumerate (files):
432- ctx.info(f " Processing { file } " )
433- await ctx.report_progress(i, len (files))
434- data, mime_type = await ctx.read_resource(f " file:// { file } " )
435- return " Processing complete"
439+ return f " Processed ' { message} ' in { steps} steps "
436440```
441+ _ Full example: [ examples/servers/everything/src/everything/server.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/servers/everything/src/everything/server.py#L43-L58 ) _
442+ <!-- /snippet-source -->
437443
438444### Completions
439445
0 commit comments