Skip to main content
Glama
haasonsaas

MCP Utility Tools

by haasonsaas

batch_operation

Process multiple operations simultaneously with configurable concurrency, timeout settings, and error handling options to manage workflows efficiently.

Instructions

Process multiple operations with configurable concurrency and error handling

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationsYesArray of operations to process
concurrencyNoMaximum number of concurrent operations
timeout_msNoTimeout per operation in milliseconds
continue_on_errorNoContinue processing even if some operations fail
use_cacheNoCache successful results
cache_ttl_secondsNoTTL for cached results

Implementation Reference

  • Main handler implementation for the 'batch_operation' tool. Processes an array of operations with configurable concurrency, per-operation timeouts, optional caching of results, and error handling (continue_on_error). Simulates operation execution and returns sorted results with success/failure status.
    case "batch_operation": {
      const {
        operations,
        concurrency = 5,
        timeout_ms = 30000,
        continue_on_error = true,
        use_cache = false,
        cache_ttl_seconds = 300
      } = args as any;
    
      const results: any[] = [];
      const queue = [...operations];
      const inProgress = new Map<string, Promise<any>>();
      
      // Process operations with controlled concurrency
      while (queue.length > 0 || inProgress.size > 0) {
        // Start new operations up to concurrency limit
        while (queue.length > 0 && inProgress.size < concurrency) {
          const op = queue.shift()!;
          
          // Check cache first if enabled
          if (use_cache) {
            const cacheKey = `batch:${op.type}:${JSON.stringify(op.data)}`;
            const cached = cache.get(cacheKey);
            if (cached && cached.expiresAt > Date.now()) {
              results.push({
                id: op.id,
                success: true,
                cached: true,
                result: cached.value
              });
              continue;
            }
          }
          
          // Create operation promise
          const promise = Promise.race([
            // Simulate operation execution
            (async () => {
              // In real implementation, this would execute the actual operation
              await setTimeout(Math.random() * 1000); // Simulate work
              
              const result = {
                id: op.id,
                type: op.type,
                data: op.data,
                processed_at: new Date().toISOString()
              };
              
              // Cache result if enabled
              if (use_cache) {
                const cacheKey = `batch:${op.type}:${JSON.stringify(op.data)}`;
                cache.set(cacheKey, {
                  value: result,
                  expiresAt: Date.now() + (cache_ttl_seconds * 1000)
                });
              }
              
              return result;
            })(),
            // Timeout promise
            setTimeout(timeout_ms).then(() => {
              throw new Error(`Operation ${op.id} timed out`);
            })
          ]);
          
          inProgress.set(op.id, promise);
          
          // Handle completion
          promise
            .then(result => {
              results.push({
                id: op.id,
                success: true,
                result
              });
            })
            .catch(error => {
              results.push({
                id: op.id,
                success: false,
                error: error.message
              });
              
              if (!continue_on_error) {
                // Cancel remaining operations
                queue.length = 0;
              }
            })
            .finally(() => {
              inProgress.delete(op.id);
            });
        }
        
        // Wait for at least one operation to complete
        if (inProgress.size > 0) {
          await Promise.race(inProgress.values());
        }
      }
    
      // Sort results to match input order
      const sortedResults = operations.map((op: any) => 
        results.find(r => r.id === op.id)
      );
    
      return {
        content: [{
          type: "text",
          text: JSON.stringify({
            success: true,
            total_operations: operations.length,
            successful: results.filter(r => r.success).length,
            failed: results.filter(r => !r.success).length,
            results: sortedResults
          }, null, 2)
        }]
      };
    }
  • Tool definition including name, description, and detailed inputSchema for 'batch_operation'. Defines structure for operations array, concurrency, timeout, caching options, etc., with validation constraints.
    {
      name: "batch_operation",
      description: "Process multiple operations with configurable concurrency and error handling",
      inputSchema: {
        type: "object",
        properties: {
          operations: {
            type: "array",
            description: "Array of operations to process",
            items: {
              type: "object",
              properties: {
                id: {
                  type: "string",
                  description: "Unique identifier for this operation"
                },
                type: {
                  type: "string",
                  description: "Type of operation"
                },
                data: {
                  type: "object",
                  description: "Operation-specific data"
                }
              },
              required: ["id", "type", "data"]
            },
            minItems: 1,
            maxItems: 100
          },
          concurrency: {
            type: "number",
            description: "Maximum number of concurrent operations",
            default: 5,
            minimum: 1,
            maximum: 20
          },
          timeout_ms: {
            type: "number",
            description: "Timeout per operation in milliseconds",
            default: 30000,
            minimum: 1000,
            maximum: 300000
          },
          continue_on_error: {
            type: "boolean",
            description: "Continue processing even if some operations fail",
            default: true
          },
          use_cache: {
            type: "boolean",
            description: "Cache successful results",
            default: false
          },
          cache_ttl_seconds: {
            type: "number",
            description: "TTL for cached results",
            default: 300
          }
        },
        required: ["operations"]
      }
    },
  • Registration of the ListToolsRequestSchema handler, which returns the tools array containing the 'batch_operation' tool definition (schema).
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return { tools };
    });
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions 'configurable concurrency and error handling,' it doesn't specify what happens on errors (are they logged, returned, ignored?), whether operations are atomic, what permissions are required, or rate limits. The description is insufficient for a mutation tool with 6 parameters.

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 a single, efficient sentence that states the core purpose upfront. Every word earns its place with no redundancy or unnecessary elaboration. It's appropriately sized for a batch processing tool.

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

Completeness2/5

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

For a batch operation tool with 6 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what 'operations' are, what types are supported, what the output looks like, error behavior details, or performance characteristics. The agent would struggle to use this effectively without trial and error.

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 schema already documents all 6 parameters thoroughly. The description adds minimal value by mentioning 'concurrency and error handling' which maps to some parameters, but doesn't provide additional context beyond what's in the schema. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'processes multiple operations' which is a clear verb+resource combination, but it's vague about what types of operations it processes or what 'process' actually means. It doesn't distinguish this from sibling tools like 'retry_operation' or 'rate_limit_check' which might handle similar batch scenarios.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'retry_operation' and 'cache_*' tools available, there's no indication whether this tool should be used for retry scenarios, caching operations, or general batch processing. No prerequisites or exclusions are mentioned.

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

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