Embed code snippets for README from executable examples (#1055)
This commit is contained in:
parent
7bc190bae8
commit
adf327164a
1 changed files with 1139 additions and 1131 deletions
20
examples/snippets/servers/tool_progress.py
Normal file
20
examples/snippets/servers/tool_progress.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from mcp.server.fastmcp import Context, FastMCP
|
||||
|
||||
mcp = FastMCP(name="Progress Example")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str:
|
||||
"""Execute a task with progress updates."""
|
||||
await ctx.info(f"Starting: {task_name}")
|
||||
|
||||
for i in range(steps):
|
||||
progress = (i + 1) / steps
|
||||
await ctx.report_progress(
|
||||
progress=progress,
|
||||
total=1.0,
|
||||
message=f"Step {i + 1}/{steps}",
|
||||
)
|
||||
await ctx.debug(f"Completed step {i + 1}")
|
||||
|
||||
return f"Task '{task_name}' completed"
|
||||
Loading…
Reference in a new issue