Skip to main content
Glama

delete_memory

Remove specific stored memories by confirming their memory_id to manage data in the Mem0 MCP Server's persistent memory system.

Instructions

Delete one memory after the user confirms its memory_id.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_idYesExact memory_id to delete.

Implementation Reference

  • The delete_memory tool handler, registered via @server.tool decorator. It resolves the API key and context, initializes the Mem0 client, and calls the underlying client.delete method with the provided memory_id, returning the JSON response or error.
    @server.tool(description="Delete one memory after the user confirms its memory_id.") def delete_memory( memory_id: Annotated[str, Field(description="Exact memory_id to delete.")], ctx: Context | None = None, ) -> str: """Delete a memory once the user explicitly confirms the memory_id to remove.""" api_key, _, _ = _resolve_settings(ctx) client = _mem0_client(api_key) return _mem0_call(client.delete, memory_id)
  • The @server.tool decorator registers the delete_memory function as an MCP tool with its description.
    @server.tool(description="Delete one memory after the user confirms its memory_id.")
  • Input schema for the memory_id parameter using Pydantic Annotated and Field for description.
    memory_id: Annotated[str, Field(description="Exact memory_id to delete.")],
  • Helper function that wraps Mem0 API calls, handling exceptions and serializing responses to JSON.
    def _mem0_call(func, *args, **kwargs): try: result = func(*args, **kwargs) except MemoryError as exc: # surface structured error back to MCP client logger.error("Mem0 call failed: %s", exc) # returns the erorr to the model return json.dumps( { "error": str(exc), "status": getattr(exc, "status", None), "payload": getattr(exc, "payload", None), }, ensure_ascii=False, ) return json.dumps(result, ensure_ascii=False)
  • Helper to resolve Mem0 API key, default user ID, and graph settings from context or environment.
    def _resolve_settings(ctx: Context | None) -> tuple[str, str, bool]: session_config = getattr(ctx, "session_config", None) api_key = _config_value(session_config, "mem0_api_key") or ENV_API_KEY if not api_key: raise RuntimeError( "MEM0_API_KEY is required (via Smithery config, session config, or environment) to run the Mem0 MCP server." ) default_user = _config_value(session_config, "default_user_id") or ENV_DEFAULT_USER_ID enable_graph_default = _config_value(session_config, "enable_graph_default") if enable_graph_default is None: enable_graph_default = ENV_ENABLE_GRAPH_DEFAULT return api_key, default_user, enable_graph_default

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/arjunkmrm/mem0-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server