Skip to main content
Glama

cleanup

Delete expired receipts using TTL metadata to reclaim storage and enforce data retention policies. Preview deletions with dry_run mode before permanent removal.

Instructions

Delete receipts that have passed their expiration time based on the expires_at field in metadata. Expired receipts are receipts where metadata.expires_at is set and is earlier than the current time. Supports dry_run mode to preview deletions without committing. Returns count of deleted receipts and remaining total. Use periodically to manage storage and enforce TTL policies set during receipt creation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dry_runNoIf true, returns what would be deleted without actually deleting. Defaults to false.

Implementation Reference

  • The MCP tool handler for 'cleanup'. Implements the tool logic including dry_run mode (preview deletions without committing) and actual cleanup execution. Validates input with Zod schema, filters expired receipts by checking metadata.expires_at, and returns JSON results with counts and details.
    import { z } from 'zod'
    import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
    import type { ReceiptEngine } from '../engine/receipt-engine.js'
    
    export function registerCleanup(server: McpServer, engine: ReceiptEngine): void {
      server.tool(
        'cleanup',
        'Delete receipts that have passed their expiration time based on the expires_at field in metadata. Expired receipts are receipts where metadata.expires_at is set and is earlier than the current time. Supports dry_run mode to preview deletions without committing. Returns count of deleted receipts and remaining total. Use periodically to manage storage and enforce TTL policies set during receipt creation.',
        {
          dry_run: z.boolean().default(false).describe('If true, returns what would be deleted without actually deleting. Defaults to false.'),
        },
        async (params) => {
          if (params.dry_run) {
            const now = new Date().toISOString()
            const all = await engine.list(undefined, 1, 100000)
            const expired = all.data.filter(r => {
              const expiresAt = (r.metadata as Record<string, unknown>)?.expires_at as string | undefined
              return expiresAt && expiresAt < now
            })
            return {
              content: [{
                type: 'text' as const,
                text: JSON.stringify({
                  dry_run: true,
                  would_delete: expired.length,
                  total: all.data.length,
                  expired_receipts: expired.map(r => ({
                    receipt_id: r.receipt_id,
                    action: r.action,
                    expires_at: (r.metadata as Record<string, unknown>)?.expires_at,
                  })),
                }, null, 2),
              }],
            }
          }
    
          const result = await engine.cleanup()
          return {
            content: [{
              type: 'text' as const,
              text: JSON.stringify({
                deleted: result.deleted,
                remaining: result.remaining,
              }, null, 2),
            }],
          }
        },
      )
    }
  • Zod schema definition for the cleanup tool's input parameters. Defines 'dry_run' as an optional boolean parameter that defaults to false, used to preview deletions without actually deleting receipts.
    {
      dry_run: z.boolean().default(false).describe('If true, returns what would be deleted without actually deleting. Defaults to false.'),
    },
  • Registration point where the cleanup tool is registered to the MCP server. Called within registerAllTools() alongside other tool registrations.
    registerCleanup(server, engine)
  • Engine helper method that delegates cleanup operations to the underlying storage store. Wraps the store's cleanup result to return deleted count and remaining count.
    async cleanup(): Promise<{ deleted: number; remaining: number }> {
      const result = await this.store.cleanup()
      return { deleted: result.deleted, remaining: result.total - result.deleted }
    }
  • Core storage layer cleanup implementation. Iterates through all receipts, identifies expired ones by checking metadata.expires_at against current time, deletes them, and returns deletion statistics.
    async cleanup(): Promise<{ deleted: number; total: number }> {
      const now = new Date().toISOString()
      const allReceipts = await this.list(undefined, 1, 100000)
      let deleted = 0
    
      for (const receipt of allReceipts.data) {
        const expiresAt = (receipt.metadata as Record<string, unknown>)?.expires_at as string | undefined
        if (expiresAt && expiresAt < now) {
          await this.delete(receipt.receipt_id)
          deleted++
        }
      }
    
      return { deleted, total: allReceipts.data.length }
    }
Behavior4/5

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

With no annotations provided, the description carries the full burden. It successfully discloses the destructive nature (Delete), explains the dry_run safety mechanism ('preview deletions without committing'), and documents return values ('Returns count of deleted receipts and remaining total'). It could be improved by mentioning whether deletions are permanent or reversible.

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

Conciseness4/5

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

Five sentences total with the main action front-loaded. There is slight redundancy between sentence 1 and 2 (both explain expiration logic), but sentence 2 adds necessary technical specificity about the metadata field. Otherwise efficiently structured with no filler content.

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

Completeness5/5

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

Despite no output schema, the description explicitly documents the return structure ('count of deleted receipts and remaining total'). It also explains the domain-specific expiration logic (expires_at field) and operational context (TTL policies), making it complete for a single-parameter maintenance tool.

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

Parameters4/5

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

Schema coverage is 100% with a complete technical description of the dry_run parameter. The description adds valuable conceptual framing ('preview deletions without committing') that complements the schema's technical definition, helping the agent understand the parameter's purpose beyond its boolean type.

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 specific action (Delete receipts), the target resource (expired receipts), and the condition (expires_at field in metadata earlier than current time). It clearly distinguishes from sibling tools like create_receipt, get_receipt, or verify_receipt by focusing on batch cleanup of expired data.

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

Usage Guidelines4/5

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

The description provides explicit usage context ('Use periodically to manage storage and enforce TTL policies') and explains the dry_run safety mechanism. While it doesn't explicitly name alternatives or exclusions, it clearly frames when and why to invoke this tool (periodic maintenance).

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/webaesbyamin/agent-receipts'

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