Skip to main content
Glama
es6kr

claude-session-manager

by es6kr

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"]
        }
    ),
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the 'repair the parentUuid chain' effect, which is valuable context about data integrity. However, it doesn't address critical aspects like whether deletion is permanent/reversible, permission requirements, error conditions, or what happens to dependent data. For a destructive operation with zero annotation coverage, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core action and a key behavioral detail without any wasted words. It's appropriately sized for the tool's complexity and gets straight to the point.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive operation with no annotations and no output schema, the description is incomplete. While it mentions the chain repair effect, it doesn't cover return values, error handling, side effects, or security implications. Given the tool's potential impact and lack of structured metadata, more comprehensive behavioral context would be needed for safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all parameters are documented in the schema. The description adds no additional parameter information beyond what the schema provides (project_name, session_id, message_uuid). It doesn't explain relationships between parameters or provide usage examples. The baseline score of 3 reflects adequate but minimal value added over the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Delete a message'), specifies the resource ('from a session'), and adds a distinctive behavioral detail ('and repair the parentUuid chain') that distinguishes it from generic deletion operations. This goes beyond just restating the tool name by explaining the specific effect on the data structure.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'delete_session' or 'clear_sessions'. It doesn't mention prerequisites, constraints, or typical scenarios for message deletion versus session-level operations. The agent must infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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