1. Learn
  2. /
  3. คอร์ส
  4. /
  5. Model Context Protocol: Advanced Topics

Connected

แบบฝึกหัด

Add progress and logs to a slow tool

Your research server has an add_all tool that sums a list of numbers, working through them one at a time. Right now it stays silent, so the client can't tell how far along it is. You'll log a message when it starts, then report progress after each number so the client can render a smooth, advancing progress bar.

FastMCP and Context are imported and the server mcp is created. run_tool(numbers) runs your tool through a real MCP client–server session and collects what the connected client receives into the lists LOGS and PROGRESS.

คำแนะนำ

100 XP
  • Use ctx.info() to log the message "Adding the numbers..." when the tool starts.
  • After adding each number, call ctx.report_progress() inside the loop.
  • Report the count done so far (i + 1) out of the total (len(numbers)).