Model Context Protocol Advanced Topics
← All lessons
Lesson 03Model Context Protocol Advanced Topics

Log and progress notifications

Summary audio

Spoken summary — press play to read along: the line being spoken stays near the top.

Study notes

Logging and Progress Notifications

  • Purpose: To enhance User Experience (UX) by providing real-time feedback to the user while long-running tool calls (e. g. , research functions) are executing on the MCP server.
  • Server-Side Implementation (The Tool Function):
  • The tool function automatically receives a context argument (as the last argument).
  • This context object provides methods for reporting status:
  • info(): Used to emit general log statements.
  • report_progress(): Used to update the user on the task's completion percentage or status.
  • Calling these methods automatically sends the updates back to the client.
  • Client-Side Implementation:
  • The client must define two separate callback functions: one for handling log statements and one for handling progress updates.
  • These callbacks are passed to the call_tool function.
  • The developer is responsible for implementing the logic within these callbacks to display the information (e. g. , printing to a terminal or updating a web browser element).
  • Key Concept: Logging and progress updates are optional UX enhancements. Developers are not required to implement or display these statements.

Takeaways

  • Purpose: Logging and progress notifications enhance User Experience (UX) by providing real-time feedback during long-running tool calls.
  • Server-Side Reporting: The tool function automatically receives a context object, which must be used to report status via:
  • context. info(): For general log statements.
  • context. report_progress(): For updating completion percentage or status.
  • Client-Side Handling: The developer must define two separate callback functions (one for logs, one for progress) and pass them to the call_tool function.
  • Developer Responsibility: The client-side callback functions are responsible for implementing the actual display logic (e. g. , printing to a terminal or updating a UI element).
  • Scope: These logging and progress updates are optional UX enhancements and are not required for basic functionality.
Flashcards 10 cards
Question
click to reveal · ←/→
Answer
click to flip back
Export to Anki (.tsv) ↓
Knowledge check 6 questions