Skip to main content
Glama
DrumRobot
by DrumRobot

get_session_diff

Compare file changes and snapshot information between Claude Code conversation sessions to track project evolution and modifications.

Instructions

Get diff summary for a session including file changes and snapshot info

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_nameYesProject folder name
session_idYesSession ID

Implementation Reference

  • Core implementation of getSessionDiffSummary: reads session messages, derives session title from first human message, iterates through messages to find file-history-snapshot events, extracts unique file changes with backup previews, counts snapshots, and returns a structured summary.
    export const getSessionDiffSummary = (projectName: string, sessionId: string) =>
      Effect.gen(function* () {
        const messages = yield* readSession(projectName, sessionId)
    
        // Extract title
        const title = pipe(
          messages,
          A.findFirst((m) => m.type === 'human'),
          O.map((m) => {
            const msg = m.message as { content?: string } | undefined
            const content = msg?.content ?? ''
            return content.slice(0, 50) + (content.length > 50 ? '...' : '')
          }),
          O.getOrElse(() => 'Untitled')
        )
    
        const changes: FileDiffSummary['changes'] = []
        const seenFiles = new Set<string>()
        let snapshotCount = 0
    
        for (const msg of messages) {
          if (msg.type === 'file-history-snapshot') {
            snapshotCount++
            const snapshot = msg as {
              type: string
              snapshot?: {
                trackedFileBackups?: Record<string, { content?: string }>
              }
            }
    
            const backups = snapshot.snapshot?.trackedFileBackups
            if (backups && typeof backups === 'object') {
              for (const [filePath, backup] of Object.entries(backups)) {
                if (!seenFiles.has(filePath)) {
                  seenFiles.add(filePath)
                  const backupData = backup as { content?: string } | undefined
                  const content = backupData?.content ?? ''
                  changes.push({
                    path: filePath,
                    action: 'modified',
                    hasBackup: content.length > 0,
                    backupPreview: content.slice(0, 100) + (content.length > 100 ? '...' : ''),
                  })
                }
              }
            }
          }
        }
    
        return {
          sessionId,
          projectName,
          title,
          changes,
          totalFiles: changes.length,
          snapshotCount,
        } satisfies FileDiffSummary
      })
  • Registers the MCP tool 'get_session_diff' with server.tool, providing description, input schema, and a thin handler that invokes the core getSessionDiffSummary function and returns JSON response.
    server.tool(
      'get_session_diff',
      'Get diff summary for a session including file changes and snapshot info',
      {
        project_name: z.string().describe('Project folder name'),
        session_id: z.string().describe('Session ID'),
      },
      async ({ project_name, session_id }) => {
        const result = await Effect.runPromise(session.getSessionDiffSummary(project_name, session_id))
        return {
          content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
        }
      }
    )
  • Zod input schema defining required string parameters: project_name and session_id for the get_session_diff tool.
    {
      project_name: z.string().describe('Project folder name'),
      session_id: z.string().describe('Session ID'),
    },

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