Skip to main content
Glama
DrumRobot

claude-session-manager

by DrumRobot

delete_message

Remove a specific message from a Claude session and automatically repair the conversation chain to maintain continuity.

Instructions

Delete a message from a session and repair the parentUuid chain

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_nameYesProject folder name
session_idYesSession ID
message_uuidYesUUID of the message to delete

Implementation Reference

  • The core handler function that implements the logic to delete a specific message from a session's JSONL file by UUID and repair the parentUuid chain of subsequent messages.
    def delete_message(project_name: str, session_id: str, message_uuid: str) -> bool:
        """Delete a message from session and repair parentUuid chain."""
        base_path = get_base_path()
        project_path = base_path / project_name
        jsonl_file = project_path / f"{session_id}.jsonl"
    
        if not jsonl_file.exists():
            return False
    
        lines = []
        deleted_uuid = None
        parent_of_deleted = None
    
        try:
            # Read all lines and find the message to delete
            with open(jsonl_file, 'r', encoding='utf-8') as f:
                for line in f:
                    line_stripped = line.strip()
                    if not line_stripped:
                        lines.append(line)
                        continue
    
                    try:
                        entry = json.loads(line_stripped)
                        entry_uuid = entry.get('uuid')
    
                        # Found the message to delete
                        if entry_uuid == message_uuid:
                            deleted_uuid = entry_uuid
                            parent_of_deleted = entry.get('parentUuid')
                            # Skip this line (don't add to lines)
                            continue
    
                        lines.append(line)
                    except json.JSONDecodeError:
                        lines.append(line)
    
            if deleted_uuid is None:
                return False
    
            # Repair parentUuid chain: find child of deleted message and update its parentUuid
            repaired_lines = []
            for line in lines:
                line_stripped = line.strip()
                if not line_stripped:
                    repaired_lines.append(line)
                    continue
    
                try:
                    entry = json.loads(line_stripped)
    
                    # If this message's parent is the deleted message, update to deleted's parent
                    if entry.get('parentUuid') == deleted_uuid:
                        entry['parentUuid'] = parent_of_deleted
                        repaired_lines.append(json.dumps(entry, ensure_ascii=False) + '\n')
                    else:
                        repaired_lines.append(line)
                except json.JSONDecodeError:
                    repaired_lines.append(line)
    
            # Write back to file
            with open(jsonl_file, 'w', encoding='utf-8') as f:
                f.writelines(repaired_lines)
    
            return True
    
        except Exception:
            return False
  • The dispatch logic in the MCP call_tool decorator that handles invocation of the delete_message tool by extracting arguments and calling the handler function.
    elif name == "delete_message":
        project_name = arguments.get("project_name", "")
        session_id = arguments.get("session_id", "")
        message_uuid = arguments.get("message_uuid", "")
        success = delete_message(project_name, session_id, message_uuid)
        result = {"success": success, "message": "Message deleted and chain repaired" if success else "Failed to delete message"}
  • The tool registration in list_tools() defining the name, description, and input schema for the delete_message tool.
    Tool(
        name="delete_message",
        description="Delete a message from a session and repair the parentUuid chain",
        inputSchema={
            "type": "object",
            "properties": {
                "project_name": {
                    "type": "string",
                    "description": "Project folder name"
                },
                "session_id": {
                    "type": "string",
                    "description": "Session ID"
                },
                "message_uuid": {
                    "type": "string",
                    "description": "UUID of the message to delete"
                }
            },
            "required": ["project_name", "session_id", "message_uuid"]
        }
    ),

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/DrumRobot/claude-session-manager'

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