Skip to main content
Glama
haasonsaas
by haasonsaas

retry_operation

Automatically retry failed operations like API calls or database queries with exponential backoff to handle temporary failures.

Instructions

Retry an operation with exponential backoff. Use this for operations that might fail temporarily (API calls, network requests, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operation_idYesUnique identifier for this operation (used for tracking retries)
operation_typeYesType of operation being retried
operation_dataYesData specific to the operation (e.g., URL for HTTP, query for DB)
max_retriesNo
initial_delay_msNo
should_executeNoIf false, just returns retry metadata without executing

Implementation Reference

  • Main handler for 'retry_operation' tool: manages retry state, enforces backoff delays, checks limits, and provides execution instructions.
    case "retry_operation": { const { operation_id, operation_type, operation_data, max_retries = 3, initial_delay_ms = 1000, should_execute = true } = args as any; // Get or create retry metadata let metadata = retryMetadata.get(operation_id) || { attempts: 0, lastAttempt: 0, success: false }; // Check if we should retry if (metadata.success) { return { content: [{ type: "text", text: JSON.stringify({ operation_id, status: "already_succeeded", attempts: metadata.attempts, message: "Operation already completed successfully" }) }] }; } if (metadata.attempts >= max_retries) { return { content: [{ type: "text", text: JSON.stringify({ operation_id, status: "max_retries_exceeded", attempts: metadata.attempts, message: "Maximum retry attempts reached" }) }] }; } // Calculate delay with exponential backoff const timeSinceLastAttempt = Date.now() - metadata.lastAttempt; const requiredDelay = initial_delay_ms * Math.pow(2, metadata.attempts); if (metadata.attempts > 0 && timeSinceLastAttempt < requiredDelay) { const waitTime = requiredDelay - timeSinceLastAttempt; return { content: [{ type: "text", text: JSON.stringify({ operation_id, status: "retry_delayed", attempts: metadata.attempts, wait_ms: waitTime, message: `Retry delayed. Wait ${waitTime}ms before next attempt` }) }] }; } if (!should_execute) { return { content: [{ type: "text", text: JSON.stringify({ operation_id, status: "ready_to_execute", attempts: metadata.attempts, next_delay_ms: requiredDelay, operation_type, operation_data }) }] }; } // Update metadata for this attempt metadata.attempts += 1; metadata.lastAttempt = Date.now(); retryMetadata.set(operation_id, metadata); // Here we return instructions for what should be retried // In practice, the calling system would execute the actual operation return { content: [{ type: "text", text: JSON.stringify({ operation_id, status: "execute_attempt", attempt_number: metadata.attempts, operation_type, operation_data, instructions: "Execute the operation and call retry_operation again with the result" }) }] }; }
  • Input schema defining parameters for retry_operation: operation_id, type, data, retry limits, delays.
    inputSchema: { type: "object", properties: { operation_id: { type: "string", description: "Unique identifier for this operation (used for tracking retries)" }, operation_type: { type: "string", enum: ["http_request", "database_query", "file_operation", "custom"], description: "Type of operation being retried" }, operation_data: { type: "object", description: "Data specific to the operation (e.g., URL for HTTP, query for DB)" }, max_retries: { type: "number", default: 3, minimum: 1, maximum: 10 }, initial_delay_ms: { type: "number", default: 1000, minimum: 100, maximum: 60000 }, should_execute: { type: "boolean", description: "If false, just returns retry metadata without executing", default: true } }, required: ["operation_id", "operation_type", "operation_data"]
  • src/index-v2.ts:56-95 (registration)
    Registration of the 'retry_operation' tool in the tools array returned by ListToolsRequestSchema handler.
    { name: "retry_operation", description: "Retry an operation with exponential backoff. Use this for operations that might fail temporarily (API calls, network requests, etc.)", inputSchema: { type: "object", properties: { operation_id: { type: "string", description: "Unique identifier for this operation (used for tracking retries)" }, operation_type: { type: "string", enum: ["http_request", "database_query", "file_operation", "custom"], description: "Type of operation being retried" }, operation_data: { type: "object", description: "Data specific to the operation (e.g., URL for HTTP, query for DB)" }, max_retries: { type: "number", default: 3, minimum: 1, maximum: 10 }, initial_delay_ms: { type: "number", default: 1000, minimum: 100, maximum: 60000 }, should_execute: { type: "boolean", description: "If false, just returns retry metadata without executing", default: true } }, required: ["operation_id", "operation_type", "operation_data"] } },
  • Global storage Map for per-operation retry metadata used by the handler.
    // Store for tracking retry metadata const retryMetadata = new Map<string, { attempts: number; lastAttempt: number; success: boolean; }>();
  • Periodic cleanup of stale retry metadata entries in the setInterval function.
    // Clean old retry metadata (older than 1 hour) for (const [key, meta] of retryMetadata.entries()) { if (meta.lastAttempt < now - 3600000) { retryMetadata.delete(key); }

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/haasonsaas/mcp-utility-tools'

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