Skip to main content
Glama

complete_receipt

Finalize a pending receipt by recording execution results, costs, and output data. Updates status to completed, failed, or timeout and re-signs with Ed25519.

Instructions

Finalize a pending receipt by recording execution results, costs, and output data. Updates the receipt status to completed, failed, or timeout and re-signs with Ed25519. Use after create_receipt when you need to record results separately from creation (two-phase tracking). Cannot complete an already-completed receipt. Returns the updated signed receipt.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
receipt_idYesThe receipt ID to complete — must be a pending receipt (status: "pending")
statusYesFinal status: "completed" (success), "failed" (error occurred), or "timeout" (timed out)
output_hashNoPre-computed SHA-256 hash of the output in format "sha256:hexstring"
output_summaryNoHuman-readable summary of the execution result
modelNoAI model used during execution
tokens_inNoInput tokens consumed
tokens_outNoOutput tokens generated
cost_usdNoTotal cost in USD
latency_msNoTotal execution time in milliseconds
tool_callsNoNames of tools called during execution
confidenceNoConfidence score for output quality, 0.0 to 1.0
callback_verifiedNoWhether an external callback verified the result
errorNoError details if status is "failed" (e.g., {"code": "TIMEOUT", "message": "..."})

Implementation Reference

  • The ReceiptEngine.complete() method that executes the core completion logic: fetches the pending receipt, updates fields (status, output_hash, timestamps, costs, etc.), evaluates constraints if present, re-signs with Ed25519, validates against the ActionReceipt schema, and persists the updated receipt.
    async complete(receiptId: string, params: CompleteParams): Promise<ActionReceipt> {
      const existing = await this.store.get(receiptId)
      if (!existing) {
        throw new Error(`Receipt not found: ${receiptId}`)
      }
    
      if (existing.status !== 'pending') {
        throw new Error(`Receipt ${receiptId} is not pending (status: ${existing.status})`)
      }
    
      const now = new Date().toISOString()
      const updated = {
        ...existing,
        status: params.status,
        completed_at: now,
        output_hash: params.output_hash ?? existing.output_hash,
        output_summary: params.output_summary ?? existing.output_summary,
        model: params.model ?? existing.model,
        tokens_in: params.tokens_in ?? existing.tokens_in,
        tokens_out: params.tokens_out ?? existing.tokens_out,
        cost_usd: params.cost_usd ?? existing.cost_usd,
        latency_ms: params.latency_ms ?? existing.latency_ms,
        tool_calls: params.tool_calls ?? existing.tool_calls,
        confidence: params.confidence ?? existing.confidence,
        callback_verified: params.callback_verified ?? existing.callback_verified,
        error: params.error ?? existing.error,
        metadata: params.metadata ? { ...existing.metadata, ...params.metadata } : existing.metadata,
        constraint_result: existing.constraint_result,
      }
    
      // Evaluate constraints if present on the receipt
      const storedConstraints = existing.constraints as { definitions: ConstraintDefinition[] } | null
      const constraints = storedConstraints?.definitions ?? null
      if (Array.isArray(constraints) && constraints.length > 0) {
        updated.constraint_result = evaluateConstraints(
          updated as unknown as ActionReceipt,
          constraints,
        )
      }
    
      // Re-sign with updated data
      const signable = getSignablePayload(updated)
      const signature = signReceipt(signable, this.keyManager.getPrivateKey())
      updated.signature = signature
    
      const receipt = ActionReceipt.parse(updated)
      await this.store.save(receipt)
    
      return receipt
    }
  • The registerCompleteReceipt function that defines the MCP tool 'complete_receipt', registers its Zod input schema, and its async handler which extracts receipt_id, delegates to engine.complete(), and returns the receipt as JSON.
    export function registerCompleteReceipt(server: McpServer, engine: ReceiptEngine): void {
      server.tool(
        'complete_receipt',
        'Finalize a pending receipt by recording execution results, costs, and output data. Updates the receipt status to completed, failed, or timeout and re-signs with Ed25519. Use after create_receipt when you need to record results separately from creation (two-phase tracking). Cannot complete an already-completed receipt. Returns the updated signed receipt.',
        {
          receipt_id: z.string().describe('The receipt ID to complete — must be a pending receipt (status: "pending")'),
          status: z.enum(['completed', 'failed', 'timeout']).describe('Final status: "completed" (success), "failed" (error occurred), or "timeout" (timed out)'),
          output_hash: z.string().nullable().optional().describe('Pre-computed SHA-256 hash of the output in format "sha256:hexstring"'),
          output_summary: z.string().nullable().optional().describe('Human-readable summary of the execution result'),
          model: z.string().nullable().optional().describe('AI model used during execution'),
          tokens_in: z.number().int().nonnegative().nullable().optional().describe('Input tokens consumed'),
          tokens_out: z.number().int().nonnegative().nullable().optional().describe('Output tokens generated'),
          cost_usd: z.number().nonnegative().nullable().optional().describe('Total cost in USD'),
          latency_ms: z.number().int().nonnegative().nullable().optional().describe('Total execution time in milliseconds'),
          tool_calls: z.array(z.string()).nullable().optional().describe('Names of tools called during execution'),
          confidence: z.number().min(0).max(1).nullable().optional().describe('Confidence score for output quality, 0.0 to 1.0'),
          callback_verified: z.boolean().nullable().optional().describe('Whether an external callback verified the result'),
          error: z.record(z.unknown()).nullable().optional().describe('Error details if status is "failed" (e.g., {"code": "TIMEOUT", "message": "..."})'),
        },
        async (params) => {
          const { receipt_id, ...completeParams } = params
          const receipt = await engine.complete(receipt_id, completeParams)
          return {
            content: [{ type: 'text' as const, text: JSON.stringify(receipt, null, 2) }],
          }
        },
      )
  • The CompleteReceiptInput Zod schema defining the input validation for the complete_receipt tool, including status enum ('completed', 'failed', 'timeout') and optional fields for output, costs, timing, tools, confidence, callback, and error details.
      ConfidenceLevel,
      Observation,
      Relationship,
      Entity,
      MemoryReceiptPayload,
      MemoryQuery,
      MemoryBundle,
    } from './memory'
    
    // Validation utilities
    export { validate, formatZodError, createErrorResponse } from './validation'
    
    // Re-export types explicitly for consumers who import types only
    export type {
      ReceiptStatus as ReceiptStatusType,
      ReceiptType as ReceiptTypeType,
      Environment as EnvironmentType,
      ErrorCode as ErrorCodeType,
    } from './enums'
  • The CompleteReceiptInput TypeScript type inferred from the Zod schema.
      ErrorCode as ErrorCodeType,
    } from './enums'
  • Registration call to registerCompleteReceipt(server, engine) within the registerAllTools function that wires up all MCP tools.
    registerCompleteReceipt(server, engine)
Behavior4/5

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

With no annotations, the description carries the full burden. It discloses behavioral traits: updates status, re-signs with Ed25519, and cannot complete an already-completed receipt. It does not mention potential side effects or immutability, but the disclosed traits are sufficient for the tool's purpose.

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 three sentences long, each serving a distinct purpose: stating the action, providing usage context, and adding constraints/return info. It is front-loaded with the key verb and resource, with no superfluous words.

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

Completeness4/5

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

Given 13 parameters (schema-documented), no output schema, and no annotations, the description covers the core functionality, usage context, constraints, and return value. It could mention the optional parameters for detailed tracking, but the schema covers them, so completeness is adequate.

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 baseline is 3. The description does not add meaning beyond the schema, merely stating the tool records results and outputs. No param-specific enrichment is provided, but the schema already handles parameter semantics well.

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 verb 'Finalize' and resource 'pending receipt', detailing that it records execution results, costs, output data, updates status, and re-signs with Ed25519. It explicitly distinguishes from 'create_receipt' by mentioning two-phase tracking, making it distinct from its sibling tools.

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

Usage Guidelines5/5

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

The description gives explicit usage guidance: 'Use after create_receipt when you need to record results separately from creation (two-phase tracking).' It also includes a constraint: 'Cannot complete an already-completed receipt.' This provides clear when-to-use and when-not-to-use information.

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