Skip to main content
Glama

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

  • Core handler function that deletes the specified message from the session JSONL file by UUID and repairs the parentUuid chain for any child 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
  • Registers the delete_message tool with the MCP server via @mcp.list_tools(), defining its name, description, and input schema.
    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"] } ),
  • MCP tool dispatcher handler that extracts arguments from the tool call and invokes the delete_message function, returning success status.
    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"}

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