MCPcopy Create free account
hub / github.com/IBM/mcp-cli / _handle_memory_tool

Method _handle_memory_tool

src/mcp_cli/chat/tool_processor.py:678–723  ·  view source on GitHub ↗

Execute a memory scope tool (remember, recall, forget). Memory tools are persistent-memory operations that bypass the MCP ToolManager and all guard checks.

(
        self,
        tool_name: str,
        arguments: dict,
        llm_tool_name: str,
        call_id: str,
    )

Source from the content-addressed store, hash-verified

676 return json.dumps(response)
677
678 async def _handle_memory_tool(
679 self,
680 tool_name: str,
681 arguments: dict,
682 llm_tool_name: str,
683 call_id: str,
684 ) -> None:
685 """Execute a memory scope tool (remember, recall, forget).
686
687 Memory tools are persistent-memory operations that bypass the MCP
688 ToolManager and all guard checks.
689 """
690 store = getattr(self.context, "memory_store", None)
691 if not store:
692 self._add_tool_result_to_history(
693 llm_tool_name, call_id, "Memory scopes not available."
694 )
695 return
696
697 logger.info("Memory tool %s called with args: %s", tool_name, arguments)
698
699 # Show tool call in UI
700 try:
701 self.ui_manager.print_tool_call(tool_name, arguments)
702 await self.ui_manager.start_tool_execution(tool_name, arguments)
703 except Exception as e:
704 logger.debug("UI error displaying memory tool call: %s", e)
705
706 from mcp_cli.memory.tools import handle_memory_tool
707
708 result_text = await handle_memory_tool(store, tool_name, arguments)
709
710 # Mark system prompt dirty so memory changes appear next turn
711 if tool_name in ("remember", "forget"):
712 if hasattr(self.context, "_system_prompt_dirty"):
713 self.context._system_prompt_dirty = True
714
715 # Finish UI display
716 try:
717 await self.ui_manager.finish_tool_execution(
718 result=result_text, success=True
719 )
720 except Exception as e:
721 logger.debug("UI error finishing memory tool display: %s", e)
722
723 self._add_tool_result_to_history(llm_tool_name, call_id, result_text)
724
725 async def _handle_plan_tool(
726 self,

Calls 5

handle_memory_toolFunction · 0.90
print_tool_callMethod · 0.45
start_tool_executionMethod · 0.45
finish_tool_executionMethod · 0.45