Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zilto opened this issue Feb 18, 2025 · 0 comments
Open

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

zilto opened this issue Feb 18, 2025 · 0 comments
Milestone

Comments

@zilto
Copy link

zilto commented Feb 18, 2025

(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
@dsp-ant dsp-ant added this to the SDK 1.3.x milestone Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants