Skip to content

How to receive notifications on mcp client side? #889

Closed

Description

@shashisingh

I am trying to send few logging events to the client during a tool invocation. I am using "Context.info('Hello)" inside a mcp.tool decorated function. I am using FASTMcp for hosting tools. I was expecting to receive these notifications in my ClientSession's "_received_notification" method. But I don't seem to get this to work. I do not see that _received_notification is getting called.

Activity

  1. kylestratis commented on Jun 9, 2025

    @kylestratis

    👍
    It doesn't seem like notification handling is yet built into the Python SDK

  2. added
    improves spec complianceWhen a change improves ability of SDK users to comply with spec definition
    enhancementRequest for a new feature that's not currently supported
    ready for workEnough information for someone to start working on
    P0Broken core functionality, security issues, critical missing feature
    improves sdk consistencyImproves consistency with other SDKs such as Tyepscript
    on Oct 7, 2025
  3. added this to the FastMCP issues milestone on Oct 7, 2025
  4. maxisbey commented on Jan 5, 2026

    @maxisbey
    Contributor

    The SDK partially supports receiving notifications on the client side today:

    Notification Type Current Support
    LoggingMessageNotification ✅ logging_callback
    ProgressNotification ✅ progress_callback on call_tool()
    CancelledNotification ✅ Automatic
    ResourceListChangedNotification ❌ message_handler only
    ResourceUpdatedNotification ❌ message_handler only
    ToolListChangedNotification ❌ message_handler only
    PromptListChangedNotification ❌ message_handler only
    ElicitCompleteNotification ❌ message_handler only
    TaskStatusNotification ❌ message_handler only

    For logging notifications (Context.info(), etc.), pass a logging_callback to ClientSession:

    async def handle_log(params: types.LoggingMessageNotificationParams) -> None:
        print(f"[{params.level}] {params.data}")
    
    async with ClientSession(read, write, logging_callback=handle_log) as session:
        ...

    For progress notifications, pass a progress_callback when calling a tool:

    await session.call_tool("my_tool", {}, progress_callback=on_progress)

    For other notifications (resource/tool/prompt list changes, etc.), use the generic message_handler parameter:

    from mcp.shared.session import RequestResponder
    import mcp.types as types
    
    async def handle_notifications(
        message: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception,
    ) -> None:
        if isinstance(message, types.ServerNotification):
            match message.root:
                case types.ResourceListChangedNotification():
                    print("Resources changed, refreshing list...")
                case types.ToolListChangedNotification():
                    print("Tools changed, refreshing list...")
                case types.PromptListChangedNotification():
                    print("Prompts changed, refreshing list...")
    
    async with ClientSession(read, write, message_handler=handle_notifications) as session:
        ...

    We do want to add proper dedicated callbacks for all notification types. PR #1611 addresses this but hasn't been reviewed yet.

    As this issue is quite old, I'm closing it for now. Feel free to re-open if you have further questions.

    AI Disclaimer

  5. added
    P1Significant bug affecting many users, highly requested feature
    and removed
    P0Broken core functionality, security issues, critical missing feature
    on Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featureenhancementRequest for a new feature that's not currently supportedimproves sdk consistencyImproves consistency with other SDKs such as Tyepscriptimproves spec complianceWhen a change improves ability of SDK users to comply with spec definitionready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions