Skip to main content
Glama

Delete Trace

delete_trace
Destructive

Removes a single trace by ID along with its spans, preserving evaluation scores for audit. Use to delete erroneous, sensitive, or test traces.

Instructions

Remove a single trace by id. Cascades to spans; eval_results keep the score history with trace_id NULLed.

Sibling tools — log_trace creates traces, get_traces queries them, evaluate_output / evaluate_with_llm_judge / verify_citations score them. delete_rule handles custom-rule deletion (separate concern); list_rules / deploy_rule manage the custom-rule lifecycle. delete_trace is the DESTRUCTIVE single-row remove for traces; it does NOT touch eval_results (preserved for audit + drift analytics), spans cascade automatically.

Behavior. DESTRUCTIVE — SQL DELETE scoped to the caller's tenant_id. Cascades: spans belonging to this trace are deleted (FK ON DELETE CASCADE); eval_results that referenced this trace have their trace_id set to NULL (FK ON DELETE SET NULL) so aggregate dashboards + historical scores remain valid even after the trace is gone. Not idempotent: deleting an already-deleted trace returns deleted: false. Does not emit an audit log entry in v0.4 — traces are user-scope data, not policy changes. Rate-limited to 20 req/min on HTTP MCP.

Output shape. Returns JSON: { "deleted": boolean, "trace_id": string }. deleted=true if a row was removed; deleted=false if no trace with that id existed (or it belonged to a different tenant — cross-tenant deletes silently fail).

Use when a trace was captured in error, contains sensitive data that must be removed for compliance (e.g., a customer exercises GDPR right-to-erasure), or when cleaning up test data. Combine with get_traces to find candidates: query with filters → review → delete_trace(id) per target. For bulk time-window deletion, use deleteTracesOlderThan via the CLI / retention config — delete_trace is the single-row surgical path.

Don't use to clean up OLD data in bulk (use retention config with --retention-days). Don't use to PAUSE a trace — traces are immutable once stored; there's nothing to pause. Don't use to delete eval_results — eval_results survive their trace's deletion intentionally (for audit + drift analysis); they're pruned only by retention.

Parameters. trace_id is the only parameter; must match 32-char lowercase hex (Zod regex). The trace_id you pass is exactly what log_trace returned in its response, or what get_traces returned per row. Format mismatch fails Zod with 400 BEFORE the storage layer is touched. Cross-tenant trace_ids return deleted: false silently — they're invisible to the caller's tenant (prevents enumeration attacks; matches delete_rule's tenant-isolation contract).

Error modes. Throws 400 on malformed trace_id (wrong format: not 32-char lowercase hex). Returns {deleted: false} when the id doesn't exist in the caller's tenant (not an error — the trace may simply have been deleted already). Returns 429 on HTTP rate limit. Storage failures propagate as 500.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
trace_idYesTrace id to delete (32-hex lowercase; obtained from log_trace response or get_traces)

Implementation Reference

  • The handler function (inline in registerTool) that calls storage.deleteTrace(LOCAL_TENANT, args.trace_id) and returns { deleted, trace_id }. This is the core execution logic of the delete_trace tool.
    async (args) => {
      const deleted = await storage.deleteTrace(LOCAL_TENANT, args.trace_id);
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify({ deleted, trace_id: args.trace_id }),
          },
        ],
      };
    },
  • Input schema for delete_trace: trace_id is a Zod string matching 32-hex lowercase regex, described as obtained from log_trace or get_traces.
    const inputSchema = {
      trace_id: z
        .string()
        .regex(/^[a-f0-9]{32}$/)
        .describe('Trace id to delete (32-hex lowercase; obtained from log_trace response or get_traces)'),
    };
  • The registerDeleteTraceTool function that registers the 'delete_trace' tool on the MCP server with title, description, inputSchema, annotations (destructiveHint: true, readOnlyHint: false), and the handler.
    export function registerDeleteTraceTool(
      server: McpServer,
      storage: IStorageAdapter,
    ): void {
      server.registerTool(
        'delete_trace',
        {
          title: 'Delete Trace',
          description: [
            'Remove a single trace by id. Cascades to spans; eval_results keep the score history with trace_id NULLed.',
            '',
            'Sibling tools — log_trace creates traces, get_traces queries them, evaluate_output / evaluate_with_llm_judge / verify_citations score them. delete_rule handles custom-rule deletion (separate concern); list_rules / deploy_rule manage the custom-rule lifecycle. delete_trace is the DESTRUCTIVE single-row remove for traces; it does NOT touch eval_results (preserved for audit + drift analytics), spans cascade automatically.',
            '',
            'Behavior. DESTRUCTIVE — SQL DELETE scoped to the caller\'s tenant_id. Cascades: spans belonging to this trace are deleted (FK ON DELETE CASCADE); eval_results that referenced this trace have their trace_id set to NULL (FK ON DELETE SET NULL) so aggregate dashboards + historical scores remain valid even after the trace is gone. Not idempotent: deleting an already-deleted trace returns `deleted: false`. Does not emit an audit log entry in v0.4 — traces are user-scope data, not policy changes. Rate-limited to 20 req/min on HTTP MCP.',
            '',
            'Output shape. Returns JSON: `{ "deleted": boolean, "trace_id": string }`. `deleted=true` if a row was removed; `deleted=false` if no trace with that id existed (or it belonged to a different tenant — cross-tenant deletes silently fail).',
            '',
            "Use when a trace was captured in error, contains sensitive data that must be removed for compliance (e.g., a customer exercises GDPR right-to-erasure), or when cleaning up test data. Combine with get_traces to find candidates: query with filters → review → delete_trace(id) per target. For bulk time-window deletion, use `deleteTracesOlderThan` via the CLI / retention config — delete_trace is the single-row surgical path.",
            '',
            "Don't use to clean up OLD data in bulk (use retention config with --retention-days). Don't use to PAUSE a trace — traces are immutable once stored; there's nothing to pause. Don't use to delete eval_results — eval_results survive their trace's deletion intentionally (for audit + drift analysis); they're pruned only by retention.",
            '',
            'Parameters. trace_id is the only parameter; must match 32-char lowercase hex (Zod regex). The trace_id you pass is exactly what log_trace returned in its response, or what get_traces returned per row. Format mismatch fails Zod with 400 BEFORE the storage layer is touched. Cross-tenant trace_ids return `deleted: false` silently — they\'re invisible to the caller\'s tenant (prevents enumeration attacks; matches delete_rule\'s tenant-isolation contract).',
            '',
            "Error modes. Throws 400 on malformed trace_id (wrong format: not 32-char lowercase hex). Returns `{deleted: false}` when the id doesn't exist in the caller's tenant (not an error — the trace may simply have been deleted already). Returns 429 on HTTP rate limit. Storage failures propagate as 500.",
          ].join('\n'),
          inputSchema,
          annotations: {
            readOnlyHint: false,
            destructiveHint: true,
            idempotentHint: false,
            openWorldHint: false,
          },
        },
        async (args) => {
          const deleted = await storage.deleteTrace(LOCAL_TENANT, args.trace_id);
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify({ deleted, trace_id: args.trace_id }),
              },
            ],
          };
        },
      );
    }
  • The SQLite storage implementation of deleteTrace(). Executes 'DELETE FROM traces WHERE tenant_id = ? AND trace_id = ?' and returns true if a row was deleted.
    async deleteTrace(tenantId: TenantId, traceId: string): Promise<boolean> {
      assertTenant(tenantId);
      // Tenant-scoped: a trace id owned by a different tenant is
      // untouchable from this call. Cross-tenant deletions are not just
      // denied — they're invisible (no indication the id even exists).
      const result = this.db
        .prepare('DELETE FROM traces WHERE tenant_id = ? AND trace_id = ?')
        .run(tenantId, traceId);
      return result.changes > 0;
    }
  • Interface definition for deleteTrace in IStorageAdapter: deleteTrace(tenantId: TenantId, traceId: string): Promise<boolean>.
    deleteTrace(tenantId: TenantId, traceId: string): Promise<boolean>;
Behavior5/5

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

Adds details beyond annotations: SQL DELETE scoped to tenant, cascades to spans (FK CASCADE), eval_results NULLed (SET NULL), no idempotency, no audit log, rate limits. No contradictions.

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?

Well-structured with sections and front-loaded purpose, but slightly verbose. Every sentence adds value, making it appropriate for complexity.

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?

Given single parameter and no output schema, description covers behavior, error modes, use cases, and limitations. Complements annotations fully.

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 already covers trace_id with 100% coverage, but description adds context on format, provenance, and error behavior. Extra value justifies above baseline.

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 'Remove a single trace by id' and differentiates from siblings like delete_rule and bulk deletion. It specifies the resource and verb precisely.

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?

Explicitly states when to use (error, compliance, cleanup) and when not to use (bulk, pause, delete eval_results). Provides alternatives like retention config and get_traces.

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/iris-eval/mcp-server'

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