Skip to main content
Glama
es6kr
by es6kr

delete_message

Remove a specific message from a Claude Code 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 a specific message from a session file by UUID (or messageId for snapshots), repairs the parent-child UUID chain by reparenting direct children to the deleted message's parent, and rewrites the session JSONL file.
    export const deleteMessage = (projectName: string, sessionId: string, messageUuid: string) =>
      Effect.gen(function* () {
        const filePath = path.join(getSessionsDir(), projectName, `${sessionId}.jsonl`)
        const content = yield* Effect.tryPromise(() => fs.readFile(filePath, 'utf-8'))
        const lines = content.trim().split('\n').filter(Boolean)
        const messages = lines.map((line) => JSON.parse(line) as Record<string, unknown>)
    
        // Find by uuid or messageId (for file-history-snapshot type)
        const targetIndex = messages.findIndex(
          (m) => m.uuid === messageUuid || m.messageId === messageUuid
        )
        if (targetIndex === -1) {
          return { success: false, error: 'Message not found' }
        }
    
        // Get the deleted message's uuid and parentUuid
        const deletedMsg = messages[targetIndex]
        const deletedUuid = deletedMsg?.uuid ?? deletedMsg?.messageId
        const parentUuid = deletedMsg?.parentUuid
    
        // Find all messages that reference the deleted message as their parent
        // and update them to point to the deleted message's parent
        for (const msg of messages) {
          if (msg.parentUuid === deletedUuid) {
            msg.parentUuid = parentUuid
          }
        }
    
        // Remove the message
        messages.splice(targetIndex, 1)
    
        const newContent = messages.map((m) => JSON.stringify(m)).join('\n') + '\n'
        yield* Effect.tryPromise(() => fs.writeFile(filePath, newContent, 'utf-8'))
    
        return { success: true }
      })
  • src/mcp/index.ts:73-89 (registration)
    MCP tool registration for 'delete_message', including Zod input schema and thin async handler that delegates to session.deleteMessage and formats the response.
    server.tool(
      'delete_message',
      'Delete a message from a session and repair the parentUuid chain',
      {
        project_name: z.string().describe('Project folder name'),
        session_id: z.string().describe('Session ID'),
        message_uuid: z.string().describe('UUID of the message to delete'),
      },
      async ({ project_name, session_id, message_uuid }) => {
        const result = await Effect.runPromise(
          session.deleteMessage(project_name, session_id, message_uuid)
        )
        return {
          content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
        }
      }
    )
  • Zod schema defining inputs for the delete_message tool: project_name, session_id, and message_uuid as strings.
    {
      project_name: z.string().describe('Project folder name'),
      session_id: z.string().describe('Session ID'),
      message_uuid: z.string().describe('UUID of the message to delete'),
    },
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 'repair the parentUuid chain,' which hints at a complex mutation with side effects, but doesn't clarify permissions needed, whether the deletion is reversible, rate limits, or what happens to associated data. This is inadequate for a destructive operation.

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 directly states the tool's purpose and key behavioral detail ('repair the parentUuid chain'). It is front-loaded with no wasted words, earning its place fully.

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?

Given the complexity of a deletion tool with chain repair, no annotations, and no output schema, the description is incomplete. It fails to address critical aspects like error handling, return values, or the implications of the repair process, leaving significant gaps for an AI agent.

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 the schema already documents all three parameters (project_name, session_id, message_uuid). The description adds no additional meaning beyond what the schema provides, such as format examples or constraints, meeting the baseline for high schema coverage.

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

Purpose4/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') and the resource ('from a session'), with the additional detail about repairing the parentUuid chain. However, it doesn't explicitly differentiate this tool from sibling tools like delete_session or clear_sessions, which would require a 5.

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 lacks context about prerequisites, exclusions, or specific scenarios where this deletion method is appropriate.

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-sessions-mcp'

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