Skip to content

Context.session.send_notification doesn't behave as expected #215

Open
@zilto

Description

@zilto

(The bug may be related to the MCP dev UI)

Describe the bug
I'm building an MCP server that adds tools dynamically over the lifecycle of the server.

The following code makes it possible to for the client to call first_tool(), which will register second_tool() and send a notification to the client to refresh the list.

async def first_tool(ctx: Context):
    """This is a the first tool"""
    ctx.fastmcp.add_tool(second_tool)
    await ctx.session.send_notification(ToolListChangedNotification(method='notifications/tools/list_changed'))


def second_tool(ctx: Context = None) -> str:
    """this is the second tool!"""
    return "hello world"

This successfully adds second_tool(), but no notification is registered by the client, nor does it trigger the expected tool refresh in the UI

mcp_issue.mp4

(forgot to show in the video, but hitting Clear then List tools will show second_tool() in the UI

Solutions
My understanding is that notification handling and UI changes are the client's responsibility. Currently, the dev toolset doesn't allow me to distinguish:

  • an error in my code (sending the wrong notification)
  • a bug in the Python SDK (notifications aren't properly sent)
  • limitations of the official dev UI (notifications aren't properly handled)

To unblock me, I would like to have clarity over the intended behavior to make sure I'm not building a castle on sand 😅

Additional info
How does this relate to NotificationOptions? AFAIK, there's no direct configuration point and I would need to override run_stdio_async() or run_sse_async() (ref) to modify these notification options

Specs

  • OS: Linux Ubuntu 24.02
  • Browser: Brave
  • mcp: 1.2.1
  • client: built-in MCP dev tool

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions