Skip to main content
Glama
DrumRobot
by DrumRobot

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'),
    },

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

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