Skip to main content
Glama
haasonsaas
by haasonsaas

retry_operation

Execute operations with exponential backoff to handle transient failures like API calls or network requests. Configure max retries, initial delay, and operation details.

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
initial_delay_msNo
max_retriesNo
operation_dataYesData specific to the operation (e.g., URL for HTTP, query for DB)
operation_idYesUnique identifier for this operation (used for tracking retries)
operation_typeYesType of operation being retried
should_executeNoIf false, just returns retry metadata without executing

Implementation Reference

  • The core handler function for the 'retry_operation' tool, managing retry metadata, exponential backoff delays, execution conditions, and returning appropriate status responses.
    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" }) }] }; }
  • Tool registration including name, description, and input schema definition for 'retry_operation', used in the listTools response.
    { 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"] } },

Other Tools

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

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