Skip to content

Commit 39262f1

Browse files
fix: properly advertise tools.listChanged capability (#26)
Override create_initialization_options to inject NotificationOptions with tools_changed=True, since FastMCP calls it without arguments (defaulting to all-false). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent df0fb21 commit 39262f1

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

mcp_starter/server.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,22 @@
8787
instructions=SERVER_INSTRUCTIONS,
8888
)
8989

90-
# Enable listChanged notifications for dynamic tool loading (load_bonus_tool)
91-
# This tells clients to subscribe to tool list change notifications
92-
mcp._mcp_server.notification_options = NotificationOptions(
93-
tools_changed=True,
94-
resources_changed=False,
95-
prompts_changed=False,
96-
)
90+
# Enable listChanged notifications for dynamic tool loading (load_bonus_tool).
91+
# FastMCP calls create_initialization_options() without args, which defaults to
92+
# NotificationOptions() with all fields False. Override to inject tools_changed=True.
93+
_original_create_init_options = mcp._mcp_server.create_initialization_options
94+
95+
96+
def _patched_create_init_options(notification_options=None, experimental_capabilities=None):
97+
if notification_options is None:
98+
notification_options = NotificationOptions(tools_changed=True)
99+
return _original_create_init_options(
100+
notification_options=notification_options,
101+
experimental_capabilities=experimental_capabilities or {},
102+
)
103+
104+
105+
mcp._mcp_server.create_initialization_options = _patched_create_init_options
97106

98107
# Register all components
99108
register_tools(mcp)

0 commit comments

Comments
 (0)