python-sdk/examples/snippets/servers/tool_change_notifications.py
2026-02-23 15:38:15 +00:00

15 lines
471 B
Python

from mcp.server.fastmcp import Context, FastMCP
from mcp.server.session import ServerSession
mcp = FastMCP("Dynamic Tools")
@mcp.tool()
async def register_plugin(name: str, ctx: Context[ServerSession, None]) -> str:
"""Dynamically register a new tool and notify the client."""
# ... register the plugin's tools ...
# Notify the client that the tool list has changed
await ctx.session.send_tool_list_changed()
return f"Plugin '{name}' registered"