Skip to content

Commit 1d24986

Browse files
author
LittleCoinCoin
committed
fix(mcp): disabled tools being called
Ensure the tool cache is replaced with fresh event data when a tool is disabled so the cache does not retain stale metadata (e.g., valid provider_format) that allowed disabled tools to be injected into LLM payloads.
1 parent ef2a2a5 commit 1d24986

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

hatchling/mcp_utils/mcp_tool_lifecycle_subscriber.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,17 @@ def _handle_tool_enabled_event(self, event: Event) -> None:
139139
def _handle_tool_disabled_event(self, event: Event) -> None:
140140
"""Handle tool disabled event."""
141141
tool_name = event.data.get("tool_name", "")
142-
143-
if tool_name in self._tool_cache:
144-
tool_info = self._tool_cache[tool_name]
145-
tool_info.status = MCPToolStatus.DISABLED
146-
147-
if "reason" in event.data:
148-
try:
149-
tool_info.reason = MCPToolStatusReason[event.data["reason"].upper()]
150-
except (KeyError, ValueError):
151-
tool_info.reason = MCPToolStatusReason.FROM_SYSTEM_ERROR
152-
153-
self.logger.debug(f"Tool disabled: {tool_name}")
142+
tool_info = event.data.get("tool_info", {})
143+
144+
if not tool_info:
145+
self.logger.error(f"'Tool disabled event' missing 'tool_info' for tool '{tool_name}'")
146+
return
147+
148+
# Update cache with the fresh tool info from the event
149+
# This ensures consistency with _handle_tool_enabled_event() and prevents
150+
# stale cache entries that could cause disabled tools to remain in payloads
151+
self._tool_cache[tool_name] = tool_info
152+
self.logger.debug(f"Tool disabled: {tool_name}")
154153

155154
def get_enabled_tools(self) -> Dict[str, MCPToolInfo]:
156155
"""Get all currently enabled tools.

0 commit comments

Comments
 (0)